Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7 Implement Custom Modal for Confirming Task Deletion #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions frontend/src/components/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from "react";

export const Modal = ({ handleClick }) => {
const [isOpen, setIsOpen] = useState(false);
// console.log(handleClick);
const openModal = () => {
setIsOpen(true);
};

const closeModal = () => {
setIsOpen(false);
};

const deleteTask = () => {
setIsOpen(false);
handleClick();
};

return (
<span>
<span className="material-symbols-outlined" onClick={openModal}>
delete
</span>
{isOpen && (
<div className="modal-overlay">
<div className="modal">
<h2>Are you sure you want to delete the task?</h2>
<div className="over-b">
<button className="button" onClick={deleteTask}>
Yes
</button>
<button className="button" onClick={closeModal}>
Close
</button>
</div>
</div>
</div>
)}
</span>
);
};
7 changes: 3 additions & 4 deletions frontend/src/components/TaskDetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTasksContext } from "../hooks/usetasksContext";
import { useAuthContext } from "../hooks/useAuthContext";

import { Modal } from "./Modal";
const TaskDetails = ({ task }) => {
const { dispatch } = useTasksContext();
const { user } = useAuthContext();
Expand Down Expand Up @@ -35,9 +35,8 @@ const TaskDetails = ({ task }) => {
<strong>Progress: </strong>
{task.progress}
</p>
<span className="material-symbols-outlined" onClick={handleClick}>
delete
</span>

<Modal handleClick={handleClick} />
</div>
);
};
Expand Down
45 changes: 40 additions & 5 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ header a {
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
background: #f1f1f1;
padding: 6px;
border-radius: 50%;
color: #333;
}

/* new task form */
Expand Down Expand Up @@ -119,4 +114,44 @@ form.signup, form.login {
padding: 20px;
background: #fff;
border-radius: 4px;
}


.modal-overlay {
z-index: 999;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* semi-transparent black overlay */
display: flex;
justify-content: center;
align-items: center;
}

.modal {
background-color: white;
padding: 20px;
border-radius: 5px;
}

.button{
background: #fff;
color: var(--primary);
border: 2px solid var(--primary);
padding: 6px 10px;
border-radius: 4px;
font-family: "Poppins";
cursor: pointer;
font-size: 1em;

}

.over-b{
display: flex;
justify-content: space-evenly;
}
.material-symbols-outlined{
cursor: pointer;
}