Skip to content

Commit

Permalink
feat: Made all prices (cocktails, ingredients, garnishes) optional
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Groß <mail@gross-johannes.de>
  • Loading branch information
jo-gross committed Feb 19, 2024
1 parent 23195f4 commit d8abd5a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions components/cocktails/CocktailRecipeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
id: props.cocktailRecipe?.id ?? '',
name: props.cocktailRecipe?.name ?? '',
description: props.cocktailRecipe?.description ?? '',
price: props.cocktailRecipe?.price ?? 0,
price: props.cocktailRecipe?.price ?? undefined,
tags: props.cocktailRecipe?.tags ?? [],
glassWithIce: props.cocktailRecipe?.glassWithIce ?? IceType.Without,
image: props.cocktailRecipe?.CocktailRecipeImage[0]?.image ?? undefined,
Expand Down Expand Up @@ -310,9 +310,6 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
if (!values.name || values.name.trim() == '') {
errors.name = 'Required';
}
if (!values.price) {
errors.price = 'Required';
}
if (!values.glassId || values.glassId == '') {
errors.glassId = 'Required';
}
Expand Down Expand Up @@ -387,8 +384,8 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
const body = {
id: props.cocktailRecipe?.id,
name: values.name,
description: values.description.trim() === '' ? undefined : values.description,
price: values.price,
description: values.description.trim() === '' ? null : values.description,
price: values.price == '' ? null : values.price,
glassId: values.glassId,
garnishId: values.garnishId,
image: values.image == '' ? null : values.image,
Expand Down Expand Up @@ -489,7 +486,7 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
<label className={'label'}>
<span className={'label-text'}>Preis</span>
<span className={'label-text-alt text-error'}>
<>{errors.price && touched.price && errors.price}</> *
<>{errors.price && touched.price && errors.price}</>
</span>
</label>
<div className={'join w-full'}>
Expand All @@ -499,7 +496,7 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
name="price"
onChange={handleChange}
onBlur={handleBlur}
value={values.price ?? undefined}
value={values.price}
/>
<span className={'btn btn-secondary join-item'}>
<FaEuroSign />
Expand Down Expand Up @@ -688,7 +685,7 @@ export function CocktailRecipeForm(props: CocktailRecipeFormProps) {
name: values.name,
description: values.description,
tags: values.tags,
price: values.price,
price: !values.price && values.price == '' ? null : values.price,
glassWithIce: values.glassWithIce,
glassId: values.glassID ?? null,
glass: glasses.find((glass) => glass.id === values.glassId) ?? null,
Expand Down
6 changes: 5 additions & 1 deletion components/cocktails/CompactCocktailRecipeInstruction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function CompactCocktailRecipeInstruction(props: CompactCocktailRecipeIns
<div className={`${props.showPrice ? 'col-span-2' : 'col-span-3'} text-xl font-bold`}>
{props.cocktailRecipe.name == '' ? '<Name>' : props.cocktailRecipe.name}
</div>
{props.showPrice == true ? <div className={'col-span-1 text-right text-xl font-bold'}>{props.specialPrice ?? props.cocktailRecipe.price}</div> : <></>}
{props.showPrice == true ? (
<div className={'col-span-1 text-right text-xl font-bold'}>{props.specialPrice ?? props.cocktailRecipe.price ?? '-'}</div>
) : (
<></>
)}
<div className={'row-span-2 flex h-min items-center justify-center'}>
<NextImage
className={'h-12 object-contain'}
Expand Down
14 changes: 4 additions & 10 deletions components/garnishes/GarnishForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export function GarnishForm(props: GarnishFormProps) {
innerRef={formRef}
initialValues={{
name: props.garnish?.name ?? '',
price: props.garnish?.price ?? 0,
price: props.garnish?.price ?? undefined,
description: props.garnish?.description ?? '',
image: props.garnish?.GarnishImage[0].image ?? undefined,
image: props.garnish?.GarnishImage?.[0]?.image ?? undefined,
}}
onSubmit={async (values) => {
try {
const body = {
id: props.garnish == undefined ? undefined : props.garnish.id,
name: values.name,
price: values.price,
price: values.price == '' ? null : values.price,
description: values.description?.trim() == '' ? null : values.description?.trim(),
image: values.image == '' ? null : values.image,
};
Expand Down Expand Up @@ -98,9 +98,6 @@ export function GarnishForm(props: GarnishFormProps) {
if (!values.name) {
errors.name = 'Required';
}
if (values.price.toString() == '' || isNaN(values.price)) {
errors.price = 'Required';
}
return errors;
}}
>
Expand Down Expand Up @@ -149,10 +146,7 @@ export function GarnishForm(props: GarnishFormProps) {
<label className={'label'}>
<span className={'label-text'}>Preis</span>
<span className={'label-text-alt space-x-2 text-error'}>
<span>
<>{errors.price && touched.price && errors.price}</>
</span>
<span>*</span>
<>{errors.price && touched.price && errors.price}</>
</span>
</label>
<div className={'join'}>
Expand Down
16 changes: 6 additions & 10 deletions components/ingredients/IngredientForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function IngredientForm(props: IngredientFormProps) {
initialValues={{
name: props.ingredient?.name ?? '',
shortName: props.ingredient?.shortName ?? '',
price: props.ingredient?.price ?? 0,
price: props.ingredient?.price ?? undefined,
volume: props.ingredient?.volume ?? 0,
unit: props.ingredient?.unit ?? CocktailIngredientUnit.CL,
link: props.ingredient?.link ?? '',
Expand All @@ -54,13 +54,13 @@ export function IngredientForm(props: IngredientFormProps) {
const body = {
id: props.ingredient == undefined ? undefined : props.ingredient.id,
name: values.name.trim(),
shortName: values.shortName?.trim() == '' ? undefined : values.shortName?.trim(),
price: values.price,
shortName: values.shortName?.trim() == '' ? null : values.shortName?.trim(),
price: values.price == '' ? null : values.price,
unit: values.unit,
volume: values.volume == 0 ? undefined : values.volume,
link: values.link?.trim() == '' ? undefined : values.link?.trim(),
volume: values.volume,
link: values.link?.trim() == '' ? null : values.link?.trim(),
tags: values.tags,
image: values.image?.trim() == '' ? undefined : values.image?.trim(),
image: values.image?.trim() == '' ? null : values.image?.trim(),
};
if (props.ingredient == undefined) {
const response = await fetch(`/api/workspaces/${workspaceId}/ingredients`, {
Expand Down Expand Up @@ -108,9 +108,6 @@ export function IngredientForm(props: IngredientFormProps) {
if (!values.name) {
errors.name = 'Required';
}
if (values.price.toString() == '' || isNaN(values.price)) {
errors.price = 'Required';
}
if (values.volume.toString() == '' || isNaN(values.volume)) {
errors.volume = 'Required';
}
Expand Down Expand Up @@ -168,7 +165,6 @@ export function IngredientForm(props: IngredientFormProps) {
<span>
<>{errors.price && touched.price && errors.price}</>
</span>
<span>*</span>
</span>
</label>
<div className={'join'}>
Expand Down
2 changes: 1 addition & 1 deletion components/modals/CocktailDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function CocktailDetailModal(props: CocktailDetailModalProps) {
)}
</>
<h2 className={'card-title flex-1'}>
{props.cocktail.name} - <span className={'font-bold'}>{props.cocktail.price}</span>
{props.cocktail.name} - <span className={'font-bold'}>{props.cocktail.price ?? '-'} </span>
</h2>
</div>
<div className={'grid grid-cols-2 gap-4'}>
Expand Down
2 changes: 1 addition & 1 deletion pages/workspaces/[workspaceId]/manage/cocktails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function CocktailsOverviewPage() {
</td>
<td>{cocktailRecipe.name}</td>
<td className={''}>
<span className={'whitespace-nowrap'}>{cocktailRecipe.price}</span>
<span className={'whitespace-nowrap'}>{cocktailRecipe.price ?? '-'}</span>
</td>
<td className={'flex items-center gap-1'}>
{cocktailRecipe.tags.map((tag) => (
Expand Down
2 changes: 1 addition & 1 deletion pages/workspaces/[workspaceId]/manage/garnishes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function ManageGlassesOverviewPage() {
<td>
<div className="font-bold">{garnish.name}</div>
</td>
<td>{garnish.price}</td>
<td>{garnish.price ?? '-'}</td>
<ManageColumn entity={'garnishes'} id={garnish.id} onRefresh={refreshGarnishes} />
</tr>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default function IngredientsOverviewPage() {
</td>
<td className={''}>{ingredient.name}</td>
<td>{ingredient.shortName}</td>
<td className={'whitespace-nowrap'}>{ingredient.price}</td>
<td className={'whitespace-nowrap'}>{ingredient.price ?? '-'}</td>
<td className={'whitespace-nowrap'}>
{ingredient.volume} {ingredient.unit}
</td>
Expand Down

0 comments on commit d8abd5a

Please sign in to comment.