Files
ai-agent/web/app/dashboard/users/_components/initial-password-dialog.tsx
T

81 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-04-09 10:01:23 +08:00
"use client"
import { useState } from "react"
import { CopyIcon } from "lucide-react"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
2026-05-25 12:06:15 +08:00
import { useI18n } from "@/i18n/provider"
2026-04-09 10:01:23 +08:00
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
type InitialPasswordDialogProps = {
open: boolean
username: string
password: string
onOpenChange: (open: boolean) => void
}
export function InitialPasswordDialog({
open,
username,
password,
onOpenChange,
}: InitialPasswordDialogProps) {
2026-05-25 12:06:15 +08:00
const t = useI18n()
2026-04-09 10:01:23 +08:00
const [copying, setCopying] = useState(false)
async function handleCopy() {
if (!password || copying) {
return
}
setCopying(true)
try {
await navigator.clipboard.writeText(password)
2026-05-25 12:06:15 +08:00
toast.success(t("user.copied"))
2026-04-09 10:01:23 +08:00
} catch {
2026-05-25 12:06:15 +08:00
toast.error(t("user.copyFailed"))
2026-04-09 10:01:23 +08:00
} finally {
setCopying(false)
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
2026-05-25 12:06:15 +08:00
<DialogTitle>{t("user.createdTitle")}</DialogTitle>
2026-04-09 10:01:23 +08:00
<DialogDescription>
2026-05-25 12:06:15 +08:00
{t("user.initialPasswordDescription", { username: username || "-" })}
2026-04-09 10:01:23 +08:00
</DialogDescription>
</DialogHeader>
<div className="rounded-md border bg-muted/35 p-4">
2026-05-25 12:06:15 +08:00
<div className="text-xs text-muted-foreground">{t("user.initialPassword")}</div>
2026-04-09 10:01:23 +08:00
<div className="mt-2 break-all font-mono text-base">{password}</div>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => void handleCopy()}
disabled={copying || !password}
>
<CopyIcon />
2026-05-25 12:06:15 +08:00
{copying ? t("user.copying") : t("user.copyPassword")}
2026-04-09 10:01:23 +08:00
</Button>
<Button type="button" onClick={() => onOpenChange(false)}>
2026-05-25 12:06:15 +08:00
{t("user.close")}
2026-04-09 10:01:23 +08:00
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}