From 00fc5d59234f7fcd6a11a606ec043484439c5e15 Mon Sep 17 00:00:00 2001 From: ljh0608 Date: Wed, 7 Aug 2024 18:26:53 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20useEffect=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SelectScheduleTable.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pages/selectSchedule/components/SelectScheduleTable.tsx b/src/pages/selectSchedule/components/SelectScheduleTable.tsx index a73152b1..74e21913 100644 --- a/src/pages/selectSchedule/components/SelectScheduleTable.tsx +++ b/src/pages/selectSchedule/components/SelectScheduleTable.tsx @@ -40,19 +40,21 @@ function SelectScheduleTable({ timeSlots, availableDates }: TimetableStructure) }; const bottomItem = bottomItems[scheduleStep]; + const resetPriorities = (selectedSlots: SelectedSlotType) => { + const updatedSelectedSlots: SelectedSlotType = {}; + for (const key in selectedSlots) { + updatedSelectedSlots[key] = { + ...selectedSlots[key], + priority: 0, + }; + } + setSelectedSlots(updatedSelectedSlots); + }; + useEffect( () => { if (scheduleStep === 'selectTimeSlot') { - const resetPriorities = () => { - const updatedSchedules = Object.entries(selectedSlots).map((schedule) => { - if (schedule[1] && typeof schedule[1] === 'object') { - return [schedule[0], { ...schedule[1], priority: 0 }]; - } - return schedule; - }); - setSelectedSlots(Object.fromEntries(updatedSchedules)); - }; - resetPriorities(); + resetPriorities(selectedSlots); } }, [scheduleStep],