"use client"; import { useState } from "react"; import { toast } from "sonner"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { updateSignupMode } from "@/lib/actions/admin"; import { SignupMode } from "@/lib/generated/prisma/enums"; const OPTIONS: { value: SignupMode; label: string; description: string; disabled?: boolean; }[] = [ { value: SignupMode.OPEN, label: "Open", description: "Anyone can sign up and gets the User role right away.", }, { value: SignupMode.APPROVED, label: "Approved", description: "Anyone can sign up, but starts Pending and can't log in until an admin changes their role to User or Administrator.", }, { value: SignupMode.CONFIRMED, label: "Confirmed", description: "Anyone can sign up, but starts Pending until they confirm their email.", disabled: true, }, { value: SignupMode.CLOSED, label: "Closed", description: "The site isn't accepting new accounts. The sign-up form and links are removed, and the sign-up action refuses new accounts.", }, ]; /** Lets an admin choose how the site handles new sign-ups. */ export function SignupModeSettings({ initialMode }: { initialMode: SignupMode }) { const [current, setCurrent] = useState(initialMode); const [pending, setPending] = useState(false); async function handleChange(next: string) { if (next === current || pending) return; const prev = current; setCurrent(next as SignupMode); setPending(true); const result = await updateSignupMode(next); setPending(false); if (result?.error) { setCurrent(prev); toast.error(result.error); } } return ( New sign-ups Choose how the site handles people signing up for an account. {OPTIONS.map((option) => (

{option.description}

))}
); }