mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 15:28:47 +02:00
Cosmetics: shared PeriodNavigator, breadcrumb, meter labels
One chevron component now drives year/month stepping in Budget and Proyecciones (UX-03). Jumping from Proyecciones to a Budget month shows a back affordance (UX-22). Water meters can be named (Casa, Cochera…) via a settings-persisted dialog; the chart legend uses the names (UX-24). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
87
frontend/src/components/MeterLabelsDialog.tsx
Normal file
87
frontend/src/components/MeterLabelsDialog.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import { useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import api, { type UserSettingsData } from '@/lib/api';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
interface Props {
|
||||
meterIds: string[];
|
||||
current: Record<string, string>;
|
||||
settingsData: UserSettingsData;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
/** Human names for water meters, persisted in UserSettings (review UX-24). */
|
||||
export default function MeterLabelsDialog({
|
||||
meterIds,
|
||||
current,
|
||||
settingsData,
|
||||
onClose,
|
||||
}: Props) {
|
||||
const queryClient = useQueryClient();
|
||||
const [labels, setLabels] = useState<Record<string, string>>(() => ({
|
||||
...current,
|
||||
}));
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const cleaned = Object.fromEntries(
|
||||
Object.entries(labels).filter(([, v]) => v.trim() !== ''),
|
||||
);
|
||||
await api.patch('/settings/', {
|
||||
data: { ...settingsData, meter_labels: cleaned },
|
||||
});
|
||||
toast.success('Etiquetas guardadas');
|
||||
queryClient.invalidateQueries({ queryKey: ['settings'] });
|
||||
onClose();
|
||||
} catch {
|
||||
toast.error('No se pudieron guardar las etiquetas');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(open) => { if (!open) onClose(); }}>
|
||||
<DialogContent className="sm:max-w-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Etiquetas de medidores</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-3">
|
||||
{meterIds.map((id) => (
|
||||
<div key={id} className="space-y-1">
|
||||
<Label className="text-xs font-mono">Medidor {id}</Label>
|
||||
<Input
|
||||
value={labels[id] ?? ''}
|
||||
placeholder="p. ej. Casa, Cochera…"
|
||||
onChange={(e) =>
|
||||
setLabels((prev) => ({ ...prev, [id]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button onClick={handleSave} disabled={saving}>
|
||||
{saving ? 'Guardando...' : 'Guardar'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
52
frontend/src/components/PeriodNavigator.tsx
Normal file
52
frontend/src/components/PeriodNavigator.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface Props {
|
||||
label: string;
|
||||
onPrev: () => void;
|
||||
onNext: () => void;
|
||||
prevDisabled?: boolean;
|
||||
nextDisabled?: boolean;
|
||||
/** 'outline' for page-level (year), 'ghost' for inline (month) */
|
||||
variant?: 'outline' | 'ghost';
|
||||
labelClassName?: string;
|
||||
}
|
||||
|
||||
/** The one way to step through periods (UX-03) — same chevron pattern for
|
||||
* years and months across Budget and Proyecciones. */
|
||||
export default function PeriodNavigator({
|
||||
label,
|
||||
onPrev,
|
||||
onNext,
|
||||
prevDisabled,
|
||||
nextDisabled,
|
||||
variant = 'outline',
|
||||
labelClassName = 'w-16 text-center font-semibold tabular-nums',
|
||||
}: Props) {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant={variant}
|
||||
size="icon"
|
||||
className={variant === 'ghost' ? 'h-7 w-7' : undefined}
|
||||
disabled={prevDisabled}
|
||||
onClick={onPrev}
|
||||
aria-label={`Período anterior (${label})`}
|
||||
>
|
||||
<ChevronLeft className="w-4 h-4" />
|
||||
</Button>
|
||||
<span className={labelClassName}>{label}</span>
|
||||
<Button
|
||||
variant={variant}
|
||||
size="icon"
|
||||
className={variant === 'ghost' ? 'h-7 w-7' : undefined}
|
||||
disabled={nextDisabled}
|
||||
onClick={onNext}
|
||||
aria-label={`Período siguiente (${label})`}
|
||||
>
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user