From d59da5d18693db9a40c6aeb1f6d2c4d64d65dc50 Mon Sep 17 00:00:00 2001 From: Ai Ling <50992674+ailing35@users.noreply.github.com> Date: Wed, 12 Oct 2022 02:26:31 +0800 Subject: [PATCH] [offers][feat] Add plaintext breadcrumb (#364) --- .../src/components/offers/Breadcrumb.tsx | 23 ++++++++++ apps/portal/src/components/offers/types.ts | 32 +++++++------- apps/portal/src/pages/offers/submit.tsx | 43 +++++++++++++------ apps/portal/src/utils/offers/form.tsx | 6 ++- 4 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 apps/portal/src/components/offers/Breadcrumb.tsx diff --git a/apps/portal/src/components/offers/Breadcrumb.tsx b/apps/portal/src/components/offers/Breadcrumb.tsx new file mode 100644 index 00000000..9700e486 --- /dev/null +++ b/apps/portal/src/components/offers/Breadcrumb.tsx @@ -0,0 +1,23 @@ +type BreadcrumbsProps = Readonly<{ + currentStep: number; + stepLabels: Array; +}>; + +export function Breadcrumbs({ stepLabels, currentStep }: BreadcrumbsProps) { + return ( +
+ {stepLabels.map((label, index) => ( + <> + {index === currentStep ? ( +

{label}

+ ) : ( +

{label}

+ )} + {index !== stepLabels.length - 1 && ( +

{'>'}

+ )} + + ))} +
+ ); +} diff --git a/apps/portal/src/components/offers/types.ts b/apps/portal/src/components/offers/types.ts index 096fe70e..9881d829 100644 --- a/apps/portal/src/components/offers/types.ts +++ b/apps/portal/src/components/offers/types.ts @@ -67,20 +67,20 @@ type SpecificYoe = { }; type FullTimeExperience = { - level: string; - totalCompensation: Money; + level?: string; + totalCompensation?: Money; }; type InternshipExperience = { - monthlySalary: Money; + monthlySalary?: Money; }; type GeneralExperience = { - companyId: string; - durationInMonths: number; - jobType: string; - specialization: string; - title: string; + companyId?: string; + durationInMonths?: number; + jobType?: string; + specialization?: string; + title?: string; }; export type Experience = @@ -88,26 +88,26 @@ export type Experience = | (GeneralExperience & InternshipExperience); type Education = { - endDate: Date; - field: string; - school: string; - startDate: Date; - type: string; + endDate?: Date; + field?: string; + school?: string; + startDate?: Date; + type?: string; }; type BackgroundFormData = { educations: Array; experiences: Array; specificYoes: Array; - totalYoe: number; + totalYoe?: number; }; -export type SubmitOfferFormData = { +export type OfferProfileFormData = { background: BackgroundFormData; offers: Array; }; -export type OfferPostData = { +export type OfferProfilePostData = { background: BackgroundFormData; offers: Array; }; diff --git a/apps/portal/src/pages/offers/submit.tsx b/apps/portal/src/pages/offers/submit.tsx index c4949bb2..2ce5fd36 100644 --- a/apps/portal/src/pages/offers/submit.tsx +++ b/apps/portal/src/pages/offers/submit.tsx @@ -4,35 +4,34 @@ import { FormProvider, useForm } from 'react-hook-form'; import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid'; import { Button } from '@tih/ui'; +import { Breadcrumbs } from '~/components/offers/Breadcrumb'; import BackgroundForm from '~/components/offers/forms/BackgroundForm'; import OfferAnalysis from '~/components/offers/forms/OfferAnalysis'; import OfferDetailsForm from '~/components/offers/forms/OfferDetailsForm'; import OfferProfileSave from '~/components/offers/forms/OfferProfileSave'; import type { OfferDetailsFormData, - SubmitOfferFormData, + OfferProfileFormData, } from '~/components/offers/types'; +import { JobType } from '~/components/offers/types'; import type { Month } from '~/components/shared/MonthYearPicker'; import { cleanObject, removeInvalidMoneyData } from '~/utils/offers/form'; import { getCurrentMonth, getCurrentYear } from '~/utils/offers/time'; import { trpc } from '~/utils/trpc'; -function Breadcrumbs() { - return ( -

- {'Offer details > Background > Analysis > Save'} -

- ); -} - const defaultOfferValues = { + background: { + educations: [], + experiences: [{ jobType: JobType.FullTime }], + specificYoes: [], + }, offers: [ { comments: '', companyId: '', job: {}, - jobType: 'FULLTIME', + jobType: JobType.FullTime, location: '', monthYearReceived: { month: getCurrentMonth() as Month, @@ -47,11 +46,12 @@ type FormStep = { component: JSX.Element; hasNext: boolean; hasPrevious: boolean; + label: string; }; export default function OffersSubmissionPage() { const [formStep, setFormStep] = useState(0); - const formMethods = useForm({ + const formMethods = useForm({ defaultValues: defaultOfferValues, mode: 'all', }); @@ -62,20 +62,30 @@ export default function OffersSubmissionPage() { component: , hasNext: true, hasPrevious: false, + label: 'Offer details', }, { component: , hasNext: false, hasPrevious: true, + label: 'Background', + }, + { + component: , + hasNext: true, + hasPrevious: false, + label: 'Analysis', }, - { component: , hasNext: true, hasPrevious: false }, { component: , hasNext: false, hasPrevious: false, + label: 'Save', }, ]; + const formStepsLabels = formSteps.map((step) => step.label); + const nextStep = async (currStep: number) => { if (currStep === 0) { const result = await trigger('offers'); @@ -98,7 +108,7 @@ export default function OffersSubmissionPage() { }, }); - const onSubmit: SubmitHandler = async (data) => { + const onSubmit: SubmitHandler = async (data) => { const result = await trigger(); if (!result) { return; @@ -118,6 +128,9 @@ export default function OffersSubmissionPage() { (specificYoe) => specificYoe.domain && specificYoe.yoe > 0, ); + if (Object.entries(postData.background.experiences[0]).length === 1) { + postData.background.experiences = []; + } createMutation.mutate(postData); }; @@ -125,7 +138,9 @@ export default function OffersSubmissionPage() {
- +
+ +
{formSteps[formStep].component} diff --git a/apps/portal/src/utils/offers/form.tsx b/apps/portal/src/utils/offers/form.tsx index 16def65d..2e88ac88 100644 --- a/apps/portal/src/utils/offers/form.tsx +++ b/apps/portal/src/utils/offers/form.tsx @@ -46,7 +46,11 @@ export function removeInvalidMoneyData(object: any) { if (k === 'currency') { if (object.value === undefined) { delete object[k]; - } else if (object.value === null || object.value !== object.value) { + } else if ( + object.value === null || + object.value !== object.value || + object.value === '' + ) { delete object[k]; delete object.value; }