"use client"; import { useActionState, useState } from "react"; import { KeyRoundIcon, MoreHorizontalIcon, PencilIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { resetClientPassword, updateClientAccount } from "@/modules/admin/actions/manage-client"; import { MIN_PASSWORD_LENGTH } from "@/modules/admin/lib/constants"; import { CopyField } from "./copy-field"; type Client = { id: string; name: string; email: string }; function ResetPasswordContent({ client, onDone }: { client: Client; onDone: () => void }) { const [mode, setMode] = useState<"generate" | "manual">("generate"); const [state, formAction, pending] = useActionState(resetClientPassword, undefined); if (state && "success" in state) { return ( <> Passwort geändert Gib das neue Passwort an {client.name} weiter. Es wird nur jetzt angezeigt. ); } return ( <> Passwort zurücksetzen Setzt das Passwort von {client.name} neu. Das alte Passwort funktioniert danach nicht mehr.
{(["generate", "manual"] as const).map((value) => ( ))}
{mode === "manual" && ( Neues Passwort Mindestens {MIN_PASSWORD_LENGTH} Zeichen. )} {state && "error" in state &&

{state.error}

}
); } function EditClientContent({ client, onDone }: { client: Client; onDone: () => void }) { async function run(prev: Parameters[0], formData: FormData) { const result = await updateClientAccount(prev, formData); if (result && "success" in result) onDone(); return result; } const [state, formAction, pending] = useActionState(run, undefined); return ( <> Client bearbeiten
Name Email Das ist auch die Login-Email des Clients. {state && "error" in state &&

{state.error}

}
); } export function ClientActionsMenu({ client }: { client: Client }) { const [dialog, setDialog] = useState<"password" | "edit" | null>(null); const [instanceKey, setInstanceKey] = useState(0); function close() { setDialog(null); setInstanceKey((key) => key + 1); } return ( <> }> setDialog("edit")}> Bearbeiten setDialog("password")}> Passwort zurücksetzen !open && close()}> {dialog === "password" && } {dialog === "edit" && } ); }