From ff9072b8d9027b28c27b5e3134b0845547d4ff56 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 21 Feb 2026 10:31:30 +0330 Subject: [PATCH] service and hooks request --- src/pages/requests/RequestList.tsx | 4 +-- src/pages/requests/hooks/useRequestData.ts | 9 ++++++ src/pages/requests/service/RequestService.ts | 7 ++++ src/pages/requests/types/Types.ts | 34 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/pages/requests/hooks/useRequestData.ts create mode 100644 src/pages/requests/service/RequestService.ts create mode 100644 src/pages/requests/types/Types.ts diff --git a/src/pages/requests/RequestList.tsx b/src/pages/requests/RequestList.tsx index 99df8a3..6c3162c 100644 --- a/src/pages/requests/RequestList.tsx +++ b/src/pages/requests/RequestList.tsx @@ -1,7 +1,7 @@ import Filters from '@/components/Filters' import Table from '@/components/Table' import { type FC } from 'react' -import { useGetRequests } from '../order/hooks/useOrderData' +import { useGetRequests } from './hooks/useRequestData' import moment from 'moment-jalaali' import { Link } from 'react-router-dom' import { Paths } from '@/config/Paths' @@ -48,7 +48,7 @@ const RequestList: FC = () => { { + return useQuery({ + queryKey: ["requests"], + queryFn: api.getRequests, + }); +}; diff --git a/src/pages/requests/service/RequestService.ts b/src/pages/requests/service/RequestService.ts new file mode 100644 index 0000000..e1bb5f7 --- /dev/null +++ b/src/pages/requests/service/RequestService.ts @@ -0,0 +1,7 @@ +import axios from "@/config/axios"; +import type { RequestResponseType } from "@/pages/requests/types/Types"; + +export const getRequests = async () => { + const { data } = await axios.get("/admin/request"); + return data; +}; diff --git a/src/pages/requests/types/Types.ts b/src/pages/requests/types/Types.ts new file mode 100644 index 0000000..63c6aa2 --- /dev/null +++ b/src/pages/requests/types/Types.ts @@ -0,0 +1,34 @@ +import type { UserType } from "@/pages/order/types/Types"; +import type { ProductType } from "@/pages/product/types/Types"; +import type { BaseResponse } from "@/shared/types/Types"; + +export type RequestItemAttributeType = { + value: string; + attributeId: string; +}; + +export type RequestItemType = { + id: string; + createdAt: string; + deletedAt: string | null; + product: ProductType; + attributes: RequestItemAttributeType[]; + request: string; + quantity: number; + description: string; + attachments: string[]; +}; + +export type RequestStatus = "pending" | string; + +export type RequestType = { + id: string; + createdAt: string; + deletedAt: string | null; + user: UserType; + requestNumber: number; + status: RequestStatus; + items: RequestItemType[]; +}; + +export type RequestResponseType = BaseResponse;