diff --git a/src/Components/DeletePlace.js b/src/Components/DeletePlace.js index 74f538f..0a92020 100644 --- a/src/Components/DeletePlace.js +++ b/src/Components/DeletePlace.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { deleteItem } from '../Redux/places/deleteItemSlice'; import { fetchPlaces } from '../Redux/places/placesSlice'; @@ -10,17 +10,31 @@ const DeletePlace = () => { const status = useSelector((state) => state.deleteItem.status); const error = useSelector((state) => state.deleteItem.error); + const [showConfirmation, setShowConfirmation] = useState(false); + const [itemIdToDelete, setItemIdToDelete] = useState(null); + useEffect(() => { dispatch(fetchPlaces()); }, [dispatch]); const handleDelete = (id) => { - dispatch(deleteItem(id)) + setShowConfirmation(true); + setItemIdToDelete(id); + }; + + const confirmDelete = () => { + dispatch(deleteItem(itemIdToDelete)) .then(() => { dispatch(fetchPlaces()); + setShowConfirmation(false); }); }; + const cancelDelete = () => { + setShowConfirmation(false); + setItemIdToDelete(null); + }; + if (places.length === 0) { return
Are you sure?
+ + +