From bcf30d92a87dd4ca5ec91c06511f4c32064a9acc Mon Sep 17 00:00:00 2001 From: Ai Ling Date: Sun, 23 Oct 2022 18:32:01 +0800 Subject: [PATCH] [offers][fix] Disable empty comments --- .../offers/profile/ProfileComments.tsx | 31 ++++++++++++++++--- .../offers/profile/comments/CommentCard.tsx | 5 +++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/apps/portal/src/components/offers/profile/ProfileComments.tsx b/apps/portal/src/components/offers/profile/ProfileComments.tsx index d30645a8..5a8ba614 100644 --- a/apps/portal/src/components/offers/profile/ProfileComments.tsx +++ b/apps/portal/src/components/offers/profile/ProfileComments.tsx @@ -1,7 +1,13 @@ import { signIn, useSession } from 'next-auth/react'; import { useState } from 'react'; import { ClipboardDocumentIcon, ShareIcon } from '@heroicons/react/24/outline'; -import { Button, HorizontalDivider, Spinner, TextArea } from '@tih/ui'; +import { + Button, + HorizontalDivider, + Spinner, + TextArea, + useToast, +} from '@tih/ui'; import ExpandableCommentCard from '~/components/offers/profile/comments/ExpandableCommentCard'; @@ -30,6 +36,7 @@ export default function ProfileComments({ const { data: session, status } = useSession(); const [currentReply, setCurrentReply] = useState(''); const [replies, setReplies] = useState>(); + const { showToast } = useToast(); const commentsQuery = trpc.useQuery( ['offers.comments.getComments', { profileId }], @@ -51,6 +58,10 @@ export default function ProfileComments({ }); function handleComment(message: string) { + if (!currentReply.length) { + return; + } + if (isEditable) { // If it is with edit permission, send comment to API with username = null createCommentMutation.mutate( @@ -104,7 +115,13 @@ export default function ProfileComments({ label="Copy profile edit link" size="sm" variant="secondary" - onClick={() => copyProfileLink(profileId, token)} + onClick={() => { + copyProfileLink(profileId, token); + showToast({ + title: `Profile edit link copied to clipboard!`, + variant: 'success', + }); + }} /> )}