2018-11-07 18:16:50 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-04-13 15:33:03 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2019-06-11 18:46:36 +03:00
|
|
|
import { Form } from '../../../components/formHelpers';
|
2020-05-22 03:24:17 +05:30
|
|
|
import {
|
2020-09-04 14:44:26 +01:00
|
|
|
backend,
|
2020-05-22 03:24:17 +05:30
|
|
|
backEndProject,
|
|
|
|
frontEndProject,
|
|
|
|
pythonProject
|
|
|
|
} from '../../../../utils/challengeTypes';
|
2018-04-13 15:33:03 +01:00
|
|
|
|
|
|
|
const propTypes = {
|
2020-05-22 03:24:17 +05:30
|
|
|
challengeType: PropTypes.number,
|
|
|
|
description: PropTypes.string,
|
2018-05-09 13:27:42 +01:00
|
|
|
isSubmitting: PropTypes.bool,
|
2019-06-11 18:46:36 +03:00
|
|
|
onSubmit: PropTypes.func.isRequired,
|
2020-05-07 17:19:06 +01:00
|
|
|
updateSolutionForm: PropTypes.func.isRequired
|
2018-04-13 15:33:03 +01:00
|
|
|
};
|
|
|
|
|
2020-09-04 14:44:26 +01:00
|
|
|
// back end challenges and front end projects use a single form field
|
2020-09-09 17:12:48 +01:00
|
|
|
const solutionField = [{ name: 'solution', label: 'Solution Link' }];
|
|
|
|
const backEndProjectFields = [
|
|
|
|
{ name: 'solution', label: 'Solution Link' },
|
|
|
|
{ name: 'githubLink', label: 'GitHub Link' }
|
|
|
|
];
|
2018-04-13 15:33:03 +01:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
types: {
|
2020-09-08 19:46:24 +02:00
|
|
|
solution: 'url',
|
2018-04-13 15:33:03 +01:00
|
|
|
githubLink: 'url'
|
|
|
|
},
|
2020-09-08 19:46:24 +02:00
|
|
|
required: ['solution']
|
2018-04-13 15:33:03 +01:00
|
|
|
};
|
|
|
|
|
2020-05-07 17:19:06 +01:00
|
|
|
export class SolutionForm extends Component {
|
2018-06-20 11:59:20 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
}
|
2018-05-24 19:45:38 +01:00
|
|
|
componentDidMount() {
|
2020-05-07 17:19:06 +01:00
|
|
|
this.props.updateSolutionForm({});
|
2018-06-20 11:59:20 +01:00
|
|
|
}
|
|
|
|
handleSubmit(values) {
|
2020-05-07 17:19:06 +01:00
|
|
|
this.props.updateSolutionForm(values);
|
2019-06-11 18:46:36 +03:00
|
|
|
this.props.onSubmit();
|
2018-06-20 11:59:20 +01:00
|
|
|
}
|
2018-04-13 15:33:03 +01:00
|
|
|
render() {
|
2020-05-22 03:24:17 +05:30
|
|
|
const { isSubmitting, challengeType, description } = this.props;
|
2018-04-13 15:33:03 +01:00
|
|
|
const buttonCopy = isSubmitting
|
|
|
|
? 'Submit and go to my next challenge'
|
|
|
|
: "I've completed this challenge";
|
2020-05-22 03:24:17 +05:30
|
|
|
|
2020-09-04 14:44:26 +01:00
|
|
|
let formFields = solutionField;
|
|
|
|
let solutionLink = 'ex: ';
|
2020-05-22 03:24:17 +05:30
|
|
|
let solutionFormID = 'front-end-form';
|
|
|
|
|
|
|
|
switch (challengeType) {
|
|
|
|
case frontEndProject:
|
2020-09-04 14:44:26 +01:00
|
|
|
formFields = solutionField;
|
2020-05-22 03:24:17 +05:30
|
|
|
solutionLink =
|
|
|
|
solutionLink + 'https://codepen.io/camperbot/full/oNvPqqo';
|
|
|
|
break;
|
|
|
|
|
2020-09-04 14:44:26 +01:00
|
|
|
case backend:
|
|
|
|
formFields = solutionField;
|
|
|
|
solutionLink = solutionLink + 'https://project-name.camperbot.repl.co/';
|
|
|
|
break;
|
|
|
|
|
2020-05-22 03:24:17 +05:30
|
|
|
case backEndProject:
|
2020-09-04 14:44:26 +01:00
|
|
|
formFields = backEndProjectFields;
|
2020-08-18 06:38:16 +09:00
|
|
|
solutionLink = solutionLink + 'https://project-name.camperbot.repl.co/';
|
2020-05-22 03:24:17 +05:30
|
|
|
solutionFormID = 'back-end-form';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case pythonProject:
|
2020-09-04 14:44:26 +01:00
|
|
|
formFields = solutionField;
|
2020-05-22 03:24:17 +05:30
|
|
|
solutionLink =
|
|
|
|
solutionLink +
|
|
|
|
(description.includes('Colaboratory')
|
|
|
|
? 'https://colab.research.google.com/drive/1i5EmInTWi1RFvFr2_aRXky96YxY6sbWy'
|
|
|
|
: 'https://repl.it/@camperbot/hello');
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-09-04 14:44:26 +01:00
|
|
|
formFields = solutionField;
|
2020-05-22 03:24:17 +05:30
|
|
|
solutionLink =
|
|
|
|
solutionLink + 'https://codepen.io/camperbot/full/oNvPqqo';
|
|
|
|
}
|
|
|
|
|
2018-04-13 15:33:03 +01:00
|
|
|
return (
|
|
|
|
<Form
|
2019-06-11 18:46:36 +03:00
|
|
|
buttonText={`${buttonCopy}`}
|
2020-09-04 14:44:26 +01:00
|
|
|
formFields={formFields}
|
2020-05-22 03:24:17 +05:30
|
|
|
id={solutionFormID}
|
2019-09-19 12:44:58 +05:30
|
|
|
options={{
|
|
|
|
...options,
|
|
|
|
placeholders: {
|
2020-09-08 19:46:24 +02:00
|
|
|
solution: solutionLink,
|
2020-05-07 17:19:06 +01:00
|
|
|
githubLink: 'ex: https://github.com/camperbot/hello'
|
2019-09-19 12:44:58 +05:30
|
|
|
}
|
|
|
|
}}
|
2018-04-13 15:33:03 +01:00
|
|
|
submit={this.handleSubmit}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 17:19:06 +01:00
|
|
|
SolutionForm.propTypes = propTypes;
|
2018-04-13 15:33:03 +01:00
|
|
|
|
2020-05-07 17:19:06 +01:00
|
|
|
export default SolutionForm;
|