validate ingredient groups as well as ingredient lists of all groups
This commit is contained in:
parent
d4e8a4d09a
commit
f23aab4b3f
2 changed files with 17 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import { useState } from "react"
|
|||
import type { Recipe } from "../types/recipe"
|
||||
import type { IngredientGroup } from "../types/ingredientGroup"
|
||||
import { IngredientGroupListEditor } from "./IngredientGroupListEditor"
|
||||
import { IngredientListEditor } from "./IngredientListEditor"
|
||||
|
||||
type RecipeEditorProps = {
|
||||
recipe: Recipe
|
||||
|
|
@ -39,10 +40,23 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
|
|||
newErrors.title = true
|
||||
}
|
||||
|
||||
// the incredient list must not be empty
|
||||
// @todo enhance validation and visualization of ingredient errors
|
||||
/* there must be at least one ingredient group
|
||||
* no group may contain an empty ingredient list
|
||||
* @todo check whether all ingredients are valid
|
||||
* @todo enhance visualization of ingredient errors
|
||||
*/
|
||||
if (!draft.ingredientGroupList || draft.ingredientGroupList.length === 0) {
|
||||
newErrors.ingredients = true
|
||||
} else {
|
||||
let isAnyIngredientListEmpty = draft.ingredientGroupList.some(
|
||||
ingGrp => {
|
||||
return !ingGrp.ingredientList || ingGrp.ingredientList.length === 0
|
||||
}
|
||||
)
|
||||
console.log(isAnyIngredientListEmpty)
|
||||
if(isAnyIngredientListEmpty){
|
||||
newErrors.ingredients = true
|
||||
}
|
||||
}
|
||||
|
||||
setErrors(newErrors)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue