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 = () => {