Files
freeCodeCamp/client/src/templates/Challenges/projects/SolutionForm.js
GM Fuster 3b056aa7b4 chore(replit): use correct brand name across codebase (#41941)
* replace repl.it with replit.com in the English version

Replace repl.it to replit.com in the English version.  Chinese and Spanish versions have the same issue.

* Updated the repl.it to replit.com or Replit

I changed the text from replit.com to Replit and added the changes to the files outside the curriculum folder.

* Forgot removing one .com.

There was on Replit.com that I missed when I reviewed the files.

* Resolve conflicts

I got an unable to auto merge so resolving conflicts and trying again.

* try committing conflicts again

* Trying the conflicts again

* chore: fix typo in personal library

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

Co-authored-by: gemmaf98 <44875585+gemmaf98@users.noreply.github.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>
2021-04-29 11:13:38 +01:00

130 lines
3.5 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { Form } from '../../../components/formHelpers';
import {
backend,
backEndProject,
frontEndProject,
pythonProject
} from '../../../../utils/challengeTypes';
const propTypes = {
challengeType: PropTypes.number,
description: PropTypes.string,
isSubmitting: PropTypes.bool,
onSubmit: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
updateSolutionForm: PropTypes.func.isRequired
};
export class SolutionForm extends Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount() {
this.props.updateSolutionForm({});
}
handleSubmit(validatedValues) {
// Do not execute challenge, if errors
if (validatedValues.errors.length === 0) {
// updates values on store
this.props.updateSolutionForm(validatedValues.values);
if (validatedValues.invalidValues.length === 0) {
this.props.onSubmit({ isShouldCompletionModalOpen: true });
} else {
this.props.onSubmit({ isShouldCompletionModalOpen: false });
}
}
}
render() {
const { isSubmitting, challengeType, description, t } = this.props;
// back end challenges and front end projects use a single form field
const solutionField = [
{ name: 'solution', label: t('learn.solution-link') }
];
const backEndProjectFields = [
{ name: 'solution', label: t('learn.solution-link') },
{ name: 'githubLink', label: t('learn.github-link') }
];
const options = {
types: {
solution: 'url',
githubLink: 'url'
},
required: ['solution'],
isEditorLinkAllowed: false,
isLocalLinkAllowed: false
};
const buttonCopy = isSubmitting
? t('learn.submit-and-go')
: t('learn.i-completed');
let formFields = solutionField;
let solutionLink = 'ex: ';
let solutionFormID = 'front-end-form';
switch (challengeType) {
case frontEndProject:
formFields = solutionField;
solutionLink =
solutionLink + 'https://codepen.io/camperbot/full/oNvPqqo';
break;
case backend:
formFields = solutionField;
options.isLocalLinkAllowed = true;
solutionLink = solutionLink + 'https://project-name.camperbot.repl.co/';
break;
case backEndProject:
formFields = backEndProjectFields;
solutionLink = solutionLink + 'https://project-name.camperbot.repl.co/';
solutionFormID = 'back-end-form';
break;
case pythonProject:
formFields = solutionField;
options.isEditorLinkAllowed = true;
solutionLink =
solutionLink +
(description.includes('Colaboratory')
? 'https://colab.research.google.com/drive/1i5EmInTWi1RFvFr2_aRXky96YxY6sbWy'
: 'https://replit.com/@camperbot/hello');
break;
default:
formFields = solutionField;
solutionLink =
solutionLink + 'https://codepen.io/camperbot/full/oNvPqqo';
}
return (
<Form
buttonText={`${buttonCopy}`}
formFields={formFields}
id={solutionFormID}
options={{
...options,
placeholders: {
solution: solutionLink,
githubLink: 'ex: https://github.com/camperbot/hello'
}
}}
submit={this.handleSubmit}
/>
);
}
}
SolutionForm.propTypes = propTypes;
export default withTranslation()(SolutionForm);