From 7d702c41f898ab01bd3df67dd2311ee8c9a245e3 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 21 Feb 2026 11:08:17 +0330 Subject: [PATCH] request detail --- src/config/Paths.tsx | 1 + src/pages/requests/Detail.tsx | 34 +++++++ src/pages/requests/RequestList.tsx | 2 +- src/pages/requests/components/RequestItem.tsx | 97 +++++++++++++++++++ src/pages/requests/hooks/useRequestData.ts | 8 ++ src/pages/requests/service/RequestService.ts | 11 ++- src/pages/requests/types/Types.ts | 52 ++++++++++ src/router/MainRouter.tsx | 3 +- 8 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 src/pages/requests/Detail.tsx create mode 100644 src/pages/requests/components/RequestItem.tsx diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index 5ed51ce..8a7bd0a 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -1,6 +1,7 @@ export const Paths = { requests: { list: '/requests', + detail: '/requests/', }, product: { list: '/product/list', diff --git a/src/pages/requests/Detail.tsx b/src/pages/requests/Detail.tsx new file mode 100644 index 0000000..d66c4a4 --- /dev/null +++ b/src/pages/requests/Detail.tsx @@ -0,0 +1,34 @@ +import { type FC } from 'react' +import { useGetRequestDetail } from './hooks/useRequestData' +import { useParams } from 'react-router-dom' +import RequestItem from './components/RequestItem' + +const RequestDetail: FC = () => { + const { id } = useParams() + const { data } = useGetRequestDetail(id!) + + return ( +
+ {/* Header Section */} +
+
+ درخواست #{data?.data?.requestNumber} +
+
+ + {/* Request Information Section */} +
+
+

اطلاعات درخواست

+
+
+ {data?.data?.items?.map((item) => ( + + ))} +
+
+
+ ) +} + +export default RequestDetail diff --git a/src/pages/requests/RequestList.tsx b/src/pages/requests/RequestList.tsx index 6c3162c..7d95ece 100644 --- a/src/pages/requests/RequestList.tsx +++ b/src/pages/requests/RequestList.tsx @@ -98,7 +98,7 @@ const RequestList: FC = () => { return (
diff --git a/src/pages/requests/components/RequestItem.tsx b/src/pages/requests/components/RequestItem.tsx new file mode 100644 index 0000000..a2da44d --- /dev/null +++ b/src/pages/requests/components/RequestItem.tsx @@ -0,0 +1,97 @@ +import { type FC } from 'react' +import type { RequestDetailItemType } from '../types/Types' +import { useGetEntityField } from '@/pages/formBuilder/hooks/useFormBuilderData' +import { Paperclip2 } from 'iconsax-react' + +type Props = { + item: RequestDetailItemType +} + +const RequestItem: FC = ({ item }) => { + const { data: fields } = useGetEntityField(Number(item.product?.id)) + + const handleOpenAttachment = (url: string) => { + window.open(url, '_blank') + } + + return ( +
+
+
#{item.id}
+
+
+ {/* Product Image */} +
+ {item.product?.images?.[0] ? ( + {item.product?.title} + ) : ( +
بدون تصویر
+ )} +
+ + {/* Request Details */} +
+
+
عنوان:
+
{item.product?.title}
+
+
+
تعداد:
+
{item.quantity}
+
+
+
+ + {/* Description */} + {item.description && ( +
+
شرح درخواست:
+

+ {item.description} +

+
+ )} + + {/* Attributes */} + {fields?.data?.length ? ( + <> +
ویژگی ها
+ { + fields.data.map((field) => { + const value = item.attributes?.find((o) => Number(o.attributeId) === Number(field.id)) + return ( +
+
{field.name}:
+
{value?.value || '-'}
+
+ ) + }) + } + + ) : null} + + {/* Attachments */} + {item.attachments?.length ? ( +
+
ضمایم:
+
+ {item.attachments + ?.filter((url): url is string => typeof url === 'string') + .map((url, index) => ( + + ))} +
+
+ ) : null} +
+ ) +} + +export default RequestItem diff --git a/src/pages/requests/hooks/useRequestData.ts b/src/pages/requests/hooks/useRequestData.ts index 256d362..9292238 100644 --- a/src/pages/requests/hooks/useRequestData.ts +++ b/src/pages/requests/hooks/useRequestData.ts @@ -7,3 +7,11 @@ export const useGetRequests = () => { queryFn: api.getRequests, }); }; + +export const useGetRequestDetail = (id: string) => { + return useQuery({ + queryKey: ["request", id], + queryFn: () => api.getRequestDetail(id), + enabled: !!id, + }); +}; diff --git a/src/pages/requests/service/RequestService.ts b/src/pages/requests/service/RequestService.ts index e1bb5f7..e36ef79 100644 --- a/src/pages/requests/service/RequestService.ts +++ b/src/pages/requests/service/RequestService.ts @@ -1,7 +1,16 @@ import axios from "@/config/axios"; -import type { RequestResponseType } from "@/pages/requests/types/Types"; +import type { + RequestDetailResponseType, + RequestResponseType, +} from "@/pages/requests/types/Types"; export const getRequests = async () => { const { data } = await axios.get("/admin/request"); return data; }; + +export const getRequestDetail = async (id: string) => { + const { data } = + await axios.get(`/admin/request/${id}`); + return data; +}; diff --git a/src/pages/requests/types/Types.ts b/src/pages/requests/types/Types.ts index 63c6aa2..3b1a6c7 100644 --- a/src/pages/requests/types/Types.ts +++ b/src/pages/requests/types/Types.ts @@ -32,3 +32,55 @@ export type RequestType = { }; export type RequestResponseType = BaseResponse; + +// Types for getRequestDetail response (matches API structure) +export type RequestDetailUserType = { + id: string; + createdAt: string; + deletedAt: string | null; + firstName: string | null; + lastName: string | null; + isActive: boolean; + gender: boolean; + maxCredit: number; + addresse: string | null; + phone: string; +}; + +export type RequestDetailProductType = { + id: string; + createdAt: string; + deletedAt: string | null; + category: string; + title: string; + desc: string; + quantities: number[]; + linkUrl: string | null; + isActive: boolean; + images: string[]; + order: number; +}; + +export type RequestDetailItemType = { + id: string; + createdAt: string; + deletedAt: string | null; + product: RequestDetailProductType; + attributes: RequestItemAttributeType[]; + request: string; + quantity: number; + description: string; + attachments: string[] | unknown[]; +}; + +export type RequestDetailType = { + id: string; + createdAt: string; + deletedAt: string | null; + user: RequestDetailUserType; + requestNumber: number; + status: RequestStatus; + items: RequestDetailItemType[]; +}; + +export type RequestDetailResponseType = BaseResponse; diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index 26b57cb..1e55d6b 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -44,6 +44,7 @@ import UsersList from "@/pages/user/List"; import AdminList from "@/pages/admin/List"; import CreateAdmin from "@/pages/admin/Create"; import EditAdmin from "@/pages/admin/Update"; +import RequestDetail from "@/pages/requests/Detail"; const MainRouter: FC = () => { return ( @@ -61,7 +62,7 @@ const MainRouter: FC = () => { } /> } /> } /> - + } /> } /> } /> } />