From c99366fa71f1aa7f65b5d7c9a2d3c33fff1e064d Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 21 May 2019 17:27:08 +0200 Subject: [PATCH] fix(client): Store backend form value on submit --- client/src/templates/Challenges/backend/Show.js | 15 ++++++++++++++- client/src/templates/Challenges/redux/index.js | 13 +++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/client/src/templates/Challenges/backend/Show.js b/client/src/templates/Challenges/backend/Show.js index 4b6c4aad0c..144f306f38 100644 --- a/client/src/templates/Challenges/backend/Show.js +++ b/client/src/templates/Challenges/backend/Show.js @@ -4,6 +4,7 @@ import { Grid, Col, Row } from '@freecodecamp/react-bootstrap'; import { createSelector } from 'reselect'; import { reduxForm } from 'redux-form'; import { graphql } from 'gatsby'; +import normalizeUrl from 'normalize-url'; import { executeChallenge, @@ -11,6 +12,7 @@ import { challengeTestsSelector, consoleOutputSelector, initTests, + updateBackendFormValues, updateChallengeMeta, updateProjectFormValues, backendNS @@ -55,6 +57,7 @@ const propTypes = { output: PropTypes.string, tests: PropTypes.array, title: PropTypes.string, + updateBackendFormValues: PropTypes.func.isRequired, updateChallengeMeta: PropTypes.func.isRequired, updateProjectFormValues: PropTypes.func.isRequired, ...reduxFormPropTypes @@ -79,6 +82,7 @@ const mapDispatchToActions = { challengeMounted, executeChallenge, initTests, + updateBackendFormValues, updateChallengeMeta, updateProjectFormValues }; @@ -96,6 +100,7 @@ export class BackEnd extends Component { super(props); this.state = {}; this.updateDimensions = this.updateDimensions.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); } componentDidMount() { @@ -151,6 +156,13 @@ export class BackEnd extends Component { } } + handleSubmit(values) { + const { updateBackendFormValues, executeChallenge } = this.props; + values.solution = normalizeUrl(values.solution); + updateBackendFormValues(values); + executeChallenge(); + } + render() { const { data: { @@ -174,6 +186,7 @@ export class BackEnd extends Component { ? 'Submit and go to my next challenge' : "I've completed this challenge"; const blockNameTitle = `${blockName} - ${title}`; + return ( @@ -191,7 +204,7 @@ export class BackEnd extends Component { formFields={formFields} id={backendNS} options={options} - submit={executeChallenge} + submit={this.handleSubmit} /> ) : ( state[ns].modal.reset; export const isBuildEnabledSelector = state => state[ns].isBuildEnabled; export const successMessageSelector = state => state[ns].successMessage; -export const backendFormValuesSelector = state => state.form[backendNS] || {}; +export const backendFormValuesSelector = state => + state[ns].backendFormValues || {}; export const projectFormValuesSelector = state => state[ns].projectFormValues || {}; @@ -187,7 +192,7 @@ export const challengeDataSelector = state => { files: challengeFilesSelector(state) }; } else if (challengeType === challengeTypes.backend) { - const { solution: { value: url } = {} } = backendFormValuesSelector(state); + const { solution: url = {} } = backendFormValuesSelector(state); challengeData = { ...challengeData, url @@ -306,6 +311,10 @@ export const reducer = handleActions( })), consoleOut: '' }), + [types.updateBackendFormValues]: (state, { payload }) => ({ + ...state, + backendFormValues: payload + }), [types.updateProjectFormValues]: (state, { payload }) => ({ ...state, projectFormValues: payload