From 58691fd7a11c8cd315f177b5b77847844bf4bb8a Mon Sep 17 00:00:00 2001
From: Hayden Hargreaves
Date: Tue, 2 Dec 2025 22:37:51 -0700
Subject: [PATCH] (FIX): Added error display list.
This looks nice and is a bit more functional! I really need to break the
form up into components...
---
.../components/forms/ValidationErrorList.tsx | 34 +++++++++++++++++++
web/src/pages/Create.tsx | 15 ++++----
2 files changed, 40 insertions(+), 9 deletions(-)
create mode 100644 web/src/components/forms/ValidationErrorList.tsx
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.