[offers][fix] Fix year options (#548)

pull/551/head
Ai Ling 2 years ago committed by GitHub
parent ff54652f54
commit 1db5e46fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,10 @@
const NUM_YEARS = 5;
export const FutureYearsOptions = Array.from({ length: NUM_YEARS }, (_, i) => {
const year = new Date().getFullYear() + i;
const OFFSET = 2;
export const YearsOptions = (yearSelected?: number) =>
Array.from({ length: NUM_YEARS }, (_, i) => {
const year = yearSelected
? yearSelected - OFFSET + i
: new Date().getFullYear() - OFFSET + i;
return {
label: String(year),
value: year,

@ -73,7 +73,7 @@ export const defaultInternshipOfferValues = {
monthlySalary: {
currency: DEFAULT_CURRENCY,
},
startYear: null,
startYear: getCurrentYear(),
},
};

@ -29,7 +29,7 @@ import FormTextInput from '../../forms/FormTextInput';
import { InternshipCycleOptions } from '../../InternshipCycles';
import JobTypeTabs from '../../JobTypeTabs';
import type { OfferFormData } from '../../types';
import { FutureYearsOptions } from '../../Years';
import { YearsOptions } from '../../Years';
import { CURRENCY_OPTIONS } from '../../../../utils/offers/currency/CurrencyEnum';
type FullTimeOfferDetailsFormProps = Readonly<{
@ -287,6 +287,9 @@ function InternshipOfferDetailsForm({
const { register, formState, control } = useFormContext<{
offers: Array<OfferFormData>;
}>();
const watchStartYear = useWatch({
name: `offers.${index}.offersIntern.startYear`,
});
const offerFields = formState.errors.offers?.[index];
return (
@ -351,7 +354,7 @@ function InternshipOfferDetailsForm({
display="block"
errorMessage={offerFields?.offersIntern?.startYear?.message}
label="Internship Year"
options={FutureYearsOptions}
options={YearsOptions(watchStartYear)}
required={true}
{...register(`offers.${index}.offersIntern.startYear`, {
required: FieldError.REQUIRED,

Loading…
Cancel
Save