Skip to content

Commit

Permalink
update create challenge form's next button functionality (#2271)
Browse files Browse the repository at this point in the history
* update create challenge form's next button functionality

* reverted a couple of changes, fixed edits code agreement checkbox validation, now coercing .env CHALLENGE_INSTRUCTIONS_MIN_LENGTH to number value in instructions schema

* better value check for env value

* fixed handling for instruction length .env value

---------

Co-authored-by: Andrew Philbin <45773707+AndrewPhilbin@users.noreply.github.com>
  • Loading branch information
CollinBeczak and AndrewPhilbin authored Feb 20, 2024
1 parent ac6c97f commit 385e413
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ export class EditChallenge extends Component {
(this.validationPromise || Promise.resolve())
.then(() => {
this.isFinishing ? this.finish() : nextStep();
window.scrollTo(0, 0);
window.scrollTo(0, 0);
return false;
})
.catch((err) => {
console.log(err);
console.log(err);
}); // Stay on current step if validation fails

return false;
};

Expand Down Expand Up @@ -967,7 +967,6 @@ export class EditChallenge extends Component {
</div>
)}

{/* Note: Next button submits the form, so nextStep isn't used here */}
<StepNavigation
activeStep={activeStep}
prevStep={(stepName) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const jsSchema = (intl) => {
title: intl.formatMessage(messages.automatedEditsCodeLabel),
type: "boolean",
default: false,
enum: [false, true],
enum: [true],
agreementDescription: intl.formatMessage(messages.automatedEditsCodeDescription),
checkboxLabel: messages.automatedEditsCodeUICheckboxLabel
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,25 @@ import messages from '../Messages'
*
* @author [Neil Rotstan](https://github.com/nrotstan)
*/

const validateMinLength = val => {
if(!val) {
// Handle undefined. null and empty string case and default to 150:
if(typeof val === 'string' && val.length === 0) return 0
if(val === 0) return 0
return 150
}
// Handle 0 separately. Non-strict equals will be true for '0' string value:
if(val == 0) return 0

// Bitwise operator coerces to number value:
return val | 0
}

export const jsSchema = (intl) => {
const instructionsMinLength = process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH || 150
const minLengthEnvValue = process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH
const instructionsMinLength = validateMinLength(minLengthEnvValue)

const schemaFields = {
"$schema": "http://json-schema.org/draft-07/schema#",
type: "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ const newChallengeSteps = {
next: 'AutomatedEditsCodeAgreement',
previous: 'Description',
}),
'AutomatedEditsCodeAgreement': Object.assign({}, automatedEditsCodeAgreementStep, {
next: 'AdvancedOptions',
previous: 'Instructions'
}),
'AdvancedOptions': Object.assign({}, advancedOptionsStep, {
next: [
'Discoverability',
Expand Down Expand Up @@ -236,10 +240,6 @@ const newChallengeSteps = {
previous: 'AdvancedOptions',
canFinish: true,
}),
'AutomatedEditsCodeAgreement': Object.assign({}, automatedEditsCodeAgreementStep, {
next: 'AdvancedOptions',
previous: 'Instructions'
})
}

// String together workflow steps for editing an existing challenge
Expand Down

0 comments on commit 385e413

Please sign in to comment.