Skip to content

Commit

Permalink
feat: timeBlock update api 관련 파일
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjiw0n committed Jul 18, 2024
1 parent 53ff83b commit 956d503
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/apis/timeBlocks/updateTimeBlock/PatchTimeBlockType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface PatchTimeBlokType {
taskId: number;
timeBlockId: number;
startTime: string;
endTime: string;
}
12 changes: 12 additions & 0 deletions src/apis/timeBlocks/updateTimeBlock/axios.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions src/apis/timeBlocks/updateTimeBlock/query.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 956d503

Please sign in to comment.