|
|
@ -4,11 +4,11 @@ import type { SubmitHandler } from 'react-hook-form';
|
|
|
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
|
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
|
|
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid';
|
|
|
|
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid';
|
|
|
|
import { JobType } from '@prisma/client';
|
|
|
|
import { JobType } from '@prisma/client';
|
|
|
|
import { Button } from '@tih/ui';
|
|
|
|
import { Button, useToast } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
|
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
|
|
|
|
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
|
|
|
|
import type { BreadcrumbStep } from '~/components/offers/Breadcrumb';
|
|
|
|
import type { BreadcrumbStep } from '~/components/offers/Breadcrumbs';
|
|
|
|
import { Breadcrumbs } from '~/components/offers/Breadcrumb';
|
|
|
|
import { Breadcrumbs } from '~/components/offers/Breadcrumbs';
|
|
|
|
import BackgroundForm from '~/components/offers/offersSubmission/submissionForm/BackgroundForm';
|
|
|
|
import BackgroundForm from '~/components/offers/offersSubmission/submissionForm/BackgroundForm';
|
|
|
|
import OfferDetailsForm from '~/components/offers/offersSubmission/submissionForm/OfferDetailsForm';
|
|
|
|
import OfferDetailsForm from '~/components/offers/offersSubmission/submissionForm/OfferDetailsForm';
|
|
|
|
import type {
|
|
|
|
import type {
|
|
|
@ -102,8 +102,9 @@ export default function OffersSubmissionForm({
|
|
|
|
token: editToken,
|
|
|
|
token: editToken,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
|
|
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
|
|
|
const { event: gaEvent } = useGoogleAnalytics();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { event: gaEvent } = useGoogleAnalytics();
|
|
|
|
|
|
|
|
const { showToast } = useToast();
|
|
|
|
const router = useRouter();
|
|
|
|
const router = useRouter();
|
|
|
|
const pageRef = useRef<HTMLDivElement>(null);
|
|
|
|
const pageRef = useRef<HTMLDivElement>(null);
|
|
|
|
const scrollToTop = () =>
|
|
|
|
const scrollToTop = () =>
|
|
|
@ -132,13 +133,7 @@ export default function OffersSubmissionForm({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const steps = [
|
|
|
|
const steps = [<OfferDetailsForm key={0} />, <BackgroundForm key={1} />];
|
|
|
|
<OfferDetailsForm
|
|
|
|
|
|
|
|
key={0}
|
|
|
|
|
|
|
|
defaultJobType={initialOfferProfileValues.offers[0].jobType}
|
|
|
|
|
|
|
|
/>,
|
|
|
|
|
|
|
|
<BackgroundForm key={1} />,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const breadcrumbSteps: Array<BreadcrumbStep> = [
|
|
|
|
const breadcrumbSteps: Array<BreadcrumbStep> = [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -157,14 +152,14 @@ export default function OffersSubmissionForm({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const goToNextStep = async (currStep: number) => {
|
|
|
|
const setStepWithValidation = async (nextStep: number) => {
|
|
|
|
if (currStep === 0) {
|
|
|
|
if (nextStep === 1) {
|
|
|
|
const result = await trigger('offers');
|
|
|
|
const result = await trigger('offers');
|
|
|
|
if (!result) {
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setStep(step + 1);
|
|
|
|
setStep(nextStep);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const mutationpath =
|
|
|
|
const mutationpath =
|
|
|
@ -175,10 +170,24 @@ export default function OffersSubmissionForm({
|
|
|
|
const createOrUpdateMutation = trpc.useMutation([mutationpath], {
|
|
|
|
const createOrUpdateMutation = trpc.useMutation([mutationpath], {
|
|
|
|
onError(error) {
|
|
|
|
onError(error) {
|
|
|
|
console.error(error.message);
|
|
|
|
console.error(error.message);
|
|
|
|
|
|
|
|
showToast({
|
|
|
|
|
|
|
|
title:
|
|
|
|
|
|
|
|
editProfileId && editToken
|
|
|
|
|
|
|
|
? 'Error updating offer profile.'
|
|
|
|
|
|
|
|
: 'Error creating offer profile',
|
|
|
|
|
|
|
|
variant: 'failure',
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onSuccess(data) {
|
|
|
|
onSuccess(data) {
|
|
|
|
setParams({ profileId: data.id, token: data.token });
|
|
|
|
setParams({ profileId: data.id, token: data.token });
|
|
|
|
setIsSubmitted(true);
|
|
|
|
setIsSubmitted(true);
|
|
|
|
|
|
|
|
showToast({
|
|
|
|
|
|
|
|
title:
|
|
|
|
|
|
|
|
editProfileId && editToken
|
|
|
|
|
|
|
|
? 'Offer profile updated successfully!'
|
|
|
|
|
|
|
|
: 'Offer profile created successfully!',
|
|
|
|
|
|
|
|
variant: 'success',
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -270,7 +279,7 @@ export default function OffersSubmissionForm({
|
|
|
|
<div className="flex justify-center bg-slate-100 px-4 py-4 sm:px-6 lg:px-8">
|
|
|
|
<div className="flex justify-center bg-slate-100 px-4 py-4 sm:px-6 lg:px-8">
|
|
|
|
<Breadcrumbs
|
|
|
|
<Breadcrumbs
|
|
|
|
currentStep={step}
|
|
|
|
currentStep={step}
|
|
|
|
setStep={setStep}
|
|
|
|
setStep={setStepWithValidation}
|
|
|
|
steps={breadcrumbSteps}
|
|
|
|
steps={breadcrumbSteps}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -288,7 +297,7 @@ export default function OffersSubmissionForm({
|
|
|
|
label="Next"
|
|
|
|
label="Next"
|
|
|
|
variant="primary"
|
|
|
|
variant="primary"
|
|
|
|
onClick={() => {
|
|
|
|
onClick={() => {
|
|
|
|
goToNextStep(step);
|
|
|
|
setStepWithValidation(step + 1);
|
|
|
|
gaEvent({
|
|
|
|
gaEvent({
|
|
|
|
action: 'offers.profile_submission_navigate_next',
|
|
|
|
action: 'offers.profile_submission_navigate_next',
|
|
|
|
category: 'submission',
|
|
|
|
category: 'submission',
|
|
|
|