|
|
@ -1,5 +1,9 @@
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import type { FieldValues, UseFieldArrayReturn } from 'react-hook-form';
|
|
|
|
import type {
|
|
|
|
|
|
|
|
FieldValues,
|
|
|
|
|
|
|
|
UseFieldArrayRemove,
|
|
|
|
|
|
|
|
UseFieldArrayReturn,
|
|
|
|
|
|
|
|
} from 'react-hook-form';
|
|
|
|
import { useWatch } from 'react-hook-form';
|
|
|
|
import { useWatch } from 'react-hook-form';
|
|
|
|
import { useFormContext } from 'react-hook-form';
|
|
|
|
import { useFormContext } from 'react-hook-form';
|
|
|
|
import { useFieldArray } from 'react-hook-form';
|
|
|
|
import { useFieldArray } from 'react-hook-form';
|
|
|
@ -35,12 +39,12 @@ import { CURRENCY_OPTIONS } from '../../../utils/offers/currency/CurrencyEnum';
|
|
|
|
|
|
|
|
|
|
|
|
type FullTimeOfferDetailsFormProps = Readonly<{
|
|
|
|
type FullTimeOfferDetailsFormProps = Readonly<{
|
|
|
|
index: number;
|
|
|
|
index: number;
|
|
|
|
setDialogOpen: (isOpen: boolean) => void;
|
|
|
|
remove: UseFieldArrayRemove;
|
|
|
|
}>;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
|
|
|
|
function FullTimeOfferDetailsForm({
|
|
|
|
function FullTimeOfferDetailsForm({
|
|
|
|
index,
|
|
|
|
index,
|
|
|
|
setDialogOpen,
|
|
|
|
remove,
|
|
|
|
}: FullTimeOfferDetailsFormProps) {
|
|
|
|
}: FullTimeOfferDetailsFormProps) {
|
|
|
|
const { register, formState, setValue } = useFormContext<{
|
|
|
|
const { register, formState, setValue } = useFormContext<{
|
|
|
|
offers: Array<FullTimeOfferDetailsFormData>;
|
|
|
|
offers: Array<FullTimeOfferDetailsFormData>;
|
|
|
@ -103,7 +107,7 @@ function FullTimeOfferDetailsForm({
|
|
|
|
})}
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mb-5 grid grid-cols-2 space-x-3">
|
|
|
|
<div className="mb-5 flex grid grid-cols-2 items-start space-x-3">
|
|
|
|
<FormSelect
|
|
|
|
<FormSelect
|
|
|
|
display="block"
|
|
|
|
display="block"
|
|
|
|
errorMessage={offerFields?.location?.message}
|
|
|
|
errorMessage={offerFields?.location?.message}
|
|
|
@ -254,7 +258,7 @@ function FullTimeOfferDetailsForm({
|
|
|
|
icon={TrashIcon}
|
|
|
|
icon={TrashIcon}
|
|
|
|
label="Delete"
|
|
|
|
label="Delete"
|
|
|
|
variant="secondary"
|
|
|
|
variant="secondary"
|
|
|
|
onClick={() => setDialogOpen(true)}
|
|
|
|
onClick={() => remove(index)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -264,12 +268,12 @@ function FullTimeOfferDetailsForm({
|
|
|
|
|
|
|
|
|
|
|
|
type InternshipOfferDetailsFormProps = Readonly<{
|
|
|
|
type InternshipOfferDetailsFormProps = Readonly<{
|
|
|
|
index: number;
|
|
|
|
index: number;
|
|
|
|
setDialogOpen: (isOpen: boolean) => void;
|
|
|
|
remove: UseFieldArrayRemove;
|
|
|
|
}>;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
|
|
|
|
function InternshipOfferDetailsForm({
|
|
|
|
function InternshipOfferDetailsForm({
|
|
|
|
index,
|
|
|
|
index,
|
|
|
|
setDialogOpen,
|
|
|
|
remove,
|
|
|
|
}: InternshipOfferDetailsFormProps) {
|
|
|
|
}: InternshipOfferDetailsFormProps) {
|
|
|
|
const { register, formState } = useFormContext<{
|
|
|
|
const { register, formState } = useFormContext<{
|
|
|
|
offers: Array<InternshipOfferDetailsFormData>;
|
|
|
|
offers: Array<InternshipOfferDetailsFormData>;
|
|
|
@ -410,7 +414,7 @@ function InternshipOfferDetailsForm({
|
|
|
|
label="Delete"
|
|
|
|
label="Delete"
|
|
|
|
variant="secondary"
|
|
|
|
variant="secondary"
|
|
|
|
onClick={() => {
|
|
|
|
onClick={() => {
|
|
|
|
setDialogOpen(true);
|
|
|
|
remove(index);
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
@ -429,7 +433,6 @@ function OfferDetailsFormArray({
|
|
|
|
jobType,
|
|
|
|
jobType,
|
|
|
|
}: OfferDetailsFormArrayProps) {
|
|
|
|
}: OfferDetailsFormArrayProps) {
|
|
|
|
const { append, remove, fields } = fieldArrayValues;
|
|
|
|
const { append, remove, fields } = fieldArrayValues;
|
|
|
|
const [isDialogOpen, setDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
@ -437,44 +440,10 @@ function OfferDetailsFormArray({
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div key={item.id}>
|
|
|
|
<div key={item.id}>
|
|
|
|
{jobType === JobType.FullTime ? (
|
|
|
|
{jobType === JobType.FullTime ? (
|
|
|
|
<FullTimeOfferDetailsForm
|
|
|
|
<FullTimeOfferDetailsForm index={index} remove={remove} />
|
|
|
|
index={index}
|
|
|
|
|
|
|
|
setDialogOpen={setDialogOpen}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
<InternshipOfferDetailsForm
|
|
|
|
<InternshipOfferDetailsForm index={index} remove={remove} />
|
|
|
|
index={index}
|
|
|
|
|
|
|
|
setDialogOpen={setDialogOpen}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
<Dialog
|
|
|
|
|
|
|
|
isShown={isDialogOpen}
|
|
|
|
|
|
|
|
primaryButton={
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
display="block"
|
|
|
|
|
|
|
|
label="OK"
|
|
|
|
|
|
|
|
variant="primary"
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
remove(index);
|
|
|
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
secondaryButton={
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
display="block"
|
|
|
|
|
|
|
|
label="Cancel"
|
|
|
|
|
|
|
|
variant="tertiary"
|
|
|
|
|
|
|
|
onClick={() => setDialogOpen(false)}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
title="Remove this offer"
|
|
|
|
|
|
|
|
onClose={() => setDialogOpen(false)}>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
Are you sure you want to remove this offer? This action cannot
|
|
|
|
|
|
|
|
be reversed.
|
|
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
})}
|
|
|
@ -501,15 +470,16 @@ export default function OfferDetailsForm() {
|
|
|
|
const [isDialogOpen, setDialogOpen] = useState(false);
|
|
|
|
const [isDialogOpen, setDialogOpen] = useState(false);
|
|
|
|
const { control } = useFormContext();
|
|
|
|
const { control } = useFormContext();
|
|
|
|
const fieldArrayValues = useFieldArray({ control, name: 'offers' });
|
|
|
|
const fieldArrayValues = useFieldArray({ control, name: 'offers' });
|
|
|
|
|
|
|
|
const { append, remove } = fieldArrayValues;
|
|
|
|
|
|
|
|
|
|
|
|
const toggleJobType = () => {
|
|
|
|
const toggleJobType = () => {
|
|
|
|
fieldArrayValues.remove();
|
|
|
|
remove();
|
|
|
|
if (jobType === JobType.FullTime) {
|
|
|
|
if (jobType === JobType.FullTime) {
|
|
|
|
setJobType(JobType.Internship);
|
|
|
|
setJobType(JobType.Internship);
|
|
|
|
fieldArrayValues.append(defaultInternshipOfferValues);
|
|
|
|
append(defaultInternshipOfferValues);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setJobType(JobType.FullTime);
|
|
|
|
setJobType(JobType.FullTime);
|
|
|
|
fieldArrayValues.append(defaultFullTimeOfferValues);
|
|
|
|
append(defaultFullTimeOfferValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|