'use client'; import { useState } from 'react'; import { useFormStatus } from 'react-dom'; import { useRouter } from 'next/navigation'; import type { User } from '@supabase/gotrue-js'; import ErrorBoundary from '@/components/app/ErrorBoundary'; import useCsrfToken from '@kit/hooks/use-csrf-token'; import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert'; import { Button } from '@kit/ui/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@kit/ui/dialog'; import { Input } from '@kit/ui/input'; import { Label } from '@kit/ui/label'; import { banUser } from '../actions.server'; function BanUserModal({ user, }: React.PropsWithChildren<{ user: User; }>) { const router = useRouter(); const [isOpen, setIsOpen] = useState(true); const csrfToken = useCsrfToken(); const displayText = user.email ?? user.phone ?? ''; const onDismiss = () => { router.back(); setIsOpen(false); }; const onConfirm = async () => { await banUser({ userId: user.id, csrfToken, }); onDismiss(); }; return ( Ban User }> You are about to ban {displayText}. You can unban them later, but they will not be able to log in or use their account until you do. Type BAN to confirm Are you sure you want to do this? ); } function SubmitButton() { const { pending } = useFormStatus(); return ( Yes, ban user ); } export default BanUserModal; function BanErrorAlert() { return ( There was an error banning this user. Check the logs for more information. ); }
You are about to ban {displayText}.
You can unban them later, but they will not be able to log in or use their account until you do.
Are you sure you want to do this?