2018-04-13 15:33:03 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import {
|
2018-05-08 00:29:45 +01:00
|
|
|
Form
|
|
|
|
// isValidURL,
|
|
|
|
// makeRequired,
|
|
|
|
// createFormValidator
|
2018-04-13 15:33:03 +01:00
|
|
|
} from '../../../components/formHelpers';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
isFrontEnd: PropTypes.bool,
|
|
|
|
isSubmitting: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
const frontEndFields = ['solution'];
|
|
|
|
const backEndFields = ['solution', 'githubLink'];
|
|
|
|
|
2018-05-08 00:29:45 +01:00
|
|
|
// const fieldValidators = {
|
|
|
|
// solution: makeRequired(isValidURL)
|
|
|
|
// };
|
2018-04-13 15:33:03 +01:00
|
|
|
|
2018-05-08 00:29:45 +01:00
|
|
|
// const backEndFieldValidators = {
|
|
|
|
// ...fieldValidators,
|
|
|
|
// githubLink: makeRequired(isValidURL)
|
|
|
|
// };
|
2018-04-13 15:33:03 +01:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
types: {
|
|
|
|
solution: 'url',
|
|
|
|
githubLink: 'url'
|
|
|
|
},
|
|
|
|
required: ['solution', 'githubLink']
|
|
|
|
};
|
|
|
|
|
|
|
|
export class ProjectForm extends PureComponent {
|
|
|
|
handleSubmit = values => {
|
|
|
|
console.log(values);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { isSubmitting, isFrontEnd } = this.props;
|
|
|
|
const buttonCopy = isSubmitting
|
|
|
|
? 'Submit and go to my next challenge'
|
|
|
|
: "I've completed this challenge";
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
buttonText={`${buttonCopy} (Ctrl + Enter)`}
|
|
|
|
formFields={isFrontEnd ? frontEndFields : backEndFields}
|
|
|
|
id={isFrontEnd ? 'front-end-form' : 'back-end-form'}
|
|
|
|
options={options}
|
|
|
|
submit={this.handleSubmit}
|
2018-05-08 00:29:45 +01:00
|
|
|
// validate={createFormValidator(
|
|
|
|
// isFrontEnd ? fieldValidators : backEndFieldValidators
|
|
|
|
// )}
|
2018-04-13 15:33:03 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectForm.propTypes = propTypes;
|
|
|
|
|
2018-04-16 12:04:25 +01:00
|
|
|
export default ProjectForm;
|