@@ -4,6 +4,7 @@ import { useId, type ReactNode } from 'react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { openJourneyHelp } from '@/components/journey-help';
|
||||
import { recoveryHints } from '@/lib/journey-help';
|
||||
import { focusFormError } from '@/lib/form-error-focus';
|
||||
import { date, money, statusLabels } from '@/types/procurement';
|
||||
import type { Requisition } from '@/types/procurement';
|
||||
|
||||
@@ -228,7 +229,13 @@ export function RequisitionTable({ rows }: { rows: Requisition[] }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export function FormErrors({ errors }: { errors: Record<string, string> }) {
|
||||
export function FormErrors({
|
||||
errors,
|
||||
targets = {},
|
||||
}: {
|
||||
errors: Record<string, string>;
|
||||
targets?: Record<string, string>;
|
||||
}) {
|
||||
if (!Object.keys(errors).length) return null;
|
||||
const hints = recoveryHints(Object.keys(errors));
|
||||
return (
|
||||
@@ -239,7 +246,22 @@ export function FormErrors({ errors }: { errors: Record<string, string> }) {
|
||||
<p className="mb-1 font-medium">Verifique os dados:</p>
|
||||
<ul className="list-inside list-disc">
|
||||
{Object.entries(errors).map(([key, value]) => (
|
||||
<li key={key}>{value}</li>
|
||||
<li key={key}>
|
||||
{targets[key] ? (
|
||||
<a
|
||||
className="underline focus-visible:ring-2 focus-visible:ring-ring"
|
||||
href={`#${targets[key]}`}
|
||||
onClick={(event) => {
|
||||
if (focusFormError(targets[key]))
|
||||
event.preventDefault();
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</a>
|
||||
) : (
|
||||
value
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{hints.length > 0 && (
|
||||
|
||||
Reference in New Issue
Block a user