Skip to content

Commit

Permalink
fix: 등록, 조회모달 동시에 열리는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hafnium1923 committed Jul 20, 2023
1 parent 2236040 commit 6a732e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
32 changes: 22 additions & 10 deletions frontend/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { generateScheduleBars } from '~/utils/generateScheduleBars';
import ScheduleModal from '~/components/ScheduleModal/ScheduleModal';
import { useScheduleModal } from '~/hooks/schedule/useScheduleModal';
import { useModal } from '~/hooks/useModal';
import { DAYS_OF_WEEK } from '~/constants/calendar';
import { DAYS_OF_WEEK, MODAL_TYPE } from '~/constants/calendar';
import ScheduleAddModal from '~/components/ScheduleAddModal/ScheduleAddModal';
import { useFetchSchedules } from '~/hooks/queries/useFetchSchedules';
import { useState } from 'react';
import type { Modal } from '~/types/schedule';

const Calendar = () => {
const {
Expand All @@ -25,15 +27,21 @@ const Calendar = () => {
const {
modalScheduleId,
modalPosition,
handlers: { onScheduleModalOpen },
handlers: { handleScheduleModalOpen },
} = useScheduleModal();

const [modalType, setModalType] = useState<Modal>(MODAL_TYPE.ADD);

if (schedules === undefined) {
return null;
}

const scheduleBars = generateScheduleBars(year, month, schedules);

const handleAddModalOpen = () => {
setModalType(MODAL_TYPE.ADD);
openModal();
};

return (
<>
<S.Container>
Expand All @@ -56,7 +64,7 @@ const Calendar = () => {
>
<ArrowRightIcon />
</Button>
<Button css={S.scheduleAddButton} onClick={openModal}>
<Button css={S.scheduleAddButton} onClick={handleAddModalOpen}>
<PlusIcon />
</Button>
</S.ButtonContainer>
Expand Down Expand Up @@ -84,14 +92,15 @@ const Calendar = () => {
row={row}
column={column}
level={level}
onScheduleModalOpen={() =>
onScheduleModalOpen({
onScheduleModalOpen={() => {
setModalType(MODAL_TYPE.VIEW);
handleScheduleModalOpen({
scheduleId,
row,
column,
level,
})
}
});
}}
{...rest}
/>
);
Expand All @@ -106,6 +115,7 @@ const Calendar = () => {
key={day.toISOString()}
rawDate={day}
currentMonth={month}
onClick={handleAddModalOpen}
/>
);
})}
Expand All @@ -116,8 +126,10 @@ const Calendar = () => {
</div>
</div>
</S.Container>
{isModalOpen && <ScheduleAddModal teamPlaceName="팀바팀" />}
{isModalOpen && (
{isModalOpen && modalType === MODAL_TYPE.ADD && (
<ScheduleAddModal teamPlaceName="팀바팀" />
)}
{isModalOpen && modalType === MODAL_TYPE.VIEW && (
<ScheduleModal scheduleId={modalScheduleId} position={modalPosition} />
)}
</>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/constants/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export const CALENDAR = {
ROW_SIZE: 6,
COLUMN_SIZE: 7,
} as const;

export const MODAL_TYPE = {
ADD: 'add',
VIEW: 'view',
} as const;

export const MODAL_TYPE_LIST = [MODAL_TYPE.ADD, MODAL_TYPE.VIEW] as const;
4 changes: 4 additions & 0 deletions frontend/src/types/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { MODAL_TYPE_LIST } from '~/constants/calendar';

export interface Schedule {
id: number;
title: string;
Expand All @@ -17,3 +19,5 @@ export interface Position {
export interface SchedulePosition extends Position {
level: number;
}

export type Modal = (typeof MODAL_TYPE_LIST)[number];

0 comments on commit 6a732e9

Please sign in to comment.