delete category
This commit is contained in:
@@ -27,7 +27,7 @@ const DefaulModal: FC<Props> = (props: Props) => {
|
|||||||
<Fragment>
|
<Fragment>
|
||||||
<div style={{ maxWidth: props.width }} className='xl:justify-center xl:items-center items-end flex overflow-x-hidden overflow-y-auto fixed inset-0 z-[9999999] h-auto top-0 bottom-0 m-auto outline-none focus:outline-none xl:max-w-xl mx-auto'>
|
<div style={{ maxWidth: props.width }} className='xl:justify-center xl:items-center items-end flex overflow-x-hidden overflow-y-auto fixed inset-0 z-[9999999] h-auto top-0 bottom-0 m-auto outline-none focus:outline-none xl:max-w-xl mx-auto'>
|
||||||
<div className='relative xl:h-full max-h-[80%] bottom-0 left-0 flex xl:items-center sm:h-auto w-full xl:my-6 xl:p-2'>
|
<div className='relative xl:h-full max-h-[80%] bottom-0 left-0 flex xl:items-center sm:h-auto w-full xl:my-6 xl:p-2'>
|
||||||
<div className='h-auto p-5 lg:min-w-full overflow-y-auto rounded-3xl rounded-b-none xl:rounded-b-3xl relative flex flex-col w-full outline-none focus:outline-none bg-card border border-border'>
|
<div className='h-auto p-5 lg:min-w-full overflow-y-auto rounded-3xl rounded-b-none xl:rounded-b-3xl relative flex flex-col w-full outline-none focus:outline-none bg-card border border-border bg-white'>
|
||||||
|
|
||||||
{
|
{
|
||||||
props.isHeader && props.title_header &&
|
props.isHeader && props.title_header &&
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { type FC, useState } from 'react'
|
||||||
|
import DefaulModal from './DefaulModal'
|
||||||
|
import Button from './Button'
|
||||||
|
import Textarea from './Textarea'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
isloading?: boolean,
|
||||||
|
close: () => void,
|
||||||
|
isOpen: boolean,
|
||||||
|
onConfrim: (text?: string) => void,
|
||||||
|
label?: string,
|
||||||
|
isHasDescription?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const ModalConfrim: FC<Props> = (props: Props) => {
|
||||||
|
|
||||||
|
const [description, setDescription] = useState<string>('')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DefaulModal
|
||||||
|
open={props.isOpen}
|
||||||
|
close={props.close}
|
||||||
|
title_header={'حذف'}
|
||||||
|
isHeader
|
||||||
|
>
|
||||||
|
<div className='mt-6'>
|
||||||
|
<div className='text-sm text-center'>
|
||||||
|
{
|
||||||
|
props.label ?
|
||||||
|
props.label
|
||||||
|
:
|
||||||
|
'برای حذف این آیتم مطمئن هستید؟'
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
props.isHasDescription &&
|
||||||
|
<div className='mt-4'>
|
||||||
|
<Textarea
|
||||||
|
placeholder={'توضیحات'}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
value={description}
|
||||||
|
className='bg-transparent border border-gray-500 rounded-xl w-[300px] p-2'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex gap-4 justify-center mt-10'>
|
||||||
|
<Button
|
||||||
|
label={'بله'}
|
||||||
|
onClick={() => props.onConfrim(props.isHasDescription ? description : undefined)}
|
||||||
|
isLoading={props.isloading}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
label={'لغو'}
|
||||||
|
className='bg-transparent text-black border border-primary'
|
||||||
|
onClick={props.close}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DefaulModal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ModalConfrim
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { Trash } from 'iconsax-react'
|
||||||
|
import { type FC, useState } from 'react'
|
||||||
|
import ModalConfrim from './ModalConfrim'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onDelete: () => void,
|
||||||
|
isloading?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const TrashWithConfrim: FC<Props> = ({ onDelete, isloading = false }) => {
|
||||||
|
const [isConfirm, setIsConfirm] = useState(false)
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Trash
|
||||||
|
onClick={() => setIsConfirm(true)}
|
||||||
|
className='size-5'
|
||||||
|
color='#888'
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ModalConfrim
|
||||||
|
isOpen={isConfirm}
|
||||||
|
close={() => setIsConfirm(false)}
|
||||||
|
onConfrim={() => onDelete()}
|
||||||
|
isloading={isloading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TrashWithConfrim
|
||||||
@@ -1,13 +1,28 @@
|
|||||||
import { type FC } from 'react'
|
import { type FC } from 'react'
|
||||||
import { useGetCategory } from '../hooks/useProductData'
|
import { useDeleteCategory, useGetCategory } from '../hooks/useProductData'
|
||||||
import Table from '@/components/Table'
|
import Table from '@/components/Table'
|
||||||
import type { ColumnType, RowDataType } from '@/components/types/TableTypes'
|
import type { ColumnType, RowDataType } from '@/components/types/TableTypes'
|
||||||
import type { CategoryType } from '../types/Types'
|
import type { CategoryType } from '../types/Types'
|
||||||
import { Edit } from 'iconsax-react'
|
import { Edit } from 'iconsax-react'
|
||||||
|
import TrashWithConfrim from '@/components/TrashWithConfrim'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
import { extractErrorMessage } from '@/config/func'
|
||||||
|
|
||||||
const CategoryList: FC = () => {
|
const CategoryList: FC = () => {
|
||||||
|
|
||||||
const { data } = useGetCategory()
|
const { data, refetch } = useGetCategory()
|
||||||
|
const { mutate, isPending } = useDeleteCategory()
|
||||||
|
|
||||||
|
const handleDelete = (id: string) => {
|
||||||
|
mutate(id, {
|
||||||
|
onSuccess: () => {
|
||||||
|
refetch()
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(extractErrorMessage(error))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const column: ColumnType<CategoryType>[] = [
|
const column: ColumnType<CategoryType>[] = [
|
||||||
{
|
{
|
||||||
@@ -41,7 +56,7 @@ const CategoryList: FC = () => {
|
|||||||
{
|
{
|
||||||
title: '',
|
title: '',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
render: () => {
|
render: (item) => {
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center gap-2'>
|
<div className='flex items-center gap-2'>
|
||||||
<Edit
|
<Edit
|
||||||
@@ -49,6 +64,10 @@ const CategoryList: FC = () => {
|
|||||||
color='#8C90A3'
|
color='#8C90A3'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TrashWithConfrim
|
||||||
|
onDelete={() => handleDelete(item.id)}
|
||||||
|
isloading={isPending}
|
||||||
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,3 +13,9 @@ export const useCreateCategory = () => {
|
|||||||
mutationFn: api.createCategory,
|
mutationFn: api.createCategory,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useDeleteCategory = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: string) => api.deleteCategory(id),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -9,4 +9,9 @@ export const getCategory = async () => {
|
|||||||
export const createCategory = async (params:CreateCategoryType) => {
|
export const createCategory = async (params:CreateCategoryType) => {
|
||||||
const { data } = await axios.post("/admin/category", params);
|
const { data } = await axios.post("/admin/category", params);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteCategory = async(id:string) => {
|
||||||
|
const { data } = await axios.delete(`/admin/category/${id}`)
|
||||||
|
return data
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user