From 45bce9d5fb1212ab4dafe19a05fcf2a28a742b2d Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 28 Jul 2023 17:37:51 +0100 Subject: [PATCH] feat: full report management --- app/panel/inspect/message/[id]/page.tsx | 8 +- app/panel/reports/[id]/page.tsx | 14 +- components/cards/CompactMessage.tsx | 8 +- components/cards/ReportCard.tsx | 19 +- components/inspector/RecentMessages.tsx | 2 +- .../inspector/RelevantModerationNotices.tsx | 4 +- components/inspector/ReportActions.tsx | 202 ++++++++++++++++-- components/inspector/UserActions.tsx | 48 ++++- lib/actions.ts | 74 +++++++ 9 files changed, 339 insertions(+), 40 deletions(-) diff --git a/app/panel/inspect/message/[id]/page.tsx b/app/panel/inspect/message/[id]/page.tsx index 4b2456c..b9b8702 100644 --- a/app/panel/inspect/message/[id]/page.tsx +++ b/app/panel/inspect/message/[id]/page.tsx @@ -28,9 +28,11 @@ export default async function Message({ - - - + {author && ( + + + + )} diff --git a/app/panel/reports/[id]/page.tsx b/app/panel/reports/[id]/page.tsx index b0d9b65..ce9cc9c 100644 --- a/app/panel/reports/[id]/page.tsx +++ b/app/panel/reports/[id]/page.tsx @@ -41,8 +41,18 @@ export default async function Reports({ params }: { params: { id: string } }) { return (
Viewing Report - - + diff --git a/components/cards/CompactMessage.tsx b/components/cards/CompactMessage.tsx index a70452e..1bfe71e 100644 --- a/components/cards/CompactMessage.tsx +++ b/components/cards/CompactMessage.tsx @@ -68,9 +68,9 @@ export function CompactMessage({
)}
- {(message.attachments || message.embeds) && ( + {message.attachments?.length || message.embeds?.length ? ( - )}{" "} + ) : null}{" "} {message.content ?? No text.}
@@ -80,9 +80,7 @@ export function CompactMessage({ {user?.avatar && ( - + )}{" "} {user?.username}#{user?.discriminator} diff --git a/components/cards/ReportCard.tsx b/components/cards/ReportCard.tsx index a14fc52..668716d 100644 --- a/components/cards/ReportCard.tsx +++ b/components/cards/ReportCard.tsx @@ -16,17 +16,28 @@ export function ReportCard({ report }: { report: Report }) { report.status !== "Created" ? "text-gray-500" : "" }`} > - {report.content.report_reason.includes("Illegal") && ( - - Urgent + {report.status === "Resolved" ? ( + Resolved + ) : report.status === "Rejected" ? ( + + Closed for {report.rejection_reason} + ) : ( + report.content.report_reason.includes("Illegal") && ( + + Urgent + + ) )}{" "} {report.additional_context || "No reason specified"} {report._id.toString().substring(20, 26)} ·{" "} {report.content.report_reason} · {report.content.type} ·{" "} - {dayjs(decodeTime(report._id)).fromNow()} + {dayjs(decodeTime(report._id)).fromNow()}{" "} + {report.status !== "Created" && report.closed_at && ( + <>· Closed {dayjs(report.closed_at).fromNow()} + )} diff --git a/components/inspector/RecentMessages.tsx b/components/inspector/RecentMessages.tsx index 3d44ebd..18b05bc 100644 --- a/components/inspector/RecentMessages.tsx +++ b/components/inspector/RecentMessages.tsx @@ -17,7 +17,7 @@ export async function RecentMessages({ query: Filter; users?: boolean | User[]; }) { - const recentMessages = await fetchMessages(query); + const recentMessages = (await fetchMessages(query)).reverse(); const userList = ( users === true diff --git a/components/inspector/RelevantModerationNotices.tsx b/components/inspector/RelevantModerationNotices.tsx index f97fab2..73f7ba3 100644 --- a/components/inspector/RelevantModerationNotices.tsx +++ b/components/inspector/RelevantModerationNotices.tsx @@ -68,7 +68,9 @@ export function RelevantModerationNotices({ {strikesDraft.map((strike) => ( {strike.reason} - {dayjs(decodeTime(strike._id)).fromNow()} + + {dayjs(decodeTime(strike._id))?.fromNow()} + ))} diff --git a/components/inspector/ReportActions.tsx b/components/inspector/ReportActions.tsx index 6a93d81..6123d74 100644 --- a/components/inspector/ReportActions.tsx +++ b/components/inspector/ReportActions.tsx @@ -11,16 +11,77 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from "../ui/dropdown-menu"; -import { useRef, useState } from "react"; +import { useState } from "react"; import { useToast } from "../ui/use-toast"; -import { updateReportNotes } from "@/lib/actions"; +import { + rejectReport, + reopenReport, + resolveReport, + sendAlert, + updateReportNotes, +} from "@/lib/actions"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "../ui/alert-dialog"; +import { ReportCard } from "../cards/ReportCard"; -export function ReportActions({ report }: { report: Report }) { +const template: Record string> = { + resolved: (ref) => + `Your report (${ref}) has been actioned and appropriate action has been taken.`, + invalid: (ref) => `Your report (${ref}) has been marked as invalid.`, + false: (ref) => + `Your report (${ref}) has been marked as false or spam. False reports may lead to additional action against your account.`, + duplicate: (ref) => `Your report (${ref}) has been marked as a duplicate.`, + "not enough evidence": (ref) => + `Your report (${ref}) has not been actioned at this time due to a lack of supporting evidence, if you have additional information to support your report, please either report individual relevant messages or send an email to contact@revolt.chat.`, + clarify: (ref) => + `Your report (${ref}) needs clarification, please provide additional information.`, + acknowledged: (ref) => + `Your report (${ref}) has been acknowledged, we will be monitoring the situation.`, + default: (ref) => + `Report (${ref})\n\nNo template found for rejection reason, please specify.`, +}; + +export function ReportActions({ + report, + reference, +}: { + report: Report; + reference: string; +}) { const { toast } = useToast(); const [reportDraft, setDraft] = useState(report); + function rejectHandler(reason: string) { + return async () => { + try { + const $set = await rejectReport(report._id, reason); + setDraft((report) => ({ ...report, ...$set })); + toast({ + title: "Rejected report", + }); + } catch (err) { + toast({ + title: "Failed to reject report", + description: String(err), + variant: "destructive", + }); + } + }; + } + return ( <> + +