Skip to content

Commit

Permalink
fix: prevent multiple post request
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed Oct 1, 2024
1 parent eed0e1b commit 4daf96e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ export function TravelerActivityRecommendation({
const { createToast } = useToast();

useEffect(() => {
createToast(
'info',
'기존 계획에 특정 시간대가 추가되어있다면, 추천에서 해당 시간대를 추가하더라도 추가되지 않습니다.',
5000,
);
if (!isLoading)
createToast(
'info',
'기존 계획에 특정 시간대가 추가되어있다면, 추천에서 해당 시간대를 추가하더라도 추가되지 않습니다.',
5000,
);
}, [isLoading]);

return (
Expand Down
39 changes: 23 additions & 16 deletions src/components/travel/traveler/TravelerScheduleConfirm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import styled from '@emotion/styled';
import { useState } from 'react';

import { useToast } from '@/features/toast';
import {
Expand All @@ -22,6 +23,8 @@ export function TravelerScheduleConfirm({
}) {
const { tourInfo, activities, setIsLoading, load } = useTripStore();

const [enabled, setEnabled] = useState<boolean>(true);

const { createToast } = useToast();

return (
Expand All @@ -46,6 +49,8 @@ export function TravelerScheduleConfirm({
))}
<styles.confirmButton
onClick={() => {
if (!enabled) return;

if (
!tourInfo.name ||
!tourInfo.locationName ||
Expand Down Expand Up @@ -76,22 +81,24 @@ export function TravelerScheduleConfirm({
contentTypeId: act.tourSpotDto.typeId,
},
})),
}).then((res) => {
const { data: logId } = res;

setIsLoading(true);
getTripSchedule(logId)
.then((dto) => {
load(dto);
onNextPage();
})
.catch(() => {
createToast('error', '다시 시도해주세요.');
})
.finally(() => {
setIsLoading(false);
});
});
})
.then((res) => {
const { data: logId } = res;

setIsLoading(true);
getTripSchedule(logId)
.then((dto) => {
load(dto);
onNextPage();
})
.catch(() => {
createToast('error', '다시 시도해주세요.');
})
.finally(() => {
setIsLoading(false);
});
})
.finally(() => setEnabled(false));
}}
>
여행 완성
Expand Down

0 comments on commit 4daf96e

Please sign in to comment.