Skip to content

Commit

Permalink
Fix: 예약 승인 및 거절 시 캘린더에 바로 반영 안되는 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
MEGUMMY1 committed Aug 7, 2024
1 parent b37ec12 commit 1013d78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 6 additions & 3 deletions components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FullCalendar from '@fullcalendar/react';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin, { DateClickArg } from '@fullcalendar/interaction';
import { EventClickArg } from '@fullcalendar/core';
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { getMyMonthSchedule } from '@/pages/api/myActivities/apimyActivities';
import { CalendarProps } from './Calendar.types';
import { getMyMonthScheduleResponse } from '@/pages/api/myActivities/apimyActivities.types';
Expand All @@ -17,8 +17,9 @@ const Calendar: React.FC<CalendarProps> = ({ activityId }) => {
const darkMode = useRecoilValue(darkModeState);
const year = new Date().getFullYear().toString();
const month = (new Date().getMonth() + 1).toString().padStart(2, '0');
const queryClient = useQueryClient();

const { data, error, isLoading } = useQuery<
const { data, error, isLoading, refetch } = useQuery<
getMyMonthScheduleResponse[],
Error
>({
Expand All @@ -39,6 +40,9 @@ const Calendar: React.FC<CalendarProps> = ({ activityId }) => {
<ReservationModalContent
selectedDate={newDate}
activityId={activityId}
onActionComplete={() => {
refetch();
}}
/>
),
});
Expand All @@ -59,7 +63,6 @@ const Calendar: React.FC<CalendarProps> = ({ activityId }) => {
const events =
data?.flatMap((item: getMyMonthScheduleResponse) => {
const { date, reservations } = item;

const events = [];

if (reservations.completed > 0) {
Expand Down
17 changes: 15 additions & 2 deletions components/Calendar/ReservationModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const ApplicationList: React.FC<{
activityId: number;
scheduleId: number;
status: string;
}> = ({ activityId, scheduleId, status }) => {
onActionComplete: () => void;
}> = ({ activityId, scheduleId, status, onActionComplete }) => {
const {
data: timeSchedule,
isLoading: isTimeScheduleLoading,
Expand Down Expand Up @@ -167,6 +168,7 @@ const ApplicationList: React.FC<{
queryKey: ['myReservations', activityId],
});
refetch();
onActionComplete();
},
onError: (error) => {
console.error('Error updating reservation:', error);
Expand Down Expand Up @@ -255,7 +257,8 @@ const ApplicationList: React.FC<{
const ReservationModalContent: React.FC<{
selectedDate: Date;
activityId: number;
}> = ({ selectedDate, activityId }) => {
onActionComplete: () => void;
}> = ({ selectedDate, activityId, onActionComplete }) => {
const [selectedScheduleId, setSelectedScheduleId] = useState<number | null>(
null
);
Expand All @@ -267,6 +270,13 @@ const ReservationModalContent: React.FC<{
setSelectedScheduleId(scheduleId);
};

const handleActionComplete = () => {
refetchPending();
refetchConfirmed();
refetchDeclined();
onActionComplete();
};

const { data: pendingData, refetch: refetchPending } = useMyTimeSchedule({
activityId,
scheduleId: selectedScheduleId || 0,
Expand Down Expand Up @@ -319,6 +329,7 @@ const ReservationModalContent: React.FC<{
activityId={activityId}
scheduleId={selectedScheduleId}
status="pending"
onActionComplete={handleActionComplete}
/>
)}
</div>
Expand All @@ -333,6 +344,7 @@ const ReservationModalContent: React.FC<{
activityId={activityId}
scheduleId={selectedScheduleId}
status="confirmed"
onActionComplete={handleActionComplete}
/>
)}
</div>
Expand All @@ -347,6 +359,7 @@ const ReservationModalContent: React.FC<{
activityId={activityId}
scheduleId={selectedScheduleId}
status="declined"
onActionComplete={handleActionComplete}
/>
)}
</div>
Expand Down

0 comments on commit 1013d78

Please sign in to comment.