Oleksandr Honcharov пре 1 година
родитељ
комит
b2522eed6f

+ 1 - 0
src/modules/api/user/queries/index.ts

@@ -1,2 +1,3 @@
 export * from './use-post-get-profile';
 export * from './use-post-set-profile';
+export * from './use-post-get-profile-info';

+ 15 - 0
src/modules/api/user/queries/use-post-get-profile-info.tsx

@@ -0,0 +1,15 @@
+import { useQuery } from '@tanstack/react-query';
+import { userApi, userQueryKeys, PostGetProfileInfoReturn } from '@api/user';
+
+import type { BaseAxiosError } from '../../../../types';
+
+export const usePostGetProfileInfoQuery = (token: string, enabled: boolean) => {
+  return useQuery<PostGetProfileInfoReturn, BaseAxiosError>({
+    queryKey: userQueryKeys.getProfileInfo(),
+    queryFn: async () => {
+      const response = await userApi.getProfileInfo(token);
+      return response.data;
+    },
+    enabled
+  });
+};

+ 42 - 2
src/modules/api/user/user-api.tsx

@@ -53,11 +53,50 @@ export interface PostSetProfileDataReturn extends ResponseType {
   not_updated: string[];
 }
 
-type SocialData = {
+export type SocialData = {
   link: string;
   active: 0 | 1;
 };
 
+export interface PostGetProfileInfoReturn extends ResponseType {
+  username: string;
+  email: string;
+  first_name: string;
+  last_name: string;
+  date_of_birth: string;
+  avatar_full_size: string;
+  avatar: string;
+  bio: string;
+  links: {
+    f?: SocialData;
+    t?: SocialData;
+    i?: SocialData;
+    y?: SocialData;
+    www?: SocialData;
+    other?: SocialData;
+  };
+  homebase: number;
+  homebase_name: string;
+  homebase_flag: string;
+  homebase2: number;
+  homebase2_name: string;
+  homebase2_flag: string;
+  series: Series[];
+  scores: Score[];
+}
+
+export type Series = {
+  id: number;
+  score: number;
+  name: string;
+  icon_png: string;
+};
+
+export type Score = {
+  name: string;
+  score: number;
+};
+
 export const userApi = {
   getProfileData: (token: string) =>
     request.postForm<PostGetProfileData>(API.GET_USER_SETTINGS_DATA, { token }),
@@ -71,5 +110,6 @@ export const userApi = {
     } as unknown as Blob);
 
     return request.postForm<PostSetProfileDataReturn>(API.SET_USER_SETTINGS_DATA, formData);
-  }
+  },
+  getProfileInfo: (token: string) => request.postForm<PostGetProfileInfoReturn>(API.PROFILE_INFO)
 };

+ 2 - 1
src/modules/api/user/user-query-keys.tsx

@@ -1,4 +1,5 @@
 export const userQueryKeys = {
   getProfileData: () => ['getProfileData'] as const,
-  setProfileData: () => ['setProfileData'] as const
+  setProfileData: () => ['setProfileData'] as const,
+  getProfileInfo: () => ['getProfileInfo'] as const
 };

+ 4 - 2
src/types/api.ts

@@ -15,7 +15,8 @@ export enum API_ENDPOINT {
   JOIN_TEST = 'pre-join-test',
   GET_SETTINGS_APP = 'get-settings-app',
   SET_SETTINGS_APP = 'set-settings-app',
-  SERIES = 'get-for-regions'
+  SERIES = 'get-for-regions',
+  PROFILE_INFO = 'profile-info'
 }
 
 export enum API {
@@ -26,7 +27,8 @@ export enum API {
   JOIN_TEST = `${API_ROUTE.USER}/${API_ENDPOINT.JOIN_TEST}`,
   GET_USER_SETTINGS_DATA = `${API_ROUTE.USER}/${API_ENDPOINT.GET_SETTINGS_APP}`,
   SET_USER_SETTINGS_DATA = `${API_ROUTE.USER}/${API_ENDPOINT.SET_SETTINGS_APP}`,
-  SERIES = `${API_ROUTE.SERIES}/${API_ENDPOINT.SERIES}`
+  SERIES = `${API_ROUTE.SERIES}/${API_ENDPOINT.SERIES}`,
+  PROFILE_INFO = `${API_ROUTE.USER}/${API_ENDPOINT.PROFILE_INFO}`
 }
 
 export type BaseAxiosError = AxiosError;