|
|
@ -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,23 +77,21 @@ export default function OffersSubmissionResult() {
|
|
|
|
scrollToTop();
|
|
|
|
scrollToTop();
|
|
|
|
}, [step]);
|
|
|
|
}, [step]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return checkToken.isLoading || getAnalysis.isLoading ? (
|
|
|
|
<>
|
|
|
|
|
|
|
|
{(checkToken.isLoading || getAnalysis.isLoading) && (
|
|
|
|
|
|
|
|
<div className="flex h-screen w-screen">
|
|
|
|
<div className="flex h-screen w-screen">
|
|
|
|
<div className="m-auto mx-auto w-screen justify-center font-medium text-slate-500">
|
|
|
|
<div className="m-auto mx-auto w-screen justify-center font-medium text-slate-500">
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
<div className="text-center">Loading...</div>
|
|
|
|
<div className="text-center">Loading...</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
) : checkToken.isError || getAnalysis.isError ? (
|
|
|
|
{checkToken.isSuccess && !isValidToken && (
|
|
|
|
<Error statusCode={404} title="Error loading page" />
|
|
|
|
|
|
|
|
) : checkToken.isSuccess && !checkToken.data ? (
|
|
|
|
<Error
|
|
|
|
<Error
|
|
|
|
statusCode={403}
|
|
|
|
statusCode={403}
|
|
|
|
title="You do not have permissions to access this page"
|
|
|
|
title="You do not have permissions to access this page"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
) : (
|
|
|
|
{getAnalysis.isSuccess && (
|
|
|
|
|
|
|
|
<div ref={pageRef} className="w-full">
|
|
|
|
<div ref={pageRef} className="w-full">
|
|
|
|
<div className="flex justify-center">
|
|
|
|
<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="block w-full max-w-screen-md overflow-hidden rounded-lg sm:shadow-lg md:my-10">
|
|
|
@ -141,7 +139,5 @@ export default function OffersSubmissionResult() {
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|