diff --git a/frontend/composables/api/account/useUpdateAccount.ts b/frontend/composables/api/account/useUpdateAccount.ts new file mode 100644 index 0000000..521d56a --- /dev/null +++ b/frontend/composables/api/account/useUpdateAccount.ts @@ -0,0 +1,45 @@ +// 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(); + + // method + + 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;