2026-07-04 19:29:42 -05:00
|
|
|
import { useState, useEffect } from 'react';
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
import { toast } from 'sonner';
|
refactor(ts): convert the API client to TypeScript (TS9)
client/api.js -> api.ts. Types the fetch infrastructure: generic _fetch<T>
and get/post/put/patch/del<T> helpers, an ApiError interface (status/code/
details/data), a QueryParams type for the query-string builder, and File-typed
upload helpers. Endpoint response shapes are typed incrementally — most methods
default to Promise<unknown>; the ones consumed by typed .ts files get real
shapes (quickPay -> PaymentRecord, togglePaid -> TogglePaidResult, settings ->
settings map).
Typing togglePaid's result surfaced a latent narrowing bug in usePaymentActions:
the un-pay Undo closure read result.paymentId (number|undefined) inside a
deferred async callback where TS re-widens the if-narrowed value — fixed by
capturing the id in a const before the closure.
The 16 files importing '@/api.js' with an explicit extension were normalized to
'@/api' so Vite/TS resolve the .ts.
Verified: typecheck 0, lint 0 errors (47 warns), build green, 48 client tests,
and 17/17 e2e probe (every page renders, all API paths respond) — the central
fetch-module rename is runtime-safe.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 22:09:04 -05:00
|
|
|
import { api } from '@/api';
|
2026-07-04 19:29:42 -05:00
|
|
|
import { fmt, errMessage } from '@/lib/utils';
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { Label } from '@/components/ui/label';
|
|
|
|
|
import {
|
|
|
|
|
Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter,
|
|
|
|
|
} from '@/components/ui/dialog';
|
2026-07-04 19:29:42 -05:00
|
|
|
import type { TrackerRow } from '@/types';
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
|
|
|
|
|
const MONTHS = [
|
|
|
|
|
'January','February','March','April','May','June',
|
|
|
|
|
'July','August','September','October','November','December',
|
|
|
|
|
];
|
|
|
|
|
|
2026-07-04 19:29:42 -05:00
|
|
|
interface MonthlyStateDialogProps {
|
|
|
|
|
row: TrackerRow;
|
|
|
|
|
year: number;
|
|
|
|
|
month: number;
|
|
|
|
|
open: boolean;
|
|
|
|
|
onOpenChange: (open: boolean) => void;
|
|
|
|
|
onSaved: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MonthlyStateDialog({ row, year, month, open, onOpenChange, onSaved }: MonthlyStateDialogProps) {
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
const [actualAmount, setActualAmount] = useState('');
|
|
|
|
|
const [notes, setNotes] = useState('');
|
|
|
|
|
const [isSkipped, setIsSkipped] = useState(false);
|
|
|
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
|
|
|
|
|
|
// Populate from current row state when dialog opens
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
setActualAmount(row.actual_amount != null ? String(row.actual_amount) : '');
|
|
|
|
|
setNotes(row.monthly_notes || '');
|
|
|
|
|
setIsSkipped(!!row.is_skipped);
|
|
|
|
|
}
|
|
|
|
|
}, [open, row]);
|
|
|
|
|
|
2026-07-04 19:29:42 -05:00
|
|
|
async function handleSave(e: React.FormEvent) {
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
const amt = actualAmount.trim() ? parseFloat(actualAmount) : null;
|
|
|
|
|
if (amt !== null && (isNaN(amt) || amt < 0)) {
|
|
|
|
|
toast.error('Amount must be a positive number or empty');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setSaving(true);
|
|
|
|
|
try {
|
|
|
|
|
await api.saveBillMonthlyState(row.id, {
|
|
|
|
|
year,
|
|
|
|
|
month,
|
|
|
|
|
actual_amount: amt,
|
|
|
|
|
notes: notes.trim() || null,
|
|
|
|
|
is_skipped: isSkipped,
|
|
|
|
|
});
|
|
|
|
|
toast.success(`${MONTHS[month - 1]} state saved`);
|
|
|
|
|
onSaved();
|
|
|
|
|
onOpenChange(false);
|
|
|
|
|
} catch (err) {
|
2026-07-04 19:29:42 -05:00
|
|
|
toast.error(errMessage(err));
|
refactor: component splits, PWA support, CommandPalette
Component Splits:
- AdminPage.jsx: 1,906 -> 82 lines (logic moved to client/components/admin/ — 9 files)
- DataPage.jsx: 3,132 -> 60 lines (logic moved to client/components/data/ — 8 files)
- TrackerPage.jsx: 2,566 -> 2,132 lines (MonthlyStateDialog, StartingAmountsEditDialog, PaymentModal)
PWA:
- vite-plugin-pwa installed with NetworkFirst caching for API routes
- Square PWA icons (192x192, 512x512, apple-touch-icon)
- theme-color, apple meta tags, touch icon in index.html
- Build generates dist/sw.js + Workbox runtime
CommandPalette:
- Navigation commands, Add bill action, month jumps
- Grouped results with empty/filtered states
2026-05-28 20:53:22 -05:00
|
|
|
} finally {
|
|
|
|
|
setSaving(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
|
|
|
<DialogContent className="sm:max-w-sm border-border/60 bg-card/95 backdrop-blur-xl">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle className="text-base font-semibold tracking-tight">
|
|
|
|
|
{row.name}
|
|
|
|
|
<span className="text-muted-foreground font-normal ml-2">
|
|
|
|
|
{MONTHS[month - 1]} {year}
|
|
|
|
|
</span>
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
<p className="text-[11px] text-muted-foreground">
|
|
|
|
|
Monthly overrides — changes only affect {MONTHS[month - 1]}
|
|
|
|
|
</p>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<form id="mbs-form" onSubmit={handleSave} className="space-y-4 py-1">
|
|
|
|
|
{/* Actual amount this month */}
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<Label htmlFor="mbs-amount" className="text-xs uppercase tracking-wider text-muted-foreground">
|
|
|
|
|
Actual Amount ($)
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="mbs-amount"
|
|
|
|
|
type="number" min="0" step="0.01"
|
|
|
|
|
placeholder={String(row.expected_amount)}
|
|
|
|
|
value={actualAmount}
|
|
|
|
|
onChange={e => setActualAmount(e.target.value)}
|
|
|
|
|
className="font-mono bg-background/50 border-border/60"
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-[11px] text-muted-foreground">
|
|
|
|
|
Leave blank to use the template default ({fmt(row.expected_amount)}).
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Monthly notes */}
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<Label htmlFor="mbs-notes" className="text-xs uppercase tracking-wider text-muted-foreground">
|
|
|
|
|
Notes (this month only)
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="mbs-notes"
|
|
|
|
|
value={notes}
|
|
|
|
|
onChange={e => setNotes(e.target.value)}
|
|
|
|
|
placeholder="e.g. higher than usual, double-billed…"
|
|
|
|
|
className="bg-background/50 border-border/60"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Skip this month */}
|
|
|
|
|
<label className="flex items-start gap-3 cursor-pointer select-none">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={isSkipped}
|
|
|
|
|
onChange={e => setIsSkipped(e.target.checked)}
|
|
|
|
|
className="mt-0.5 h-4 w-4 rounded border-border accent-primary"
|
|
|
|
|
/>
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-sm font-medium leading-tight">Skip this month</p>
|
|
|
|
|
<p className="text-[11px] text-muted-foreground mt-0.5">
|
|
|
|
|
Excludes this bill from {MONTHS[month - 1]} totals. Other months are unchanged.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<DialogFooter className="mt-2">
|
|
|
|
|
<Button type="button" variant="ghost" disabled={saving} onClick={() => onOpenChange(false)} className="text-xs">
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button type="submit" form="mbs-form" disabled={saving} className="text-xs">
|
|
|
|
|
{saving ? 'Saving…' : 'Save'}
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MonthlyStateDialog;
|