46 lines
986 B
TypeScript
46 lines
986 B
TypeScript
// imports
|
|
|
|
import { useMutation } from "@tanstack/vue-query";
|
|
import { API_ENDPOINTS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type UpdateAccountRequest = {
|
|
profile_photo?: File | null;
|
|
first_name?: string;
|
|
last_name?: string;
|
|
phone?: string;
|
|
gender?: string | undefined;
|
|
email?: string;
|
|
birth_date?: string;
|
|
};
|
|
|
|
const useUpdateAccount = () => {
|
|
// state
|
|
|
|
const { $axios: axios } = useNuxtApp();
|
|
|
|
// methods
|
|
|
|
const handleUpdateAccount = async (params: UpdateAccountRequest) => {
|
|
const { data } = await axios.patch(
|
|
API_ENDPOINTS.account.update,
|
|
{
|
|
...params,
|
|
},
|
|
{
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
}
|
|
);
|
|
return data;
|
|
};
|
|
|
|
return useMutation({
|
|
mutationFn: (data: UpdateAccountRequest) => handleUpdateAccount(data),
|
|
});
|
|
};
|
|
|
|
export default useUpdateAccount;
|