diff --git a/client/src/components/formHelpers/Form.js b/client/src/components/formHelpers/Form.js
index 8a33fd9181..76bf71d5ab 100644
--- a/client/src/components/formHelpers/Form.js
+++ b/client/src/components/formHelpers/Form.js
@@ -51,7 +51,12 @@ export function DynamicForm({
onSubmit={handleSubmit(submit)}
style={{ width: '100%' }}
>
-
+
{hideButton ? null : (
- bindActionCreators({ updateLegacyCertificate }, dispatch);
+ bindActionCreators({ updateLegacyCert }, dispatch);
const propTypes = {
completedChallenges: PropTypes.arrayOf(
@@ -51,7 +52,7 @@ const propTypes = {
isInfosecQaCert: PropTypes.bool,
isJsAlgoDataStructCert: PropTypes.bool,
isRespWebDesignCert: PropTypes.bool,
- updateLegacyCertificate: PropTypes.func.isRequired,
+ updateLegacyCert: PropTypes.func.isRequired,
username: PropTypes.string,
verifyCert: PropTypes.func.isRequired
};
@@ -107,6 +108,13 @@ const isCertMapSelector = createSelector(
})
);
+const honestyInfoMessage = {
+ type: 'info',
+ message:
+ 'To claim a certification, you must first accept our academic ' +
+ 'honesty policy'
+};
+
const initialState = {
solutionViewer: {
projectTitle: '',
@@ -249,12 +257,7 @@ class CertificationSettings extends Component {
}
return isHonest
? verifyCert(superBlock)
- : createFlashMessage({
- type: 'info',
- message:
- 'To claim a certification, you must first accept our academic ' +
- 'honesty policy'
- });
+ : createFlashMessage(honestyInfoMessage);
};
return projectMap[certName]
.map(({ link, title, id }) => (
@@ -284,18 +287,83 @@ class CertificationSettings extends Component {
};
// legacy projects rendering
+ handleSubmit(formChalObj) {
+ const {
+ isHonest,
+ createFlashMessage,
+ verifyCert,
+ updateLegacyCert
+ } = this.props;
+ let legacyTitle;
+ let superBlock;
+ let certs = Object.keys(legacyProjectMap);
+ let loopBreak = false;
+ for (let certTitle of certs) {
+ for (let chalTitle of legacyProjectMap[certTitle]) {
+ if (chalTitle.title === Object.keys(formChalObj)[0]) {
+ superBlock = chalTitle.superBlock;
+ loopBreak = true;
+ legacyTitle = certTitle;
+ break;
+ }
+ }
+ if (loopBreak) {
+ break;
+ }
+ }
- handleSubmit(values) {
- const { updateLegacyCertificate } = this.props;
- updateLegacyCertificate(values);
+ // make an object with keys as challenge ids and values as solutions
+ let idsToSolutions = {};
+ for (let i of Object.keys(formChalObj)) {
+ for (let j of legacyProjectMap[legacyTitle]) {
+ if (i === j.title) {
+ idsToSolutions[j.id] = formChalObj[i];
+ break;
+ }
+ }
+ }
+
+ // filter the new solutions that need to be updated
+ const completedChallenges = this.props.completedChallenges;
+ let challengesToUpdate = {};
+ let newChalleneFound = true;
+ let oldSubmissions = 0;
+ for (let submittedChal of Object.keys(idsToSolutions)) {
+ for (let i of completedChallenges) {
+ if (i.id === submittedChal) {
+ if (idsToSolutions[submittedChal] !== i.solution) {
+ challengesToUpdate[submittedChal] = idsToSolutions[submittedChal];
+ }
+ oldSubmissions++;
+ newChalleneFound = false;
+ break;
+ }
+ }
+ if (newChalleneFound && idsToSolutions[submittedChal] !== '') {
+ challengesToUpdate[submittedChal] = idsToSolutions[submittedChal];
+ }
+ newChalleneFound = true;
+ }
+
+ const valuesSaved = values(formChalObj)
+ .filter(Boolean)
+ .filter(isString);
+
+ const isProjectSectionComplete = valuesSaved.length === oldSubmissions;
+
+ if (isProjectSectionComplete) {
+ return isHonest
+ ? verifyCert(superBlock)
+ : createFlashMessage(honestyInfoMessage);
+ }
+ return updateLegacyCert({ challengesToUpdate, superBlock });
}
renderLegacyCertifications = certName => {
- const { username, isHonest, createFlashMessage, verifyCert } = this.props;
+ const { username, createFlashMessage, completedChallenges } = this.props;
const { superBlock } = first(legacyProjectMap[certName]);
const certLocation = `/certification/${username}/${superBlock}`;
const challengeTitles = legacyProjectMap[certName].map(item => item.title);
- const { completedChallenges } = this.props;
const isCertClaimed = this.getUserIsCertMap()[certName];
const initialObject = {};
let filledforms = 0;
@@ -321,19 +389,12 @@ class CertificationSettings extends Component {
const fullForm = filledforms === challengeTitles.length;
- const createClickHandler = superBlock => e => {
+ const createClickHandler = certLocation => e => {
e.preventDefault();
if (isCertClaimed) {
return navigate(certLocation);
}
- return isHonest
- ? verifyCert(superBlock)
- : createFlashMessage({
- type: 'info',
- message:
- 'To claim a certification, you must first accept our academic ' +
- 'honesty policy'
- });
+ return createFlashMessage(reallyWeirdErrorMessage);
};
const buttonStyle = {
@@ -341,7 +402,7 @@ class CertificationSettings extends Component {
};
return (
-
+
{certName}