Skip to content

Commit

Permalink
feat : 회원 입력 여부에 따른 버튼 상태 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
keemsebin committed Oct 8, 2024
1 parent 0a49032 commit da41794
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/components/features/MeetingDetail/MemberScheduleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { css } from '@emotion/react';
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';

Expand All @@ -13,12 +14,33 @@ export type MemberScheduleProps = UuidProps & NavigateProps;

export const MemberScheduleCard = ({ uuid, onNavigate }: MemberScheduleProps) => {
const accessToken = localStorage.getItem('accessToken');
const { data: checkScheduleData } = useQuery({

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 (
<Button variant="primary" height="medium" disabled>
로딩 중..
</Button>
);
}

const buttonText = checkScheduleData ? '일정 수정하기' : '일정 입력하기';
const navigatePath = checkScheduleData ? `/${uuid}/edit` : `/${uuid}/new`;

return (
<Button variant="primary" height="medium" onClick={() => onNavigate(navigatePath)}>
{buttonText}
</Button>
);
};

return (
<FlexBox width="100%" padding="30px 20px 10px 20px">
<Card emojiPosition="top-right">
Expand All @@ -39,15 +61,7 @@ export const MemberScheduleCard = ({ uuid, onNavigate }: MemberScheduleProps) =>
)}
</FlexBox>
<FlexBox flexDir="row" gap={10} padding="20px 0 0 0">
{accessToken && checkScheduleData ? (
<Button variant="primary" height="medium" onClick={() => onNavigate(`/${uuid}/edit`)}>
일정 수정하기
</Button>
) : (
<Button variant="primary" height="medium" onClick={() => onNavigate(`/${uuid}/new`)}>
일정 입력하기
</Button>
)}
{renderButton()}
<Button
variant={bestTime ? 'tertiary' : 'primary'}
height="medium"
Expand Down

0 comments on commit da41794

Please sign in to comment.