From ce70e3ec42ca608e2fcc63fb6da09d88cbfec3e6 Mon Sep 17 00:00:00 2001 From: keemsebeen <108217858+keemsebin@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:49:38 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=ED=9A=8C=EC=9B=90=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EC=9E=91=EC=84=B1=20=EC=97=AC=EB=B6=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=97=B0=EA=B2=B0=20(#242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/meeting/api.ts | 10 ++++++ src/apis/meeting/queries.ts | 4 +++ .../MeetingDetail/MemberScheduleCard.tsx | 32 ++++++++++++++++--- src/pages/MeetingDetail.tsx | 23 +++++++------ 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/apis/meeting/api.ts b/src/apis/meeting/api.ts index 4dcc051..825690d 100644 --- a/src/apis/meeting/api.ts +++ b/src/apis/meeting/api.ts @@ -45,4 +45,14 @@ export const meeting = { const response = await instance.get(`/meetings/${uuid}/participants`); return response.data; }, + /** + * @description 회원 일정 작성 여부 조회 + */ + checkSchedule: async (uuid: string) => { + const response = await instance.get(`/meetings/${uuid}/schedules/check`, { + withCredentials: true, + headers: { Authorization: localStorage.getItem('accessToken') }, + }); + return response.data; + }, }; diff --git a/src/apis/meeting/queries.ts b/src/apis/meeting/queries.ts index 27d19df..d0530a7 100644 --- a/src/apis/meeting/queries.ts +++ b/src/apis/meeting/queries.ts @@ -17,4 +17,8 @@ export const meeting = { queryKey: ['participants', uuid], queryFn: () => meetingApi.participants(uuid), }), + checkSchedule: (uuid: string) => ({ + queryKey: ['check-schedule', uuid], + queryFn: () => meetingApi.checkSchedule(uuid), + }), } as const; diff --git a/src/components/features/MeetingDetail/MemberScheduleCard.tsx b/src/components/features/MeetingDetail/MemberScheduleCard.tsx index 49f52bf..1938d97 100644 --- a/src/components/features/MeetingDetail/MemberScheduleCard.tsx +++ b/src/components/features/MeetingDetail/MemberScheduleCard.tsx @@ -1,5 +1,5 @@ import { css } from '@emotion/react'; -import { useSuspenseQuery } from '@tanstack/react-query'; +import { useQuery, useSuspenseQuery } from '@tanstack/react-query'; import { queries } from '@/apis'; import { Button } from '@/components/common/Button'; @@ -12,8 +12,34 @@ import { UuidProps, NavigateProps } from './MeetingDetail.type'; export type MemberScheduleProps = UuidProps & NavigateProps; export const MemberScheduleCard = ({ uuid, onNavigate }: MemberScheduleProps) => { + const accessToken = localStorage.getItem('accessToken'); + + const { data: checkScheduleData, isLoading: isScheduleLoading } = useQuery({ + ...queries.meeting.checkSchedule(uuid as string), + enabled: !!accessToken, + }); const { data: bestTime } = useSuspenseQuery(queries.meeting.bestTime(uuid)); + const renderButton = () => { + // TODO : 버튼에 로딩뷰 추가되면 변경 + if (isScheduleLoading) { + return ( + + ); + } + + const buttonText = checkScheduleData ? '일정 수정하기' : '일정 입력하기'; + const navigatePath = checkScheduleData ? `/${uuid}/edit` : `/${uuid}/new`; + + return ( + + ); + }; + return ( @@ -34,9 +60,7 @@ export const MemberScheduleCard = ({ uuid, onNavigate }: MemberScheduleProps) => )} - + {renderButton()}