add fetch users data, add loagout endpoints
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { fetchUsesData } from '@/app/actions/usersActions';
|
||||
|
||||
interface ApiResponse {
|
||||
files: ApiUser[];
|
||||
}
|
||||
|
||||
interface ApiUser {
|
||||
id: string;
|
||||
mimeType: string;
|
||||
userEmail: number;
|
||||
userCompany: number;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export const useUsersData = (page: number, size: number) => {
|
||||
return useQuery<ApiResponse, Error, any>({
|
||||
queryKey: ['usersData'],
|
||||
queryFn: () => {
|
||||
return fetchUsesData(page, size)
|
||||
},
|
||||
|
||||
select: (data: ApiResponse): any => {
|
||||
if (!data?.files) return [
|
||||
{
|
||||
id: 1,
|
||||
userId: 1,
|
||||
userName: 'userName',
|
||||
userEmail: 'userEmail',
|
||||
userCompany: 'userCompany',
|
||||
userSubscription: 'userSubscription',
|
||||
userRole: 'role',
|
||||
userContent: 0,
|
||||
}
|
||||
];
|
||||
|
||||
return data.files.map((item: ApiUser) => {
|
||||
const [datePart, timePart] = item.updatedAt.split(' ');
|
||||
const [day, month, year] = datePart.split('-').map(Number);
|
||||
const [hours, minutes, seconds] = timePart.split(':').map(Number);
|
||||
const newDate = new Date(year, month - 1, day, hours, minutes, seconds).getTime();
|
||||
|
||||
return {
|
||||
id: item.id,
|
||||
userName: item.mimeType.toLocaleLowerCase(),
|
||||
userEmail: item.userEmail,
|
||||
userCompany: item.userCompany,
|
||||
userSubscription: newDate,
|
||||
userRole: 'role',
|
||||
userContent: 0,
|
||||
_original: item
|
||||
};
|
||||
});
|
||||
},
|
||||
retry: false,
|
||||
placeholderData: (previousData) => previousData // для оптимистичных обновлений
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user