import { t } from "@lingui/core/macro"; import Button from "~/components/Button"; import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; import { api } from "~/utils/api"; interface DeleteCommentConfirmationProps { cardPublicId: string; commentPublicId: string; } export function DeleteCommentConfirmation({ cardPublicId, commentPublicId, }: DeleteCommentConfirmationProps) { const { closeModal } = useModal(); const utils = api.useUtils(); const { showPopup } = usePopup(); const queryParams = { cardPublicId, }; const deleteCommentMutation = api.card.deleteComment.useMutation({ onMutate: async (args) => { closeModal(); await utils.card.byId.cancel(); const currentState = utils.card.byId.getData(queryParams); utils.card.byId.setData(queryParams, (oldCard) => { if (!oldCard) return oldCard; const updatedActivities = oldCard.activities.filter( (activity) => activity.comment?.publicId !== args.commentPublicId, ); return { ...oldCard, activities: updatedActivities }; }); return { previousState: currentState }; }, onError: (_error, _newList, context) => { utils.card.byId.setData(queryParams, context?.previousState); showPopup({ header: t`Unable to delete comment`, message: t`Please try again later, or contact customer support.`, icon: "error", }); }, onSettled: async () => { await utils.card.byId.invalidate(queryParams); }, }); const handleDeleteComment = () => { deleteCommentMutation.mutate({ cardPublicId, commentPublicId, }); }; return (

{t`Are you sure you want to delete this comment?`}

{t`This action can't be undone.`}

); }