Skip to content

Commit

Permalink
Allow editing recipe title (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgegebbett committed Apr 19, 2024
1 parent b7c3edc commit 1c56730
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/app/(dashboard)/recipes/[id]/recipeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
} from "~/server/api/modules/grocy/procedures/createRecipeInGrocySchema"
import { api } from "~/trpc/react"
import { RouterOutputs } from "~/trpc/shared"
import { FormProvider, useForm } from "react-hook-form"
import { Controller, FormProvider, useForm } from "react-hook-form"
import { toast } from "sonner"

import { Button } from "~/components/ui/button"
import { DashboardHeader } from "~/components/header"
import { IngredientTable } from "~/components/ingredient-table"
import { RecipeTitleInput } from "~/components/recipe-title-input"

type RecipeFormProps = {
recipeId: number
Expand Down Expand Up @@ -73,18 +73,22 @@ function RecipeFormInner({
<FormProvider {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<input hidden {...form.register("recipeBuddyRecipeId")} />
<DashboardHeader
heading={recipe.name}
className="flex-col items-start gap-2"
>
<div className="flex flex-col gap-2">
<Controller
render={({ field }) => (
<RecipeTitleInput value={field.value} onChange={field.onChange} />
)}
name="recipeName"
control={form.control}
/>
<Link
href={recipe.url}
className="text-muted-foreground text-lg"
className="text-muted-foreground pl-1 text-lg"
target="_blank"
>
View Original
</Link>
</DashboardHeader>
</div>
<div className="flex flex-col gap-2">
<IngredientTable grocyBaseUrl={grocyBaseUrl ?? ""} />
<Button type="submit" isLoading={mutLoading} className="self-end">
Expand Down
15 changes: 15 additions & 0 deletions src/components/recipe-title-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client"

import { cn } from "~/lib/utils"
import { Input, InputProps } from "~/components/ui/input"

interface RecipeTitleInputProps extends InputProps {}

export function RecipeTitleInput({
className,
...props
}: RecipeTitleInputProps) {
return (
<Input className={cn("py-6 text-3xl md:text-4xl", className)} {...props} />
)
}

0 comments on commit 1c56730

Please sign in to comment.