From 7e301432681dc2f2a289331a6fea269c62b8e9cd Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Tue, 3 Feb 2026 11:26:03 +0330 Subject: [PATCH] users of list --- .env | 2 +- src/config/Paths.tsx | 3 ++ src/pages/formBuilder/types/Types.ts | 3 +- src/pages/user/List.tsx | 58 +++++++++++++++++++++++++++ src/pages/user/hooks/useUserData.ts | 6 +-- src/pages/user/service/UserService.ts | 6 ++- src/pages/user/types/Types.ts | 5 ++- src/router/MainRouter.tsx | 3 ++ src/shared/Sidebar.tsx | 2 +- 9 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 src/pages/user/List.tsx diff --git a/.env b/.env index d1840ce..03b6f18 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -VITE_API_BASE_URL = 'http://10.86.60.88:4000' +VITE_API_BASE_URL = 'http://192.168.99.218:4000' VITE_TOKEN_NAME = 'negareh_at' VITE_REFRESH_TOKEN_NAME = 'negareh_art' \ No newline at end of file diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index 67827d5..9feaa9b 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -20,6 +20,9 @@ export const Paths = { list: '/product/attribute-value/' } }, + users: { + list: '/users/list' + }, formBuilder: { list: '/form-builder/list/', create: '/form-builder/create/', diff --git a/src/pages/formBuilder/types/Types.ts b/src/pages/formBuilder/types/Types.ts index 4a90d99..cc630e6 100644 --- a/src/pages/formBuilder/types/Types.ts +++ b/src/pages/formBuilder/types/Types.ts @@ -1,5 +1,6 @@ import { type BaseResponse } from "@/shared/types/Types"; import type { FieldTypeEnum } from "../enum/Enum"; +import type { RowDataType } from "@/components/types/TableTypes"; export type CreateFieldType = { name: string, @@ -10,7 +11,7 @@ export type CreateFieldType = { entityType:string, // 'product' | 'print' } -export interface FieldType { +export interface FieldType extends RowDataType { createdAt: string, id: number, isRequired: boolean, diff --git a/src/pages/user/List.tsx b/src/pages/user/List.tsx new file mode 100644 index 0000000..2ec0d10 --- /dev/null +++ b/src/pages/user/List.tsx @@ -0,0 +1,58 @@ +import { useState, type FC } from 'react' +import { useGetUsers } from './hooks/useUserData' +import Table from '@/components/Table' +import moment from 'moment-jalaali' + +const UsersList: FC = () => { + + const [page, setPage] = useState(1) + const { data } = useGetUsers(page) + + return ( +
+
+

کاربران

+
+ + { + if (item.firstName) + return ( +
{item.firstName + ' ' + item.lastName}
+ ) + else return ( +
{item.phone}
+ ) + } + }, + { + key: 'phone', + title: 'موبایل' + }, + { + key: 'createdAt', + title: 'تاریخ ثبت نام', + render: (item) => { + return ( +
{moment(item.createdAt).format('jYYYY-jMM-jDD')}
+ ) + } + }, + ]} + data={data?.data} + pagination={{ + currentPage: page, + onPageChange: setPage, + totalPages: data?.meta?.totalPages as number + }} + /> + + + ) +} + +export default UsersList \ No newline at end of file diff --git a/src/pages/user/hooks/useUserData.ts b/src/pages/user/hooks/useUserData.ts index 0b124c0..9fe0d8f 100644 --- a/src/pages/user/hooks/useUserData.ts +++ b/src/pages/user/hooks/useUserData.ts @@ -1,9 +1,9 @@ import { useQuery } from "@tanstack/react-query"; import * as api from "../service/UserService"; -export const useGetUsers = () => { +export const useGetUsers = (page: number = 1) => { return useQuery({ - queryKey: ["users"], - queryFn: api.getUsers, + queryKey: ["users", page], + queryFn: () => api.getUsers(page), }); }; diff --git a/src/pages/user/service/UserService.ts b/src/pages/user/service/UserService.ts index 0415acf..45a5b64 100644 --- a/src/pages/user/service/UserService.ts +++ b/src/pages/user/service/UserService.ts @@ -1,7 +1,9 @@ import axios from "@/config/axios"; import type { UsersResponseType } from "../types/Types"; -export const getUsers = async () => { - const { data } = await axios.get(`/admin/users`); +export const getUsers = async (page: number) => { + const { data } = await axios.get( + `/admin/users?page=${page}` + ); return data; }; diff --git a/src/pages/user/types/Types.ts b/src/pages/user/types/Types.ts index 6900396..63bc965 100644 --- a/src/pages/user/types/Types.ts +++ b/src/pages/user/types/Types.ts @@ -1,6 +1,7 @@ +import type { RowDataType } from "@/components/types/TableTypes"; import type { BaseResponse } from "@/shared/types/Types"; -export type UserType = { +export interface UserType extends RowDataType { id: string; firstName: string | null; lastName: string | null; @@ -11,6 +12,6 @@ export type UserType = { isActive: boolean; createdAt: string; deletedAt: string | null; -}; +} export type UsersResponseType = BaseResponse; diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index 5203b70..57a844f 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -44,6 +44,7 @@ import SectionList from '@/pages/print/List' import CreateSection from '@/pages/print/Create' import UpdateSection from '@/pages/print/Update' import PrintForm from '@/pages/print/Form' +import UsersList from '@/pages/user/List' const MainRouter: FC = () => { return ( @@ -87,6 +88,8 @@ const MainRouter: FC = () => { } /> } /> + } /> + } /> } /> } /> diff --git a/src/shared/Sidebar.tsx b/src/shared/Sidebar.tsx index f0af87b..0cdc71e 100644 --- a/src/shared/Sidebar.tsx +++ b/src/shared/Sidebar.tsx @@ -82,7 +82,7 @@ const SideBar: FC = () => { icon={} title={'مشتریان'} isActive={isActive('customer')} - link={'Paths.'} + link={Paths.users.list} />