prile form:
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import * as api from "../service/Service";
|
||||
import { useSharedStore } from "@/share/store/sharedStore";
|
||||
import { UpdateProfileRequest } from "../types/ProfileTypes";
|
||||
|
||||
export const useGetProfile = () => {
|
||||
const { isLogin } = useSharedStore();
|
||||
@@ -10,3 +11,18 @@ export const useGetProfile = () => {
|
||||
enabled: isLogin,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateProfile = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (profileData: UpdateProfileRequest) =>
|
||||
api.updateProfile(profileData),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error("خطا در بهروزرسانی پروفایل:", error);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user