Skip to content

Commit

Permalink
Merge pull request #292 from roshinjimmy/dev
Browse files Browse the repository at this point in the history
fixed: Delete message confirmation toast
  • Loading branch information
subru-37 authored Mar 29, 2024
2 parents 16e1845 + 93cd14b commit 4ffb1ec
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
64 changes: 46 additions & 18 deletions src/Components/DeleteConfirmationModal/DeleteConfirmation.js
Original file line number Diff line number Diff line change
@@ -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 (
<Modal show={showModal} onHide={hideModal} centered>
<Modal.Header closeButton closeVariant="white">
<Modal.Title>Delete Confirmation</Modal.Title>
<Modal.Title>Do you want to delete your project?</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className="alert alert-danger">
Are you sure you want to delete this Project?
</div>
<div className="alert alert-danger">
Are you sure you want to delete <strong>{actualProjectName}</strong>?
</div>
<Form.Group controlId="projectName">
<Form.Label>Please type the exact project name to confirm:</Form.Label>
<Form.Control
type="text"
value={projectName}
onChange={(e) => setProjectName(e.target.value)}
placeholder="Enter project name"
/>
</Form.Group>
</Modal.Body>
<Modal.Footer>
<Button variant="light" onClick={hideModal}>
Expand All @@ -43,4 +70,5 @@ const DeleteConfirmation = ({ showModal, hideModal, id }) => {
</Modal>
);
};
export default DeleteConfirmation;

export default DeleteConfirmation;
10 changes: 10 additions & 0 deletions src/Components/DeleteConfirmationModal/modal.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
.modal-header :hover {
background-color: white !important;
}

.modal-header button {
outline: none !important;
}

.modal-footer {
display: flex;
justify-content: space-between;
}

.modal-footer button {
margin: 0 10px;
}

0 comments on commit 4ffb1ec

Please sign in to comment.