From 298d57fdea82a3d919c1fad1de9a9e9a1955c25f Mon Sep 17 00:00:00 2001 From: Salomo309 <109785084+Salomo309@users.noreply.github.com> Date: Fri, 17 Nov 2023 02:34:42 +0700 Subject: [PATCH] feat: integrate delete song --- src/components/delete-dialog-song.tsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/delete-dialog-song.tsx b/src/components/delete-dialog-song.tsx index cea7360..391c71e 100644 --- a/src/components/delete-dialog-song.tsx +++ b/src/components/delete-dialog-song.tsx @@ -1,6 +1,21 @@ -import React from 'react'; +import axios from 'axios'; +import { useNavigate, useParams } from 'react-router'; + +const DeleteSongDialog = () => { + const { albumId, songId } = useParams(); + const navigate = useNavigate(); + const handleDeleteSong = () => { + try { + axios.delete(`http://localhost:3000/api/premium-album/${albumId}/${songId}`); + } catch (error) { + console.error('Error deleting song:', error); + } + }; + + const handleCancel = () => { + navigate(-1); + }; -const DeleteSongDialog: React.FC = () => { return ( <> {( @@ -14,14 +29,16 @@ const DeleteSongDialog: React.FC = () => { <div className="mb-4">Are you sure you want to delete this Song?</div> <div className="flex justify-end"> <button + onClick={handleCancel} className="px-4 py-2 mr-2 bg-gray-300 hover:bg-gray-400 rounded" > - Batal + Cancel </button> <button + onClick={handleDeleteSong} className="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded" > - Hapus + Delete </button> </div> </div> -- GitLab