import type { CreateRecipeFormEntries } from "../../pages/Create"; interface ValidationErrorListProps { validation: CreateRecipeFormEntries; } const MESSAGES: Record = { title: "Invalid title provided.", description: "Invalid description provided.", prepTime: "Invalid preparation time provided.", cookTime: "Invalid cook time provided.", servingSize: "Invalid serving size provided.", category: "Invalid category selected.", difficulty: "Invalid difficulty selected.", ingredients: "Invalid ingredients provided.", instructions: "Invalid instructions provided.", } export default function ValidationErrorList({ validation }: ValidationErrorListProps) { return (
{Object.entries(validation) .filter(([, isValid]) => !isValid) .map(([name]) => { const key = name as keyof CreateRecipeFormEntries; return (

{MESSAGES[key]}

); })} {validation.ingredients.filter(x => !x.valid).length > 0 && (

{MESSAGES.ingredients}

)} {validation.instructions.filter(x => !x.valid).length > 0 && (

{MESSAGES.instructions}

)}
); }