From e3620faafe64c392dfb11b530fada2172bbf4e0c Mon Sep 17 00:00:00 2001 From: Terence <45381509+Vielheim@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:21:03 +0800 Subject: [PATCH] [resumes][refactor] redirect user to signin on vote (#443) Co-authored-by: Terence Ho <> --- .../comments/comment/ResumeCommentVoteButtons.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx b/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx index 4faf1397..12c3a387 100644 --- a/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx +++ b/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx @@ -1,4 +1,5 @@ import clsx from 'clsx'; +import { useRouter } from 'next/router'; import { useState } from 'react'; import { ArrowDownCircleIcon, @@ -21,6 +22,7 @@ export default function ResumeCommentVoteButtons({ const [downvoteAnimation, setDownvoteAnimation] = useState(false); const trpcContext = trpc.useContext(); + const router = useRouter(); // COMMENT VOTES const commentVotesQuery = trpc.useQuery([ @@ -47,6 +49,11 @@ export default function ResumeCommentVoteButtons({ ); const onVote = async (value: Vote, setAnimation: (_: boolean) => void) => { + if (!userId) { + router.push('/api/auth/signin'); + return; + } + setAnimation(true); if (commentVotesQuery.data?.userVote?.value === value) { @@ -74,7 +81,6 @@ export default function ResumeCommentVoteButtons({ <> <button disabled={ - !userId || commentVotesQuery.isLoading || commentVotesUpsertMutation.isLoading || commentVotesDeleteMutation.isLoading @@ -103,7 +109,6 @@ export default function ResumeCommentVoteButtons({ <button disabled={ - !userId || commentVotesQuery.isLoading || commentVotesUpsertMutation.isLoading || commentVotesDeleteMutation.isLoading