From fd97f25de1d3886f5f6d27c56f74b81342c6c6a5 Mon Sep 17 00:00:00 2001 From: Ai Ling <50992674+ailing35@users.noreply.github.com> Date: Wed, 9 Nov 2022 00:50:38 +0800 Subject: [PATCH] [offers][feat] Add currency detection in forms (#542) * [offers][feat] Tweak OEA text * [offers][feat] Add currency detection in forms --- .../offers/offerAnalysis/OfferAnalysis.tsx | 6 +-- .../offersSubmission/OffersSubmissionForm.tsx | 14 ++++++- .../submissionForm/BackgroundForm.tsx | 41 ++++++++++++------ .../submissionForm/OfferDetailsForm.tsx | 42 +++++++++++++------ .../offers/profile/edit/[offerProfileId].tsx | 14 ++++++- apps/portal/src/pages/offers/submit.tsx | 14 ------- apps/portal/src/pages/offers/submit/index.tsx | 15 ++++++- 7 files changed, 99 insertions(+), 47 deletions(-) delete mode 100644 apps/portal/src/pages/offers/submit.tsx diff --git a/apps/portal/src/components/offers/offerAnalysis/OfferAnalysis.tsx b/apps/portal/src/components/offers/offerAnalysis/OfferAnalysis.tsx index 1d8aa2ae..d28cfe19 100644 --- a/apps/portal/src/components/offers/offerAnalysis/OfferAnalysis.tsx +++ b/apps/portal/src/components/offers/offerAnalysis/OfferAnalysis.tsx @@ -58,9 +58,9 @@ function OfferAnalysisContent({ tab={tab} />

- {isSubmission - ? 'Here are some of the top offers relevant to you:' - : 'Relevant top offers:'} + {tab === OVERALL_TAB + ? 'Here are some of the highest offers with the same job title and YOE(±1):' + : 'Here are some of the highest offers with the same company, job title and YOE(±1):'}

{analysis.topPercentileOffers.map((topPercentileOffer) => ( , ]; + const defaultCurrency = getCurrencyForCountry(country).toString(); + + const steps = [ + , + , + ]; const breadcrumbSteps: Array = [ { diff --git a/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx b/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx index 63e0148b..df34d81d 100644 --- a/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx +++ b/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx @@ -5,10 +5,7 @@ import { Collapsible, RadioList } from '@tih/ui'; import { FieldError } from '~/components/offers/constants'; import type { BackgroundPostData } from '~/components/offers/types'; -import { - Currency, - CURRENCY_OPTIONS, -} from '~/utils/offers/currency/CurrencyEnum'; +import { CURRENCY_OPTIONS } from '~/utils/offers/currency/CurrencyEnum'; import { EducationFieldOptions } from '../../EducationFields'; import { EducationLevelOptions } from '../../EducationLevels'; @@ -82,7 +79,11 @@ function YoeSection() { ); } -function FullTimeJobFields() { +type FullTimeJobFieldsProps = Readonly<{ + defaultCurrency: string; +}>; + +function FullTimeJobFields({ defaultCurrency }: FullTimeJobFieldsProps) { const { register, formState } = useFormContext<{ background: BackgroundPostData; }>(); @@ -104,7 +105,7 @@ function FullTimeJobFields() { endAddOn={ ; + +function InternshipJobFields({ defaultCurrency }: InternshipJobFieldsProps) { const { register, formState } = useFormContext<{ background: BackgroundPostData; }>(); @@ -175,7 +180,7 @@ function InternshipJobFields() { endAddOn={ ; + +function CurrentJobSection({ defaultCurrency }: CurrentJobSectionProps) { const { register } = useFormContext(); const watchJobType = useWatch({ name: 'background.experiences.0.jobType', @@ -243,9 +252,9 @@ function CurrentJobSection() { /> {watchJobType === JobType.FULLTIME ? ( - + ) : ( - + )} ); @@ -280,7 +289,13 @@ function EducationSection() { ); } -export default function BackgroundForm() { +type BackgroundFormProps = Readonly<{ + defaultCurrency: string; +}>; + +export default function BackgroundForm({ + defaultCurrency, +}: BackgroundFormProps) { return (

@@ -288,7 +303,7 @@ export default function BackgroundForm() {

- +
diff --git a/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx b/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx index 9b24c5e6..9f1f5f43 100644 --- a/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx +++ b/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx @@ -30,12 +30,10 @@ import { InternshipCycleOptions } from '../../InternshipCycles'; import JobTypeTabs from '../../JobTypeTabs'; import type { OfferFormData } from '../../types'; import { FutureYearsOptions } from '../../Years'; -import { - Currency, - CURRENCY_OPTIONS, -} from '../../../../utils/offers/currency/CurrencyEnum'; +import { CURRENCY_OPTIONS } from '../../../../utils/offers/currency/CurrencyEnum'; type FullTimeOfferDetailsFormProps = Readonly<{ + defaultCurrency: string; index: number; remove: UseFieldArrayRemove; }>; @@ -43,6 +41,7 @@ type FullTimeOfferDetailsFormProps = Readonly<{ function FullTimeOfferDetailsForm({ index, remove, + defaultCurrency, }: FullTimeOfferDetailsFormProps) { const { register, formState, setValue, control } = useFormContext<{ offers: Array; @@ -135,7 +134,7 @@ function FullTimeOfferDetailsForm({ endAddOn={ ; @@ -282,6 +282,7 @@ type InternshipOfferDetailsFormProps = Readonly<{ function InternshipOfferDetailsForm({ index, remove, + defaultCurrency, }: InternshipOfferDetailsFormProps) { const { register, formState, control } = useFormContext<{ offers: Array; @@ -373,7 +374,7 @@ function InternshipOfferDetailsForm({ endAddOn={ ; jobType: JobType; }>; @@ -442,6 +444,7 @@ type OfferDetailsFormArrayProps = Readonly<{ function OfferDetailsFormArray({ fieldArrayValues, jobType, + defaultCurrency, }: OfferDetailsFormArrayProps) { const { append, remove, fields } = fieldArrayValues; @@ -451,9 +454,17 @@ function OfferDetailsFormArray({ return (
{jobType === JobType.FULLTIME ? ( - + ) : ( - + )}
); @@ -476,7 +487,13 @@ function OfferDetailsFormArray({ ); } -export default function OfferDetailsForm() { +type OfferDetailsFormProps = Readonly<{ + defaultCurrency: string; +}>; + +export default function OfferDetailsForm({ + defaultCurrency, +}: OfferDetailsFormProps) { const watchJobType = useWatch({ name: `offers.0.jobType`, }); @@ -515,6 +532,7 @@ export default function OfferDetailsForm() { }} /> diff --git a/apps/portal/src/pages/offers/profile/edit/[offerProfileId].tsx b/apps/portal/src/pages/offers/profile/edit/[offerProfileId].tsx index 647e5c8f..338eb067 100644 --- a/apps/portal/src/pages/offers/profile/edit/[offerProfileId].tsx +++ b/apps/portal/src/pages/offers/profile/edit/[offerProfileId].tsx @@ -1,3 +1,4 @@ +import type { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import Error from 'next/error'; import Head from 'next/head'; import { useRouter } from 'next/router'; @@ -14,7 +15,17 @@ import { getProfilePath } from '~/utils/offers/link'; import { convertToMonthYear } from '~/utils/offers/time'; import { trpc } from '~/utils/trpc'; -export default function OffersEditPage() { +export const getServerSideProps: GetServerSideProps = async ({ req }) => { + return { + props: { + country: req.cookies.country ?? null, + }, + }; +}; + +export default function OffersEditPage({ + country, +}: InferGetServerSidePropsType) { const [initialData, setInitialData] = useState(); const router = useRouter(); const { offerProfileId, token = '' } = router.query; @@ -104,6 +115,7 @@ export default function OffersEditPage() { )} {!getProfileResult.isLoading && initialData && ( - - Analyze your offers - - - - ); -} diff --git a/apps/portal/src/pages/offers/submit/index.tsx b/apps/portal/src/pages/offers/submit/index.tsx index 2cbef615..7ed2a4f2 100644 --- a/apps/portal/src/pages/offers/submit/index.tsx +++ b/apps/portal/src/pages/offers/submit/index.tsx @@ -1,14 +1,25 @@ +import type { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import Head from 'next/head'; import OffersSubmissionForm from '~/components/offers/offersSubmission/OffersSubmissionForm'; -export default function OffersSubmissionPage() { +export const getServerSideProps: GetServerSideProps = async ({ req }) => { + return { + props: { + country: req.cookies.country ?? null, + }, + }; +}; + +export default function OffersSubmissionPage({ + country, +}: InferGetServerSidePropsType) { return ( <> Analyze your offers - + ); }