diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index c30fd6e..7219803 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -13,24 +13,26 @@ function AddRecipe() { const [ingredients, setIngredients] = useState([]); const [steps, setSteps] = useState([]); const [showBulkForm, setShowBulkForm] = useState(true); + const [recipeName, setRecipeName] = useState(""); + const [recipeCuisine, setRecipeCuisine] = useState(""); const addRecipeForm = async (event: React.FormEvent) => { event.preventDefault(); - const nameElement = document.getElementById('ar-name') as HTMLInputElement | null; - const cuisineElement = document.getElementById('ar-cuisine') as HTMLInputElement | null; const stepsHash = Object.fromEntries( steps.map(step => [step.idx, step.instructions]) ); - if (nameElement && cuisineElement) { + if (recipeName && recipeCuisine && Object.keys(stepsHash).length > 0 && ingredients.length > 0) { const recipeData = { - name: nameElement.value, - cuisine: cuisineElement.value, + name: recipeName, + cuisine: recipeCuisine, ingredients: ingredients, steps: stepsHash } console.log(recipeData) const data = await addRecipe(recipeData); setNewRecipeId(data.id); + } else { + alert('missing required data') } }; @@ -46,14 +48,16 @@ function AddRecipe() { setRecipeName(e.target.value)} /> setRecipeCuisine(e.target.value)} />