-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEAT] Task 타임블로킹 삭제 api 연결 #220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface DeleteTimeBlokType { | ||
taskId: number; | ||
timeBlockId: number; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DeleteTimeBlokType } from './DeleteTimeBlockType'; | ||
|
||
import { privateInstance } from '@/apis/instance'; | ||
|
||
/** TimeBlock 삭제 */ | ||
const deleteTimeBlock = async ({ taskId, timeBlockId }: DeleteTimeBlokType) => { | ||
await privateInstance.delete(`/api/tasks/${taskId}/time-blocks/${timeBlockId}`); | ||
}; | ||
|
||
export default deleteTimeBlock; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import deleteTimeBlock from './axios'; | ||
import { DeleteTimeBlokType } from './DeleteTimeBlockType'; | ||
|
||
/** TimeBlock 삭제 */ | ||
const useDeleteTimeBlock = () => { | ||
const queryClient = useQueryClient(); | ||
const mutation = useMutation({ | ||
mutationFn: ({ taskId, timeBlockId }: DeleteTimeBlokType) => deleteTimeBlock({ taskId, timeBlockId }), | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['timeblock'] }), | ||
}); | ||
|
||
return { mutate: mutation.mutate }; | ||
}; | ||
|
||
export default useDeleteTimeBlock; |
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.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ function FullCalendarBox({ size, selectDate, selectedTarget }: FullCalendarBoxPr | |
const [startDate, setStartDate] = useState<string>(todayDate); | ||
|
||
const [isModalOpen, setModalOpen] = useState(false); | ||
const [modalTaskId, setModalTaskId] = useState<number | null>(null); | ||
const [modalTimeBlockId, setModalTimeBlockId] = useState<number | null>(null); | ||
|
||
const handleViewChange = (view: ViewMountArg) => { | ||
setCurrentView(view.view.type); | ||
|
@@ -84,21 +86,38 @@ function FullCalendarBox({ size, selectDate, selectedTarget }: FullCalendarBoxPr | |
const adjustedTop = Math.min(calculatedTop, MODAL.SCREEN_HEIGHT - MODAL.TASK_MODAL_HEIGHT); | ||
setTop(adjustedTop); | ||
setLeft(rect.left - MODAL.TASK_MODAL_WIDTH + 40); | ||
setModalOpen(true); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
const clickedEvent = info.event._def.extendedProps; | ||
|
||
if (clickedEvent) { | ||
setModalTaskId(clickedEvent.taskId); | ||
setModalTimeBlockId(clickedEvent.timeBlockId); | ||
setModalOpen(true); | ||
} | ||
}; | ||
|
||
/** 모달 닫기 */ | ||
const closeModal = () => { | ||
setModalOpen(false); | ||
setModalTaskId(null); | ||
setModalTimeBlockId(null); | ||
}; | ||
|
||
// Get timeblock | ||
const { data: timeBlockData } = useGetTimeBlock({ startDate, range }); | ||
console.log('timeBlockData.data.data', timeBlockData?.data.data); | ||
console.log(timeBlockData?.data.data); | ||
|
||
const { mutate } = usePostTimeBlock(); | ||
|
||
const calendarEvents = timeBlockData ? processEvents(timeBlockData.data.data) : []; | ||
const { events, taskEvents } = timeBlockData | ||
? processEvents(timeBlockData.data.data) | ||
: { events: [], taskEvents: [] }; | ||
|
||
// TODO: 캘린더 모달 상세조회 부분 구현 시 해당 부분 참고 | ||
console.log('taskEvents', taskEvents); | ||
|
||
const calendarEvents = timeBlockData ? events : []; | ||
|
||
/** 드래그해서 이벤트 추가하기 */ | ||
const addEventWhenDragged = (selectInfo: DateSelectArg) => { | ||
|
@@ -123,20 +142,15 @@ function FullCalendarBox({ size, selectDate, selectedTarget }: FullCalendarBoxPr | |
classNames: 'tasks', | ||
}); | ||
|
||
// console.log('selectedTarget.name,', selectedTarget.name); | ||
|
||
const removeTimezone = (str: string) => str.replace(/:\d{2}[+-]\d{2}:\d{2}$/, ''); | ||
|
||
const startStr = removeTimezone(selectInfo.startStr); | ||
const endStr = removeTimezone(selectInfo.endStr); | ||
Comment on lines
145
to
148
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. 굳 |
||
|
||
// console.log('selectedTarget.id.toString(),', selectedTarget.id.toString()); | ||
// console.log('startStr:', startStr); | ||
// console.log('endStr:', endStr); | ||
|
||
mutate({ taskId: selectedTarget.id, startTime: startStr, endTime: endStr }); | ||
} | ||
}; | ||
|
||
return ( | ||
<FullCalendarLayout size={size}> | ||
<CustomButtonContainer> | ||
|
@@ -199,15 +213,15 @@ function FullCalendarBox({ size, selectDate, selectedTarget }: FullCalendarBoxPr | |
eventClick={handleEventClick} | ||
select={addEventWhenDragged} | ||
/> | ||
{isModalOpen && ( | ||
// 🚨 임시 taskID ... 데이터 형식 확정 후 수정할 것 🚨 | ||
{isModalOpen && modalTaskId !== null && modalTimeBlockId !== null && ( | ||
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. 모달 테스크 아이디와 타임블록 아이디가 존재할 때만 모달이 열리도록 처리해주셨군용! 쪼아요 |
||
<Modal | ||
isOpen={isModalOpen} | ||
sizeType={{ type: 'short' }} | ||
top={top} | ||
left={left} | ||
onClose={closeModal} | ||
taskId={5} | ||
taskId={modalTaskId} | ||
timeBlockId={modalTimeBlockId} | ||
/> | ||
)} | ||
</FullCalendarLayout> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,18 +8,33 @@ interface EventData { | |||||||||||||||||||||||||||
classNames: string; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const processEvents = (timeBlockData: TimeBlockData): EventData[] => { | ||||||||||||||||||||||||||||
interface TasksEventData { | ||||||||||||||||||||||||||||
taskId: number; | ||||||||||||||||||||||||||||
timeBlockId: number; | ||||||||||||||||||||||||||||
title: string; | ||||||||||||||||||||||||||||
start: string; | ||||||||||||||||||||||||||||
end: string; | ||||||||||||||||||||||||||||
allDay?: boolean; | ||||||||||||||||||||||||||||
classNames: string; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+11
to
+19
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.
Suggested change
여기 인터페이스 상속으로 이렇게 써줄 수 있을 것 같네요! 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. 오 오 이렇게도 할 수 있군요 배우고 갑니닷 👍👍👍 |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const processEvents = (timeBlockData: TimeBlockData): { events: EventData[]; taskEvents: TasksEventData[] } => { | ||||||||||||||||||||||||||||
const events: EventData[] = []; | ||||||||||||||||||||||||||||
const taskEvents: TasksEventData[] = []; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// tasks 데이터 처리 | ||||||||||||||||||||||||||||
timeBlockData.tasks.forEach((task) => { | ||||||||||||||||||||||||||||
task.timeBlocks.forEach((timeBlock) => { | ||||||||||||||||||||||||||||
events.push({ | ||||||||||||||||||||||||||||
const taskEvent = { | ||||||||||||||||||||||||||||
taskId: task.id, | ||||||||||||||||||||||||||||
timeBlockId: timeBlock.id, | ||||||||||||||||||||||||||||
title: task.name, | ||||||||||||||||||||||||||||
start: timeBlock.startTime, | ||||||||||||||||||||||||||||
end: timeBlock.endTime, | ||||||||||||||||||||||||||||
classNames: 'tasks', | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
events.push(taskEvent); | ||||||||||||||||||||||||||||
taskEvents.push(taskEvent); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -36,7 +51,7 @@ const processEvents = (timeBlockData: TimeBlockData): EventData[] => { | |||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return events; | ||||||||||||||||||||||||||||
return { events, taskEvents }; | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export default processEvents; |
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.
태스크 삭제 적용까지 시간이 많이 걸려서 isLoading이면 스피너를 추가하면 더욱 좋을 것 같습니다!