Skip to content

Commit

Permalink
fix: 리뷰 페이지 이동 조건 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoleee committed Feb 2, 2024
1 parent 93d3c64 commit 47fbd4b
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/components/main/WriteLogButton/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
});

Expand Down Expand Up @@ -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 (
<Button
Expand Down

0 comments on commit 47fbd4b

Please sign in to comment.