feat(tracker-web): overview MetricCard + ConfirmDialog delete (UX-2.2)
Replace the bespoke total-count card chrome with the shared MetricCard on the dashboard overview (breakdown cards stay until the UX-4 chart swap), and surface load errors via AlertBanner. Wrap the items-list delete confirm() in the accessible ConfirmDialog (focus-trapped AlertDialog) instead of the native browser prompt. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
a7a6f191ca
commit
c9e65d435c
@ -12,6 +12,7 @@ import {
|
|||||||
Field,
|
Field,
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
Modal,
|
Modal,
|
||||||
|
ConfirmDialog,
|
||||||
StatusBadge,
|
StatusBadge,
|
||||||
AlertBanner,
|
AlertBanner,
|
||||||
type StatusTone,
|
type StatusTone,
|
||||||
@ -60,6 +61,9 @@ export default function ItemsListPage() {
|
|||||||
const [newPriority, setNewPriority] = useState<'critical' | 'high' | 'medium' | 'low'>('medium');
|
const [newPriority, setNewPriority] = useState<'critical' | 'high' | 'medium' | 'low'>('medium');
|
||||||
const [newDescription, setNewDescription] = useState('');
|
const [newDescription, setNewDescription] = useState('');
|
||||||
|
|
||||||
|
// Delete confirmation
|
||||||
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
|
|
||||||
const fetchItems = useCallback(async () => {
|
const fetchItems = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError('');
|
setError('');
|
||||||
@ -101,18 +105,19 @@ export default function ItemsListPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = useCallback(
|
const handleDelete = useCallback((id: string) => setDeleteId(id), []);
|
||||||
async (id: string) => {
|
|
||||||
if (!confirm('Delete this item?')) return;
|
const confirmDelete = useCallback(async () => {
|
||||||
try {
|
if (!deleteId) return;
|
||||||
await deleteItem(id);
|
try {
|
||||||
fetchItems();
|
await deleteItem(deleteId);
|
||||||
} catch (err: unknown) {
|
setDeleteId(null);
|
||||||
setError(err instanceof Error ? err.message : 'Failed to delete');
|
fetchItems();
|
||||||
}
|
} catch (err: unknown) {
|
||||||
},
|
setDeleteId(null);
|
||||||
[fetchItems]
|
setError(err instanceof Error ? err.message : 'Failed to delete');
|
||||||
);
|
}
|
||||||
|
}, [deleteId, fetchItems]);
|
||||||
|
|
||||||
const columns = useMemo<ColumnDef<TrackerItem, unknown>[]>(
|
const columns = useMemo<ColumnDef<TrackerItem, unknown>[]>(
|
||||||
() => [
|
() => [
|
||||||
@ -331,6 +336,18 @@ export default function ItemsListPage() {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/* Delete confirmation */}
|
||||||
|
<ConfirmDialog
|
||||||
|
open={deleteId !== null}
|
||||||
|
onOpenChange={open => {
|
||||||
|
if (!open) setDeleteId(null);
|
||||||
|
}}
|
||||||
|
title="Delete item"
|
||||||
|
description="Delete this item? This action cannot be undone."
|
||||||
|
confirmLabel="Delete"
|
||||||
|
onConfirm={confirmDelete}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { PageHeader, LoadingSpinner } from '@bytelyst/dashboard-components';
|
import { PageHeader, LoadingSpinner } from '@bytelyst/dashboard-components';
|
||||||
|
import { MetricCard, AlertBanner } from '@/components/ui/Primitives';
|
||||||
import { useAuth } from '@/lib/auth-context';
|
import { useAuth } from '@/lib/auth-context';
|
||||||
import { getStats, type TrackerStats } from '@/lib/tracker-client';
|
import { getStats, type TrackerStats } from '@/lib/tracker-client';
|
||||||
|
|
||||||
@ -59,18 +60,19 @@ export default function DashboardOverview() {
|
|||||||
<p className="-mt-4 text-sm text-muted-foreground">Overview of all tracked items</p>
|
<p className="-mt-4 text-sm text-muted-foreground">Overview of all tracked items</p>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="rounded-md bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
<AlertBanner tone="error" title="Something went wrong">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</AlertBanner>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{stats ? (
|
{stats ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{/* Total count */}
|
{/* Total count */}
|
||||||
<div className="rounded-xl border border-border bg-card p-6">
|
<MetricCard
|
||||||
<div className="text-4xl font-bold">{stats.total}</div>
|
label={`Total items for ${stats.productId}`}
|
||||||
<div className="text-sm text-muted-foreground">Total items for {stats.productId}</div>
|
value={stats.total}
|
||||||
</div>
|
helper="All tracked items"
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Breakdown cards */}
|
{/* Breakdown cards */}
|
||||||
<div className="grid gap-4 md:grid-cols-3">
|
<div className="grid gap-4 md:grid-cols-3">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user