From 5fab1cf55aa388378388268946f4857e94b19434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=BAt?= Date: Fri, 9 Aug 2024 10:13:39 +0700 Subject: [PATCH] fix: fix btn cancel diplay toast --- .../@component/crud/c.review.comments.tsx | 54 ++++++------ .../@component/crud/r.review.comments.tsx | 32 ++++--- .../@component/crud/u.review.comments.tsx | 88 ++++++++++--------- 3 files changed, 88 insertions(+), 86 deletions(-) diff --git a/src/app/title/[slug]/reviews/@component/crud/c.review.comments.tsx b/src/app/title/[slug]/reviews/@component/crud/c.review.comments.tsx index b746a25..19173f7 100644 --- a/src/app/title/[slug]/reviews/@component/crud/c.review.comments.tsx +++ b/src/app/title/[slug]/reviews/@component/crud/c.review.comments.tsx @@ -16,7 +16,8 @@ const CReviewComments = (props: any) => { const [rating, setRating] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); - const handleSubmit = async () => { + const handleSubmit = async (e:React.FormEvent) => { + e.preventDefault() if (rating == null) { toast({ title: "Error!", @@ -33,35 +34,34 @@ const CReviewComments = (props: any) => { icon: , }); } - setTimeout(async () => { - if (rating != null && !hasReviewId) { - const data = await sendRequest({ - url: `${process.env.NEXT_PUBLIC_WEB_COMIC_API}/api/reviews`, - method: "POST", - body: { - comicId: id, - authorId: currentIdUser, - content: yourReviewComment, - rated: rating, - }, + + if (rating != null && !hasReviewId) { + const data = await sendRequest({ + url: `${process.env.NEXT_PUBLIC_WEB_COMIC_API}/api/reviews`, + method: "POST", + body: { + comicId: id, + authorId: currentIdUser, + content: yourReviewComment, + rated: rating, + }, + }); + if (data) { + fetchReviews(); + toast({ + title: "Success!", + description: "You have successfully reviewed", + icon: , }); - if (data) { - fetchReviews(); - toast({ - title: "Success!", - description: "You have successfully reviewed", - icon: , - }); - setYourReviewComment(""); - } + setYourReviewComment(""); } - setIsSubmitting(false); - }, 1); + } + setIsSubmitting(false); }; return (
e.preventDefault()} + onSubmit={handleSubmit} className={hasReviewId && "hidden"} > @@ -82,12 +82,12 @@ const CReviewComments = (props: any) => {