Files
no-copy-frontend/src/app/hooks/react-query/useUserDataInfo.ts
T
2026-02-13 13:44:03 +07:00

81 lines
1.5 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { getUserData } from '@/app/actions/action';
export interface Tariff {
id: number;
type: string;
name: string;
price: number;
tokens: number;
maxFilesCount: number;
diskSize: number;
maxUsers?: number;
}
export interface TariffInfo {
id: string;
status: string;
startTariff: string;
endTariff: string;
tariffId: number | null;
tariffName: string | null;
tokens: number | null;
maxFileOnDisk: number | null;
currentFileOnDisk: number;
currentFileCounts: number;
maxFileCounts: number;
}
export interface UserData {
fullName: string;
company: string | null;
email: string;
active: boolean;
phone: string;
genderType: string | null;
birthday: string | null;
createdAt: string;
subscriptionType: string;
tariffs: Tariff[];
tariffInfo: TariffInfo;
permission: number;
}
export const useUserProfile = () => {
return useQuery({
queryKey: ['userData'],
queryFn: getUserData,
select: (data): UserData => {
if (!data) {
return {
fullName: '',
company: null,
email: '',
active: false,
phone: '',
genderType: '',
birthday: null,
createdAt: '',
subscriptionType: '',
tariffs: [],
tariffInfo: {
id: '',
status: '',
startTariff: '',
endTariff: '',
tariffId: 0,
tariffName: null,
tokens: 0,
maxFileOnDisk: null,
currentFileOnDisk: 0,
currentFileCounts: 0,
maxFileCounts: 0,
},
permission: 0,
};
}
return data;
},
});
};