From 93cd14bcd303bf8d2425078a83723f78b5c1755f Mon Sep 17 00:00:00 2001 From: Roshin Jimmy Date: Fri, 29 Mar 2024 21:37:26 +0530 Subject: [PATCH] fixed: Delete message confirmation toast --- .../DeleteConfirmation.js | 64 +++++++++++++------ .../DeleteConfirmationModal/modal.css | 10 +++ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/Components/DeleteConfirmationModal/DeleteConfirmation.js b/src/Components/DeleteConfirmationModal/DeleteConfirmation.js index 56b499bf..00b234b8 100644 --- a/src/Components/DeleteConfirmationModal/DeleteConfirmation.js +++ b/src/Components/DeleteConfirmationModal/DeleteConfirmation.js @@ -1,36 +1,63 @@ -import { Modal, Button } from "react-bootstrap"; -import React from "react"; +import { Modal, Button, Form } from "react-bootstrap"; +import React, { useState } from "react"; import "./modal.css"; import { useHistory } from "react-router-dom"; import { doDeleteProject } from "../../Firebase/firebase"; import { useContext } from "react"; import { ProjectContext } from "../../contexts/ProjectContext"; - import { toast } from "react-toastify"; + const DeleteConfirmation = ({ showModal, hideModal, id }) => { const { fetchData, projects } = useContext(ProjectContext); const history = useHistory(); + const [projectName, setProjectName] = useState(""); + + const photoDetails = projects.find((value) => value.id === id); + let actualProjectName = ''; + if (photoDetails) { + actualProjectName = photoDetails.name.trim(); + } + const submitDelete = (id) => { - const photoDetails = projects.filter((value, index) => value.id === id)[0]; - const photoId = photoDetails.projectPhoto; - const photoName = photoDetails.projectPhotoName; - var myid = photoId.slice(91) - myid = myid.slice(0,myid.indexOf('?')) - doDeleteProject(id, myid, photoName, () => { - toast("Project deleted successfully"); - history.push("/projects"); - fetchData(); - }); + + if (!photoDetails) return; + + const enteredProjectName = projectName.trim(); + + if (enteredProjectName === actualProjectName) { + const photoId = photoDetails.projectPhoto; + const photoName = photoDetails.projectPhotoName; + const myid = photoId.slice(91, photoId.indexOf('?')); + + doDeleteProject(id, myid, photoName, () => { + toast("Project deleted successfully"); + history.push("/projects"); + fetchData(); + hideModal(); + }); + } else { + toast.error("Project name does not match. Please enter the correct project name."); + } }; + return ( - Delete Confirmation + Do you want to delete your project? -
- Are you sure you want to delete this Project? -
+
+ Are you sure you want to delete {actualProjectName}? +
+ + Please type the exact project name to confirm: + setProjectName(e.target.value)} + placeholder="Enter project name" + /> +