"use client"; import * as React from "react"; import { useRouter } from "next/navigation"; import { Ban, BadgeCheck, ShieldCheck, ShieldOff, Undo2 } from "lucide-react"; import { banUser, unbanUser, setUserRole, forceVerifyEmail } from "@/actions/admin"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/input"; import { Field, Label, Hint } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { ActionButton } from "./action-button"; export function UserActions({ userId, banned, role, emailVerified, isSelf }: { userId: string; banned: boolean; role: string; emailVerified: boolean; isSelf: boolean }) { const router = useRouter(); const [banOpen, setBanOpen] = React.useState(false); const [reason, setReason] = React.useState(""); const [error, setError] = React.useState(null); const [pending, start] = React.useTransition(); const doBan = () => start(async () => { setError(null); const r = await banUser(userId, reason); if (!r.ok) return setError(r.error); setBanOpen(false); setReason(""); router.refresh(); }); return (
{banned ? ( unbanUser(userId)}> Unban ) : ( )} {role === "admin" ? ( setUserRole(userId, "user")} confirm={{ title: "Remove admin role?", description: "This user will lose access to /admin immediately.", confirmLabel: "Demote", variant: "danger" }} > Demote to user ) : ( setUserRole(userId, "admin")} confirm={{ title: "Grant admin role?", description: "Admins can see upstream provider names, costs and every customer's data. Only for Fetcha staff.", confirmLabel: "Promote", variant: "primary" }} > Promote to admin )} {!emailVerified ? ( forceVerifyEmail(userId)} confirm={{ title: "Mark email as verified?", description: "Unlocks production API access without the user clicking the verification link.", confirmLabel: "Verify", variant: "primary" }}> Force verify email ) : null} Ban this user All active sessions are revoked and the user cannot sign in until unbanned. The reason is stored on the account and in the audit log.