"use client"; import { useEffect, useState, useTransition } from "react"; import { createPortal } from "react-dom"; import { useRouter } from "next/navigation"; import { X, Loader2 } from "lucide-react"; import { updateActressMeta } from "@/app/actions/actressMeta"; interface Props { actressId: number; initial: { name: string; altNames: string | null; notes: string | null; bornOn?: string | null; heightCm?: number | null; weightKg?: number | null; cupSize?: string | null; }; onClose: () => void; } export function ActressMetaEditor({ actressId, initial, onClose }: Props) { const router = useRouter(); const [name, setName] = useState(initial.name); const [altNames, setAltNames] = useState(initial.altNames ?? ""); const [notes, setNotes] = useState(initial.notes ?? ""); const [bornOn, setBornOn] = useState(initial.bornOn ?? ""); const [height, setHeight] = useState(initial.heightCm != null ? String(initial.heightCm) : ""); const [weight, setWeight] = useState(initial.weightKg != null ? String(initial.weightKg) : ""); const [cup, setCup] = useState(initial.cupSize ?? ""); const [busy, setBusy] = useState(false); const [, start] = useTransition(); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); async function save() { setBusy(true); try { const r = await updateActressMeta(actressId, { name, altNames, notes, bornOn: bornOn || null, heightCm: height ? Number(height) : null, weightKg: weight ? Number(weight) : null, cupSize: cup || null, }); router.refresh(); onClose(); if (r && r.slug) router.push(`/actress/${r.slug}`); } finally { setBusy(false); } } if (typeof document === "undefined") return null; return createPortal(
{ if (e.target === e.currentTarget) onClose(); }} >
Edit Actress
Identity setName(e.target.value)} maxLength={80} className="w-full glass rounded-lg px-3 py-2 text-sm outline-none focus:border-[var(--color-cyan)]" /> setAltNames(e.target.value)} placeholder="松本いちか" className="w-full glass rounded-lg px-3 py-2 text-sm outline-none focus:border-[var(--color-cyan)]" />
Notes