diff --git a/src/apis/timeBlocks/updateTimeBlock/PatchTimeBlockType.ts b/src/apis/timeBlocks/updateTimeBlock/PatchTimeBlockType.ts new file mode 100644 index 00000000..e07973df --- /dev/null +++ b/src/apis/timeBlocks/updateTimeBlock/PatchTimeBlockType.ts @@ -0,0 +1,6 @@ +export interface PatchTimeBlokType { + taskId: number; + timeBlockId: number; + startTime: string; + endTime: string; +} diff --git a/src/apis/timeBlocks/updateTimeBlock/axios.ts b/src/apis/timeBlocks/updateTimeBlock/axios.ts new file mode 100644 index 00000000..93bb5758 --- /dev/null +++ b/src/apis/timeBlocks/updateTimeBlock/axios.ts @@ -0,0 +1,12 @@ +import { PatchTimeBlokType } from './PatchTimeBlockType'; + +import { privateInstance } from '@/apis/instance'; + +const PatchTimeBlock = async ({ taskId, timeBlockId, startTime, endTime }: PatchTimeBlokType) => { + await privateInstance.patch(`/api/tasks/${taskId}/time-blocks/${timeBlockId}`, { + startTime, + endTime, + }); +}; + +export default PatchTimeBlock; diff --git a/src/apis/timeBlocks/updateTimeBlock/query.ts b/src/apis/timeBlocks/updateTimeBlock/query.ts new file mode 100644 index 00000000..45928e39 --- /dev/null +++ b/src/apis/timeBlocks/updateTimeBlock/query.ts @@ -0,0 +1,18 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; + +import PatchTimeBlock from './axios'; +import { PatchTimeBlokType } from './PatchTimeBlockType'; + +const usePatchTimeBlock = () => { + const queryClient = useQueryClient(); + + const mutation = useMutation({ + mutationFn: ({ taskId, timeBlockId, startTime, endTime }: PatchTimeBlokType) => + PatchTimeBlock({ taskId, timeBlockId, startTime, endTime }), + onSuccess: () => queryClient.invalidateQueries({ queryKey: ['timeblock'] }), + }); + + return { mutate: mutation.mutate }; +}; + +export default usePatchTimeBlock;