[resumes][refactor] Add check for user session in comments

pull/313/head
Terence Ho 3 years ago
parent 63ac210ef7
commit c41669ee0a

@ -65,8 +65,11 @@ export default function CommentsForm({
}; };
return ( return (
<> <div className="h-[calc(100vh-13rem)] overflow-y-scroll">
<h2 className="text-xl font-semibold text-gray-800">Add your review</h2> <h2 className="text-xl font-semibold text-gray-800">Add your review</h2>
<p className="text-gray-800">
Please fill in at least one section to submit your review
</p>
<form <form
className="w-full space-y-8 divide-y divide-gray-200" className="w-full space-y-8 divide-y divide-gray-200"
@ -155,6 +158,6 @@ export default function CommentsForm({
}}> }}>
<div>Note that your review will not be saved!</div> <div>Note that your review will not be saved!</div>
</Dialog> </Dialog>
</> </div>
); );
} }

@ -1,8 +1,9 @@
import { useState } from 'react'; import { useState } from 'react';
import { Button, Tabs } from '@tih/ui'; import { Tabs } from '@tih/ui';
import { trpc } from '~/utils/trpc'; import { trpc } from '~/utils/trpc';
import CommentsListButton from './CommentsListButton';
import { COMMENTS_SECTIONS } from './constants'; import { COMMENTS_SECTIONS } from './constants';
type CommentsListProps = Readonly<{ type CommentsListProps = Readonly<{
@ -23,13 +24,8 @@ export default function CommentsList({
/* eslint-enable no-console */ /* eslint-enable no-console */
return ( return (
<> <div className="space-y-3">
<Button <CommentsListButton setShowCommentsForm={setShowCommentsForm} />
display="block"
label="Add your review"
variant="tertiary"
onClick={() => setShowCommentsForm(true)}
/>
<Tabs <Tabs
label="comments" label="comments"
tabs={COMMENTS_SECTIONS} tabs={COMMENTS_SECTIONS}
@ -37,6 +33,6 @@ export default function CommentsList({
onChange={(value) => setTab(value)} onChange={(value) => setTab(value)}
/> />
{/* TODO: Add comments lists */} {/* TODO: Add comments lists */}
</> </div>
); );
} }

@ -0,0 +1,48 @@
import { signIn, useSession } from 'next-auth/react';
import { Button } from '@tih/ui';
type CommentsListButtonProps = {
setShowCommentsForm: (show: boolean) => void;
};
export default function CommentsListButton({
setShowCommentsForm,
}: CommentsListButtonProps) {
const { data: session, status } = useSession();
const isSessionLoading = status === 'loading';
// Don't render anything
if (isSessionLoading) {
return null;
}
// Not signed in
if (session == null) {
return (
<div className="flex justify-center">
<p>
<a
className="text-primary-800 hover:text-primary-500"
href="/api/auth/signin"
onClick={(event) => {
event.preventDefault();
signIn();
}}>
Sign in
</a>{' '}
to join discussion
</p>
</div>
);
}
// Signed in. Return Add review button
return (
<Button
display="block"
label="Add your review"
variant="tertiary"
onClick={() => setShowCommentsForm(true)}
/>
);
}
Loading…
Cancel
Save