Skip to content

Bug hunt - Set current step #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ export function buildUpdateBody(workTypeConfig: WorkTypeConfig, challenge: Chall
const form: IntakeForm = !!intakeForm?.value ? JSON.parse(intakeForm.value)?.form : {}
form.basicInfo = formData

// TODO: Add the progress.currentStep to form to determine if it's in the review phase (review page)
// or not. The legacy intakes use currentStep 7 for review and 5 for taking the user to the login step
// as those numbers map to the routes configured for each work type (see IntakeForm.jsx for an example).
// We can probably clean that up as we don't need that many routes

// --- Build Metadata --- //
const intakeMetadata: Array<ChallengeMetadata> = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ const BugHuntIntakeForm: React.FC = () => {
const [formDef, setFormDef]: [FormDefinition, Dispatch<SetStateAction<FormDefinition>>]
= useState<FormDefinition>({ ...BugHuntFormConfig })

const [formValues, setFormValues]: [any, Dispatch<any>] = useState({
const [formValues, setFormValues]: [any, Dispatch<any>] = useState({
currentStep: 'basicInfo',
[ChallengeMetadataName.packageType]: 'standard',
})

function findMetadata(metadataName: ChallengeMetadataName): ChallengeMetadata | undefined {
return challenge?.metadata?.find((item: ChallengeMetadata) => item.name === metadataName)
}

const [selectedPackage, setSelectedPackage]: [PricePackageName, Dispatch<SetStateAction<PricePackageName>>]
= useState<PricePackageName>(formValues.packageType)

Expand All @@ -77,17 +73,9 @@ const BugHuntIntakeForm: React.FC = () => {

const intakeFormBH: ChallengeMetadata | undefined = response.metadata?.find((item: ChallengeMetadata) => item.name === ChallengeMetadataName.intakeForm)
if (intakeFormBH) {
const formData: Record<string, any> = JSON.parse(intakeFormBH.value)
// TODO: Set the correct currentStep into challenge's form data when saving form and moving on to a new page
if (formData.currentStep && formData.currentStep !== 'basicInfo') {
if (!isLoggedIn) {
navigate(WorkIntakeFormRoutes[WorkType.bugHunt]['loginPrompt'])
} else {
navigate(WorkIntakeFormRoutes[WorkType.bugHunt][formData.currentStep])
}
}
const formData: Record<string, any> = JSON.parse(intakeFormBH.value).form.basicInfo

setFormValues(formData.form.basicInfo)
setFormValues(formData)

if (formData.form.basicInfo.packageType !== selectedPackage) {
setSelectedPackage(formData.form.basicInfo.packageType)
Expand Down Expand Up @@ -128,6 +116,11 @@ const BugHuntIntakeForm: React.FC = () => {

const onSave: (val: any) => Promise<void> = (val: any) => {
if (!challenge) { return Promise.resolve() }
if (action === 'save') {
val.currentStep = 'basicInfo'
} else if (action === 'submit') {
val.currentStep = 'review'
}

return workUpdateAsync(WorkType.bugHunt, challenge, val)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface FormFieldValues {

const Review: React.FC = () => {
const workId: string | undefined = useParams().workId
const redirectUrl: string = WorkIntakeFormRoutes[WorkType.bugHunt]['basicInfo']
const redirectUrl: string = `${WorkIntakeFormRoutes[WorkType.bugHunt]['basicInfo']}/${workId}`

const [formData, setFormData]: [any, Dispatch<any>] = useState({})

Expand Down