diff --git a/src/app/dashboard/trust/passport/page.tsx b/src/app/dashboard/trust/passport/page.tsx new file mode 100644 index 0000000..d401b6f --- /dev/null +++ b/src/app/dashboard/trust/passport/page.tsx @@ -0,0 +1,152 @@ +'use client'; + +import { useMemo, useState } from 'react'; +import { useQuery } from '@tanstack/react-query'; +import Link from 'next/link'; +import { apiFetch } from '../../../lib/api'; +import { useSession } from '../../../components/session-provider'; + +interface Observation { id: string; metric: string; value: string; source: string | null; confidence: number | null; observedAt: string | null; createdAt: string; } +interface Goal { id: string; title: string; status: string; } +interface Contact { id: string; consentStatus: string | null; } + +const SECTIONS = [ + { id: 'credentials', label: 'Credențiale & Certificări', icon: '🎓' }, + { id: 'professional', label: 'Reputație Profesională', icon: '💼' }, + { id: 'goals', label: 'Obiective finalizate', icon: '🎯' }, + { id: 'skills', label: 'Competențe cheie', icon: '🛠️' }, +]; + +const CRED_METRICS = ['certificare', 'certification', 'certificate', 'diploma', 'curs', 'course', 'badge']; +const SKILL_METRICS = ['skill', 'competenta', 'abilitate', 'limbaj', 'framework', 'tool']; + +export default function TrustPassportPage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + const [selected, setSelected] = useState>({ credentials: true, professional: true, goals: false, skills: true }); + const [generated, setGenerated] = useState(false); + + const { data: observations = [] } = useQuery({ queryKey: ['pp-obs', tenantId], queryFn: () => apiFetch('/v1/observations', { tenantId }), enabled: Boolean(tenantId), staleTime: 120_000 }); + const { data: goals = [] } = useQuery({ queryKey: ['pp-goals', tenantId], queryFn: () => apiFetch('/v1/goals?limit=200', { tenantId }), enabled: Boolean(tenantId), staleTime: 120_000 }); + + const preview = useMemo(() => { + const creds = observations.filter((o) => CRED_METRICS.some((k) => o.metric.toLowerCase().includes(k))); + const skills = observations.filter((o) => SKILL_METRICS.some((k) => o.metric.toLowerCase().includes(k))); + const completedGoals = goals.filter((g) => g.status === 'completed'); + return { creds, skills, completedGoals }; + }, [observations, goals]); + + function generatePassport() { + const lines: string[] = []; + lines.push('=== TRUST PASSPORT ==='); + lines.push(`Generat: ${new Date().toLocaleDateString('ro-RO', { dateStyle: 'full' })}`); + lines.push('Titular: CEO OS Platform'); + lines.push(''); + lines.push('IMPORTANT: Aceste date sunt auto-raportate. Partajarea este voluntară.'); + lines.push(''); + + if (selected.credentials && preview.creds.length > 0) { + lines.push('--- CREDENȚIALE & CERTIFICĂRI ---'); + for (const c of preview.creds.slice(0, 20)) { + lines.push(`• ${c.value} (${c.source ?? 'necunoscut'}) — ${c.metric}`); + } + lines.push(''); + } + if (selected.skills && preview.skills.length > 0) { + lines.push('--- COMPETENȚE ---'); + for (const s of preview.skills.slice(0, 20)) { + lines.push(`• ${s.value} (${s.metric})`); + } + lines.push(''); + } + if (selected.goals && preview.completedGoals.length > 0) { + lines.push('--- OBIECTIVE FINALIZATE ---'); + for (const g of preview.completedGoals.slice(0, 15)) { + lines.push(`• ${g.title}`); + } + lines.push(''); + } + lines.push('---'); + lines.push('Generat de CEO OS — date sub controlul exclusiv al titularului.'); + + const blob = new Blob([lines.join('\n')], { type: 'text/plain;charset=utf-8' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; a.download = `trust-passport-${new Date().toISOString().slice(0,10)}.txt`; + a.click(); + URL.revokeObjectURL(url); + setGenerated(true); + } + + return ( +
+
+ +

Trust Passport

+

Selectează ce partajezi. Tu controlezi datele.

+
+ +
+

Principii de partajare

+
    +
  • Datele se exportă local — nimic nu se trimite automat nicăieri
  • +
  • Tu decizi cu cine partajezi fișierul generat
  • +
  • Orice destinatar poate vedea că datele sunt auto-raportate
  • +
  • Pașaportul nu are valoare legală sau contractuală
  • +
+
+ + {/* Section selector */} +
+

Ce incluzi în pașaport

+ {SECTIONS.map((s) => ( + + ))} +
+ + {/* Preview counts */} +
+
+

{selected.credentials ? preview.creds.length : 0}

+

credențiale

+
+
+

{selected.skills ? preview.skills.length : 0}

+

competențe

+
+
+

{selected.goals ? preview.completedGoals.length : 0}

+

obiective

+
+
+ + + + {generated && ( +
+

Pașaport generat și descărcat.

+

Partajează fișierul manual cu cine dorești.

+
+ )} +
+ ); +}