File size: 783 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 |
import type { UpdateUserDto, UserDto } from "@reactive-resume/dto";
import { useMutation } from "@tanstack/react-query";
import type { AxiosResponse } from "axios";
import { axios } from "@/client/libs/axios";
import { queryClient } from "@/client/libs/query-client";
export const updateUser = async (data: UpdateUserDto) => {
const response = await axios.patch<UserDto, AxiosResponse<UserDto>, UpdateUserDto>(
"/user/me",
data,
);
return response.data;
};
export const useUpdateUser = () => {
const {
error,
isPending: loading,
mutateAsync: updateUserFn,
} = useMutation({
mutationFn: updateUser,
onSuccess: (data) => {
queryClient.setQueryData(["user"], data);
},
});
return { updateUser: updateUserFn, loading, error };
};
|