-
Notifications
You must be signed in to change notification settings - Fork 0
featu: web-23 캘린더 일정 조회 페이지 #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chlgusdn0203
wants to merge
1
commit into
develop
Choose a base branch
from
feature-web-23
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,5 +12,3 @@ export const DROPDOWN_TYPE = { | |
| MONTH: 'month', | ||
| YEAR: 'year', | ||
| }; | ||
|
|
||
| export const SCHEDULES = []; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| import { useEffect, useMemo, useRef, useState } from 'react'; | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
|
|
||
| import { | ||
| createCalendarSchedule, | ||
| deleteCalendarSchedules, | ||
| getAdminCalendar, | ||
| getAdminCalendarMonth, | ||
| updateCalendarSchedule, | ||
| } from '@/apis/calendar'; | ||
| import AlertModal from '@/components/admin/AlertModal'; | ||
| import Header from '@/components/layout/Header'; | ||
| import AdminCalendarView from '@/components/schedule/AdminCalendarView'; | ||
| import AllScheduleView from '@/components/schedule/AllScheduleView'; | ||
| import ScheduleStyles from '@/styles/ScheduleStyles'; | ||
| import { CLUB_START_YEAR, DROPDOWN_TYPE, SCHEDULES, VIEW_MODE } from '@/constants/schedule'; | ||
| import { CLUB_START_YEAR, DROPDOWN_TYPE, VIEW_MODE } from '@/constants/schedule'; | ||
| import { | ||
| formatAdminDate, | ||
| formatDateKey, | ||
|
|
@@ -17,6 +25,10 @@ import { | |
| updateScrollThumb, | ||
| } from '@/utils/schedule'; | ||
|
|
||
| const FETCH_ERROR_MESSAGE = '일정을 불러오지 못했습니다.\n잠시 후 다시 시도해주세요.'; | ||
| const SAVE_ERROR_MESSAGE = '일정 저장에 실패했습니다.\n잠시 후 다시 시도해주세요.'; | ||
| const DELETE_ERROR_MESSAGE = '일정 삭제에 실패했습니다.\n잠시 후 다시 시도해주세요.'; | ||
|
|
||
| function AdminSchedulePage() { | ||
| const monthListRef = useRef(null); | ||
| const monthTrackRef = useRef(null); | ||
|
|
@@ -46,21 +58,21 @@ function AdminSchedulePage() { | |
| const [viewMode, setViewMode] = useState(VIEW_MODE.CALENDAR); | ||
| const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
| const [schedulesToDelete, setSchedulesToDelete] = useState([]); | ||
| const [localSchedules, setLocalSchedules] = useState([]); | ||
|
|
||
| const allSchedules = useMemo(() => [...SCHEDULES, ...localSchedules], [localSchedules]); | ||
| const [yearSchedules, setYearSchedules] = useState([]); | ||
| const [monthSchedules, setMonthSchedules] = useState([]); | ||
| const [alertMessage, setAlertMessage] = useState(null); | ||
|
|
||
| const calendarDates = useMemo(() => getCalendarDates(year, month), [year, month]); | ||
| const scheduleDateKeys = useMemo(() => getScheduleDateKeys(allSchedules), [allSchedules]); | ||
| const scheduleDateKeys = useMemo(() => getScheduleDateKeys(monthSchedules), [monthSchedules]); | ||
| const visibleSchedules = useMemo(() => { | ||
| const filteredSchedules = | ||
| viewMode === VIEW_MODE.ALL | ||
| ? allSchedules.filter( | ||
| ? yearSchedules.filter( | ||
| (schedule) => parseLocalDate(schedule.startDate).getFullYear() === year | ||
| ) | ||
| : allSchedules.filter((schedule) => isScheduleInMonth(schedule, year, month)); | ||
| : monthSchedules.filter((schedule) => isScheduleInMonth(schedule, year, month)); | ||
| return [...filteredSchedules].sort(sortByStartDate); | ||
| }, [allSchedules, month, viewMode, year]); | ||
| }, [month, monthSchedules, viewMode, year, yearSchedules]); | ||
| const scheduleMonthEntries = useMemo( | ||
| () => Object.entries(groupSchedulesByMonth(visibleSchedules)), | ||
| [visibleSchedules] | ||
|
|
@@ -87,37 +99,89 @@ function AdminSchedulePage() { | |
| setOpenedDropdown(null); | ||
| }; | ||
|
|
||
| const handleAddSchedule = ({ dateKey, endDateKey, title }) => { | ||
| setLocalSchedules((prev) => [ | ||
| ...prev, | ||
| { id: `local-${Date.now()}`, startDate: dateKey, endDate: endDateKey ?? dateKey, title }, | ||
| ]); | ||
| const fetchYearSchedules = useCallback(async () => { | ||
| try { | ||
| const scheduleList = await getAdminCalendar(year); | ||
| setYearSchedules(scheduleList); | ||
| } catch (error) { | ||
| console.error('[AdminSchedulePage] 연간 일정 조회 실패', error); | ||
| setYearSchedules([]); | ||
| setAlertMessage(FETCH_ERROR_MESSAGE); | ||
| } | ||
| }, [year]); | ||
|
|
||
| const fetchMonthSchedules = useCallback(async () => { | ||
| try { | ||
| const scheduleList = await getAdminCalendarMonth({ year, month: month + 1 }); | ||
| setMonthSchedules(scheduleList); | ||
| } catch (error) { | ||
| console.error('[AdminSchedulePage] 월간 일정 조회 실패', error); | ||
| setMonthSchedules([]); | ||
| setAlertMessage(FETCH_ERROR_MESSAGE); | ||
| } | ||
| }, [month, year]); | ||
|
|
||
| useEffect(() => { | ||
| if (viewMode === VIEW_MODE.ALL) fetchYearSchedules(); | ||
| }, [viewMode, fetchYearSchedules]); | ||
|
|
||
| useEffect(() => { | ||
| if (viewMode === VIEW_MODE.CALENDAR) fetchMonthSchedules(); | ||
| }, [viewMode, fetchMonthSchedules]); | ||
|
|
||
| const handleAddSchedule = async ({ dateKey, endDateKey, title }) => { | ||
| try { | ||
| await createCalendarSchedule({ | ||
| title, | ||
| startDate: dateKey, | ||
| endDate: endDateKey ?? dateKey, | ||
| }); | ||
| await fetchMonthSchedules(); | ||
| } catch (error) { | ||
| console.error('[AdminSchedulePage] 일정 등록 실패', error); | ||
| setAlertMessage(SAVE_ERROR_MESSAGE); | ||
| } | ||
| }; | ||
|
|
||
| const handleSaveEdits = (updatedSchedules) => { | ||
| setLocalSchedules((prev) => | ||
| prev.map((s) => { | ||
| const edited = updatedSchedules.find((u) => u.id === s.id); | ||
| return edited ? { ...s, title: edited.title } : s; | ||
| }) | ||
| const handleSaveEdits = async (updatedSchedules) => { | ||
| const changedSchedules = updatedSchedules.filter( | ||
| (edited, index) => edited.title !== visibleSchedules[index]?.title | ||
| ); | ||
| if (changedSchedules.length === 0) return; | ||
|
|
||
| try { | ||
| await Promise.all( | ||
| changedSchedules.map((schedule) => | ||
| updateCalendarSchedule(schedule.calendarId, { | ||
| title: schedule.title, | ||
| startDate: schedule.startDate, | ||
| endDate: schedule.endDate, | ||
| }) | ||
| ) | ||
| ); | ||
| await fetchMonthSchedules(); | ||
| } catch (error) { | ||
| console.error('[AdminSchedulePage] 일정 수정 실패', error); | ||
| setAlertMessage(SAVE_ERROR_MESSAGE); | ||
| } | ||
|
Comment on lines
+152
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
오류가 발생하더라도 최종적으로 try {
await Promise.all(
changedSchedules.map((schedule) =>
updateCalendarSchedule(schedule.calendarId, {
title: schedule.title,
startDate: schedule.startDate,
endDate: schedule.endDate,
})
)
);
} catch (error) {
console.error('[AdminSchedulePage] 일정 수정 실패', error);
setAlertMessage(SAVE_ERROR_MESSAGE);
} finally {
await fetchMonthSchedules();
} |
||
| }; | ||
|
|
||
| const handleDeleteSchedule = (toDelete) => { | ||
| if (!toDelete || toDelete.length === 0) return; | ||
| setSchedulesToDelete(toDelete); | ||
| setIsDeleteModalOpen(true); | ||
| }; | ||
| const handleDeleteConfirm = () => { | ||
| setLocalSchedules((prev) => | ||
| prev.filter( | ||
| (s) => | ||
| !schedulesToDelete.some( | ||
| (d) => d.startDate === s.startDate && d.endDate === s.endDate && d.title === s.title | ||
| ) | ||
| ) | ||
| ); | ||
| setIsDeleteModalOpen(false); | ||
| setSchedulesToDelete([]); | ||
| const handleDeleteConfirm = async () => { | ||
| try { | ||
| await deleteCalendarSchedules(schedulesToDelete.map((schedule) => schedule.calendarId)); | ||
| await (viewMode === VIEW_MODE.ALL ? fetchYearSchedules() : fetchMonthSchedules()); | ||
| } catch (error) { | ||
| console.error('[AdminSchedulePage] 일정 삭제 실패', error); | ||
| setAlertMessage(DELETE_ERROR_MESSAGE); | ||
| } finally { | ||
| setIsDeleteModalOpen(false); | ||
| setSchedulesToDelete([]); | ||
| } | ||
| }; | ||
| const handleDeleteCancel = () => { | ||
| setIsDeleteModalOpen(false); | ||
|
|
@@ -291,6 +355,10 @@ function AdminSchedulePage() { | |
| </div> | ||
| )} | ||
| </section> | ||
|
|
||
| {alertMessage && ( | ||
| <AlertModal message={alertMessage} onConfirm={() => setAlertMessage(null)} /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updatedSchedules와visibleSchedules를 인덱스(index) 기준으로 비교하여 변경 여부를 판단하고 있습니다.하지만 React의 상태 변경이나 비동기 데이터 갱신 등으로 인해
visibleSchedules의 순서나 원소 개수가 변할 경우, 인덱스 기반 비교는 잘못된 객체를 비교하거나undefined참조 오류를 발생시킬 수 있어 안전하지 않습니다.고유 식별자인
calendarId를 사용하여 원래 일정을 찾아 비교하는 것이 훨씬 안전하고 견고합니다.