From 6697fdfd38af225e112c511a2f593e0184e34a4b Mon Sep 17 00:00:00 2001 From: William Tanardi Date: Sun, 4 Jun 2023 00:02:46 +0700 Subject: [PATCH] added modal to recipe onclick on user dashboard --- app/api/recipe/route.ts | 19 ++++++--- app/dashboard/user/page.tsx | 14 +++++-- components/RecipeCard.tsx | 84 +++++++++++++++++++++++++++++++------ 3 files changed, 97 insertions(+), 20 deletions(-) diff --git a/app/api/recipe/route.ts b/app/api/recipe/route.ts index 9f0359e..09af056 100644 --- a/app/api/recipe/route.ts +++ b/app/api/recipe/route.ts @@ -7,25 +7,34 @@ export async function GET(req: Request) { id: true, name: true, img: true, - ingredients: true, + ingredients: { + select: { + amount: true, + measurement: true, + ingredient: true, + }, + }, desc: true, price: true, - step: true + step: true, }, }); - return NextResponse.json(recipes) + return NextResponse.json(recipes); } export async function POST(req: Request) { - const { id, name, desc, price, step} = await req.json(); + const { id, name, desc, price, step } = await req.json(); const exists = await prisma.recipe.findUnique({ where: { id, }, }); if (exists) { - return NextResponse.json({ error: "Recipe already exists" }, { status: 400 }); + return NextResponse.json( + { error: "Recipe already exists" }, + { status: 400 } + ); } else { const recipe = await prisma.recipe.create({ data: { diff --git a/app/dashboard/user/page.tsx b/app/dashboard/user/page.tsx index 0e4eb64..462ea85 100644 --- a/app/dashboard/user/page.tsx +++ b/app/dashboard/user/page.tsx @@ -24,13 +24,20 @@ type Category = Prisma.CategoryGetPayload<{ ingredients: true; }; }>; + type Recipe = Prisma.RecipeGetPayload<{ select: { id: true; name: true; img: true; - ingredients: true; step: true; + ingredients: { + select: { + amount: true; + measurement: true; + ingredient: { select: { name: true } }; + }; + }; }; }>; @@ -180,8 +187,9 @@ export default function UserDashboard() { ))} diff --git a/components/RecipeCard.tsx b/components/RecipeCard.tsx index e7904d2..45bb9d3 100644 --- a/components/RecipeCard.tsx +++ b/components/RecipeCard.tsx @@ -1,32 +1,92 @@ +import React, { FC, useState } from "react"; import Image from "next/image"; -import { FC } from "react"; +import { Prisma } from "@prisma/client"; +import { X } from "lucide-react"; -interface RecipeCardProps { - name: string; - ingCount: number; - imgPath: string; -} +type Recipe = Prisma.RecipeGetPayload<{ + select: { + name: true; + img: true; + step: true; + ingredients: { + select: { + amount: true; + measurement: true; + ingredient: { + select: { + name: true; + }; + }; + }; + }; + }; +}>; + +const RecipeCard: FC = ({ name, img, ingredients, step }) => { + const [isOpen, setIsOpen] = useState(false); + + const handleModal = () => { + setIsOpen(!isOpen); + }; -const RecipeCard: FC = ({ name, ingCount, imgPath }) => { return ( <> {/* Recipe Card */} -
+
{/* Card Image */}
{`${name} + className="rounded-lg w-24" + />
{/* Recipe Details */}
{name}
- You have all {ingCount} Ingredients + You have all {ingredients.length} Ingredients +
+
+
+ {/* Modal */} +
+
+ {`${name} +
+

{name}

+

Ingredients:

+
    + {ingredients.map((e, i) => ( +
  • + {`- ${e.amount} ${e.measurement} ${e.ingredient.name}`} +
  • + ))} +
+ +

Instructions:

+
    + {step.map((e, i) => ( +
  1. {`${i + 1}. ${e}`}
  2. + ))} +
+
+
+