complete profile

This commit is contained in:
2026-07-02 21:01:20 +03:30
parent 2366f5ee02
commit f7deabd52a
11 changed files with 220 additions and 17 deletions
+15 -2
View File
@@ -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);
},
});
};
+11 -1
View File
@@ -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;
};
+5
View File
@@ -14,3 +14,8 @@ export interface UserMeType {
}
export type GetMeResponseType = BaseResponse<UserMeType>;
export type UpdateProfileType = {
firstName: string;
lastName: string;
};
+9
View File
@@ -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();
};