Skip to content

Commit

Permalink
Merge pull request #235 from depromeet/fix/review
Browse files Browse the repository at this point in the history
fix: 리뷰 페이지 이동 조건 수정
  • Loading branch information
sjoleee authored Feb 2, 2024
2 parents 93d3c64 + 313205d commit d925b15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default function Home() {
/>
</Map>
</motion.div>
<div className="absolute top-[54px] z-above w-full px-[16px]">
<div className="absolute top-[8px] z-above w-full px-[16px]">
<SearchField onClick={handleSearchFieldClick} />
<FilterTagList
selectedTag={selectedTag}
Expand Down
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
1 change: 1 addition & 0 deletions src/hooks/api/useDeleteLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useDeleteLog = (): UseMutationResult<void, AxiosError, number> => {
mutationFn: (storeId) => deleteLog(storeId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['get-myLog'] });
queryClient.invalidateQueries({ queryKey: ['get-store'] });
},
});
};

0 comments on commit d925b15

Please sign in to comment.