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

Sl/226 tag deletion #228

Merged
merged 2 commits into from
Oct 31, 2023
Merged
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
2 changes: 2 additions & 0 deletions src/components/Tag/TagSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ const TagSelect = ({ tag }) => {
isOpen={isOpenDeleteModal}
onClose={onCloseDeleteModal}
mainText="Are you sure you want to delete this tag?"
subText="Deleting a tag will remove the tag from all of its linked standard cards."
confirmButtonText="Yes, delete tag"
cancelButtonText="No, return to add standard"
handleAction={updateTags}
isDanger={true}
/>
</CheckboxArrayControl>
</div>
Expand Down
16 changes: 14 additions & 2 deletions src/pages/api/tag/delete.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import { deleteTagById } from "server/mongodb/actions/Tag";
import { getCards, updateCardById } from "server/mongodb/actions/Card";
import { deleteTagById, getTagById } from "server/mongodb/actions/Tag";
import { withSessionRoute } from "src/lib/utils/session";

// @route DELETE api/report/delete
// @desc Delete Report Request
// @access Public
const handler = async (req, res) => {
try {
let tag = await getTagById(req.body);
if (tag && tag.length > 0) {
tag = tag[0]
const cards = await getCards();
cards.forEach(async (card) => {
if (card.tags.includes(tag.name)) {
await updateCardById(card._id, {
tags: card.tags.filter((name) => name != tag.name),
});
}
});
}
await deleteTagById(req.body);

return res.status(200).json({
success: true,
});
Expand Down