import { useState } from 'react'; import type { ReactNode } from 'react'; import { PLAN_LIMITS } from '@cra-compliance/types'; import { computeReadiness } from '@cra-compliance/shared'; import type { ReadinessKey } from '@cra-compliance/shared'; import type { Page } from '../App'; import { useDashboardStats } from '../hooks/useAccount'; import type { AccountStats } from '../hooks/useAccount'; import { useConfig } from '../hooks/useApi'; import { useFindings } from '../hooks/useFindings'; import { useCompliance } from '../context/ComplianceContext'; import { useDocuments } from '../hooks/useDocuments'; import { CHECKLIST } from '../content/checklist'; import { CRA_DATES, hasStarted, legalDate } from '../content/cra'; import { LINKS } from '../content/links'; import { isOpen } from '../lib/types'; import { dateTime, plural, relative } from '../lib/format'; import { PlanTable } from '../components/PlanTable'; import { Cite, Empty, ExternalLink, Meter, Notice, PageHead, Panel, Skel } from '../components/ui'; interface DashboardProps { onNavigate: (page: Page) => void; } export function Dashboard({ onNavigate }: DashboardProps) { const config = useConfig(); const { progress, loading, loadError, reload, totalItems, completedItems, compliancePercent } = useCompliance(); const stats = useDashboardStats(); const documents = useDocuments(); const findings = useFindings(); const exploited = (findings.data?.items ?? []).filter((v) => v.actively_exploited === true && isOpen(v)); const savedTemplates = new Set((documents.data ?? []).map((doc) => doc.template_id)); return (
{config.connected && stats.data && stats.data.overdue_incidents > 0 && ( onNavigate('incidents')}>Open incidents} >

Submit the outstanding report as soon as you can and record when you sent it.

)} {exploited.length > 0 && ( onNavigate('scanner')}>Review} >

If one is exploitable in a product you make, the 24-hour early warning under CRA Article 14 may apply.

)} {loadError ? ( Try again} >

{loadError}

) : ( )}
onNavigate('checklist')}>Open checklist} > {loading ? (
{[0, 1, 2, 3, 4, 5].map((i) => )}
) : (
{CHECKLIST.map((category) => { const done = category.items.filter((item) => progress[item.id]?.completed).length; return (
{category.title} {done} of {category.items.length}
); })}
)}
{config.connected && stats.data && } {!config.paid && ( Compare plans {!config.connected && ( )} } flush > )}
); } function RegulationTimeline({ onNavigate }: { onNavigate: (page: Page) => void }) { const now = Date.now(); const start = Date.parse(`${CRA_DATES.entryIntoForce}T00:00:00Z`); const end = Date.parse(`${CRA_DATES.fullApplication}T00:00:00Z`); const reporting = Date.parse(`${CRA_DATES.reporting}T00:00:00Z`); const position = (time: number) => Math.min(100, Math.max(0, ((time - start) / (end - start)) * 100)); const reportingLive = hasStarted(CRA_DATES.reporting); const fullLive = hasStarted(CRA_DATES.fullApplication); return ( onNavigate('education')}>About the CRA} >
In force Regulation (EU) 2024/2847
Reporting Art. 14 {reportingLive ? 'Applies now' : 'Not yet in application'}
Everything else Annex I, technical file, CE marking
); } function Figures({ loading, completed, total, documents, stats, statsLoading, statsError, connected, paid, onNavigate }: { loading: boolean; completed: number; total: number; documents?: number; stats?: AccountStats; statsLoading: boolean; statsError: boolean; connected: boolean; paid: boolean; onNavigate: (page: Page) => void; }) { const serviceValue = (render: (s: AccountStats) => ReactNode) => { if (!connected) return Not connected; if (statsLoading) return ; if (statsError || !stats) return Unavailable; return render(stats); }; return (
Checklist
{loading ? : <>{completed} of {total}}
Saved documents
{documents === undefined ? : documents}
Open vulnerabilities
{serviceValue((s) => s.open_vulnerabilities)}
0 ? ' is-critical' : ''}`}> {connected && stats ? stats.critical_vulnerabilities > 0 ? `${stats.critical_vulnerabilities} critical` : stats.total_projects > 0 // The count covers the whole account, including packages monitored on resiliencewp.com. ? `${plural(stats.total_plugins, 'plugin', 'plugins')} and ${plural(stats.total_projects, 'package', 'packages')} monitored` : `${plural(stats.total_plugins, 'plugin', 'plugins')} monitored` : connected ? '' : 'Needs an account'}
Open incidents
{paid ? serviceValue((s) => s.open_incidents) : Not connected}
0 ? ' is-critical' : ''}`}> {paid && stats ? stats.overdue_incidents > 0 ? `${stats.overdue_incidents} overdue` : stats.most_urgent_deadline_at ? `Next deadline ${relative(stats.most_urgent_deadline_at)}` : 'No deadlines running' : paid ? '' : 'Needs an account'}
); } function NextSteps({ checklistPercent, savedTemplates, connected, monitored, onNavigate }: { checklistPercent: number; savedTemplates: Set; connected: boolean; monitored: number; onNavigate: (page: Page) => void; }) { const hasDisclosure = savedTemplates.has('vulnerability-disclosure-policy') || savedTemplates.has('security-txt'); const steps = [ { title: 'Check that the CRA applies to you', text: 'Plugins and themes supplied in the course of a commercial activity are in scope. Free software outside a commercial activity is not.', done: false, action: Applicability checker, }, { title: 'Publish a way to report vulnerabilities', text: 'A disclosure policy and a security contact, for example in security.txt.', done: hasDisclosure, action: , }, { title: 'Be ready to report within 24 hours', text: 'Write an incident response plan and set up access to ENISA\'s Single Reporting Platform.', done: savedTemplates.has('incident-response-plan'), action: , }, { title: 'Monitor the plugins you ship', text: connected ? monitored > 0 ? `${plural(monitored, 'plugin is', 'plugins are')} monitored for known vulnerabilities.` : 'Add your plugin and the plugins it depends on.' : 'Connect an account to check them against known vulnerabilities.', done: connected && monitored > 0, action: , }, { title: 'Work through the checklist', text: `${checklistPercent}% done. It runs from scope and reporting to the requirements that apply from December 2027.`, done: checklistPercent === 100, action: , }, ]; return (
    {steps.map((step, index) => (
  1. {step.title} {step.done && (done)}

    {step.text}

    {step.action}
  2. ))}
); } const READINESS_LABELS: Record = { overdue: 'Incidents past a reporting deadline', critical: 'Open critical vulnerabilities', high: 'Open high vulnerabilities', medium: 'Open medium vulnerabilities', }; /** * The score comes from the service. The breakdown uses the service's own lines * when it sends them, and otherwise the same shared formula. If the two ever * disagree (the service changed its formula after this version shipped), the * points are left out and only the counts are shown, so the panel never * contradicts the score. */ function ScorePanel({ stats }: { stats: AccountStats }) { const computed = computeReadiness(stats); const lines = stats.readiness_lines ?? computed.lines; const pointsKnown = Boolean(stats.readiness_lines) || computed.score === stats.compliance_score; const active = lines.filter((line) => line.count > 0); return (
{stats.compliance_score} of 100

{stats.last_scan_at ? `Last scan ${dateTime(stats.last_scan_at)}` : 'No scan yet'} {stats.next_scan_at ? `. Next scan ${dateTime(stats.next_scan_at)}.` : ''}

{active.length === 0 ? ( Nothing open is lowering the score. ) : (
{active.map((line) => ( ))}
)}
); } function FragmentRow({ label, value }: { label: string; value: string }) { return ( <>
{label}
{value}
); } const FIRST_SEEN_KEY = 'resicoma_first_load'; const REVIEW_DISMISSED_KEY = 'resicoma_review_dismissed'; function storageGet(key: string): string | null { try { return window.localStorage.getItem(key); } catch { return null; } } function storageSet(key: string, value: string) { try { window.localStorage.setItem(key, value); } catch { /* storage unavailable */ } } /** A one-time, dismissible request for a WordPress.org review. */ function ReviewPrompt({ percent, paid }: { percent: number; paid: boolean }) { const [dismissed, setDismissed] = useState(() => storageGet(REVIEW_DISMISSED_KEY) !== null); const [firstSeen] = useState(() => { const stored = Number(storageGet(FIRST_SEEN_KEY)); if (stored > 0) return stored; const nowMs = Date.now(); storageSet(FIRST_SEEN_KEY, String(nowMs)); return nowMs; }); const days = (Date.now() - firstSeen) / 86_400_000; if (paid || dismissed || percent < 50 || days < 30) return null; const dismiss = () => { storageSet(REVIEW_DISMISSED_KEY, '1'); setDismissed(true); }; return ( Write a review } >

A short review on WordPress.org helps other developers find it.

); }