"use client"; import Link from "next/link"; import { Button, buttonVariants } from "../../ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "../../ui/dropdown-menu"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "../../ui/alert-dialog"; import { Input } from "../../ui/input"; import { banUser, closeReportsByUser, sendAlert, suspendUser, unsuspendUser, updateBotDiscoverability, updateUserBadges, } from "@/lib/actions"; import { useRef, useState } from "react"; import { useToast } from "../../ui/use-toast"; import { Bot, User } from "revolt-api"; import { Card, CardHeader } from "../../ui/card"; import { cn } from "@/lib/utils"; import { decodeTime } from "ulid"; const badges = [1, 2, 4, 8, 16, 32, 128, 0, 256, 512, 1024]; export function UserActions({ user, bot }: { user: User; bot?: Bot }) { const alertMessage = useRef(""); const { toast } = useToast(); const [userDraft, setUserDraft] = useState(user); const [botDraft, setBotDraft] = useState(bot); const userInaccessible = userDraft.flags === 4 || userDraft.flags === 2; return ( <> {badges.map((badge) => { const sysBadge = (badge === 0 && user._id === "01EX2NCWQ0CHS3QJF0FEQS1GR4") || (badge === 256 && decodeTime(user._id) < 1629638578431); return ( // eslint-disable-next-line { if (sysBadge) return; try { const badges = (decodeTime(user._id) < 1629638578431 ? 256 : 0) | ((userDraft.badges ?? 0) ^ badge); await updateUserBadges(user._id, badges); setUserDraft((user) => ({ ...user!, badges })); toast({ title: "Updated user badges", }); } catch (err) { toast({ title: "Failed to update user badges", description: String(err), variant: "destructive", }); } }} /> ); })}
{bot ? ( botDraft!.discoverable ? ( ) : ( ) ) : ( Account )} Are you sure you want to{" "} {userDraft.flags === 1 ? "unsuspend" : "suspend"} this user? Cancel userDraft.flags === 1 ? unsuspendUser(user._id) .then(() => { setUserDraft((user) => ({ ...user, flags: 0 })); toast({ title: "Unsuspended user" }); }) .catch((err) => toast({ title: "Failed to unsuspend user!", description: String(err), variant: "destructive", }) ) : suspendUser(user._id) .then(() => { setUserDraft((user) => ({ ...user, flags: 1 })); toast({ title: "Suspended user" }); }) .catch((err) => toast({ title: "Failed to suspend user!", description: String(err), variant: "destructive", }) ) } > Suspend Are you sure you want to ban this user? This action is irreversible! Cancel banUser(user._id) .then(() => { setUserDraft((user) => ({ ...user, flags: 4 })); toast({ title: "Banned user" }); }) .catch((err) => toast({ title: "Failed to ban user!", description: String(err), variant: "destructive", }) ) } > Ban Release the bees Are you sure you want to send the bees? Cancel toast({ title: "🐝" })}> Send ‘em! Send Alert This will send a message from the Platform Moderation account. (alertMessage.current = e.currentTarget.value) } /> Cancel { if (!alertMessage.current) return; alertMessage.current = ""; sendAlert(user._id, alertMessage.current) .then(() => toast({ title: "Sent Alert" })) .catch((err) => toast({ title: "Failed to send alert!", description: String(err), variant: "destructive", }) ); }} > Send Close Open Reports This will close all reports still open by this user. Cancel closeReportsByUser(user._id) .then((reports) => toast({ title: `Closed ${reports} Reports` }) ) .catch((err) => toast({ title: "Failed to close reports!", description: String(err), variant: "destructive", }) ) } > Continue {/* Clear ({counts.pending}) Friend Requests Clear All ({counts.all}) Relations */}
); }