diff --git a/src/app/dashboard/decisions/page.tsx b/src/app/dashboard/decisions/page.tsx index cd1dddf..ef06e0f 100644 --- a/src/app/dashboard/decisions/page.tsx +++ b/src/app/dashboard/decisions/page.tsx @@ -1,175 +1,177 @@ 'use client'; import Link from 'next/link'; +import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; -import { apiFetch, type Decision } from '../../../lib/api'; +import { apiFetch } from '../../../lib/api'; +import type { Decision } from '../../../lib/api'; import { useSession } from '../../../components/session-provider'; -export default function DecisionsDashboardPage() { +function fmtDate(s: string | null) { + if (!s) return '—'; + return new Date(s).toLocaleDateString('ro-RO', { day: 'numeric', month: 'short', year: 'numeric' }); +} + +export default function DecisionsPage() { const { activeTenant } = useSession(); const tenantId = activeTenant?.tenantId ?? ''; + const B = '/dashboard'; - const { data: decisions = [], isLoading } = useQuery({ - queryKey: ['decisions-dashboard', tenantId], + const { data: decisions = [], isLoading, refetch } = useQuery({ + queryKey: ['decisions', 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 [showForm, setShowForm] = useState(false); + const [form, setForm] = useState({ context: '', options: '', reviewDueAt: '' }); + const [saving, setSaving] = useState(false); - 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', - }, - ]; + const open = decisions.filter((d) => !d.selectedOption); + const decided = decisions.filter((d) => d.selectedOption && !d.outcomeReview); + const reviewed = decisions.filter((d) => d.outcomeReview); + + async function handleCreate(e: React.FormEvent) { + e.preventDefault(); + if (!form.context) return; + setSaving(true); + const options = form.options ? form.options.split('\n').map((o) => o.trim()).filter(Boolean) : []; + await apiFetch('/v1/decisions', { + tenantId, method: 'POST', + body: { context: form.context, options, reviewDueAt: form.reviewDueAt || undefined }, + }); + setForm({ context: '', options: '', reviewDueAt: '' }); + setShowForm(false); + setSaving(false); + refetch(); + } return ( -
+
-

Decizii

+

Decision Dashboard

- Vizualizare agregată a registrului de decizii. + Log de decizii cu context, opțiuni și review de rezultat.

- - 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 +
+ + Registru complet +
- ) : ( +
+ + {showForm && ( +
+

Decizie nouă

+
+ +