|
|
@ -1,5 +1,6 @@
|
|
|
|
import Error from 'next/error';
|
|
|
|
import Error from 'next/error';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
|
|
|
import { useSession } from 'next-auth/react';
|
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
|
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid';
|
|
|
|
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid';
|
|
|
|
import { EyeIcon } from '@heroicons/react/24/outline';
|
|
|
|
import { EyeIcon } from '@heroicons/react/24/outline';
|
|
|
@ -13,44 +14,43 @@ import OffersSubmissionAnalysis from '~/components/offers/offersSubmission/Offer
|
|
|
|
import { getProfilePath } from '~/utils/offers/link';
|
|
|
|
import { getProfilePath } from '~/utils/offers/link';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
|
|
import type { ProfileAnalysis } from '~/types/offers';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function OffersSubmissionResult() {
|
|
|
|
export default function OffersSubmissionResult() {
|
|
|
|
const router = useRouter();
|
|
|
|
const router = useRouter();
|
|
|
|
let { offerProfileId, token = '' } = router.query;
|
|
|
|
let { offerProfileId, token = '' } = router.query;
|
|
|
|
offerProfileId = offerProfileId as string;
|
|
|
|
offerProfileId = offerProfileId as string;
|
|
|
|
token = token as string;
|
|
|
|
token = token as string;
|
|
|
|
const [step, setStep] = useState(0);
|
|
|
|
const [step, setStep] = useState(0);
|
|
|
|
const [analysis, setAnalysis] = useState<ProfileAnalysis | null>(null);
|
|
|
|
const { data: session } = useSession();
|
|
|
|
const [isValidToken, setIsValidToken] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pageRef = useRef<HTMLDivElement>(null);
|
|
|
|
const pageRef = useRef<HTMLDivElement>(null);
|
|
|
|
const scrollToTop = () =>
|
|
|
|
const scrollToTop = () =>
|
|
|
|
pageRef.current?.scrollTo({ behavior: 'smooth', top: 0 });
|
|
|
|
pageRef.current?.scrollTo({ behavior: 'smooth', top: 0 });
|
|
|
|
|
|
|
|
|
|
|
|
const checkToken = trpc.useQuery(
|
|
|
|
const checkToken = trpc.useQuery([
|
|
|
|
['offers.profile.isValidToken', { profileId: offerProfileId, token }],
|
|
|
|
'offers.profile.isValidToken',
|
|
|
|
{
|
|
|
|
{ profileId: offerProfileId, token },
|
|
|
|
onSuccess(data) {
|
|
|
|
]);
|
|
|
|
setIsValidToken(data);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getAnalysis = trpc.useQuery(
|
|
|
|
const getAnalysis = trpc.useQuery([
|
|
|
|
['offers.analysis.get', { profileId: offerProfileId }],
|
|
|
|
'offers.analysis.get',
|
|
|
|
{
|
|
|
|
{ profileId: offerProfileId },
|
|
|
|
onSuccess(data) {
|
|
|
|
]);
|
|
|
|
setAnalysis(data);
|
|
|
|
|
|
|
|
},
|
|
|
|
const isSavedQuery = trpc.useQuery([
|
|
|
|
},
|
|
|
|
`offers.profile.isSaved`,
|
|
|
|
);
|
|
|
|
{ profileId: offerProfileId, userId: session?.user?.id },
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const steps = [
|
|
|
|
const steps = [
|
|
|
|
<OffersProfileSave key={0} profileId={offerProfileId} token={token} />,
|
|
|
|
<OffersProfileSave
|
|
|
|
|
|
|
|
key={0}
|
|
|
|
|
|
|
|
isSavedQuery={isSavedQuery}
|
|
|
|
|
|
|
|
profileId={offerProfileId}
|
|
|
|
|
|
|
|
token={token}
|
|
|
|
|
|
|
|
/>,
|
|
|
|
<OffersSubmissionAnalysis
|
|
|
|
<OffersSubmissionAnalysis
|
|
|
|
key={1}
|
|
|
|
key={1}
|
|
|
|
analysis={analysis}
|
|
|
|
analysis={getAnalysis.data}
|
|
|
|
isError={getAnalysis.isError}
|
|
|
|
isError={getAnalysis.isError}
|
|
|
|
isLoading={getAnalysis.isLoading}
|
|
|
|
isLoading={getAnalysis.isLoading}
|
|
|
|
/>,
|
|
|
|
/>,
|
|
|
@ -77,71 +77,67 @@ export default function OffersSubmissionResult() {
|
|
|
|
scrollToTop();
|
|
|
|
scrollToTop();
|
|
|
|
}, [step]);
|
|
|
|
}, [step]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return checkToken.isLoading || getAnalysis.isLoading ? (
|
|
|
|
<>
|
|
|
|
<div className="flex h-screen w-screen">
|
|
|
|
{(checkToken.isLoading || getAnalysis.isLoading) && (
|
|
|
|
<div className="m-auto mx-auto w-screen justify-center font-medium text-slate-500">
|
|
|
|
<div className="flex h-screen w-screen">
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
<div className="m-auto mx-auto w-screen justify-center font-medium text-slate-500">
|
|
|
|
<div className="text-center">Loading...</div>
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
</div>
|
|
|
|
<div className="text-center">Loading...</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : checkToken.isError || getAnalysis.isError ? (
|
|
|
|
|
|
|
|
<Error statusCode={404} title="Error loading page" />
|
|
|
|
|
|
|
|
) : checkToken.isSuccess && !checkToken.data ? (
|
|
|
|
|
|
|
|
<Error
|
|
|
|
|
|
|
|
statusCode={403}
|
|
|
|
|
|
|
|
title="You do not have permissions to access this page"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
|
|
|
|
<div ref={pageRef} className="w-full">
|
|
|
|
|
|
|
|
<div className="flex justify-center">
|
|
|
|
|
|
|
|
<div className="block w-full max-w-screen-md overflow-hidden rounded-lg sm:shadow-lg md:my-10">
|
|
|
|
|
|
|
|
<div className="flex justify-center bg-slate-100 px-4 py-4 sm:px-6 lg:px-8">
|
|
|
|
|
|
|
|
<Breadcrumbs
|
|
|
|
|
|
|
|
currentStep={step}
|
|
|
|
|
|
|
|
setStep={setStep}
|
|
|
|
|
|
|
|
steps={breadcrumbSteps}
|
|
|
|
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="bg-white p-6 sm:p-10">
|
|
|
|
)}
|
|
|
|
{steps[step]}
|
|
|
|
{checkToken.isSuccess && !isValidToken && (
|
|
|
|
{step === 0 && (
|
|
|
|
<Error
|
|
|
|
<div className="flex justify-end">
|
|
|
|
statusCode={403}
|
|
|
|
<Button
|
|
|
|
title="You do not have permissions to access this page"
|
|
|
|
disabled={false}
|
|
|
|
/>
|
|
|
|
icon={ArrowRightIcon}
|
|
|
|
)}
|
|
|
|
label="Next"
|
|
|
|
{getAnalysis.isSuccess && (
|
|
|
|
variant="primary"
|
|
|
|
<div ref={pageRef} className="w-full">
|
|
|
|
onClick={() => setStep(step + 1)}
|
|
|
|
<div className="flex justify-center">
|
|
|
|
|
|
|
|
<div className="block w-full max-w-screen-md overflow-hidden rounded-lg sm:shadow-lg md:my-10">
|
|
|
|
|
|
|
|
<div className="flex justify-center bg-slate-100 px-4 py-4 sm:px-6 lg:px-8">
|
|
|
|
|
|
|
|
<Breadcrumbs
|
|
|
|
|
|
|
|
currentStep={step}
|
|
|
|
|
|
|
|
setStep={setStep}
|
|
|
|
|
|
|
|
steps={breadcrumbSteps}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="bg-white p-6 sm:p-10">
|
|
|
|
)}
|
|
|
|
{steps[step]}
|
|
|
|
{step === 1 && (
|
|
|
|
{step === 0 && (
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<div className="flex justify-end">
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
addonPosition="start"
|
|
|
|
disabled={false}
|
|
|
|
icon={ArrowLeftIcon}
|
|
|
|
icon={ArrowRightIcon}
|
|
|
|
label="Previous"
|
|
|
|
label="Next"
|
|
|
|
variant="secondary"
|
|
|
|
variant="primary"
|
|
|
|
onClick={() => setStep(step - 1)}
|
|
|
|
onClick={() => setStep(step + 1)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
</div>
|
|
|
|
href={getProfilePath(
|
|
|
|
)}
|
|
|
|
offerProfileId as string,
|
|
|
|
{step === 1 && (
|
|
|
|
token as string,
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
)}
|
|
|
|
<Button
|
|
|
|
icon={EyeIcon}
|
|
|
|
addonPosition="start"
|
|
|
|
label="View your profile"
|
|
|
|
icon={ArrowLeftIcon}
|
|
|
|
variant="primary"
|
|
|
|
label="Previous"
|
|
|
|
/>
|
|
|
|
variant="secondary"
|
|
|
|
|
|
|
|
onClick={() => setStep(step - 1)}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
href={getProfilePath(
|
|
|
|
|
|
|
|
offerProfileId as string,
|
|
|
|
|
|
|
|
token as string,
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
icon={EyeIcon}
|
|
|
|
|
|
|
|
label="View your profile"
|
|
|
|
|
|
|
|
variant="primary"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|