Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 예약 승인 및 거절 시 캘린더에 바로 반영 안되는 이슈 해결 #81

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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