[offers][fix] Use companies typeahead in form

pull/398/head
Ai Ling 3 years ago
parent e3995be147
commit 80075326b9

@ -22,29 +22,6 @@ export const titleOptions = [
}, },
]; ];
export const companyOptions = [
{
label: 'Amazon',
value: 'cl93patjt0000txewdi601mub',
},
{
label: 'Microsoft',
value: 'cl93patjt0001txewkglfjsro',
},
{
label: 'Apple',
value: 'cl93patjt0002txewf3ug54m8',
},
{
label: 'Google',
value: 'cl93patjt0003txewyiaky7xx',
},
{
label: 'Meta',
value: 'cl93patjt0004txew88wkcqpu',
},
];
export const locationOptions = [ export const locationOptions = [
{ {
label: 'Singapore, Singapore', label: 'Singapore, Singapore',

@ -2,7 +2,6 @@ import { useFormContext, useWatch } from 'react-hook-form';
import { Collapsible, RadioList } from '@tih/ui'; import { Collapsible, RadioList } from '@tih/ui';
import { import {
companyOptions,
educationFieldOptions, educationFieldOptions,
educationLevelOptions, educationLevelOptions,
emptyOption, emptyOption,
@ -14,6 +13,7 @@ import FormRadioList from '~/components/offers/forms/components/FormRadioList';
import FormSelect from '~/components/offers/forms/components/FormSelect'; import FormSelect from '~/components/offers/forms/components/FormSelect';
import FormTextInput from '~/components/offers/forms/components/FormTextInput'; import FormTextInput from '~/components/offers/forms/components/FormTextInput';
import { JobType } from '~/components/offers/types'; import { JobType } from '~/components/offers/types';
import CompaniesTypeahead from '~/components/shared/CompaniesTypeahead';
import { CURRENCY_OPTIONS } from '~/utils/offers/currency/CurrencyEnum'; import { CURRENCY_OPTIONS } from '~/utils/offers/currency/CurrencyEnum';
@ -74,7 +74,7 @@ function YoeSection() {
} }
function FullTimeJobFields() { function FullTimeJobFields() {
const { register } = useFormContext(); const { register, setValue } = useFormContext();
return ( return (
<> <>
<div className="mb-5 grid grid-cols-2 space-x-3"> <div className="mb-5 grid grid-cols-2 space-x-3">
@ -85,14 +85,14 @@ function FullTimeJobFields() {
placeholder={emptyOption} placeholder={emptyOption}
{...register(`background.experiences.0.title`)} {...register(`background.experiences.0.title`)}
/> />
<FormSelect <div>
display="block" <CompaniesTypeahead
label="Company" onSelect={({ value }) =>
options={companyOptions} setValue(`background.experiences.0.companyId`, value)
placeholder={emptyOption} }
{...register(`background.experiences.0.companyId`)}
/> />
</div> </div>
</div>
<div className="mb-5 grid grid-cols-1 space-x-3"> <div className="mb-5 grid grid-cols-1 space-x-3">
<FormTextInput <FormTextInput
endAddOn={ endAddOn={
@ -151,7 +151,7 @@ function FullTimeJobFields() {
} }
function InternshipJobFields() { function InternshipJobFields() {
const { register } = useFormContext(); const { register, setValue } = useFormContext();
return ( return (
<> <>
<div className="mb-5 grid grid-cols-2 space-x-3"> <div className="mb-5 grid grid-cols-2 space-x-3">
@ -162,14 +162,14 @@ function InternshipJobFields() {
placeholder={emptyOption} placeholder={emptyOption}
{...register(`background.experiences.0.title`)} {...register(`background.experiences.0.title`)}
/> />
<FormSelect <div>
display="block" <CompaniesTypeahead
label="Company" onSelect={({ value }) =>
options={companyOptions} setValue(`background.experiences.0.companyId`, value)
placeholder={emptyOption} }
{...register(`background.experiences.0.company`)}
/> />
</div> </div>
</div>
<div className="mb-5 grid grid-cols-1 space-x-3"> <div className="mb-5 grid grid-cols-1 space-x-3">
<FormTextInput <FormTextInput
endAddOn={ endAddOn={

@ -11,6 +11,8 @@ import { PlusIcon } from '@heroicons/react/20/solid';
import { TrashIcon } from '@heroicons/react/24/outline'; import { TrashIcon } from '@heroicons/react/24/outline';
import { Button, Dialog } from '@tih/ui'; import { Button, Dialog } from '@tih/ui';
import CompaniesTypeahead from '~/components/shared/CompaniesTypeahead';
import { import {
defaultFullTimeOfferValues, defaultFullTimeOfferValues,
defaultInternshipOfferValues, defaultInternshipOfferValues,
@ -21,7 +23,6 @@ import FormSelect from './components/FormSelect';
import FormTextArea from './components/FormTextArea'; import FormTextArea from './components/FormTextArea';
import FormTextInput from './components/FormTextInput'; import FormTextInput from './components/FormTextInput';
import { import {
companyOptions,
emptyOption, emptyOption,
FieldError, FieldError,
internshipCycleOptions, internshipCycleOptions,
@ -85,18 +86,14 @@ function FullTimeOfferDetailsForm({
})} })}
/> />
</div> </div>
<div className="mb-5 grid grid-cols-2 space-x-3"> <div className="mb-5 flex grid grid-cols-2 space-x-3">
<FormSelect <div>
display="block" <CompaniesTypeahead
errorMessage={offerFields?.companyId?.message} onSelect={({ value }) =>
label="Company" setValue(`offers.${index}.companyId`, value)
options={companyOptions} }
placeholder={emptyOption}
required={true}
{...register(`offers.${index}.companyId`, {
required: FieldError.Required,
})}
/> />
</div>
<FormTextInput <FormTextInput
errorMessage={offerFields?.job?.level?.message} errorMessage={offerFields?.job?.level?.message}
label="Level" label="Level"
@ -275,7 +272,7 @@ function InternshipOfferDetailsForm({
index, index,
remove, remove,
}: InternshipOfferDetailsFormProps) { }: InternshipOfferDetailsFormProps) {
const { register, formState } = useFormContext<{ const { register, formState, setValue } = useFormContext<{
offers: Array<InternshipOfferDetailsFormData>; offers: Array<InternshipOfferDetailsFormData>;
}>(); }>();
@ -308,17 +305,13 @@ function InternshipOfferDetailsForm({
/> />
</div> </div>
<div className="mb-5 grid grid-cols-2 space-x-3"> <div className="mb-5 grid grid-cols-2 space-x-3">
<FormSelect <div>
display="block" <CompaniesTypeahead
errorMessage={offerFields?.companyId?.message} onSelect={({ value }) =>
label="Company" setValue(`offers.${index}.companyId`, value)
options={companyOptions} }
placeholder={emptyOption}
required={true}
{...register(`offers.${index}.companyId`, {
required: FieldError.Required,
})}
/> />
</div>
<FormSelect <FormSelect
display="block" display="block"
errorMessage={offerFields?.location?.message} errorMessage={offerFields?.location?.message}

@ -120,7 +120,6 @@ export default function OffersSubmissionPage() {
console.error(error.message); console.error(error.message);
}, },
onSuccess() { onSuccess() {
alert('offer profile submit success!');
setFormStep(formStep + 1); setFormStep(formStep + 1);
scrollToTop(); scrollToTop();
}, },

Loading…
Cancel
Save