From fc06de187cdbfade54c92840f9e0c8a43ef1dddf Mon Sep 17 00:00:00 2001 From: Ai Ling Date: Thu, 20 Oct 2022 16:44:30 +0800 Subject: [PATCH] [offers][fix] Fix offer analysis and save --- .../offers-submission/OfferAnalysis.tsx | 61 +++++++++---------- .../offers-submission/OfferProfileSave.tsx | 38 +++++++++--- .../analysis/OfferPercentileAnalysis.tsx | 0 .../analysis/OfferProfileCard.tsx | 2 +- .../offers/profile/ProfileComments.tsx | 18 +----- .../pages/offers/profile/[offerProfileId].tsx | 3 +- apps/portal/src/pages/offers/submit.tsx | 8 ++- .../router/offers/offers-analysis-router.ts | 2 +- apps/portal/src/utils/offers/link.tsx | 15 +++++ 9 files changed, 89 insertions(+), 58 deletions(-) rename apps/portal/src/components/offers/{ => offers-submission}/analysis/OfferPercentileAnalysis.tsx (100%) rename apps/portal/src/components/offers/{ => offers-submission}/analysis/OfferProfileCard.tsx (97%) create mode 100644 apps/portal/src/utils/offers/link.tsx diff --git a/apps/portal/src/components/offers/offers-submission/OfferAnalysis.tsx b/apps/portal/src/components/offers/offers-submission/OfferAnalysis.tsx index 6a0717da..72700766 100644 --- a/apps/portal/src/components/offers/offers-submission/OfferAnalysis.tsx +++ b/apps/portal/src/components/offers/offers-submission/OfferAnalysis.tsx @@ -1,12 +1,11 @@ -import Error from 'next/error'; import { useEffect } from 'react'; import { useState } from 'react'; import { HorizontalDivider, Spinner, Tabs } from '@tih/ui'; import { trpc } from '~/utils/trpc'; -import OfferPercentileAnalysis from '../analysis/OfferPercentileAnalysis'; -import OfferProfileCard from '../analysis/OfferProfileCard'; +import OfferPercentileAnalysis from './analysis/OfferPercentileAnalysis'; +import OfferProfileCard from './analysis/OfferProfileCard'; import { OVERALL_TAB } from '../constants'; import type { @@ -105,34 +104,32 @@ export default function OfferAnalysis({ profileId }: OfferAnalysisProps) { ]; return ( - <> - {getAnalysisResult.isError && ( - - )} - {!getAnalysisResult.isError && analysis && ( -
-
- Result -
- {getAnalysisResult.isLoading ? ( - - ) : ( -
- - - -
- )} -
- )} - + analysis && ( +
+
+ Result +
+ {getAnalysisResult.isError && ( +

+ An error occurred while generating profile analysis. +

+ )} + {getAnalysisResult.isLoading && ( + + )} + {!getAnalysisResult.isError && !getAnalysisResult.isLoading && ( +
+ + + +
+ )} +
+ ) ); } diff --git a/apps/portal/src/components/offers/offers-submission/OfferProfileSave.tsx b/apps/portal/src/components/offers/offers-submission/OfferProfileSave.tsx index 44c61ed7..071da82a 100644 --- a/apps/portal/src/components/offers/offers-submission/OfferProfileSave.tsx +++ b/apps/portal/src/components/offers/offers-submission/OfferProfileSave.tsx @@ -1,13 +1,30 @@ +import { useRouter } from 'next/router'; import { useState } from 'react'; import { setTimeout } from 'timers'; import { CheckIcon, DocumentDuplicateIcon } from '@heroicons/react/20/solid'; import { BookmarkSquareIcon, EyeIcon } from '@heroicons/react/24/outline'; import { Button, TextInput } from '@tih/ui'; -export default function OfferProfileSave() { +import { + copyProfileLink, + getProfileLink, + getProfilePath, +} from '~/utils/offers/link'; + +type OfferProfileSaveProps = Readonly<{ + profileId: string; + token?: string; +}>; + +export default function OfferProfileSave({ + profileId, + token, +}: OfferProfileSaveProps) { const [linkCopied, setLinkCopied] = useState(false); const [isSaving, setSaving] = useState(false); const [isSaved, setSaved] = useState(false); + const router = useRouter(); + const saveProfile = () => { setSaving(true); setTimeout(() => { @@ -27,13 +44,13 @@ export default function OfferProfileSave() { To keep you offer profile strictly anonymous, only people who have the link below can edit it.

-
+
-
+
{linkCopied && (

Link copied to clipboard!

)} @@ -60,13 +79,18 @@ export default function OfferProfileSave() { disabled={isSaved} icon={isSaved ? CheckIcon : BookmarkSquareIcon} isLoading={isSaving} - label="Save to user profile" + label={isSaved ? 'Saved to user profile' : 'Save to user profile'} variant="primary" onClick={saveProfile} />
-
diff --git a/apps/portal/src/components/offers/analysis/OfferPercentileAnalysis.tsx b/apps/portal/src/components/offers/offers-submission/analysis/OfferPercentileAnalysis.tsx similarity index 100% rename from apps/portal/src/components/offers/analysis/OfferPercentileAnalysis.tsx rename to apps/portal/src/components/offers/offers-submission/analysis/OfferPercentileAnalysis.tsx diff --git a/apps/portal/src/components/offers/analysis/OfferProfileCard.tsx b/apps/portal/src/components/offers/offers-submission/analysis/OfferProfileCard.tsx similarity index 97% rename from apps/portal/src/components/offers/analysis/OfferProfileCard.tsx rename to apps/portal/src/components/offers/offers-submission/analysis/OfferProfileCard.tsx index 9969c953..8d087a0c 100644 --- a/apps/portal/src/components/offers/analysis/OfferProfileCard.tsx +++ b/apps/portal/src/components/offers/offers-submission/analysis/OfferProfileCard.tsx @@ -3,7 +3,7 @@ import { UserCircleIcon } from '@heroicons/react/24/outline'; import { HorizontalDivider } from '~/../../../packages/ui/dist'; import { formatDate } from '~/utils/offers/time'; -import { JobType } from '../types'; +import { JobType } from '../../types'; import type { AnalysisOffer } from '~/types/offers'; diff --git a/apps/portal/src/components/offers/profile/ProfileComments.tsx b/apps/portal/src/components/offers/profile/ProfileComments.tsx index ecf1843d..d30645a8 100644 --- a/apps/portal/src/components/offers/profile/ProfileComments.tsx +++ b/apps/portal/src/components/offers/profile/ProfileComments.tsx @@ -5,6 +5,7 @@ import { Button, HorizontalDivider, Spinner, TextArea } from '@tih/ui'; import ExpandableCommentCard from '~/components/offers/profile/comments/ExpandableCommentCard'; +import { copyProfileLink } from '~/utils/offers/link'; import { trpc } from '~/utils/trpc'; import type { OffersDiscussion, Reply } from '~/types/offers'; @@ -84,19 +85,6 @@ export default function ProfileComments({ } } - function handleCopyEditLink() { - // TODO: Add notification - navigator.clipboard.writeText( - `${window.location.origin}/offers/profile/${profileId}?token=${token}`, - ); - } - - function handleCopyPublicLink() { - navigator.clipboard.writeText( - `${window.location.origin}/offers/profile/${profileId}`, - ); - } - if (isLoading) { return (
@@ -116,7 +104,7 @@ export default function ProfileComments({ label="Copy profile edit link" size="sm" variant="secondary" - onClick={handleCopyEditLink} + onClick={() => copyProfileLink(profileId, token)} /> )}

Discussions

diff --git a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx index 6bef7241..84f23620 100644 --- a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx +++ b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx @@ -8,6 +8,7 @@ import ProfileHeader from '~/components/offers/profile/ProfileHeader'; import type { BackgroundCard, OfferEntity } from '~/components/offers/types'; import { convertCurrencyToString } from '~/utils/offers/currency'; +import { getProfilePath } from '~/utils/offers/link'; import { formatDate } from '~/utils/offers/time'; import { trpc } from '~/utils/trpc'; @@ -38,7 +39,7 @@ export default function OfferProfile() { } // If the profile is not editable with a wrong token, redirect to the profile page if (!data?.isEditable && token !== '') { - router.push(`/offers/profile/${offerProfileId}`); + router.push(getProfilePath(offerProfileId as string)); } setIsEditable(data?.isEditable ?? false); diff --git a/apps/portal/src/pages/offers/submit.tsx b/apps/portal/src/pages/offers/submit.tsx index 6847bbf7..0f9714fc 100644 --- a/apps/portal/src/pages/offers/submit.tsx +++ b/apps/portal/src/pages/offers/submit.tsx @@ -96,7 +96,13 @@ export default function OffersSubmissionPage() { label: 'Analysis', }, { - component: , + component: ( + + ), hasNext: false, hasPrevious: false, label: 'Save', diff --git a/apps/portal/src/server/router/offers/offers-analysis-router.ts b/apps/portal/src/server/router/offers/offers-analysis-router.ts index 25611507..37b0d83b 100644 --- a/apps/portal/src/server/router/offers/offers-analysis-router.ts +++ b/apps/portal/src/server/router/offers/offers-analysis-router.ts @@ -216,7 +216,7 @@ export const offersAnalysisRouter = createRouter() // TODO: Shift yoe out of background to make it mandatory if ( !overallHighestOffer.profile.background || - !overallHighestOffer.profile.background.totalYoe + overallHighestOffer.profile.background.totalYoe === undefined ) { throw new TRPCError({ code: 'BAD_REQUEST', diff --git a/apps/portal/src/utils/offers/link.tsx b/apps/portal/src/utils/offers/link.tsx new file mode 100644 index 00000000..791e335c --- /dev/null +++ b/apps/portal/src/utils/offers/link.tsx @@ -0,0 +1,15 @@ +export function getProfileLink(profileId: string, token?: string) { + return `${window.location.origin}${getProfilePath(profileId, token)}`; +} + +export function copyProfileLink(profileId: string, token?: string) { + // TODO: Add notification + navigator.clipboard.writeText(getProfileLink(profileId, token)); +} + +export function getProfilePath(profileId: string, token?: string) { + if (token) { + return `/offers/profile/${profileId}?token=${token}`; + } + return `/offers/profile/${profileId}`; +}