Skip to content

Fix Draft Links -> PROD-2321 #212

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
merged 3 commits into from
Jul 22, 2022
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 @@ -57,6 +57,7 @@ export function create(challenge: Challenge, workPrices: WorkPricesType): Work {
cost: getCost(challenge, priceConfig, type),
created: submittedDate,
description: getDescription(challenge, type),
draftStep: getDraftStep(challenge, status),
id: challenge.id,
messageCount: Number((Math.random() * 10).toFixed(0)), // TODO: real message count
participantsCount: challenge.numOfRegistrants,
Expand Down Expand Up @@ -91,10 +92,16 @@ export function buildCreateBody(workTypeConfig: WorkTypeConfig): ChallengeCreate
legacy: {
selfService: true,
},
metadata: [{
name: ChallengeMetadataName.intakeForm,
value: JSON.stringify({ form }),
}],
metadata: [
{
name: ChallengeMetadataName.intakeForm,
value: JSON.stringify({ form }),
},
{
name: ChallengeMetadataName.currentStep,
value: 'basicInfo',
},
],
name: 'new-self-service-project',
tags: workTypeConfig.tags,
timelineTemplateId: workTypeConfig.timelineTemplateId,
Expand Down Expand Up @@ -478,6 +485,14 @@ function getDescription(challenge: Challenge, type: WorkType): string | undefine
}
}

function getDraftStep(challenge: Challenge, status: WorkStatus): string | undefined {

if (status !== WorkStatus.draft) { return undefined }

const currentStep: ChallengeMetadata | undefined = findMetadata(challenge, ChallengeMetadataName.currentStep)
return currentStep?.value
}

function getProgress(challenge: Challenge, workStatus: WorkStatus): WorkProgress {

const steps: ReadonlyArray<WorkProgressStep> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Work {
cost?: number
created: Date
description?: string
draftStep?: string
id: string
messageCount?: number
participantsCount?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const BugHuntIntakeForm: React.FC = () => {
})

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

const formInputs: Array<FormInputModel> = formGetInputFields(formDef.groups)
if (!workId && !challenge) {
Expand All @@ -90,7 +90,7 @@ const BugHuntIntakeForm: React.FC = () => {

setFormValues(formData)

if (formData.form.basicInfo.packageType !== selectedPackage) {
if (formData?.form?.basicInfo.packageType && formData?.form?.basicInfo.packageType !== selectedPackage) {
setSelectedPackage(formData.form.basicInfo.packageType)
}
}
Expand Down
19 changes: 11 additions & 8 deletions src-ts/tools/work/work-table/WorkTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
WorkStatus,
WorkStatusFilter,
} from '../work-lib'
import { WorkIntakeFormRoutes } from '../work-lib/work-provider/work-functions/work-store/work-intake-form-routes.config'
import { selfServiceStartRoute, workDetailRoute } from '../work.routes'

import { workDashboardTabs } from './work-nav.config'
Expand Down Expand Up @@ -93,17 +94,19 @@ const WorkTable: FC<{}> = () => {

const isDraft: boolean = selectedWork.status === WorkStatus.draft

// TODO: move the tabs definition to src-ts
// so we don't have to hard-code this tab id
let url: string = workDetailRoute(selectedWork.id, selectedWork.status === WorkStatus.ready ? 'solutions' : undefined)

if (isDraft) {
cacheChallengeId(selectedWork.id)
if (selectedWork.draftStep) {
url = `${WorkIntakeFormRoutes[selectedWork.type][selectedWork.draftStep]}/${selectedWork.id}`
} else {
cacheChallengeId(selectedWork.id)
url = selfServiceStartRoute
}
}

// TODO: get these routes from an object/function that's not hard-coded
const url: string = isDraft
? selfServiceStartRoute
// TODO: move the tabs definition to src-ts
// so we don't have to hard-code this tab id
: workDetailRoute(selectedWork.id, selectedWork.status === WorkStatus.ready ? 'solutions' : undefined)

navigate(url)
}

Expand Down