From a5361e926c1b9ed0580622e02669a134dfc0bbba Mon Sep 17 00:00:00 2001 From: Eunseo Sim <55528304+simeunseo@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:35:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ts=EC=97=90=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/OverallSchedule/OverallSchedule.tsx | 5 ++++- src/pages/selectSchedule/SelectSchedule.tsx | 5 ++++- .../components/selectPriority/PriorityDropdown.tsx | 3 ++- .../components/selectTimeSlot/hooks/useSlotSelection.ts | 6 ++++-- src/pages/selectSchedule/contexts/useSelectContext.ts | 8 ++++---- src/pages/selectSchedule/utils.ts | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/pages/OverallSchedule/OverallSchedule.tsx b/src/pages/OverallSchedule/OverallSchedule.tsx index 0ad82738..84a2d4ef 100644 --- a/src/pages/OverallSchedule/OverallSchedule.tsx +++ b/src/pages/OverallSchedule/OverallSchedule.tsx @@ -14,6 +14,9 @@ function OverallSchedule() { meetingId, ); + // 시간대 선택 단계가 없어질 것을 고려하여 상수값을 설정해놓음 + const PREFER_TIMES = { startTime: '06:00', endTime: '24:00' }; + return ( @@ -22,7 +25,7 @@ function OverallSchedule() { dataTimetable && dataOverallSchedule && ( <OverallScheduleTable - timeSlots={getAvailableTimes(dataTimetable.preferTimes[0])} + timeSlots={getAvailableTimes(PREFER_TIMES)} availableDates={dataTimetable.availableDates} dataOverallSchedule={dataOverallSchedule} /> diff --git a/src/pages/selectSchedule/SelectSchedule.tsx b/src/pages/selectSchedule/SelectSchedule.tsx index 7be6912b..6e8dadc1 100644 --- a/src/pages/selectSchedule/SelectSchedule.tsx +++ b/src/pages/selectSchedule/SelectSchedule.tsx @@ -18,6 +18,9 @@ function SelectSchedule() { const { meetingId } = useParams(); const { data, isLoading } = useGetTimetable(meetingId); + // 시간대 선택 단계가 없어질 것을 고려하여 상수값을 설정해놓음 + const PREFER_TIMES = { startTime: '06:00', endTime: '24:00' }; + return ( <ScheduleStepContext.Provider value={{ scheduleStep, setScheduleStep }}> <SelectScheduleWrapper> @@ -38,7 +41,7 @@ function SelectSchedule() { padding={scheduleStep === 'selectTimeSlot' ? `0 0 2.6rem` : `4.4rem 0 3.2rem 0`} /> <SelectScheduleTable - timeSlots={getAvailableTimes(data.preferTimes[0])} + timeSlots={getAvailableTimes(PREFER_TIMES)} availableDates={data.availableDates} /> </> diff --git a/src/pages/selectSchedule/components/selectPriority/PriorityDropdown.tsx b/src/pages/selectSchedule/components/selectPriority/PriorityDropdown.tsx index 10a317a5..2631b4e2 100644 --- a/src/pages/selectSchedule/components/selectPriority/PriorityDropdown.tsx +++ b/src/pages/selectSchedule/components/selectPriority/PriorityDropdown.tsx @@ -72,8 +72,9 @@ function PriorityDropdown() { temp = 0; break; } + setSelectedSlots((prev: SelectedSlotType) => { - const updatedSelectedSlots = Object.entries(prev).map(([key, value]) => { + const updatedSelectedSlots = Object.entries(prev).map(([_, value]) => { if (value.priority === temp) { return { ...value, priority: 0 }; } diff --git a/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts b/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts index 3d269310..abfadf2a 100644 --- a/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts +++ b/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts @@ -10,7 +10,7 @@ const useSlotSeletion = () => { const handleCompleteSlot = (targetSlot: string) => { const dateOfStartSlot = startSlot?.substring(0, startSlot.lastIndexOf('/')); const dateOfTargetSlot = targetSlot.substring(0, targetSlot.lastIndexOf('/')) - if (dateOfStartSlot === dateOfTargetSlot){ + if (startSlot && dateOfStartSlot === dateOfTargetSlot){ const newSelectedSlot = { date:dateOfStartSlot, startSlot:startSlot?.substring(startSlot.lastIndexOf('/')+1), @@ -20,7 +20,9 @@ const useSlotSeletion = () => { const keys = Object.keys(selectedSlots).map(Number) const newKey = keys.length ? Math.max(...keys) + 1 : 0; - setSelectedSlots({...selectedSlots, [newKey]:newSelectedSlot}) + const newSelectedSlots = {...selectedSlots}; + newSelectedSlots[newKey] = newSelectedSlot; + setSelectedSlots(newSelectedSlots) } setStartSlot(undefined); } diff --git a/src/pages/selectSchedule/contexts/useSelectContext.ts b/src/pages/selectSchedule/contexts/useSelectContext.ts index dd180135..2ab073d0 100644 --- a/src/pages/selectSchedule/contexts/useSelectContext.ts +++ b/src/pages/selectSchedule/contexts/useSelectContext.ts @@ -1,8 +1,8 @@ -import { createContext, useContext } from 'react'; +import { Dispatch, SetStateAction, createContext, useContext } from 'react'; export interface SelectSlotType { date: string; - startSlot?: string; + startSlot: string; endSlot: string; priority: number; } @@ -13,9 +13,9 @@ export interface SelectedSlotType { interface SelectContextType { startSlot: string | undefined; - setStartSlot: (startSlot?: string) => void; + setStartSlot: Dispatch<SetStateAction<SelectContextType['startSlot']>>; selectedSlots: SelectedSlotType; - setSelectedSlots: (selectedSlots: SelectedSlotType) => void; + setSelectedSlots: Dispatch<SetStateAction<SelectedSlotType>>; } export const SelectContext = createContext<SelectContextType>({ diff --git a/src/pages/selectSchedule/utils.ts b/src/pages/selectSchedule/utils.ts index 65f56b72..f05805a3 100644 --- a/src/pages/selectSchedule/utils.ts +++ b/src/pages/selectSchedule/utils.ts @@ -1,6 +1,6 @@ -import { SelectedSlotType } from 'components/timetableComponents/context'; import { addMinutes } from 'components/timetableComponents/utils'; +import { SelectedSlotType } from './contexts/useSelectContext'; import { TitlesType } from './types'; export const DURATION = {