Skip to content

Commit 15d6c06

Browse files
committed
add confirmation modal on announcement delete
1 parent 28d2b7b commit 15d6c06

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

  • client/pages/announcements/[slug]

client/pages/announcements/[slug]/index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import { NotificationContext } from "../../../components/Notifications";
1818
import Input from "../../../components/Input";
1919
import Comment from "../../../components/Comment";
2020
import LoadingContext from "../../../utils/LoadingContext";
21+
import Modal from "../../../components/Modal";
2122

2223
const Announcement = ({ announcement, token, userRole }) => {
2324
const [pinned, setPinned] = useState(announcement.pinned);
2425
const [comments, setComments] = useState(announcement.comments);
26+
const [showDeleteModal, setShowDeleteModal] = useState(false);
2527

2628
const { addNotification } = useContext(NotificationContext);
2729
const { setLoading } = useContext(LoadingContext);
@@ -180,7 +182,10 @@ const Announcement = ({ announcement, token, userRole }) => {
180182
</Button>
181183
</a>
182184
</Link>
183-
<Button onClick={handleDelete} variant="secondary">
185+
<Button
186+
onClick={() => setShowDeleteModal(true)}
187+
variant="secondary"
188+
>
184189
Delete
185190
</Button>
186191
</Box>
@@ -246,6 +251,26 @@ const Announcement = ({ announcement, token, userRole }) => {
246251
</Box>
247252
)}
248253
</Box>
254+
{showDeleteModal && (
255+
<Modal close={() => setShowDeleteModal(false)}>
256+
<Text mb={5}>
257+
Are you sure you want to delete this announcement? This cannot be
258+
undone.
259+
</Text>
260+
<Box display="flex" justifyContent="flex-end">
261+
<Button
262+
onClick={() => setShowDeleteModal(false)}
263+
variant="secondary"
264+
mr={3}
265+
>
266+
Cancel
267+
</Button>
268+
<Button onClick={handleDelete} variant="danger">
269+
Delete
270+
</Button>
271+
</Box>
272+
</Modal>
273+
)}
249274
</>
250275
);
251276
};

0 commit comments

Comments
 (0)