trash attribute value
This commit is contained in:
@@ -1,14 +1,29 @@
|
|||||||
import { type FC } from 'react'
|
import { type FC } from 'react'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
import { useGetAttributeValues } from '../hooks/useProductData'
|
import { useDeleteAttributeValue, useGetAttributeValues } from '../hooks/useProductData'
|
||||||
import CreateValue from '../components/CreateValue'
|
import CreateValue from '../components/CreateValue'
|
||||||
import Table from '@/components/Table'
|
import Table from '@/components/Table'
|
||||||
import UpdateValue from '../components/UpdateValue'
|
import UpdateValue from '../components/UpdateValue'
|
||||||
|
import TrashWithConfrim from '@/components/TrashWithConfrim'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
import { extractErrorMessage } from '@/config/func'
|
||||||
|
|
||||||
const AttributeValues: FC = () => {
|
const AttributeValues: FC = () => {
|
||||||
|
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
const { data, refetch } = useGetAttributeValues(Number(id))
|
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 (
|
return (
|
||||||
<div className='mt-5'>
|
<div className='mt-5'>
|
||||||
@@ -42,6 +57,12 @@ const AttributeValues: FC = () => {
|
|||||||
id={item.id}
|
id={item.id}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TrashWithConfrim
|
||||||
|
onDelete={() => handleDelete(item.id)}
|
||||||
|
colorIcon='red'
|
||||||
|
isloading={isPending}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,3 +180,9 @@ export const useGetAttributeValueDetail = (id: number, enabled: boolean) => {
|
|||||||
enabled: !!id && enabled,
|
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) => {
|
export const getAttributeValueDetail = async (id: number) => {
|
||||||
const { data } = await axios.get<AttributeValueDetailResponseType>(`/admin/products/attributes/value/${id}`);
|
const { data } = await axios.get<AttributeValueDetailResponseType>(`/admin/products/attributes/value/${id}`);
|
||||||
return data;
|
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