Skip to content

Commit

Permalink
feat: add coffee detail and coffee edit pages
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelblijleven committed Sep 29, 2023
1 parent 5cea0d0 commit ca9c342
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/app/coffee/[coffeeId]/edit/page.tsx
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}/>
</>
)
}
49 changes: 49 additions & 0 deletions src/app/coffee/[coffeeId]/page.tsx
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} />
</>
)
}

0 comments on commit ca9c342

Please sign in to comment.