Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
810170abb7
commit
2cb2ed7766
@@ -352,3 +352,62 @@ function SmallStat({ label, value }: { label: string; value: string }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EditableRateStat({
|
||||
value,
|
||||
onSave,
|
||||
}: {
|
||||
value: number | null;
|
||||
onSave: (raw: string) => Promise<boolean>;
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [raw, setRaw] = useState(value != null ? String(value) : "");
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setRaw(value != null ? String(value) : "");
|
||||
}, [value]);
|
||||
|
||||
const commit = async () => {
|
||||
setSaving(true);
|
||||
const ok = await onSave(raw);
|
||||
setSaving(false);
|
||||
if (ok) setEditing(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="border rounded-md py-2 px-3 text-left">
|
||||
<div className="text-[10px] uppercase tracking-wider text-muted-foreground text-center">Case rate</div>
|
||||
{editing ? (
|
||||
<div className="flex items-center gap-1 mt-1">
|
||||
<span className="text-sm text-muted-foreground">$</span>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={raw}
|
||||
placeholder="0.00"
|
||||
onChange={(e) => setRaw(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") commit();
|
||||
if (e.key === "Escape") { setRaw(value != null ? String(value) : ""); setEditing(false); }
|
||||
}}
|
||||
autoFocus
|
||||
className="h-7 px-2 text-sm"
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">/hr</span>
|
||||
<Button size="sm" variant="ghost" className="h-7 px-2 text-xs" disabled={saving} onClick={commit}>Save</Button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing(true)}
|
||||
className="text-sm font-medium mt-0.5 truncate hover:text-primary w-full text-center"
|
||||
title="Click to edit case rate"
|
||||
>
|
||||
{value ? formatCurrency(value) + "/hr" : "Set rate…"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user