From 001a18649b574cd3c29dfdda0feeb65c84f4852e Mon Sep 17 00:00:00 2001 From: Tan Su Yin Date: Mon, 10 Oct 2022 13:43:13 +0800 Subject: [PATCH] [resumes][refactor] Abstract out sign in button --- .../src/components/resumes/SignInButton.tsx | 24 ++++++++++ .../resumes/comments/CommentsList.tsx | 19 +++++++- .../resumes/comments/CommentsListButton.tsx | 48 ------------------- 3 files changed, 41 insertions(+), 50 deletions(-) create mode 100644 apps/portal/src/components/resumes/SignInButton.tsx delete mode 100644 apps/portal/src/components/resumes/comments/CommentsListButton.tsx diff --git a/apps/portal/src/components/resumes/SignInButton.tsx b/apps/portal/src/components/resumes/SignInButton.tsx new file mode 100644 index 00000000..8718e588 --- /dev/null +++ b/apps/portal/src/components/resumes/SignInButton.tsx @@ -0,0 +1,24 @@ +import { signIn } from 'next-auth/react'; + +type Props = Readonly<{ + text: string; +}>; + +export default function SignInButton({ text }: Props) { + return ( +
+

+ { + event.preventDefault(); + signIn(); + }}> + Sign in + {' '} + {text} +

+
+ ); +} diff --git a/apps/portal/src/components/resumes/comments/CommentsList.tsx b/apps/portal/src/components/resumes/comments/CommentsList.tsx index 56a1affa..b6907d27 100644 --- a/apps/portal/src/components/resumes/comments/CommentsList.tsx +++ b/apps/portal/src/components/resumes/comments/CommentsList.tsx @@ -1,12 +1,13 @@ import { useSession } from 'next-auth/react'; import { useState } from 'react'; import { Tabs } from '@tih/ui'; +import { Button } from '@tih/ui'; import { trpc } from '~/utils/trpc'; import Comment from './comment/Comment'; -import CommentsListButton from './CommentsListButton'; import { COMMENTS_SECTIONS } from './constants'; +import SignInButton from '../SignInButton'; type CommentsListProps = Readonly<{ resumeId: string; @@ -22,11 +23,25 @@ export default function CommentsList({ const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]); + const renderButton = () => { + if (session === null) { + return ; + } + return ( +