diff --git a/web/src/components/forms/ValidationErrorList.tsx b/web/src/components/forms/ValidationErrorList.tsx new file mode 100644 index 0000000..a10c3ca --- /dev/null +++ b/web/src/components/forms/ValidationErrorList.tsx @@ -0,0 +1,34 @@ +import type { CreateRecipeFormToggles } from "../../pages/Create"; + +interface ValidationErrorListProps { + validation: CreateRecipeFormToggles; +} + +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 CreateRecipeFormToggles; + return ( +

+ {MESSAGES[key]} +

+ ); + })} +
+ ); +} diff --git a/web/src/pages/Create.tsx b/web/src/pages/Create.tsx index 2586e6b..834f903 100644 --- a/web/src/pages/Create.tsx +++ b/web/src/pages/Create.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; import Banner from "../components/Banner"; import { isRecipeMeal } from "../types/recipe"; import InstructionForm from "../components/forms/InstructionForm"; +import ValidationErrorList from "../components/forms/ValidationErrorList"; interface CreateRecipeForm { title: string; @@ -18,7 +19,7 @@ interface CreateRecipeForm { image: File | null; }; -interface CreateRecipeFormToggles { +export interface CreateRecipeFormToggles { title: boolean; description: boolean; prepTime: boolean; @@ -175,7 +176,6 @@ export default function Create() { Please provide a unique title for your recipe. This is the most important part!

e.g., easy, dairy-free, gluten-free, high protein.

-