Skip to content

Commit

Permalink
fix: Cocktail forms calculation was not shown properly, changed volum…
Browse files Browse the repository at this point in the history
…e validation at ingredients form (#188)

Signed-off-by: Johannes Groß <mail@gross-johannes.de>
  • Loading branch information
jo-gross authored Mar 4, 2024
1 parent 96cc360 commit f3ef485
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
42 changes: 19 additions & 23 deletions components/cocktails/CocktailRecipeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -713,31 +713,27 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
<div className={'divider-sm col-span-2'}>Zutaten</div>
{(values.steps as CocktailRecipeStepFull[]).filter((step) => step.ingredients.some((ingredient) => ingredient.ingredient != undefined))
.length > 0 ? (
(values.garnishes as CocktailRecipeGarnishFull[]).length > 0 ? (
<>
{(values.steps as CocktailRecipeStepFull[])
.map((step) => step.ingredients.filter((ingredient) => ingredient.ingredient != undefined))
.flat()
?.map((ingredient, indexIngredient) => (
<>
<div key={`price-calculation-step-${indexIngredient}-name`}>
{ingredient.ingredient?.shortName ?? ingredient.ingredient?.name}
<>
{(values.steps as CocktailRecipeStepFull[])
.map((step) => step.ingredients.filter((ingredient) => ingredient.ingredient != undefined))
.flat()
?.map((ingredient, indexIngredient) => (
<>
<div key={`price-calculation-step-${indexIngredient}-name`}>
{ingredient.ingredient?.shortName ?? ingredient.ingredient?.name}
</div>
<div key={`price-calculation-step-${indexIngredient}-price`} className={'grid grid-cols-2'}>
<div>
{ingredient.amount} x {((ingredient.ingredient?.price ?? 0) / (ingredient.ingredient?.volume ?? 1)).toFixed(2)}
</div>
<div key={`price-calculation-step-${indexIngredient}-price`} className={'grid grid-cols-2'}>
<div>
{ingredient.amount} x {((ingredient.ingredient?.price ?? 0) / (ingredient.ingredient?.volume ?? 1)).toFixed(2)}
</div>
<div className={'text-end'}>
{indexIngredient > 0 ? '+ ' : ''}
{(((ingredient.ingredient?.price ?? 0) / (ingredient.ingredient?.volume ?? 1)) * (ingredient.amount ?? 0)).toFixed(2)}
</div>
<div className={'text-end'}>
{indexIngredient > 0 ? '+ ' : ''}
{(((ingredient.ingredient?.price ?? 0) / (ingredient.ingredient?.volume ?? 1)) * (ingredient.amount ?? 0)).toFixed(2)}
</div>
</>
))}
</>
) : (
<></>
)
</div>
</>
))}
</>
) : (
<div className={'col-span-2 text-center font-thin italic'}>Keine Zutaten</div>
)}
Expand Down
3 changes: 3 additions & 0 deletions components/ingredients/IngredientForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export function IngredientForm(props: IngredientFormProps) {
if (values.volume.toString() == '' || isNaN(values.volume)) {
errors.volume = 'Required';
}
if (values.volume <= 0) {
errors.volume = 'Muss größer 0 sein';
}
if (!values.unit) {
errors.unit = 'Required';
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8656,11 +8656,11 @@ __metadata:

"typescript@patch:typescript@5.3.3#~builtin<compat/typescript>":
version: 5.3.3
resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin<compat/typescript>::version=5.3.3&hash=e012d7"
resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin<compat/typescript>::version=5.3.3&hash=1f5320"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 4e604a9e107ce0c23b16a2f8d79d0531d4d8fe9ebbb7a8c395c66998c39892f0e0a071ef0b0d4e66420a8ec2b8d6cfd9cdb29ba24f25b37cba072e9282376df9
checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610
languageName: node
linkType: hard

Expand Down

0 comments on commit f3ef485

Please sign in to comment.