diff --git a/backend/src/db/daos/groupDao.js b/backend/src/db/daos/groupDao.js index 9dfc1d34..88043cfb 100644 --- a/backend/src/db/daos/groupDao.js +++ b/backend/src/db/daos/groupDao.js @@ -4,7 +4,8 @@ import Group from "../models/group"; import Scene from "../models/scene"; const getGroup = async (groupId) => { - return await Group.findById(groupId); + const group = await Group.findById(groupId); + return group; }; const getGroupByScenarioId = async (SId) => { diff --git a/backend/src/db/daos/noteDao.js b/backend/src/db/daos/noteDao.js index 17f6d532..b3084fdd 100644 --- a/backend/src/db/daos/noteDao.js +++ b/backend/src/db/daos/noteDao.js @@ -25,15 +25,12 @@ const createNote = async (groupId, title, role, text = "") => { */ const deleteNote = async (noteId, groupId) => { const note = await Note.findById(noteId); - console.log("note:", note); - console.log("groupId:", groupId); const updateQuery = { $pull: { [`notes.${note.role}`]: noteId }, }; // delete note from group - let res = await Group.updateOne({ _id: groupId }, updateQuery); - console.log(res); + await Group.updateOne({ _id: groupId }, updateQuery); // delete note from note collection await note.delete(); }; diff --git a/frontend/src/components/Note.jsx b/frontend/src/components/Note.jsx index 2ee02883..e560df8c 100644 --- a/frontend/src/components/Note.jsx +++ b/frontend/src/components/Note.jsx @@ -9,6 +9,7 @@ export default function Note({ role, id, group, user, refetchGroup }) { const [open, setOpen] = useState(false); const [save, setSave] = useState(false); const [isRole, setRole] = useState(false); + const [showConfirm, setShowConfirm] = useState(false); const [date, setDate] = useState(); const checkRole = () => { @@ -82,9 +83,8 @@ export default function Note({ role, id, group, user, refetchGroup }) { setOpen(false); }; - const handleDelete = async () => { - const res = window.confirm("Are you sure you want to delete this note?"); - if (!res) return; + const deleteNote = async () => { + setShowConfirm(false); try { await usePost("/api/note/delete", { noteId: id, groupId: group._id }); refetchGroup(); @@ -95,6 +95,10 @@ export default function Note({ role, id, group, user, refetchGroup }) { } }; + const handleDelete = () => { + setShowConfirm(true); + }; + const handleKeyPress = (e) => { if (e.key === "Escape") { handleClose(); @@ -195,6 +199,34 @@ export default function Note({ role, id, group, user, refetchGroup }) { )} + {showConfirm && ( +
Are you sure you want to delete this note?
+ + +