feat(F-085): completed feature

This commit is contained in:
chattie
2026-08-20 06:10:48 +02:00
parent 3b5ea8f261
commit 7ece045e13
10 changed files with 190 additions and 23 deletions

View File

@@ -14,6 +14,9 @@ export default function TaxRatesPage() {
const [toggling, setToggling] = useState<Record<string, boolean>>({});
const [msg, setMsg] = useState('');
const [tipoEditing, setTipoEditing] = useState<string | null>(null);
const [savingTipo, setSavingTipo] = useState<string | null>(null);
const load = useCallback(async () => {
setLoading(true);
try { const d = await taxApi.list(); setRates(d.items ?? []); }
@@ -50,6 +53,19 @@ export default function TaxRatesPage() {
}
};
const saveTipo = async (id: string, newTipo: 'general' | 'reduced' | 'super-reduced') => {
setSavingTipo(id);
try {
await taxApi.update(id, { appliesTo: newTipo });
setRates(prev => prev.map(r => r.id === id ? { ...r, appliesTo: newTipo } : r));
setTipoEditing(null);
} catch (er) {
alert(er instanceof Error ? er.message : 'Error al cambiar tipo');
} finally {
setSavingTipo(null);
}
};
return (
<div className="space-y-6">
<div>
@@ -110,7 +126,37 @@ export default function TaxRatesPage() {
) : (
<>
<td className="px-6 py-4 text-sm font-medium text-gray-900">{r.name}</td>
<td className="px-6 py-4 text-sm text-gray-500 capitalize">{r.appliesTo}</td>
<td className="px-6 py-4 text-sm text-gray-500">
{tipoEditing === r.id ? (
<select
autoFocus
defaultValue={r.appliesTo}
disabled={savingTipo === r.id}
onBlur={(e) => {
const next = e.target.value as 'general' | 'reduced' | 'super-reduced';
if (next !== r.appliesTo) saveTipo(r.id, next);
else setTipoEditing(null);
}}
onChange={(e) => {
const next = e.target.value as 'general' | 'reduced' | 'super-reduced';
if (next !== r.appliesTo) saveTipo(r.id, next);
}}
className="px-2 py-1 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-[#2D6A4F] outline-none disabled:opacity-50"
>
<option value="general">General</option>
<option value="reduced">Reducido</option>
<option value="super-reduced">Superreducido</option>
</select>
) : (
<button
onClick={() => setTipoEditing(r.id)}
title="Clic para cambiar tipo"
className="capitalize text-gray-500 hover:text-[#2D6A4F] cursor-text"
>
{r.appliesTo}
</button>
)}
</td>
<td className="px-6 py-4 text-sm font-bold text-gray-800">{fmt(r)}</td>
<td className="px-6 py-4">
<button