import { FC, useState } from 'react' import { useTranslation } from 'react-i18next' import Button from '../../components/Button' import { Add, Edit, Trash } from 'iconsax-react' import Td from '../../components/Td' import { Link } from 'react-router-dom' import { Pages } from '../../config/Pages' import Input from '../../components/Input' import { useGetDiscounts, useDeleteDiscount } from './hooks/useDiscountData' import { DiscountItemType } from './types/DiscountTypes' import moment from 'moment-jalaali' import ToggleStatusDiscount from './components/ToggleStatusDiscount' import PageLoading from '../../components/PageLoading' import { NumberFormat } from '../../config/func' import { toast } from '../../components/Toast'; import { ErrorType } from '../../helpers/types' import { usePermissions } from '../../hooks/usePermissions' const DiscountList: FC = () => { const { t } = useTranslation('global') const { canCreate, canUpdate, canDelete } = usePermissions() const [search, setSearch] = useState('') const getDiscounts = useGetDiscounts(search) const deleteDiscount = useDeleteDiscount() const handleDelete = (id: string) => { deleteDiscount.mutate(id, { onSuccess: () => { getDiscounts.refetch() toast(t('success'), 'success') }, onError: (error: ErrorType) => { toast(error.response?.data?.error.message[0], 'error') } }) } return (
{t('discount.list')}
{canCreate('discounts') && }
setSearch(value)} />
{ getDiscounts.isPending ? :
{ getDiscounts.data?.data?.discounts?.map((item: DiscountItemType) => { return ( ) }) }
{canUpdate('discounts') && } {canDelete('discounts') && handleDelete(item.id)} /> }
}
) } export default DiscountList