mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-26 06:32:03 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
35
apps/client/src/services/resume/import.ts
Normal file
35
apps/client/src/services/resume/import.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { ImportResumeDto, ResumeDto } from "@reactive-resume/dto";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
||||
import { axios } from "@/client/libs/axios";
|
||||
import { queryClient } from "@/client/libs/query-client";
|
||||
|
||||
export const importResume = async (data: ImportResumeDto) => {
|
||||
const response = await axios.post<ResumeDto, AxiosResponse<ResumeDto>, ImportResumeDto>(
|
||||
"/resume/import",
|
||||
data,
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const useImportResume = () => {
|
||||
const {
|
||||
error,
|
||||
isPending: loading,
|
||||
mutateAsync: importResumeFn,
|
||||
} = useMutation({
|
||||
mutationFn: importResume,
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData<ResumeDto>(["resume", { id: data.id }], data);
|
||||
|
||||
queryClient.setQueryData<ResumeDto[]>(["resumes"], (cache) => {
|
||||
if (!cache) return [data];
|
||||
return [...cache, data];
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return { importResume: importResumeFn, loading, error };
|
||||
};
|
||||
Reference in New Issue
Block a user