diff --git a/src/vite-project/src/pages/voucherpageadmin.jsx b/src/vite-project/src/pages/voucherpageadmin.jsx index 079af3248b130a8f1c2b63d7836f8106cf47e7e1..359a1167503142bc39610e3c16d96777b1dbb5b9 100644 --- a/src/vite-project/src/pages/voucherpageadmin.jsx +++ b/src/vite-project/src/pages/voucherpageadmin.jsx @@ -28,14 +28,22 @@ const DataDummy = [ ]; const VoucherPage = () => { - const GunakanButton = (index) => { - const confirmation = window.confirm('Yakin mau menghapus voucher?'); - - if (confirmation) { - const deleteVoucher = DataDummy[index]; - console.log(`${deleteVoucher.name} berhasil dihapus!`); - window.alert('Voucher berhasil dihapus!'); - } + const GunakanButton = (id) => { + const fetchData = async () => { + try { + const response = await axios.delete(`/voucher/${id}`, { + headers: { + 'Authorization': `${localStorage.getItem('token')}` + } + }); + const data = response.data.data; + setPackageData(data); + window.alert('voucher berhasil dihapus!'); + } catch (error) { + window.alert(error); + } + }; + fetchData(); }; const [voucherData, setVoucherData] = useState([]); @@ -77,7 +85,7 @@ const VoucherPage = () => { Detail </button> </Link> - <button class="voucher-detail-button bg-red-500 hover:bg-red-400 text-white font-bold py-2 px-4 border-b-4 border-red-700 hover:border-red-500 rounded" onClick={() => GunakanButton(index)}> + <button class="voucher-detail-button bg-red-500 hover:bg-red-400 text-white font-bold py-2 px-4 border-b-4 border-red-700 hover:border-red-500 rounded" onClick={() => GunakanButton(item.VoucherID)}> Delete </button> </div>