trash attribute value

This commit is contained in:
hamid zarghami
2026-01-25 12:07:46 +03:30
parent 375ea9d669
commit 7e5184529e
3 changed files with 33 additions and 1 deletions
@@ -1,14 +1,29 @@
import { type FC } from 'react'
import { useParams } from 'react-router-dom'
import { useGetAttributeValues } from '../hooks/useProductData'
import { useDeleteAttributeValue, useGetAttributeValues } from '../hooks/useProductData'
import CreateValue from '../components/CreateValue'
import Table from '@/components/Table'
import UpdateValue from '../components/UpdateValue'
import TrashWithConfrim from '@/components/TrashWithConfrim'
import { toast } from 'react-toastify'
import { extractErrorMessage } from '@/config/func'
const AttributeValues: FC = () => {
const { id } = useParams()
const { data, refetch } = useGetAttributeValues(Number(id))
const { mutate: deleteValue, isPending } = useDeleteAttributeValue()
const handleDelete = (id: number) => {
deleteValue(id, {
onSuccess: () => {
refetch()
},
onError: (error) => {
toast.error(extractErrorMessage(error))
}
})
}
return (
<div className='mt-5'>
@@ -42,6 +57,12 @@ const AttributeValues: FC = () => {
id={item.id}
refetch={refetch}
/>
<TrashWithConfrim
onDelete={() => handleDelete(item.id)}
colorIcon='red'
isloading={isPending}
/>
</div>
)
}
@@ -180,3 +180,9 @@ export const useGetAttributeValueDetail = (id: number, enabled: boolean) => {
enabled: !!id && enabled,
});
};
export const useDeleteAttributeValue = () => {
return useMutation({
mutationFn: (id: number) => api.deleteAttributeValue(id),
});
};
@@ -94,4 +94,9 @@ export const updateAttributeValues = async (id: number, params:CreateAttributeVa
export const getAttributeValueDetail = async (id: number) => {
const { data } = await axios.get<AttributeValueDetailResponseType>(`/admin/products/attributes/value/${id}`);
return data;
};
export const deleteAttributeValue = async (id: number) => {
const { data } = await axios.delete(`/admin/products/attributes/value/${id}`);
return data;
};