|
|
|
@ -4,7 +4,7 @@ import Error from 'next/error';
|
|
|
|
|
import Head from 'next/head';
|
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
import { useSession } from 'next-auth/react';
|
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import {
|
|
|
|
|
AcademicCapIcon,
|
|
|
|
|
BriefcaseIcon,
|
|
|
|
@ -22,12 +22,11 @@ import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
export default function ResumeReviewPage() {
|
|
|
|
|
const ErrorPage = (
|
|
|
|
|
<Error statusCode={404} title="Requested resume does not exist." />
|
|
|
|
|
<Error statusCode={404} title="Requested resume does not exist" />
|
|
|
|
|
);
|
|
|
|
|
const { data: session } = useSession();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { resumeId } = router.query;
|
|
|
|
|
const trpcContext = trpc.useContext();
|
|
|
|
|
// Safe to assert resumeId type as string because query is only sent if so
|
|
|
|
|
const detailsQuery = trpc.useQuery(
|
|
|
|
|
['resumes.resume.findOne', { resumeId: resumeId as string }],
|
|
|
|
@ -35,31 +34,59 @@ export default function ResumeReviewPage() {
|
|
|
|
|
enabled: typeof resumeId === 'string',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const starMutation = trpc.useMutation('resumes.star.user.create_or_delete', {
|
|
|
|
|
onSuccess() {
|
|
|
|
|
trpcContext.invalidateQueries(['resumes.resume.findOne']);
|
|
|
|
|
const starMutation = trpc.useMutation('resumes.resume.star', {
|
|
|
|
|
onError() {
|
|
|
|
|
setStarDetails({
|
|
|
|
|
isStarred: false,
|
|
|
|
|
numStars: starDetails.numStars - 1,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const unstarMutation = trpc.useMutation('resumes.resume.unstar', {
|
|
|
|
|
onError() {
|
|
|
|
|
setStarDetails({
|
|
|
|
|
isStarred: true,
|
|
|
|
|
numStars: starDetails.numStars + 1,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const [starDetails, setStarDetails] = useState({
|
|
|
|
|
isStarred: false,
|
|
|
|
|
numStars: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (detailsQuery.data?.stars.length) {
|
|
|
|
|
document.getElementById('star-button')?.focus();
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('star-button')?.blur();
|
|
|
|
|
if (detailsQuery?.data !== undefined) {
|
|
|
|
|
setStarDetails({
|
|
|
|
|
isStarred: !!detailsQuery.data?.stars.length,
|
|
|
|
|
numStars: detailsQuery.data?._count.stars ?? 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [detailsQuery.data?.stars]);
|
|
|
|
|
}, [detailsQuery.data]);
|
|
|
|
|
|
|
|
|
|
const onStarButtonClick = () => {
|
|
|
|
|
setStarDetails({
|
|
|
|
|
isStarred: !starDetails.isStarred,
|
|
|
|
|
numStars: starDetails.isStarred
|
|
|
|
|
? starDetails.numStars - 1
|
|
|
|
|
: starDetails.numStars + 1,
|
|
|
|
|
});
|
|
|
|
|
// Star button only rendered if resume exists
|
|
|
|
|
// Star button only clickable if user exists
|
|
|
|
|
starMutation.mutate({
|
|
|
|
|
resumeId: resumeId as string,
|
|
|
|
|
});
|
|
|
|
|
if (starDetails.isStarred) {
|
|
|
|
|
unstarMutation.mutate({
|
|
|
|
|
resumeId: resumeId as string,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
starMutation.mutate({
|
|
|
|
|
resumeId: resumeId as string,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{detailsQuery.isError && ErrorPage}
|
|
|
|
|
{(detailsQuery.isError || detailsQuery.data === null) && ErrorPage}
|
|
|
|
|
{detailsQuery.isLoading && (
|
|
|
|
|
<div className="w-full pt-4">
|
|
|
|
|
{' '}
|
|
|
|
@ -71,14 +98,19 @@ export default function ResumeReviewPage() {
|
|
|
|
|
<Head>
|
|
|
|
|
<title>{detailsQuery.data.title}</title>
|
|
|
|
|
</Head>
|
|
|
|
|
<main className="h-[calc(100vh-2rem)] flex-1 overflow-y-scroll p-4">
|
|
|
|
|
<main className="h-[calc(100vh-2rem)] flex-1 overflow-y-auto p-4">
|
|
|
|
|
<div className="flex flex-row space-x-8">
|
|
|
|
|
<h1 className="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
|
|
|
|
|
{detailsQuery.data.title}
|
|
|
|
|
</h1>
|
|
|
|
|
<button
|
|
|
|
|
className="isolate inline-flex max-h-10 items-center space-x-4 rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:z-10 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
|
|
|
|
|
disabled={session?.user === null}
|
|
|
|
|
className={clsx(
|
|
|
|
|
starDetails.isStarred
|
|
|
|
|
? 'z-10 border-indigo-500 outline-none ring-1 ring-indigo-500'
|
|
|
|
|
: '',
|
|
|
|
|
'isolate inline-flex max-h-10 items-center space-x-4 rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 disabled:hover:bg-white',
|
|
|
|
|
)}
|
|
|
|
|
disabled={session?.user === undefined}
|
|
|
|
|
id="star-button"
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onStarButtonClick}>
|
|
|
|
@ -86,7 +118,7 @@ export default function ResumeReviewPage() {
|
|
|
|
|
<StarIcon
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
className={clsx(
|
|
|
|
|
detailsQuery.data?.stars.length
|
|
|
|
|
starDetails.isStarred
|
|
|
|
|
? 'text-orange-400'
|
|
|
|
|
: 'text-gray-400',
|
|
|
|
|
'-ml-1 mr-2 h-5 w-5',
|
|
|
|
@ -96,7 +128,7 @@ export default function ResumeReviewPage() {
|
|
|
|
|
Star
|
|
|
|
|
</span>
|
|
|
|
|
<span className="relative -ml-px inline-flex">
|
|
|
|
|
{detailsQuery.data._count.stars}
|
|
|
|
|
{starDetails.numStars}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|