diff --git a/src/routes/admin.users.tsx b/src/routes/admin.users.tsx index eb634b4..62bd671 100644 --- a/src/routes/admin.users.tsx +++ b/src/routes/admin.users.tsx @@ -265,6 +265,51 @@ function UsersPage() { ); } +function RateInput({ + value, + onSave, +}: { + value: number | null; + onSave: (v: number | null) => void | Promise; +}) { + const [text, setText] = useState(value != null ? String(value) : ""); + useEffect(() => setText(value != null ? String(value) : ""), [value]); + const dirty = text !== (value != null ? String(value) : ""); + + const commit = () => { + if (!dirty) return; + if (text.trim() === "") return onSave(null); + const n = parseFloat(text); + if (Number.isNaN(n) || n < 0) { + toast.error("Invalid rate"); + setText(value != null ? String(value) : ""); + return; + } + onSave(n); + }; + + return ( +
+ $ + setText(e.target.value)} + onBlur={commit} + onKeyDown={(e) => { + if (e.key === "Enter") (e.target as HTMLInputElement).blur(); + }} + placeholder="—" + className="h-8 w-24" + /> + /hr +
+ ); +} + + function InviteDialog({ onCreated }: { onCreated: () => void }) { const [email, setEmail] = useState(""); const [fullName, setFullName] = useState("");