67 lines
2.4 KiB
TypeScript
67 lines
2.4 KiB
TypeScript
import { useState } from 'react';
|
|
import {
|
|
businessPlanWarnings,
|
|
type PlanWarningMetrics,
|
|
type PlanWarningLimits,
|
|
type PlanWarning,
|
|
} from '@/lib/business-plan-guidance';
|
|
|
|
export function BusinessPlanWarnings({
|
|
metrics = {},
|
|
limits,
|
|
warnings: suppliedWarnings,
|
|
}: {
|
|
metrics?: PlanWarningMetrics;
|
|
limits?: PlanWarningLimits;
|
|
warnings?: PlanWarning[];
|
|
}) {
|
|
const [dismissed, setDismissed] = useState<string[]>([]);
|
|
const scope = JSON.stringify([metrics, suppliedWarnings, limits]);
|
|
const warnings = (
|
|
suppliedWarnings ?? businessPlanWarnings(metrics, limits)
|
|
).filter((warning) => !dismissed.includes(`${scope}:${warning.id}`));
|
|
if (!warnings.length) return null;
|
|
return (
|
|
<aside
|
|
aria-label="Avisos de planeamento"
|
|
className="my-3 space-y-2 rounded border border-amber-400 bg-amber-50 p-3 text-sm text-amber-950"
|
|
>
|
|
<h4 className="font-semibold">Avisos — pode continuar</h4>
|
|
{warnings.map((warning) => (
|
|
<div
|
|
key={warning.id}
|
|
className="flex items-start justify-between gap-3"
|
|
>
|
|
<p role="status">
|
|
<span aria-hidden="true">⚠ </span>
|
|
{warning.message}
|
|
{warning.id === 'optional-texts' && (
|
|
<span className="mt-1 block text-xs">
|
|
Secções opcionais em falta:{' '}
|
|
{metrics.optionalTexts
|
|
?.filter((field) => !field.value.trim())
|
|
.map((field) => field.label)
|
|
.join(', ')}
|
|
.
|
|
</span>
|
|
)}
|
|
</p>
|
|
<button
|
|
type="button"
|
|
className="shrink-0 underline"
|
|
aria-label={`Dispensar aviso: ${warning.message}`}
|
|
onClick={() =>
|
|
setDismissed((previous) => [
|
|
...previous,
|
|
`${scope}:${warning.id}`,
|
|
])
|
|
}
|
|
>
|
|
Dispensar
|
|
</button>
|
|
</div>
|
|
))}
|
|
</aside>
|
|
);
|
|
}
|