From a18c52358b6e494a563fa92ca6c6cf58f139a9b9 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 21 Sep 2025 15:43:48 +0330 Subject: [PATCH] category attibute --- src/components/Textarea.tsx | 4 +- src/config/Pages.ts | 1 + src/pages/category/Attributes.tsx | 214 ++++++++++++++++++ src/pages/category/List.tsx | 8 + .../category/components/AttributesModal.tsx | 162 +++++++++++++ src/pages/category/components/index.ts | 1 + .../category/hooks/useAttributesLogic.tsx | 102 +++++++++ src/pages/category/hooks/useCategoryData.tsx | 17 +- src/pages/category/index.ts | 1 + src/pages/category/service/CategoryService.ts | 12 +- src/pages/category/types/Types.ts | 37 +++ src/router/Main.tsx | 2 + 12 files changed, 557 insertions(+), 4 deletions(-) create mode 100644 src/pages/category/Attributes.tsx create mode 100644 src/pages/category/components/AttributesModal.tsx create mode 100644 src/pages/category/hooks/useAttributesLogic.tsx diff --git a/src/components/Textarea.tsx b/src/components/Textarea.tsx index b66940f..01cdef9 100644 --- a/src/components/Textarea.tsx +++ b/src/components/Textarea.tsx @@ -1,11 +1,11 @@ -import { type FC, type InputHTMLAttributes } from 'react' +import { type FC } from 'react' import Error from './Error' import { clx } from '../helpers/utils' type Props = { label?: string, error_text?: string -} & InputHTMLAttributes +} & React.TextareaHTMLAttributes const Textarea: FC = (props: Props) => { return ( diff --git a/src/config/Pages.ts b/src/config/Pages.ts index 05f52fe..963f2c7 100644 --- a/src/config/Pages.ts +++ b/src/config/Pages.ts @@ -122,5 +122,6 @@ export const Pages = { update: "/category/update/", detail: "/category/", variant: "/category/variant/", + attributes: "/category/attributes/", }, }; diff --git a/src/pages/category/Attributes.tsx b/src/pages/category/Attributes.tsx new file mode 100644 index 0000000..77088fa --- /dev/null +++ b/src/pages/category/Attributes.tsx @@ -0,0 +1,214 @@ +import { type FC } from 'react' +import { useParams } from 'react-router-dom' +import TitleLine from '../../components/TitleLine' +import Button from '../../components/Button' +import { AttributesModal } from './components' +import { useAttributesLogic } from './hooks/useAttributesLogic' +import { useGetCategoryAttributes } from './hooks/useCategoryData' +import { type CategoryAttributeType } from './types/Types' +import { Add, Edit, Trash } from 'iconsax-react' + +const Attributes: FC = () => { + const { id } = useParams() + const { data: attributesData, isLoading: attributesLoading } = useGetCategoryAttributes(id!) + const { + category, + isLoading, + isModalOpen, + newAttribute, + openModal, + closeModal, + setNewAttribute, + addAttribute, + addValueToAttribute, + removeValueFromAttribute, + isAddingLoading + } = useAttributesLogic({ id }) + + const attributes = attributesData?.results?.data?.category?.attributes || [] + + if (isLoading) { + return
در حال بارگذاری...
+ } + + if (!category) { + return ( +
+
+
+ +
+

+ دسته‌بندی یافت نشد +

+
+
+
+
+ ) + } + + if (!category.leaf) { + return ( +
+
+
+ +
+

+ {category.title_fa} +

+

+ این دسته‌بندی امکان داشتن ویژگی ندارد +

+
+
+ +
+
+
+
+ + + +
+
+

امکان ساخت ویژگی وجود ندارد

+

ویژگی‌ها فقط برای دسته‌بندی‌های نهایی (leaf) قابل تعریف هستند

+
+
+
+
+
+
+ ) + } + + return ( +
+
+
+ +
+

+ {category.title_fa} +

+

+ مدیریت ویژگی‌های دسته‌بندی +

+
+
+ +
+
+

+ ویژگی‌ها ({attributes.length}) +

+ +
+ + {attributesLoading ? ( +
+
در حال بارگذاری ویژگی‌ها...
+
+ ) : attributes.length === 0 ? ( +
+
+ + + +
+

هنوز ویژگی‌ای اضافه نشده

+

ویژگی‌های دسته‌بندی به شما کمک می‌کنند محصولات را بهتر توصیف کنید

+ +
+ ) : ( +
+ {attributes.map((attribute: CategoryAttributeType) => ( +
+
+
+

{attribute.title}

+ + {attribute.type === 'text' ? 'متن' : + attribute.type === 'number' ? 'عدد' : + attribute.type === 'select' ? 'انتخابی' : + attribute.type === 'boolean' ? 'بله/خیر' : attribute.type} + + {attribute.required && ( + + اجباری + + )} +
+
+ + +
+
+ {attribute.hint && ( +

{attribute.hint}

+ )} + {attribute.type === 'select' && attribute.values.length > 0 && ( +
+ {attribute.values.map((value, index) => ( + + {value.text} + + ))} +
+ )} +
+ ))} +
+ )} +
+
+ + +
+ ) +} + +export default Attributes diff --git a/src/pages/category/List.tsx b/src/pages/category/List.tsx index 54d75b9..68ba64d 100644 --- a/src/pages/category/List.tsx +++ b/src/pages/category/List.tsx @@ -68,6 +68,13 @@ const CategoryList: FC = () => {