complete profile
This commit is contained in:
@@ -1,9 +1,22 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import * as api from "../service/UserService";
|
||||
import type { UpdateProfileType } from "../types/Types";
|
||||
|
||||
export const useGetMe = () => {
|
||||
export const useGetMe = (options?: { enabled?: boolean }) => {
|
||||
return useQuery({
|
||||
queryKey: ["me"],
|
||||
queryFn: api.getMe,
|
||||
enabled: options?.enabled ?? true,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateProfile = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (variables: UpdateProfileType) => api.updateProfile(variables),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(["me"], data);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { GetMeResponseType } from "@/pages/user/types/Types";
|
||||
import type { GetMeResponseType, UpdateProfileType } from "@/pages/user/types/Types";
|
||||
|
||||
export const getMe = async (): Promise<GetMeResponseType["data"]> => {
|
||||
const { data } = await axios.get<GetMeResponseType>("/public/users/me");
|
||||
return data.data;
|
||||
};
|
||||
|
||||
export const updateProfile = async (
|
||||
params: UpdateProfileType,
|
||||
): Promise<GetMeResponseType["data"]> => {
|
||||
const { data } = await axios.patch<GetMeResponseType>(
|
||||
"/public/users/update",
|
||||
params,
|
||||
);
|
||||
return data.data;
|
||||
};
|
||||
|
||||
@@ -14,3 +14,8 @@ export interface UserMeType {
|
||||
}
|
||||
|
||||
export type GetMeResponseType = BaseResponse<UserMeType>;
|
||||
|
||||
export type UpdateProfileType = {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
type ProfileNameFields = {
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
};
|
||||
|
||||
export const needsProfileCompletion = (user?: ProfileNameFields | null): boolean => {
|
||||
if (!user) return false;
|
||||
return !user.firstName?.trim() || !user.lastName?.trim();
|
||||
};
|
||||
Reference in New Issue
Block a user