From 47fbd4bd28369b905085873a53dc38f41911bc37 Mon Sep 17 00:00:00 2001 From: sjoleee Date: Sat, 3 Feb 2024 02:27:40 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A6=AC=EB=B7=B0=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99=20=EC=A1=B0=EA=B1=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/main/WriteLogButton/index.tsx | 41 +++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/main/WriteLogButton/index.tsx b/src/components/main/WriteLogButton/index.tsx index 64195b49..514097de 100644 --- a/src/components/main/WriteLogButton/index.tsx +++ b/src/components/main/WriteLogButton/index.tsx @@ -1,7 +1,7 @@ 'use client'; import { useRouter } from 'next/navigation'; -import { ButtonHTMLAttributes, useEffect } from 'react'; +import { ButtonHTMLAttributes, useEffect, useState } from 'react'; import { toast } from 'sonner'; import { SearchedPinFromSearchParams } from '../StorePreviewSection'; @@ -27,13 +27,8 @@ export default function WriteLogButton({ ...restProps }: WriteLogButtonProps) { const router = useRouter(); - - const { - refetch: getReviewAvailable, - isRefetching, - isSuccess, - data, - } = useGetReviewAvailable({ + const [isFetched, setIsFetched] = useState(false); + const { refetch: getReviewAvailable, data } = useGetReviewAvailable({ storeId: storeId ?? undefined, }); @@ -81,24 +76,32 @@ export default function WriteLogButton({ router.push(String(url)); }; + const handleWriteLogButtonClick = async () => { + if (!storeId) { + goToReview(); + return; + } + + try { + await getReviewAvailable(); + + setIsFetched(true); + } catch (error) { + toast('에러 발생! 다시 시도해주세요.'); + } + }; + useEffect(() => { - if (isRefetching || !isSuccess) return; + if (!isFetched) return; + setIsFetched(false); - if (!data.isAvailable) { + if (data?.isAvailable === false) { toast('같은 곳은 하루에 3번만 기록 가능해요!'); return; } goToReview(); - }, [isRefetching, isSuccess]); - - const handleWriteLogButtonClick = () => { - if (!storeId) { - goToReview(); - return; - } - getReviewAvailable(); - }; + }, [isFetched]); return (