Skip to content

Commit 96c597f

Browse files
committed
feat: wiring update profile user
1 parent 287be4e commit 96c597f

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/features/profile/components/ProfileForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/Popover
1212
import { Calendar } from "@/components/ui/Calendar";
1313
import { createProfileFormSchema, ProfileFormType } from "@/domains/Profile";
1414
import { cn } from "@/lib/utils";
15-
import { useGetProfile } from "../hooks";
15+
import { useGetProfile, useUpdateProfile } from "../hooks";
1616
import Loader from "@/components/common/Loader";
1717
import { useEffect } from "react";
1818

@@ -24,6 +24,7 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
2424
const t = useTranslations();
2525
const profileFormSchema = createProfileFormSchema(t);
2626
const { data, isLoading } = useGetProfile();
27+
const { mutate } = useUpdateProfile();
2728

2829
const form = useForm<ProfileFormType>({
2930
resolver: zodResolver(profileFormSchema),
@@ -57,9 +58,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
5758
const onSubmit = (data: ProfileFormType) => {
5859
// ! TODO handle query mutation
5960
console.log("Profile data:", data);
61+
mutate(data);
6062
};
6163

62-
console.log("dataaa", data);
6364
if (isLoading) {
6465
return <Loader />;
6566
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as useGetProfile } from "./useGetProfile";
2+
export { default as useUpdateProfile } from "./useUpdateProfile";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ProfileFormType } from "@/domains/Profile";
2+
import { profileService } from "@/services/profile";
3+
import { useMutation } from "@tanstack/react-query";
4+
5+
const useUpdateProfile = () =>
6+
useMutation({
7+
mutationKey: ["updateProfile"],
8+
mutationFn: async (payload: ProfileFormType) => profileService.updateProfile(payload),
9+
});
10+
11+
export default useUpdateProfile;

src/services/home/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const homeService = {
77
*/
88
async getAllTestimonial(): Promise<{ status: number; message: string; data: TestimonialType[] }> {
99
const res = await axios.get("/api/testimonial");
10-
console.log("resss", res);
1110
return res.data;
1211
},
1312
};

src/services/profile/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpResponse } from "@/types/http";
22
import { fetcher } from "../instance";
3-
import { ProfileResType } from "@/domains/Profile";
3+
import { ProfileResType, ProfileFormType } from "@/domains/Profile";
44

55
export const profileService = {
66
/**
@@ -9,4 +9,12 @@ export const profileService = {
99
getProfile: async (): Promise<HttpResponse<ProfileResType>> => {
1010
return fetcher.get("/user");
1111
},
12+
13+
/**
14+
* API to update profile user
15+
* @param payload - new profile user data
16+
*/
17+
updateProfile: async (payload: ProfileFormType): Promise<HttpResponse<ProfileResType>> => {
18+
return fetcher.put("/update", payload);
19+
},
1220
};

0 commit comments

Comments
 (0)