feat: align frontend types with unified /me API response
- Add THackathonProfile, TQrProfile, TMentorProfile, TSessionProfile and TUsersMeResponse types matching the backend unified /me endpoint - getUserMe() now accepts optional include[] param for selective module loading (?include=hackathon,qr,mentor,sessions) - useSessionQuery() accepts include[] to control which modules load - Fix SessionUser storage to use optional fields matching backend - Remove hardcoded fallback values in useLogin (birthdate, gender) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
53ad40f3fd
commit
c6719b19e5
@@ -4,6 +4,7 @@ import type {
|
|||||||
TUsersDetailItem,
|
TUsersDetailItem,
|
||||||
TUserCreateRequest,
|
TUserCreateRequest,
|
||||||
TUserUpdateRequest,
|
TUserUpdateRequest,
|
||||||
|
TUsersMeResponse,
|
||||||
} from '../../types/users';
|
} from '../../types/users';
|
||||||
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
||||||
|
|
||||||
@@ -11,13 +12,16 @@ import type { TApiPaginated, TPaginationParams } from '../../types/common';
|
|||||||
export type UserDetailResponseDto = TUsersDetailItem;
|
export type UserDetailResponseDto = TUsersDetailItem;
|
||||||
export type UserUpdateRequestDto = TUserUpdateRequest;
|
export type UserUpdateRequestDto = TUserUpdateRequest;
|
||||||
|
|
||||||
|
export type TUserMeInclude = 'hackathon' | 'qr' | 'mentor' | 'sessions';
|
||||||
|
|
||||||
export const getUserList = async (params?: TPaginationParams): Promise<TApiPaginated<TUsersListItem>> => {
|
export const getUserList = async (params?: TPaginationParams): Promise<TApiPaginated<TUsersListItem>> => {
|
||||||
const response = await api.get<TApiPaginated<TUsersListItem>>('/v1/iam/users', { params });
|
const response = await api.get<TApiPaginated<TUsersListItem>>('/v1/iam/users', { params });
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserMe = async (): Promise<TUsersDetailItem> => {
|
export const getUserMe = async (include?: TUserMeInclude[]): Promise<TUsersMeResponse> => {
|
||||||
const response = await api.get<ApiResponse<TUsersDetailItem>>('/v1/iam/users/me');
|
const params = include?.length ? { include: include.join(',') } : undefined;
|
||||||
|
const response = await api.get<ApiResponse<TUsersMeResponse>>('/v1/iam/users/me', { params });
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
postForgotPassword,
|
postForgotPassword,
|
||||||
postNewPassword,
|
postNewPassword,
|
||||||
} from '../../api/auth';
|
} from '../../api/auth';
|
||||||
import { getUserMe } from '../../api/users';
|
import { getUserMe, type TUserMeInclude } from '../../api/users';
|
||||||
|
|
||||||
export * from './use-auth-store';
|
export * from './use-auth-store';
|
||||||
|
|
||||||
@@ -27,15 +27,13 @@ export const useLogin = () => {
|
|||||||
id: u.id,
|
id: u.id,
|
||||||
email: u.email,
|
email: u.email,
|
||||||
fullname: u.fullname,
|
fullname: u.fullname,
|
||||||
phone_number: u.phone_number || '',
|
phone_number: u.phone_number,
|
||||||
avatar: u.avatar || '',
|
avatar: u.avatar,
|
||||||
birthdate: u.birthdate || '',
|
|
||||||
gender: u.gender || '',
|
|
||||||
is_active: u.is_active,
|
is_active: u.is_active,
|
||||||
location: u.location,
|
location: u.location,
|
||||||
bio: u.bio,
|
bio: u.bio,
|
||||||
skills: u.skills,
|
skills: u.skills,
|
||||||
role: u.role ?? { id: '', name: 'user', permissions: [], created_at: '', updated_at: '' },
|
role: u.role ?? { id: '', name: 'user', permissions: [] },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -57,15 +55,13 @@ export const useBackofficeLogin = () => {
|
|||||||
id: u.id,
|
id: u.id,
|
||||||
email: u.email,
|
email: u.email,
|
||||||
fullname: u.fullname,
|
fullname: u.fullname,
|
||||||
phone_number: u.phone_number || '',
|
phone_number: u.phone_number,
|
||||||
avatar: u.avatar || '',
|
avatar: u.avatar,
|
||||||
birthdate: u.birthdate || '',
|
|
||||||
gender: u.gender || '',
|
|
||||||
is_active: u.is_active,
|
is_active: u.is_active,
|
||||||
location: u.location,
|
location: u.location,
|
||||||
bio: u.bio,
|
bio: u.bio,
|
||||||
skills: u.skills,
|
skills: u.skills,
|
||||||
role: u.role ?? { id: '', name: 'admin', permissions: [], created_at: '', updated_at: '' },
|
role: u.role ?? { id: '', name: 'admin', permissions: [] },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -115,12 +111,12 @@ export const useSignOut = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSessionQuery = () => {
|
export const useSessionQuery = (include?: TUserMeInclude[]) => {
|
||||||
const { session } = useAuthStore();
|
const { session } = useAuthStore();
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['auth-session'],
|
queryKey: ['auth-session', include],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const user = await getUserMe();
|
const user = await getUserMe(include);
|
||||||
return { user };
|
return { user };
|
||||||
},
|
},
|
||||||
enabled: !!session?.token,
|
enabled: !!session?.token,
|
||||||
|
|||||||
@@ -1,26 +1,22 @@
|
|||||||
import type { TPermissionItem } from '../types/permissions';
|
import type { TRoleDetailItem } from '../types/roles';
|
||||||
|
import type { THackathonProfile, TQrProfile, TMentorProfile } from '../types/users';
|
||||||
type TRoleItem = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
created_at: string;
|
|
||||||
updated_at: string;
|
|
||||||
permissions: TPermissionItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type TUserItem = {
|
type TUserItem = {
|
||||||
id: string;
|
id: string;
|
||||||
avatar: string;
|
avatar?: string;
|
||||||
birthdate: string;
|
birthdate?: string;
|
||||||
email: string;
|
email: string;
|
||||||
fullname: string;
|
fullname: string;
|
||||||
gender: string;
|
gender?: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
phone_number: string;
|
phone_number?: string;
|
||||||
role: TRoleItem;
|
role: TRoleDetailItem;
|
||||||
bio?: string;
|
bio?: string;
|
||||||
location?: string;
|
location?: string;
|
||||||
skills?: string[];
|
skills?: string[];
|
||||||
|
hackathon?: THackathonProfile;
|
||||||
|
qr?: TQrProfile;
|
||||||
|
mentor?: TMentorProfile;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SessionUser = {
|
export const SessionUser = {
|
||||||
|
|||||||
@@ -76,6 +76,47 @@ export type TUsersDetailItem = {
|
|||||||
updated_at: string;
|
updated_at: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --- Unified /me response types ---
|
||||||
|
|
||||||
|
export type THackathonProfile = {
|
||||||
|
is_admin: boolean;
|
||||||
|
phone_number?: string;
|
||||||
|
location?: string;
|
||||||
|
bio?: string;
|
||||||
|
skills?: string[] | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TQrProfile = {
|
||||||
|
role: string;
|
||||||
|
provider: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TMentorProfile = {
|
||||||
|
mentor_id: string;
|
||||||
|
status?: string;
|
||||||
|
current_company?: string;
|
||||||
|
current_role?: string;
|
||||||
|
years_of_experience?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TSessionProfile = {
|
||||||
|
id: string;
|
||||||
|
topic: string;
|
||||||
|
description?: string;
|
||||||
|
scheduled_at: string;
|
||||||
|
duration_minutes: number;
|
||||||
|
session_type: string;
|
||||||
|
status: string;
|
||||||
|
role: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TUsersMeResponse = TUsersDetailItem & {
|
||||||
|
hackathon?: THackathonProfile;
|
||||||
|
qr?: TQrProfile;
|
||||||
|
mentor?: TMentorProfile;
|
||||||
|
sessions?: TSessionProfile[];
|
||||||
|
};
|
||||||
|
|
||||||
export type TUserCreateRequest = {
|
export type TUserCreateRequest = {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user