Update pages and components for new module paths

Repoints imports at the relocated lib/api and src/contexts modules,
and refreshes Layout + Login alongside the rest of the migration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Carlos Escalante
2026-04-29 22:02:46 -06:00
parent cf8b7be778
commit c92bfc66fe
16 changed files with 80 additions and 96 deletions

View File

@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Calendar } from 'lucide-react'; import { Calendar } from 'lucide-react';
import api from '../api'; import api from '@/lib/api';
import { import {
Select, Select,
SelectContent, SelectContent,

View File

@@ -1,6 +1,7 @@
import { NavLink, Outlet, useNavigate } from 'react-router-dom'; import { useState, useEffect } from "react";
import { Link, Outlet, useLocation, useNavigate } from "react-router-dom";
import { import {
LayoutDashboard, Sparkles,
Calculator, Calculator,
BarChart3, BarChart3,
Landmark, Landmark,
@@ -15,24 +16,20 @@ import {
Eye, Eye,
EyeOff, EyeOff,
type LucideIcon, type LucideIcon,
} from 'lucide-react'; } from "lucide-react";
import { useEffect, useState } from 'react'; import { useTheme } from "@/contexts/theme-context";
import { useAuth } from '../AuthContext'; import { usePrivacy } from "@/contexts/privacy-context";
import { useTheme } from '../ThemeContext'; import { useAuth } from "@/AuthContext";
import { usePrivacy } from '../PrivacyContext'; import { Button } from "@/components/ui/button";
import { subscribeToPush } from '../pushNotifications';
import { Button } from '@/components/ui/button';
import { import {
Sheet, Sheet,
SheetContent, SheetContent,
SheetHeader, SheetHeader,
SheetTitle, SheetTitle,
SheetClose, SheetClose,
} from '@/components/ui/sheet'; } from "@/components/ui/sheet";
import { Separator } from '@/components/ui/separator'; import { Separator } from "@/components/ui/separator";
import { cn } from '@/lib/utils'; import { cn } from "@/lib/utils";
// ─── Navigation Structure ────────────────────────────────────────────────────
interface NavSection { interface NavSection {
label: string; label: string;
@@ -41,32 +38,32 @@ interface NavSection {
const navSections: NavSection[] = [ const navSections: NavSection[] = [
{ {
label: 'General', label: "General",
items: [{ to: "/asistente", icon: Sparkles, label: "Asistente" }],
},
{
label: "Finanzas",
items: [ items: [
{ to: '/', icon: LayoutDashboard, label: 'Dashboard' }, { to: "/budget", icon: Calculator, label: "Presupuesto" },
{ to: "/salarios", icon: Landmark, label: "Salarios" },
{ to: "/pensions", icon: PiggyBank, label: "Pensiones" },
{ to: "/proyecciones", icon: TrendingUp, label: "Proyecciones" },
{ to: "/analytics", icon: BarChart3, label: "Analytics" },
], ],
}, },
{ {
label: 'Finanzas', label: "Servicios",
items: [ items: [
{ to: '/budget', icon: Calculator, label: 'Presupuesto' }, { to: "/servicios-municipales", icon: Droplets, label: "Municipalidad" },
{ to: '/salarios', icon: Landmark, label: 'Salarios' },
{ to: '/pensions', icon: PiggyBank, label: 'Pensiones' },
{ to: '/proyecciones', icon: TrendingUp, label: 'Proyecciones' },
{ to: '/analytics', icon: BarChart3, label: 'Analytics' },
],
},
{
label: 'Servicios',
items: [
{ to: '/servicios-municipales', icon: Droplets, label: 'Municipalidad' },
], ],
}, },
]; ];
// ─── Shared Nav Renderer ─────────────────────────────────────────────────────
function SidebarNav({ onNavigate }: { onNavigate?: () => void }) { function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
const { pathname } = useLocation();
const isActive = (to: string) =>
pathname === to || pathname.startsWith(`${to}/`);
return ( return (
<nav className="flex flex-col gap-0.5 px-3"> <nav className="flex flex-col gap-0.5 px-3">
{navSections.map((section) => ( {navSections.map((section) => (
@@ -75,23 +72,20 @@ function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
{section.label} {section.label}
</p> </p>
{section.items.map(({ to, icon: Icon, label }) => ( {section.items.map(({ to, icon: Icon, label }) => (
<NavLink <Link
key={to} key={to}
to={to} to={to}
end={to === '/'}
onClick={onNavigate} onClick={onNavigate}
className={({ isActive }) => className={cn(
cn( "flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-colors",
'flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-colors', isActive(to)
isActive ? "bg-primary/10 text-primary"
? 'bg-primary/10 text-primary' : "text-muted-foreground hover:text-foreground hover:bg-muted",
: 'text-muted-foreground hover:text-foreground hover:bg-muted' )}
)
}
> >
<Icon className="w-4 h-4" /> <Icon className="w-4 h-4" />
{label} {label}
</NavLink> </Link>
))} ))}
</div> </div>
))} ))}
@@ -99,27 +93,20 @@ function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
); );
} }
// ─── Main Layout ─────────────────────────────────────────────────────────────
export default function Layout() { export default function Layout() {
const { logout } = useAuth();
const { theme, toggleTheme } = useTheme(); const { theme, toggleTheme } = useTheme();
const { privacyMode, togglePrivacy } = usePrivacy(); const { privacyMode, togglePrivacy } = usePrivacy();
const { logout } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const [mobileOpen, setMobileOpen] = useState(false); const [mobileOpen, setMobileOpen] = useState(false);
useEffect(() => { const handleLogout = async () => {
subscribeToPush(); await logout();
}, []); navigate("/login", { replace: true });
const handleLogout = () => {
logout();
navigate('/login');
}; };
return ( return (
<div className="min-h-screen bg-background text-foreground"> <div className="min-h-screen bg-background text-foreground">
{/* ── Top bar ───────────────────────────────────────────────────── */}
<header className="border-b border-border backdrop-blur-sm sticky top-0 z-50 bg-background/90"> <header className="border-b border-border backdrop-blur-sm sticky top-0 z-50 bg-background/90">
<div className="px-4 sm:px-6 py-3 flex items-center justify-between"> <div className="px-4 sm:px-6 py-3 flex items-center justify-between">
<div className="flex items-center gap-2.5"> <div className="flex items-center gap-2.5">
@@ -136,7 +123,7 @@ export default function Layout() {
<div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center"> <div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center">
<Wallet className="w-4 h-4 text-primary-foreground" strokeWidth={2.5} /> <Wallet className="w-4 h-4 text-primary-foreground" strokeWidth={2.5} />
</div> </div>
<span className="text-lg font-bold tracking-tight hidden sm:inline font-heading"> <span className="text-lg font-bold tracking-tight hidden sm:inline" style={{ fontFamily: "var(--font-heading)" }}>
Wealthy<span className="text-primary">Smart</span> Wealthy<span className="text-primary">Smart</span>
</span> </span>
</div> </div>
@@ -146,7 +133,7 @@ export default function Layout() {
{privacyMode ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />} {privacyMode ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
</Button> </Button>
<Button variant="ghost" size="icon" onClick={toggleTheme} title="Toggle theme" aria-label="Toggle theme"> <Button variant="ghost" size="icon" onClick={toggleTheme} title="Toggle theme" aria-label="Toggle theme">
{theme === 'dark' ? <Sun className="w-4 h-4" /> : <Moon className="w-4 h-4" />} {theme === "dark" ? <Sun className="w-4 h-4" /> : <Moon className="w-4 h-4" />}
</Button> </Button>
<Button <Button
variant="ghost" variant="ghost"
@@ -163,7 +150,6 @@ export default function Layout() {
</header> </header>
<div className="flex"> <div className="flex">
{/* ── Desktop sidebar ───────────────────────────────────────── */}
<aside className="hidden md:flex md:flex-col md:w-56 md:flex-shrink-0 border-r border-border sticky top-[57px] h-[calc(100vh-57px)] overflow-y-auto bg-background"> <aside className="hidden md:flex md:flex-col md:w-56 md:flex-shrink-0 border-r border-border sticky top-[57px] h-[calc(100vh-57px)] overflow-y-auto bg-background">
<div className="flex-1"> <div className="flex-1">
<SidebarNav /> <SidebarNav />
@@ -180,7 +166,6 @@ export default function Layout() {
</div> </div>
</aside> </aside>
{/* ── Mobile nav sheet ──────────────────────────────────────── */}
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}> <Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
<SheetContent side="left" className="p-0 w-64"> <SheetContent side="left" className="p-0 w-64">
<SheetHeader className="p-4"> <SheetHeader className="p-4">
@@ -188,7 +173,7 @@ export default function Layout() {
<div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center"> <div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center">
<Wallet className="w-4 h-4 text-primary-foreground" strokeWidth={2.5} /> <Wallet className="w-4 h-4 text-primary-foreground" strokeWidth={2.5} />
</div> </div>
<span className="font-heading"> <span style={{ fontFamily: "var(--font-heading)" }}>
Wealthy<span className="text-primary">Smart</span> Wealthy<span className="text-primary">Smart</span>
</span> </span>
</SheetTitle> </SheetTitle>
@@ -202,7 +187,10 @@ export default function Layout() {
<Separator className="mb-2" /> <Separator className="mb-2" />
<SheetClose render={<span />}> <SheetClose render={<span />}>
<button <button
onClick={() => { setMobileOpen(false); handleLogout(); }} onClick={() => {
setMobileOpen(false);
void handleLogout();
}}
className="flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-muted w-full cursor-pointer" className="flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-muted w-full cursor-pointer"
> >
<LogOut className="w-4 h-4" /> <LogOut className="w-4 h-4" />
@@ -214,7 +202,6 @@ export default function Layout() {
</SheetContent> </SheetContent>
</Sheet> </Sheet>
{/* ── Main content ──────────────────────────────────────────── */}
<main className="flex-1 min-w-0 px-4 sm:px-6 lg:px-8 py-6"> <main className="flex-1 min-w-0 px-4 sm:px-6 lg:px-8 py-6">
<div className="max-w-6xl mx-auto"> <div className="max-w-6xl mx-auto">
<Outlet /> <Outlet />

View File

@@ -1,6 +1,6 @@
import { useState } from 'react'; import { useState } from 'react';
import { ClipboardPaste, CheckCircle, AlertTriangle } from 'lucide-react'; import { ClipboardPaste, CheckCircle, AlertTriangle } from 'lucide-react';
import api, { type ImportResult } from '../api'; import api, { type ImportResult } from '@/lib/api';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea'; import { Textarea } from '@/components/ui/textarea';

View File

@@ -1,6 +1,6 @@
import { useState } from 'react'; import { useState } from 'react';
import { ClipboardPaste, CheckCircle, AlertTriangle } from 'lucide-react'; import { ClipboardPaste, CheckCircle, AlertTriangle } from 'lucide-react';
import { type PensionUploadResult, submitPensionManualEntries } from '../api'; import { type PensionUploadResult, submitPensionManualEntries } from '@/lib/api';
import { parsePensionPaste, type PensionParsedEntry } from '@/lib/parsePensionPaste'; import { parsePensionPaste, type PensionParsedEntry } from '@/lib/parsePensionPaste';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';

View File

@@ -11,7 +11,7 @@ import {
Banknote, Banknote,
} from 'lucide-react'; } from 'lucide-react';
import api, { type Transaction } from '../api'; import api, { type Transaction } from '@/lib/api';
import TransactionModal from './TransactionModal'; import TransactionModal from './TransactionModal';
import ConfirmDialog from './ConfirmDialog'; import ConfirmDialog from './ConfirmDialog';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';

View File

@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import api, { type Category, type Transaction } from '../api'; import api, { type Category, type Transaction } from '@/lib/api';
import { formatLocalDatetime } from '@/lib/format'; import { formatLocalDatetime } from '@/lib/format';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';

View File

@@ -5,7 +5,7 @@ import {
type RecurringItemUpdate, type RecurringItemUpdate,
type RecurringItemType, type RecurringItemType,
type RecurringFrequency, type RecurringFrequency,
} from '@/api'; } from '@/lib/api';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { import {
Dialog, Dialog,

View File

@@ -4,7 +4,7 @@ import {
type RecurringItem, type RecurringItem,
type RecurringItemCreate, type RecurringItemCreate,
type RecurringItemUpdate, type RecurringItemUpdate,
} from '@/api'; } from '@/lib/api';
import { formatAmount } from '@/lib/format'; import { formatAmount } from '@/lib/format';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';

View File

@@ -1,7 +1,7 @@
import { useState, useRef, useEffect } from 'react'; import { useState, useRef, useEffect } from 'react';
import { Pencil } from 'lucide-react'; import { Pencil } from 'lucide-react';
import { type MonthlyProjection } from '@/api'; import { type MonthlyProjection } from '@/lib/api';
import { formatAmount } from '@/lib/format'; import { formatAmount } from '@/lib/format';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';

View File

@@ -1,7 +1,7 @@
import { type ColumnDef } from '@tanstack/react-table'; import { type ColumnDef } from '@tanstack/react-table';
import { ArrowLeftRight, ArrowRightFromLine, Banknote, Pencil, Trash2, TrendingDown, TrendingUp } from 'lucide-react'; import { ArrowLeftRight, ArrowRightFromLine, Banknote, Pencil, Trash2, TrendingDown, TrendingUp } from 'lucide-react';
import { type Transaction } from '@/api'; import { type Transaction } from '@/lib/api';
import { formatAmount } from '@/lib/format'; import { formatAmount } from '@/lib/format';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';

View File

@@ -13,7 +13,7 @@ import {
deleteRecurringItem as apiDeleteItem, deleteRecurringItem as apiDeleteItem,
upsertBalanceOverride, upsertBalanceOverride,
deleteBalanceOverride, deleteBalanceOverride,
} from '@/api'; } from '@/lib/api';
export function useBudget(initialYear: number) { export function useBudget(initialYear: number) {
const [year, setYear] = useState(initialYear); const [year, setYear] = useState(initialYear);

View File

@@ -12,8 +12,8 @@ import {
} from 'recharts'; } from 'recharts';
import { BarChart3 } from 'lucide-react'; import { BarChart3 } from 'lucide-react';
import api from '../api'; import api from '@/lib/api';
import BillingCycleSelector from '../components/BillingCycleSelector'; import BillingCycleSelector from '@/components/BillingCycleSelector';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { import {
ChartContainer, ChartContainer,

View File

@@ -1,34 +1,31 @@
import { useState } from 'react'; import { useState, type FormEvent } from "react";
import { useNavigate } from 'react-router-dom'; import { useNavigate } from "react-router-dom";
import { Wallet, ArrowRight, AlertCircle } from 'lucide-react'; import { Wallet, ArrowRight, AlertCircle } from "lucide-react";
import { login } from "@/lib/api";
import { useAuth } from "@/AuthContext";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { login } from '../api'; export default function LoginPage() {
import { useAuth } from '../AuthContext'; const [username, setUsername] = useState("");
import { subscribeToPush } from '../pushNotifications'; const [password, setPassword] = useState("");
import { Button } from '@/components/ui/button'; const [error, setError] = useState("");
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
export default function Login() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
const { setAuthenticated } = useAuth(); const { setAuthenticated } = useAuth();
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: FormEvent) => {
e.preventDefault(); e.preventDefault();
setLoading(true); setLoading(true);
setError(''); setError("");
try { try {
await login(username, password); await login(username, password);
setAuthenticated(true); setAuthenticated(true);
subscribeToPush(); navigate("/asistente", { replace: true });
navigate('/');
} catch { } catch {
setError('Invalid credentials'); setError("Invalid credentials");
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -41,7 +38,7 @@ export default function Login() {
<div className="w-10 h-10 rounded-lg bg-primary flex items-center justify-center"> <div className="w-10 h-10 rounded-lg bg-primary flex items-center justify-center">
<Wallet className="w-6 h-6 text-primary-foreground" strokeWidth={2.5} /> <Wallet className="w-6 h-6 text-primary-foreground" strokeWidth={2.5} />
</div> </div>
<span className="text-2xl font-bold tracking-tight font-heading"> <span className="text-2xl font-bold tracking-tight" style={{ fontFamily: "var(--font-heading)" }}>
Wealthy<span className="text-primary">Smart</span> Wealthy<span className="text-primary">Smart</span>
</span> </span>
</div> </div>
@@ -84,7 +81,7 @@ export default function Login() {
)} )}
<Button type="submit" disabled={loading} className="w-full h-10"> <Button type="submit" disabled={loading} className="w-full h-10">
{loading ? 'Signing in...' : 'Sign in'} {loading ? "Signing in..." : "Sign in"}
{!loading && <ArrowRight className="w-4 h-4" />} {!loading && <ArrowRight className="w-4 h-4" />}
</Button> </Button>
</form> </form>

View File

@@ -34,7 +34,7 @@ import {
getPensionSnapshots, getPensionSnapshots,
type PensionSnapshot, type PensionSnapshot,
type PensionUploadResult, type PensionUploadResult,
} from '@/api'; } from '@/lib/api';
import PensionManualEntryModal from '@/components/PensionManualEntryModal'; import PensionManualEntryModal from '@/components/PensionManualEntryModal';
import { ClipboardPaste } from 'lucide-react'; import { ClipboardPaste } from 'lucide-react';

View File

@@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
import { type ColumnDef } from '@tanstack/react-table'; import { type ColumnDef } from '@tanstack/react-table';
import { Landmark, RefreshCw, Hash, CalendarDays, Banknote } from 'lucide-react'; import { Landmark, RefreshCw, Hash, CalendarDays, Banknote } from 'lucide-react';
import { type Transaction, type SalariosSummary, getSalarios, getSalariosSummary } from '../api'; import { type Transaction, type SalariosSummary, getSalarios, getSalariosSummary } from '@/lib/api';
import { formatAmount, formatDate } from '@/lib/format'; import { formatAmount, formatDate } from '@/lib/format';
import { DataTable } from '@/components/ui/data-table'; import { DataTable } from '@/components/ui/data-table';
import { DataTableColumnHeader } from '@/components/ui/data-table-column-header'; import { DataTableColumnHeader } from '@/components/ui/data-table-column-header';

View File

@@ -41,7 +41,7 @@ import {
type MunicipalReceipt, type MunicipalReceipt,
type MunicipalReceiptUploadResult, type MunicipalReceiptUploadResult,
type WaterMeterReading, type WaterMeterReading,
} from '@/api'; } from '@/lib/api';
// ─── Constants ─────────────────────────────────────────────────────────────── // ─── Constants ───────────────────────────────────────────────────────────────