+
+
- )}
- {getProfileQuery.isLoading && (
-
-
+
- )}
- {!getProfileQuery.isLoading && !getProfileQuery.isError && (
-
- )}
- >
+
+
+
);
}
diff --git a/apps/portal/src/pages/offers/submit/result/[offerProfileId].tsx b/apps/portal/src/pages/offers/submit/result/[offerProfileId].tsx
index f507283d..b8bde4a5 100644
--- a/apps/portal/src/pages/offers/submit/result/[offerProfileId].tsx
+++ b/apps/portal/src/pages/offers/submit/result/[offerProfileId].tsx
@@ -1,5 +1,6 @@
import Error from 'next/error';
import { useRouter } from 'next/router';
+import { useSession } from 'next-auth/react';
import { useEffect, useRef, useState } from 'react';
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/20/solid';
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 { trpc } from '~/utils/trpc';
-import type { ProfileAnalysis } from '~/types/offers';
-
export default function OffersSubmissionResult() {
const router = useRouter();
let { offerProfileId, token = '' } = router.query;
offerProfileId = offerProfileId as string;
token = token as string;
const [step, setStep] = useState(0);
- const [analysis, setAnalysis] = useState
(null);
- const [isValidToken, setIsValidToken] = useState(false);
+ const { data: session } = useSession();
const pageRef = useRef(null);
const scrollToTop = () =>
pageRef.current?.scrollTo({ behavior: 'smooth', top: 0 });
- const checkToken = trpc.useQuery(
- ['offers.profile.isValidToken', { profileId: offerProfileId, token }],
- {
- onSuccess(data) {
- setIsValidToken(data);
- },
- },
- );
+ const checkToken = trpc.useQuery([
+ 'offers.profile.isValidToken',
+ { profileId: offerProfileId, token },
+ ]);
- const getAnalysis = trpc.useQuery(
- ['offers.analysis.get', { profileId: offerProfileId }],
- {
- onSuccess(data) {
- setAnalysis(data);
- },
- },
- );
+ const getAnalysis = trpc.useQuery([
+ 'offers.analysis.get',
+ { profileId: offerProfileId },
+ ]);
+
+ const isSavedQuery = trpc.useQuery([
+ `offers.profile.isSaved`,
+ { profileId: offerProfileId, userId: session?.user?.id },
+ ]);
const steps = [
- ,
+ ,
,
@@ -77,71 +77,67 @@ export default function OffersSubmissionResult() {
scrollToTop();
}, [step]);
- return (
- <>
- {(checkToken.isLoading || getAnalysis.isLoading) && (
-
-
-
-
Loading...
+ return checkToken.isLoading || getAnalysis.isLoading ? (
+
+ ) : checkToken.isError || getAnalysis.isError ? (
+
+ ) : checkToken.isSuccess && !checkToken.data ? (
+
+ ) : (
+
+
+
- )}
- {checkToken.isSuccess && !isValidToken && (
-
- )}
- {getAnalysis.isSuccess && (
-
-
-
-
-
+ {steps[step]}
+ {step === 0 && (
+
+
-
- {steps[step]}
- {step === 0 && (
-
-
- )}
- {step === 1 && (
-
-
- )}
+ )}
+ {step === 1 && (
+
+ setStep(step - 1)}
+ />
+
-
+ )}
- )}
- >
+
+
);
}
diff --git a/apps/portal/src/utils/offers/time.tsx b/apps/portal/src/utils/offers/time.tsx
index 5c7305dd..d61ef3a6 100644
--- a/apps/portal/src/utils/offers/time.tsx
+++ b/apps/portal/src/utils/offers/time.tsx
@@ -55,3 +55,18 @@ export function getCurrentYear() {
export function convertToMonthYear(date: Date) {
return { month: date.getMonth() + 1, year: date.getFullYear() } as MonthYear;
}
+
+export function getDurationDisplayText(months: number) {
+ const years = Math.floor(months / 12);
+ const monthsRemainder = months % 12;
+ let durationDisplay = '';
+ if (years > 0) {
+ durationDisplay = `${years} year${years > 1 ? 's' : ''}`;
+ }
+ if (monthsRemainder > 0) {
+ durationDisplay = durationDisplay.concat(
+ ` ${monthsRemainder} month${monthsRemainder > 1 ? 's' : ''}`,
+ );
+ }
+ return durationDisplay;
+}