trash attribute value
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user