41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import * as api from "../service/Service";
|
|
import { useSharedStore } from "@/share/store/sharedStore";
|
|
import { UpdateAddressType, UpdateProfileRequest } from "../types/ProfileTypes";
|
|
|
|
export const useGetProfile = () => {
|
|
const { isLogin } = useSharedStore();
|
|
return useQuery({
|
|
queryKey: ["profile"],
|
|
queryFn: api.getProfile,
|
|
enabled: isLogin,
|
|
});
|
|
};
|
|
|
|
export const useUpdateProfile = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (profileData: UpdateProfileRequest) =>
|
|
api.updateProfile(profileData),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useGetAddressByLocation = (lat?: number, lon?: number) => {
|
|
return useQuery({
|
|
queryKey: ["address-by-location", lat, lon],
|
|
queryFn: () => api.getAddressByLocation(lat!, lon!),
|
|
enabled: lat !== undefined && lon !== undefined,
|
|
});
|
|
};
|
|
|
|
export const useUpdateAddress = () => {
|
|
return useMutation({
|
|
mutationFn: (addressData: UpdateAddressType) =>
|
|
api.updateAddress(addressData),
|
|
});
|
|
};
|