File size: 996 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import type { ResumeDto } from "@reactive-resume/dto";
import { useMutation } from "@tanstack/react-query";
import { axios } from "@/client/libs/axios";
import { queryClient } from "@/client/libs/query-client";
type LockResumeArgs = {
id: string;
set: boolean;
};
export const lockResume = async ({ id, set }: LockResumeArgs) => {
const response = await axios.patch(`/resume/${id}/lock`, { set });
queryClient.setQueryData<ResumeDto>(["resume", { id: response.data.id }], response.data);
queryClient.setQueryData<ResumeDto[]>(["resumes"], (cache) => {
if (!cache) return [response.data];
return cache.map((resume) => {
if (resume.id === response.data.id) return response.data;
return resume;
});
});
return response.data;
};
export const useLockResume = () => {
const {
error,
isPending: loading,
mutateAsync: lockResumeFn,
} = useMutation({
mutationFn: lockResume,
});
return { lockResume: lockResumeFn, loading, error };
};
|