diff --git a/index.html b/index.html index 26f94ef..1b2597c 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - negareh-console + پنل مدیریت
diff --git a/src/components/CopyWithConfirm.tsx b/src/components/CopyWithConfirm.tsx new file mode 100644 index 0000000..160ad1d --- /dev/null +++ b/src/components/CopyWithConfirm.tsx @@ -0,0 +1,48 @@ +import { Copy } from 'iconsax-react' +import { type FC, useEffect, useState } from 'react' +import ModalConfrim from './ModalConfrim' + +interface Props { + onDuplicate: () => void, + isloading?: boolean, + colorIcon?: string, +} + +const CopyWithConfirm: FC = ({ onDuplicate, isloading = false, colorIcon }) => { + const [isConfirm, setIsConfirm] = useState(false) + const [isSubmitting, setIsSubmitting] = useState(false) + + useEffect(() => { + if (isSubmitting && !isloading) { + setIsConfirm(false) + setIsSubmitting(false) + } + }, [isloading, isSubmitting]) + + return ( +
+ + + setIsConfirm(false)} + onConfrim={() => { + setIsSubmitting(true) + onDuplicate() + }} + isloading={isloading} + title_header='کپی محصول' + label='آیا از کپی این محصول مطمئن هستید؟' + /> +
+ ) +} + +export default CopyWithConfirm diff --git a/src/components/ModalConfrim.tsx b/src/components/ModalConfrim.tsx index 5fc3fc2..4e5c788 100644 --- a/src/components/ModalConfrim.tsx +++ b/src/components/ModalConfrim.tsx @@ -9,7 +9,8 @@ type Props = { isOpen: boolean, onConfrim: (text?: string) => void, label?: string, - isHasDescription?: boolean + isHasDescription?: boolean, + title_header?: string, } const ModalConfrim: FC = (props: Props) => { @@ -20,7 +21,7 @@ const ModalConfrim: FC = (props: Props) => {
diff --git a/src/pages/product/List.tsx b/src/pages/product/List.tsx index e71539b..c4228da 100644 --- a/src/pages/product/List.tsx +++ b/src/pages/product/List.tsx @@ -2,11 +2,12 @@ import Button from '@/components/Button' import Filters from '@/components/Filters' import Table from '@/components/Table' import { AddSquare, Edit, More2 } from 'iconsax-react' -import { type FC } from 'react' -import { useDeleteProduct, useGetProducts } from './hooks/useProductData' +import { type FC, useState } from 'react' +import { useDeleteProduct, useDuplicateProduct, useGetProducts } from './hooks/useProductData' import { Link } from 'react-router-dom' import { Paths } from '@/config/Paths' import TrashWithConfrim from '@/components/TrashWithConfrim' +import CopyWithConfirm from '@/components/CopyWithConfirm' import { toast } from 'react-toastify' import { extractErrorMessage } from '@/config/func' @@ -14,6 +15,23 @@ const ProductList: FC = () => { const { data: products, refetch } = useGetProducts() const { mutate: deleteProduct, isPending: isDeleting } = useDeleteProduct() + const { mutate: duplicateProduct, isPending: isDuplicating } = useDuplicateProduct() + const [duplicatingId, setDuplicatingId] = useState(null) + + const handleDuplicate = (id: string) => { + setDuplicatingId(id) + duplicateProduct(id, { + onSuccess: () => { + refetch() + toast.success('محصول با موفقیت کپی شد') + setDuplicatingId(null) + }, + onError: (error) => { + toast.error(extractErrorMessage(error)) + setDuplicatingId(null) + }, + }) + } const handleDelete = (id: string) => { deleteProduct(id, { @@ -97,6 +115,10 @@ const ProductList: FC = () => { render: (item) => { return (
+ handleDuplicate(item.id)} + isloading={isDuplicating && duplicatingId === item.id} + /> diff --git a/src/pages/product/category/Create.tsx b/src/pages/product/category/Create.tsx index d8298e5..3bb5914 100644 --- a/src/pages/product/category/Create.tsx +++ b/src/pages/product/category/Create.tsx @@ -12,9 +12,13 @@ import SwitchComponent from '@/components/Switch' import { useSingleUpload } from '@/pages/uploader/hooks/useUploader' import { toast } from 'react-toastify' import { extractErrorMessage } from '@/config/func' +import { useNavigate } from 'react-router-dom' +import { Paths } from '@/config/Paths' +import BackButton from '@/components/BackButton' const ProductCategory: FC = () => { + const navigate = useNavigate() const { data } = useGetCategory() const { mutate, isPending } = useCreateCategory() const { mutate: upload, isPending: isUploading } = useSingleUpload() @@ -29,6 +33,7 @@ const ProductCategory: FC = () => { mutate(values, { onSuccess: () => { toast.success('با موفقیت ذخیره شد') + navigate(Paths.product.category.list) }, onError: (error) => { toast.error(extractErrorMessage(error)) @@ -64,8 +69,10 @@ const ProductCategory: FC = () => { return (
- -

دسته جدید

+
+ +

دسته جدید

+