-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add coffee detail and coffee edit pages
- Loading branch information
1 parent
5cea0d0
commit ca9c342
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {CoffeeForm} from "@/app/coffee/components/coffee-form"; | ||
import {Title} from "@/components/layout/title"; | ||
import {User} from "@clerk/nextjs/api"; | ||
import {currentUser} from "@clerk/nextjs"; | ||
import {getBeanDetails} from "@/lib/db/beans/get-bean-details"; | ||
import {notFound} from "next/navigation"; | ||
import {Inputs} from "@/app/coffee/actions/coffee-form/form-schema"; | ||
import {undefined} from "zod"; | ||
|
||
export default async function EditCoffeePage({ params }: { params: { coffeeId: string } }) { | ||
const user: User | null = await currentUser(); | ||
|
||
if (!user) return notFound(); | ||
|
||
const bean = await getBeanDetails(params.coffeeId, user.publicMetadata.databaseId as number) | ||
|
||
if (!bean) return notFound(); | ||
|
||
const values: Inputs = { | ||
buyDate: bean.buyDate, | ||
isArchived: bean.isArchived, | ||
isPublic: bean.isPublic, | ||
name: bean.name, | ||
notes: bean.notes, | ||
price: bean.price, | ||
publicId: bean.publicId, | ||
roastDate: bean.roastDate, | ||
roaster: bean.roaster.name, | ||
roasterId: bean.roasterId, | ||
varieties: bean.varieties, | ||
weight: bean.weight | ||
|
||
} | ||
|
||
return ( | ||
<> | ||
<Title | ||
title={"Coffee"} | ||
subtitle={"Add a coffee to your coffee backlog"} | ||
/> | ||
<CoffeeForm roasters={[]} values={values}/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {Title} from "@/components/layout/title"; | ||
import {User} from "@clerk/nextjs/api"; | ||
import {currentUser} from "@clerk/nextjs"; | ||
import {notFound} from "next/navigation"; | ||
import {canView} from "@/lib/perms"; | ||
import {getBeanDetails} from "@/lib/db/beans/get-bean-details"; | ||
import {BeanDetail} from "@/app/coffee/[coffeeId]/components/bean-detail"; | ||
import Link from "next/link"; | ||
import {Button, buttonVariants} from "@/components/ui/button"; | ||
import Image from "next/image"; | ||
|
||
function Buttons({user, bean} :{user: User | null, bean: Awaited<ReturnType<typeof getBeanDetails>>}) { | ||
if (!bean || !user || user.publicMetadata.databaseId !== bean.userId) return null; | ||
|
||
return ( | ||
<div className={"flex flex-row-reverse gap-2"}> | ||
<Link href={`/coffee/${bean.publicId}/edit`} className={buttonVariants({size: "sm", variant: "outline"})}> | ||
Edit | ||
</Link> | ||
{/*<BeanConquerorButton bean={bean} />*/} | ||
</div> | ||
); | ||
} | ||
|
||
function BeanConquerorButton({bean}: {bean:Awaited<ReturnType<typeof getBeanDetails>>}) { | ||
return ( | ||
<Button variant={"outline"} size={"sm"}> | ||
<Image src={"/beanconqueror_logo.png"} alt={"Beanconqueror logo"} height={20} width={20} /> | ||
</Button> | ||
) | ||
} | ||
|
||
export default async function CoffeeDetailPage({ params }: { params: { coffeeId: string } }) { | ||
const user: User | null = await currentUser(); | ||
const bean = await getBeanDetails(params.coffeeId, user?.publicMetadata?.databaseId as number || undefined) | ||
|
||
if (!bean || !canView(user, bean)) return notFound(); | ||
|
||
return ( | ||
<> | ||
<Title | ||
title={bean.name} | ||
subtitle={`Roasted by ${bean.roaster.name}`} | ||
/> | ||
<Buttons user={user} bean={bean} /> | ||
<BeanDetail bean={bean} /> | ||
</> | ||
) | ||
} |