Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Content = styled.div`
export const TextWrapper = styled.div`
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
`

Expand Down
11 changes: 8 additions & 3 deletions src/features/Calendar/hooks/useCalendarDraftEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ export const useCalendarDraftEvent = ({
updateEventTiming,
}: UseCalendarDraftEventArgs) => {
const handleCloseModalWithCleanup = useCallback(() => {
if (!isModalEditing && modal.eventId != null) {
removeEvent(modal.eventId)
if (modal.eventId != null) {
const shouldRemoveDraft =
!isModalEditing ||
events.some((eventItem) => eventItem.id === modal.eventId && eventItem.isTemporary)
if (shouldRemoveDraft) {
removeEvent(modal.eventId)
}
}
handleCloseModal()
}, [handleCloseModal, isModalEditing, modal.eventId, removeEvent])
}, [events, handleCloseModal, isModalEditing, modal.eventId, removeEvent])

const clearPendingDraftEvent = useCallback(() => {
if (!modal.isOpen || isModalEditing || modal.eventId == null) return
Expand Down
4 changes: 3 additions & 1 deletion src/features/Calendar/hooks/useCalendarEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export const useCalendarEvents = (options: UseCalendarEventsOptions = {}) => {
// 서버 응답 후 임시 이벤트 id를 실제 id로 교체
const updateEventId = useCallback((tempId: CalendarEvent['id'], nextId: CalendarEvent['id']) => {
setEvents((prev) =>
prev.map((event) => (event.id === tempId ? { ...event, id: nextId } : event)),
prev.map((event) =>
event.id === tempId ? { ...event, id: nextId, isTemporary: false } : event,
),
)
}, [])

Expand Down
1 change: 1 addition & 0 deletions src/features/Calendar/utils/helpers/calendarPageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const createEvent = (date: Date, index: number, allDay = false): Calendar
recurrenceGroup: null,
friendIds: [],
type: 'schedule',
isTemporary: true,
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/features/Todo/components/TodoCard/TodoCard.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export const ButtonWrapper = styled.div`
}
}
`
export const DeleteButton = styled.button`
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0;
border: 0;
background: transparent;
cursor: pointer;
`
export const TodoLeftWrapper = styled.div`
display: flex;
gap: 16px;
Expand Down
9 changes: 6 additions & 3 deletions src/features/Todo/components/TodoCard/TodoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ const TodoCard = ({
</S.TodoLeftWrapper>
<S.ButtonWrapper>
<PriorityBadge priority={priority} />
<Trash
color="#c5c5c5"
<S.DeleteButton
type="button"
aria-label={`${title} 삭제`}
onClick={(event) => {
event.stopPropagation()
handleDelete()
}}
/>
>
<Trash color="#c5c5c5" />
</S.DeleteButton>
</S.ButtonWrapper>
{openDeleteModal && isRecurringTodo && (
<DeleteConfirmModal
Expand Down
9 changes: 8 additions & 1 deletion src/shared/hooks/addSchedule/useScheduleFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const useScheduleFooter = ({
const occurrenceDateRef = useRef(occurrenceDate)
const closeModalRef = useRef(closeModal)
const deleteEventMutateRef = useRef(deleteEventMutate)
const isTemporaryEventRef = useRef(Boolean(initialEvent?.isTemporary))
const canEditRef = useRef(canEdit)
const onReadOnlyAttemptRef = useRef(onReadOnlyAttempt)
const eventColorRef = useRef(eventColor)
Expand All @@ -72,6 +73,7 @@ export const useScheduleFooter = ({
occurrenceDateRef.current = occurrenceDate
closeModalRef.current = closeModal
deleteEventMutateRef.current = deleteEventMutate
isTemporaryEventRef.current = Boolean(initialEvent?.isTemporary)
canEditRef.current = canEdit
onReadOnlyAttemptRef.current = onReadOnlyAttempt
eventColorRef.current = eventColor
Expand All @@ -86,6 +88,11 @@ export const useScheduleFooter = ({
onReadOnlyAttemptRef.current?.()
return
}
if (eventIdRef.current == null || eventIdRef.current === 0 || isTemporaryEventRef.current) {
setDeleteWarningVisible(false)
closeModalRef.current()
return
}
if (repeatConfigRef.current.repeatType !== 'none') {
setDeleteWarningVisible(true)
return
Expand Down Expand Up @@ -130,7 +137,7 @@ export const useScheduleFooter = ({
if (currentEventId != null && currentEventId !== 0) {
onEventColorChangeRef.current?.(currentEventId, value)
}
if (!isEditingRef.current) {
if (!isEditingRef.current || isTemporaryEventRef.current) {
return
}
const nextValues = { ...getValuesRef.current(), eventColor: value }
Expand Down
2 changes: 1 addition & 1 deletion src/shared/hooks/addSchedule/useSchedulePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const useSchedulePatch = ({
}: UseSchedulePatchArgs) =>
useCallback(
(values: ScheduleEditorFormValues, scope?: RecurrenceEventScope, occurrenceDate?: string) => {
if (eventId == null || eventId === 0) return Promise.resolve()
if (eventId == null || eventId === 0 || initialEvent?.isTemporary) return Promise.resolve()
const startDate = values.eventStartDate ?? new Date(date)
const endDate = values.eventEndDate ?? startDate
const [start, end] = values.isAllday
Expand Down
3 changes: 2 additions & 1 deletion src/shared/hooks/addSchedule/useScheduleSubmitFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const useScheduleSubmitFlow = ({
}, [])

const showToast = useToastStore.getState().showToast
const isTemporaryEvent = Boolean(initialEvent?.isTemporary)

const confirmTitle = useCallback(
(values: ScheduleEditorFormValues) => {
Expand Down Expand Up @@ -163,7 +164,7 @@ export const useScheduleSubmitFlow = ({
return
}
await submitScheduleValues(values, {
mode: isEditing ? 'patch' : 'create',
mode: isEditing && !isTemporaryEvent ? 'patch' : 'create',
})
},
(errors) => {
Expand Down
5 changes: 4 additions & 1 deletion src/shared/hooks/addTodo/useTodoDetailHydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type UseTodoDetailHydrationProps = {
date: string
eventId: CalendarEvent['id']
isEditing: boolean
initialEvent?: CalendarEvent | null
todoDate: Date | null
setValue: UseFormSetValue<TodoEditorFormValues>
}
Expand All @@ -20,11 +21,13 @@ export const useTodoDetailHydration = ({
date,
eventId,
isEditing,
initialEvent,
todoDate,
setValue,
}: UseTodoDetailHydrationProps) => {
const hydratedDetailKeyRef = useRef<string | null>(null)
const isPersistedTodo = isEditing && eventId != null && eventId !== 0
const isPersistedTodo =
isEditing && eventId != null && eventId !== 0 && !initialEvent?.isTemporary
const shouldFetchDetail = isPersistedTodo
const detailOccurrenceDate = moment(date).format('YYYY-MM-DD')
const { data: detailData } = useGetDetailTodoQuery(
Expand Down
7 changes: 6 additions & 1 deletion src/shared/hooks/addTodo/useTodoFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ export const useTodoFooter = ({
if (eventIdRef.current != null && eventIdRef.current !== 0) {
onEventColorChangeRef.current?.(eventIdRef.current, value)
}
if (!isEditingRef.current || eventIdRef.current == null || eventIdRef.current === 0) {
if (
!isEditingRef.current ||
eventIdRef.current == null ||
eventIdRef.current === 0 ||
!isPersistedTodoRef.current
) {
return
}
patchTodoMutateRef.current(
Expand Down
2 changes: 1 addition & 1 deletion src/shared/hooks/form/useTodoEditorForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const useTodoEditorForm = ({
recurrenceGroup,
}

const isPersistedTodoId = typeof id === 'number' && id > 0
const isPersistedTodoId = typeof id === 'number' && id > 0 && !initialEvent?.isTemporary
if (isEditing && isPersistedTodoId) {
const occurrenceDate = options?.occurrenceDate ?? formatIsoDate(date)
return patchTodoMutate({
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/calendar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type CalendarEvent = Omit<Event, 'start' | 'end'> & {
type?: 'todo' | 'schedule'
isDone?: boolean
isRecurring?: boolean
isTemporary?: boolean
}

export type GetEventsResponseDTO = {
Expand Down
1 change: 1 addition & 0 deletions src/shared/ui/Modals/TodoEditor/TodoEditorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const TodoEditorContent = ({
date,
eventId,
isEditing,
initialEvent,
todoDate: todo.todoDate,
setValue,
})
Expand Down