diff --git a/src/app/dashboard/decisions/page.tsx b/src/app/dashboard/decisions/page.tsx new file mode 100644 index 0000000..cd1dddf --- /dev/null +++ b/src/app/dashboard/decisions/page.tsx @@ -0,0 +1,177 @@ +'use client'; + +import Link from 'next/link'; +import { useQuery } from '@tanstack/react-query'; +import { apiFetch, type Decision } from '../../../lib/api'; +import { useSession } from '../../../components/session-provider'; + +export default function DecisionsDashboardPage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + + const { data: decisions = [], isLoading } = useQuery({ + queryKey: ['decisions-dashboard', tenantId], + queryFn: () => apiFetch('/v1/decisions', { tenantId }), + enabled: Boolean(tenantId), + }); + + const now = new Date(); + const pending = decisions.filter((d) => !d.selectedOption); + const decided = decisions.filter((d) => d.selectedOption); + const overdueReviews = decisions.filter( + (d) => d.selectedOption && d.reviewDueAt && new Date(d.reviewDueAt) < now, + ); + + const stats = [ + { label: 'Total', value: decisions.length, color: 'text-ink' }, + { + label: 'În așteptare', + value: pending.length, + color: pending.length > 0 ? 'text-signal-warn' : 'text-ink', + }, + { + label: 'Decise', + value: decided.length, + color: decided.length > 0 ? 'text-signal-ok' : 'text-ink', + }, + { + label: 'Review întârziat', + value: overdueReviews.length, + color: overdueReviews.length > 0 ? 'text-signal-danger' : 'text-ink', + }, + ]; + + return ( +
+
+
+

Decizii

+

+ Vizualizare agregată a registrului de decizii. +

+
+ + Deschide registrul → + +
+ +
+ {stats.map(({ label, value, color }) => ( +
+

{label}

+

{value}

+
+ ))} +
+ + {isLoading ? ( +

Se încarcă…

+ ) : decisions.length === 0 ? ( +
+

Nicio decizie înregistrată

+

+ Documentează deciziile importante pentru a le putea revizui ulterior. +

+ + Adaugă prima decizie + +
+ ) : ( + <> + {overdueReviews.length > 0 && ( +
+

+ Review întârziat ({overdueReviews.length}) +

+
    + {overdueReviews.map((d) => ( +
  • +
    +

    {d.context}

    +

    + Review due: {new Date(d.reviewDueAt!).toLocaleDateString('ro-RO')} +

    +
    + + {d.selectedOption} + +
  • + ))} +
+
+ )} + + {pending.length > 0 && ( +
+

+ În așteptare ({pending.length}) +

+
    + {pending.slice(0, 6).map((d) => ( +
  • + +

    {d.context}

    + + {new Date(d.createdAt).toLocaleDateString('ro-RO')} + +
  • + ))} +
+
+ )} + +
+

+ Toate deciziile ({decisions.length}) +

+
    + {decisions.slice(0, 10).map((d) => ( +
  • + +

    {d.context}

    +
    + {d.selectedOption ? ( + + Decis + + ) : ( + + Pending + + )} + + {new Date(d.createdAt).toLocaleDateString('ro-RO')} + +
    +
  • + ))} +
+ {decisions.length > 10 && ( +
+ + Toate {decisions.length} deciziile în registru → + +
+ )} +
+ + )} +
+ ); +}