diff --git a/.prettierrc.js b/.prettierrc.js
new file mode 100644
index 0000000..e10a46d
--- /dev/null
+++ b/.prettierrc.js
@@ -0,0 +1,5 @@
+module.exports = {
+ semi: false,
+ singleQuote: true,
+ trailingComma: 'all',
+}
diff --git a/app/about/page.tsx b/app/about/page.tsx
index bbdf938..a3c8174 100644
--- a/app/about/page.tsx
+++ b/app/about/page.tsx
@@ -1,8 +1,8 @@
-import Footer from "@/components/Footer";
-import Header from "@/components/Header";
-import Image from "next/image";
-import billy from "@/public/billy-portrait.webp";
-import cakra from "@/public/cakra-portrait.webp";
+import Footer from '@/components/Footer'
+import Header from '@/components/Header'
+import Image from 'next/image'
+import billy from '@/public/billy-portrait.webp'
+import cakra from '@/public/cakra-portrait.webp'
const AboutPage = () => {
return (
@@ -41,7 +41,7 @@ const AboutPage = () => {
- );
-};
+ )
+}
-export default AboutPage;
+export default AboutPage
diff --git a/app/api/adminOrder/route.ts b/app/api/adminOrder/route.ts
index 0f3f366..959f72d 100644
--- a/app/api/adminOrder/route.ts
+++ b/app/api/adminOrder/route.ts
@@ -1,5 +1,5 @@
-import prisma from "@/lib/prisma";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { NextResponse } from 'next/server'
export async function GET() {
const recipes = await prisma.order.findMany({
@@ -20,7 +20,7 @@ export async function GET() {
userId: true,
isPaid: true,
},
- });
+ })
- return NextResponse.json(recipes);
+ return NextResponse.json(recipes)
}
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts
index b952721..23e7e7c 100644
--- a/app/api/auth/[...nextauth]/route.ts
+++ b/app/api/auth/[...nextauth]/route.ts
@@ -1,33 +1,36 @@
-import NextAuth, { type NextAuthOptions } from "next-auth";
-import CredentialsProvider from "next-auth/providers/credentials";
-import prisma from "@/lib/prisma";
-import { compare } from "bcrypt";
+import NextAuth, { type NextAuthOptions } from 'next-auth'
+import CredentialsProvider from 'next-auth/providers/credentials'
+import prisma from '@/lib/prisma'
+import { compare } from 'bcrypt'
export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
credentials: {
- name: {label: "Name", type: "name"},
- email: { label: "Email", type: "email" },
- password: { label: "Password", type: "password" }
+ name: { label: 'Name', type: 'name' },
+ email: { label: 'Email', type: 'email' },
+ password: { label: 'Password', type: 'password' },
},
//@ts-expect-error
async authorize(credentials) {
- const { email, password } = credentials as {email: string, password: string}
+ const { email, password } = credentials as {
+ email: string
+ password: string
+ }
if (!email || !password) {
- throw new Error("Missing username or password");
+ throw new Error('Missing username or password')
}
const user = await prisma.user.findUnique({
where: {
email,
},
- });
+ })
// if user doesn't exist or password doesn't match
if (!user || !(await compare(password, user.password))) {
- throw new Error("Invalid username or password");
+ throw new Error('Invalid username or password')
}
- return user;
+ return user
},
}),
],
@@ -38,24 +41,24 @@ export const authOptions: NextAuthOptions = {
user: {
...session.user,
id: token.id,
- isAdmin: token.isAdmin
+ isAdmin: token.isAdmin,
},
- };
+ }
},
jwt: ({ token, user }) => {
if (user) {
- const u = user as unknown as any;
+ const u = user as unknown as any
return {
...token,
id: u.id,
isAdmin: u.isAdmin,
- };
+ }
}
- return token;
+ return token
},
},
-};
+}
-const handler = NextAuth(authOptions);
+const handler = NextAuth(authOptions)
-export { handler as GET, handler as POST };
+export { handler as GET, handler as POST }
diff --git a/app/api/auth/register/route.ts b/app/api/auth/register/route.ts
index 7bba696..c1d111f 100644
--- a/app/api/auth/register/route.ts
+++ b/app/api/auth/register/route.ts
@@ -1,16 +1,16 @@
-import prisma from "@/lib/prisma";
-import { hash } from "bcrypt";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { hash } from 'bcrypt'
+import { NextResponse } from 'next/server'
export async function POST(req: Request) {
- const { name, email, password } = await req.json();
+ const { name, email, password } = await req.json()
const exists = await prisma.user.findUnique({
where: {
email,
},
- });
+ })
if (exists) {
- return NextResponse.json({ error: "User already exists" }, { status: 400 });
+ return NextResponse.json({ error: 'User already exists' }, { status: 400 })
} else {
const user = await prisma.user.create({
data: {
@@ -18,7 +18,7 @@ export async function POST(req: Request) {
email,
password: await hash(password, 10),
},
- });
- return NextResponse.json(user);
+ })
+ return NextResponse.json(user)
}
}
diff --git a/app/api/category/route.ts b/app/api/category/route.ts
index 6fff877..508d78d 100644
--- a/app/api/category/route.ts
+++ b/app/api/category/route.ts
@@ -1,5 +1,5 @@
-import prisma from "@/lib/prisma";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { NextResponse } from 'next/server'
export async function GET() {
const categories = await prisma.category.findMany({
@@ -9,7 +9,7 @@ export async function GET() {
img: true,
ingredients: true,
},
- });
+ })
- return NextResponse.json(categories);
+ return NextResponse.json(categories)
}
diff --git a/app/api/ingredient/[id]/route.ts b/app/api/ingredient/[id]/route.ts
index aa8243e..f8bf185 100644
--- a/app/api/ingredient/[id]/route.ts
+++ b/app/api/ingredient/[id]/route.ts
@@ -1,26 +1,32 @@
-import { NextResponse } from "next/server";
-import { Ingredient, PrismaClient } from "@prisma/client";
-const prisma = new PrismaClient();
+import { NextResponse } from 'next/server'
+import { Ingredient, PrismaClient } from '@prisma/client'
+const prisma = new PrismaClient()
-export const PATCH = async (req: Request, {params}: {params: {id: string}}) =>{
- const body: Ingredient= await req.json();
- const ingredient= await prisma.ingredient.update({
- where:{
- id: Number(params.id)
- },
- data:{
- name: body.name,
- categoryId: body.categoryId
- }
- });
- return NextResponse.json(ingredient, {status: 200});
+export const PATCH = async (
+ req: Request,
+ { params }: { params: { id: string } },
+) => {
+ const body: Ingredient = await req.json()
+ const ingredient = await prisma.ingredient.update({
+ where: {
+ id: Number(params.id),
+ },
+ data: {
+ name: body.name,
+ categoryId: body.categoryId,
+ },
+ })
+ return NextResponse.json(ingredient, { status: 200 })
}
-export const DELETE = async (req: Request, {params}: {params: {id: string}}) =>{
- const ingredient = await prisma.ingredient.delete({
- where:{
- id: Number(params.id)
- }
- });
- return NextResponse.json(ingredient, {status: 200});
-}
\ No newline at end of file
+export const DELETE = async (
+ req: Request,
+ { params }: { params: { id: string } },
+) => {
+ const ingredient = await prisma.ingredient.delete({
+ where: {
+ id: Number(params.id),
+ },
+ })
+ return NextResponse.json(ingredient, { status: 200 })
+}
diff --git a/app/api/ingredient/route.ts b/app/api/ingredient/route.ts
index e72b62f..b5ecbd1 100644
--- a/app/api/ingredient/route.ts
+++ b/app/api/ingredient/route.ts
@@ -1,5 +1,5 @@
-import prisma from "@/lib/prisma";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { NextResponse } from 'next/server'
export async function GET() {
const ingredients = await prisma.ingredient.findMany({
@@ -8,31 +8,31 @@ export async function GET() {
name: true,
category: true,
},
- });
+ })
- return NextResponse.json(ingredients);
+ return NextResponse.json(ingredients)
}
export async function POST(req: Request) {
- const { id, name, categoryId } = await req.json();
- console.log("categoryId: ", categoryId);
+ const { id, name, categoryId } = await req.json()
+ console.log('categoryId: ', categoryId)
const exists = await prisma.ingredient.findUnique({
where: {
id,
},
- });
+ })
if (exists) {
return NextResponse.json(
- { error: "Ingredient already exists" },
- { status: 400 }
- );
+ { error: 'Ingredient already exists' },
+ { status: 400 },
+ )
} else {
const ingredient = await prisma.ingredient.create({
data: {
name,
categoryId,
},
- });
- return NextResponse.json(ingredient);
+ })
+ return NextResponse.json(ingredient)
}
}
diff --git a/app/api/order/[id]/route.ts b/app/api/order/[id]/route.ts
index cdea178..49065fe 100644
--- a/app/api/order/[id]/route.ts
+++ b/app/api/order/[id]/route.ts
@@ -1,12 +1,12 @@
-import { NextResponse } from "next/server";
-import { PrismaClient, Order } from "@prisma/client";
-const prisma = new PrismaClient();
+import { NextResponse } from 'next/server'
+import { PrismaClient, Order } from '@prisma/client'
+const prisma = new PrismaClient()
export const PATCH = async (
req: Request,
- { params }: { params: { id: string } }
+ { params }: { params: { id: string } },
) => {
- const body: Order = await req.json();
+ const body: Order = await req.json()
const order = await prisma.order.update({
where: {
id: Number(params.id),
@@ -14,18 +14,18 @@ export const PATCH = async (
data: {
isPaid: body.isPaid,
},
- });
- return NextResponse.json(order, { status: 200 });
-};
+ })
+ return NextResponse.json(order, { status: 200 })
+}
export const DELETE = async (
req: Request,
- { params }: { params: { id: string } }
+ { params }: { params: { id: string } },
) => {
const recipe = await prisma.order.delete({
where: {
id: Number(params.id),
},
- });
- return NextResponse.json(recipe, { status: 200 });
-};
+ })
+ return NextResponse.json(recipe, { status: 200 })
+}
diff --git a/app/api/order/route.ts b/app/api/order/route.ts
index c1261db..b07ca5e 100644
--- a/app/api/order/route.ts
+++ b/app/api/order/route.ts
@@ -1,5 +1,5 @@
-import prisma from "@/lib/prisma";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { NextResponse } from 'next/server'
export async function GET() {
const recipes = await prisma.order.findFirst({
@@ -11,13 +11,13 @@ export async function GET() {
isPaid: true,
},
take: -1,
- });
+ })
- return NextResponse.json(recipes);
+ return NextResponse.json(recipes)
}
export async function POST(req: Request) {
- const { totalPrice, foodId, userId, isPaid } = await req.json();
+ const { totalPrice, foodId, userId, isPaid } = await req.json()
const order = await prisma.order.create({
data: {
@@ -26,7 +26,7 @@ export async function POST(req: Request) {
userId,
isPaid,
},
- });
+ })
- return NextResponse.json(order);
+ return NextResponse.json(order)
}
diff --git a/app/api/recipe/[id]/route.ts b/app/api/recipe/[id]/route.ts
index 9481294..7fa565a 100644
--- a/app/api/recipe/[id]/route.ts
+++ b/app/api/recipe/[id]/route.ts
@@ -1,12 +1,12 @@
-import { NextResponse } from "next/server";
-import { Recipe, PrismaClient } from "@prisma/client";
-const prisma = new PrismaClient();
+import { NextResponse } from 'next/server'
+import { Recipe, PrismaClient } from '@prisma/client'
+const prisma = new PrismaClient()
export const PATCH = async (
req: Request,
- { params }: { params: { id: string } }
+ { params }: { params: { id: string } },
) => {
- const body: Recipe = await req.json();
+ const body: Recipe = await req.json()
const recipe = await prisma.recipe.update({
where: {
id: Number(params.id),
@@ -17,18 +17,18 @@ export const PATCH = async (
price: body.price,
step: body.step,
},
- });
- return NextResponse.json(recipe, { status: 200 });
-};
+ })
+ return NextResponse.json(recipe, { status: 200 })
+}
export const DELETE = async (
req: Request,
- { params }: { params: { id: string } }
+ { params }: { params: { id: string } },
) => {
const recipe = await prisma.recipe.delete({
where: {
id: Number(params.id),
},
- });
- return NextResponse.json(recipe, { status: 200 });
-};
+ })
+ return NextResponse.json(recipe, { status: 200 })
+}
diff --git a/app/api/recipe/route.ts b/app/api/recipe/route.ts
index b5452e9..88a0700 100644
--- a/app/api/recipe/route.ts
+++ b/app/api/recipe/route.ts
@@ -1,5 +1,5 @@
-import prisma from "@/lib/prisma";
-import { NextResponse } from "next/server";
+import prisma from '@/lib/prisma'
+import { NextResponse } from 'next/server'
export async function GET() {
const recipes = await prisma.recipe.findMany({
@@ -19,23 +19,23 @@ export async function GET() {
price: 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 }
- );
+ { error: 'Recipe already exists' },
+ { status: 400 },
+ )
} else {
const recipe = await prisma.recipe.create({
data: {
@@ -44,7 +44,7 @@ export async function POST(req: Request) {
price,
step,
},
- });
- return NextResponse.json(recipe);
+ })
+ return NextResponse.json(recipe)
}
}
diff --git a/app/api/userIngredient/route.ts b/app/api/userIngredient/route.ts
index 4da59b2..2084358 100644
--- a/app/api/userIngredient/route.ts
+++ b/app/api/userIngredient/route.ts
@@ -1,11 +1,11 @@
-import prisma from "@/lib/prisma";
-import { getServerSession } from "next-auth";
-import { NextResponse } from "next/server";
-import { authOptions } from "../auth/[...nextauth]/route";
+import prisma from '@/lib/prisma'
+import { getServerSession } from 'next-auth'
+import { NextResponse } from 'next/server'
+import { authOptions } from '../auth/[...nextauth]/route'
export async function GET() {
- const session = await getServerSession(authOptions);
- const userEmail = session?.user.email;
+ const session = await getServerSession(authOptions)
+ const userEmail = session?.user.email
const user = await prisma.user.findUnique({
where: {
@@ -18,12 +18,12 @@ export async function GET() {
},
},
},
- });
- return NextResponse.json(user?.ingredients);
+ })
+ return NextResponse.json(user?.ingredients)
}
export async function PATCH(req: Request) {
- const { userId, ingredientId } = await req.json();
+ const { userId, ingredientId } = await req.json()
const user = await prisma.user.findUnique({
where: {
@@ -32,9 +32,9 @@ export async function PATCH(req: Request) {
include: {
ingredients: true,
},
- });
+ })
- const exists = user?.ingredients.some((ing) => ing.id === ingredientId);
+ const exists = user?.ingredients.some((ing) => ing.id === ingredientId)
if (!exists) {
const user = await prisma.user.update({
@@ -49,9 +49,9 @@ export async function PATCH(req: Request) {
include: {
ingredients: true,
},
- });
+ })
- return NextResponse.json(user);
+ return NextResponse.json(user)
} else {
const user = await prisma.user.update({
where: {
@@ -65,8 +65,8 @@ export async function PATCH(req: Request) {
include: {
ingredients: true,
},
- });
+ })
- return NextResponse.json(user);
+ return NextResponse.json(user)
}
}
diff --git a/app/dashboard/admin/DeleteIngredient.tsx b/app/dashboard/admin/DeleteIngredient.tsx
index 21eab56..c1f117b 100644
--- a/app/dashboard/admin/DeleteIngredient.tsx
+++ b/app/dashboard/admin/DeleteIngredient.tsx
@@ -1,34 +1,34 @@
-"use client";
-import { useState } from "react";
-import { useRouter } from "next/navigation";
-import axios from "axios";
-import { XSquare } from "lucide-react";
-import toast from "react-hot-toast";
+'use client'
+import { useState } from 'react'
+import { useRouter } from 'next/navigation'
+import axios from 'axios'
+import { XSquare } from 'lucide-react'
+import toast from 'react-hot-toast'
type Ingredient = {
- id: number;
- name: string;
- categoryId: number;
-};
+ id: number
+ name: string
+ categoryId: number
+}
const Deleteingredient = ({ ingredient }: { ingredient: Ingredient }) => {
- const [isOpen, setIsOpen] = useState(false);
- const [isLoading, setIsLoading] = useState(false);
+ const [isOpen, setIsOpen] = useState(false)
+ const [isLoading, setIsLoading] = useState(false)
- const router = useRouter();
+ const router = useRouter()
const handleDelete = async (ingredientId: number) => {
- setIsLoading(true);
- await axios.delete(`/api/ingredient/${ingredientId}`);
- toast.success(`${ingredient.name} deleted`);
- setIsLoading(false);
- router.refresh();
- setIsOpen(false);
- };
+ setIsLoading(true)
+ await axios.delete(`/api/ingredient/${ingredientId}`)
+ toast.success(`${ingredient.name} deleted`)
+ setIsLoading(false)
+ router.refresh()
+ setIsOpen(false)
+ }
const handleModal = () => {
- setIsOpen(!isOpen);
- };
+ setIsOpen(!isOpen)
+ }
return (
@@ -36,7 +36,7 @@ const Deleteingredient = ({ ingredient }: { ingredient: Ingredient }) => {
-
+
Are you sure to delete {ingredient.name}?
@@ -63,7 +63,7 @@ const Deleteingredient = ({ ingredient }: { ingredient: Ingredient }) => {
- );
-};
+ )
+}
-export default Deleteingredient;
+export default Deleteingredient
diff --git a/app/dashboard/admin/DeleteRecipe.tsx b/app/dashboard/admin/DeleteRecipe.tsx
index a118378..a1f384e 100644
--- a/app/dashboard/admin/DeleteRecipe.tsx
+++ b/app/dashboard/admin/DeleteRecipe.tsx
@@ -1,37 +1,37 @@
-"use client";
-import { useState } from "react";
-import { useRouter } from "next/navigation";
-import axios from "axios";
-import { XSquare } from "lucide-react";
-import toast from "react-hot-toast";
+'use client'
+import { useState } from 'react'
+import { useRouter } from 'next/navigation'
+import axios from 'axios'
+import { XSquare } from 'lucide-react'
+import toast from 'react-hot-toast'
type Recipe = {
- id: number;
- name: string;
- img: string | null;
- desc: string | null;
- price: number;
- step: string[];
-};
+ id: number
+ name: string
+ img: string | null
+ desc: string | null
+ price: number
+ step: string[]
+}
const DeleteRecipe = ({ recipes }: { recipes: Recipe }) => {
- const [isOpen, setIsOpen] = useState(false);
- const [isLoading, setIsLoading] = useState(false);
+ const [isOpen, setIsOpen] = useState(false)
+ const [isLoading, setIsLoading] = useState(false)
- const router = useRouter();
+ const router = useRouter()
const handleDelete = async (recipeId: number) => {
- setIsLoading(true);
- await axios.delete(`/api/recipe/${recipeId}`);
- toast.success(`${recipes.name} deleted`);
- setIsLoading(false);
- await router.refresh();
- setIsOpen(false);
- };
+ setIsLoading(true)
+ await axios.delete(`/api/recipe/${recipeId}`)
+ toast.success(`${recipes.name} deleted`)
+ setIsLoading(false)
+ await router.refresh()
+ setIsOpen(false)
+ }
const handleModal = () => {
- setIsOpen(!isOpen);
- };
+ setIsOpen(!isOpen)
+ }
return (
@@ -39,7 +39,7 @@ const DeleteRecipe = ({ recipes }: { recipes: Recipe }) => {
-
+
Are you sure to delete {recipes.name}?
@@ -66,7 +66,7 @@ const DeleteRecipe = ({ recipes }: { recipes: Recipe }) => {
- );
-};
+ )
+}
-export default DeleteRecipe;
+export default DeleteRecipe
diff --git a/app/dashboard/admin/UpdateIngredient.tsx b/app/dashboard/admin/UpdateIngredient.tsx
index a3c1b90..f237d49 100644
--- a/app/dashboard/admin/UpdateIngredient.tsx
+++ b/app/dashboard/admin/UpdateIngredient.tsx
@@ -1,54 +1,54 @@
-"use client";
-import { useState, SyntheticEvent } from "react";
-import type { Category } from "@prisma/client";
-import { useRouter } from "next/navigation";
-import axios from "axios";
-import { Edit } from "lucide-react";
-import { toast } from "react-hot-toast";
+'use client'
+import { useState, SyntheticEvent } from 'react'
+import type { Category } from '@prisma/client'
+import { useRouter } from 'next/navigation'
+import axios from 'axios'
+import { Edit } from 'lucide-react'
+import { toast } from 'react-hot-toast'
type Ingredient = {
- id: number;
- name: string;
- categoryId: number;
-};
+ id: number
+ name: string
+ categoryId: number
+}
const UpdateIngredient = ({
categories,
ingredient,
}: {
- categories: Category[];
- ingredient: Ingredient;
+ categories: Category[]
+ ingredient: Ingredient
}) => {
- const [name, setName] = useState(ingredient.name);
- const [categoryId, setCategoryId] = useState(ingredient.categoryId);
- const [isOpen, setIsOpen] = useState(false);
- const [isLoading, setIsLoading] = useState(false);
+ const [name, setName] = useState(ingredient.name)
+ const [categoryId, setCategoryId] = useState(ingredient.categoryId)
+ const [isOpen, setIsOpen] = useState(false)
+ const [isLoading, setIsLoading] = useState(false)
- const router = useRouter();
+ const router = useRouter()
const handleUpdate = async (e: SyntheticEvent) => {
- e.preventDefault();
- setIsLoading(true);
+ e.preventDefault()
+ setIsLoading(true)
await axios.patch(`/api/ingredient/${ingredient.id}`, {
name: name,
categoryId: categoryId,
- });
- toast.success(`${name} updated`);
- setIsLoading(false);
- router.refresh();
- setIsOpen(false);
- };
+ })
+ toast.success(`${name} updated`)
+ setIsLoading(false)
+ router.refresh()
+ setIsOpen(false)
+ }
const handleModal = () => {
- setIsOpen(!isOpen);
- };
+ setIsOpen(!isOpen)
+ }
return (
-
- );
-};
+ )
+}
-export default UpdateIngredient;
+export default UpdateIngredient
diff --git a/app/dashboard/admin/UpdateRecipe.tsx b/app/dashboard/admin/UpdateRecipe.tsx
index 2257058..0a1ada8 100644
--- a/app/dashboard/admin/UpdateRecipe.tsx
+++ b/app/dashboard/admin/UpdateRecipe.tsx
@@ -1,70 +1,70 @@
-import { useState, SyntheticEvent } from "react";
-import { useRouter } from "next/navigation";
-import axios from "axios";
-import { Edit } from "lucide-react";
-import { toast } from "react-hot-toast";
+import { useState, SyntheticEvent } from 'react'
+import { useRouter } from 'next/navigation'
+import axios from 'axios'
+import { Edit } from 'lucide-react'
+import { toast } from 'react-hot-toast'
type Recipe = {
- id: number;
- name: string;
- img: string | null;
- desc: string | null;
- price: number;
- step: string[];
-};
+ id: number
+ name: string
+ img: string | null
+ desc: string | null
+ price: number
+ step: string[]
+}
const UpdateRecipe = ({ recipes }: { recipes: Recipe }) => {
- const [name, setName] = useState(recipes.name);
- const [desc, setDesc] = useState(recipes.desc || "");
- const [price, setPrice] = useState(recipes.price);
- const [step, setStep] = useState(recipes.step);
+ const [name, setName] = useState(recipes.name)
+ const [desc, setDesc] = useState(recipes.desc || '')
+ const [price, setPrice] = useState(recipes.price)
+ const [step, setStep] = useState(recipes.step)
- const [isOpen, setIsOpen] = useState(false);
- const [isLoading, setIsLoading] = useState(false);
+ const [isOpen, setIsOpen] = useState(false)
+ const [isLoading, setIsLoading] = useState(false)
- const router = useRouter();
+ const router = useRouter()
const handleUpdate = async (e: SyntheticEvent) => {
- e.preventDefault();
- setIsLoading(true);
+ e.preventDefault()
+ setIsLoading(true)
await axios.patch(`/api/recipe/${recipes.id}`, {
name: name,
desc: desc,
price: price,
step: step,
- });
- toast.success(`${name} updated`);
- setIsLoading(false);
- router.refresh; // Use replace instead of refresh to avoid infinite reloading
- setIsOpen(false);
- };
+ })
+ toast.success(`${name} updated`)
+ setIsLoading(false)
+ router.refresh // Use replace instead of refresh to avoid infinite reloading
+ setIsOpen(false)
+ }
const handleModal = () => {
- setIsOpen(!isOpen);
- };
+ setIsOpen(!isOpen)
+ }
const addStep = () => {
- setStep([...step, ""]);
- };
+ setStep([...step, ''])
+ }
const removeStep = (index: number) => {
- const updatedStep = [...step];
- updatedStep.splice(index, 1);
- setStep(updatedStep);
- };
+ const updatedStep = [...step]
+ updatedStep.splice(index, 1)
+ setStep(updatedStep)
+ }
const updateStep = (index: number, value: string) => {
- const updatedStep = [...step];
- updatedStep[index] = value;
- setStep(updatedStep);
- };
+ const updatedStep = [...step]
+ updatedStep[index] = value
+ setStep(updatedStep)
+ }
return (
-
- );
-};
+ )
+}
-export default UpdateRecipe;
+export default UpdateRecipe
diff --git a/app/dashboard/admin/page.tsx b/app/dashboard/admin/page.tsx
index dab0bc6..6763093 100644
--- a/app/dashboard/admin/page.tsx
+++ b/app/dashboard/admin/page.tsx
@@ -1,9 +1,9 @@
-"use client";
-import { Prisma } from "@prisma/client";
-import axios from "axios";
-import { Carrot, LogOut, Plus, Receipt, Soup } from "lucide-react";
-import { signOut } from "next-auth/react";
-import React, { FormEventHandler, useEffect, useState } from "react";
+'use client'
+import { Prisma } from '@prisma/client'
+import axios from 'axios'
+import { Carrot, LogOut, Plus, Receipt, Soup } from 'lucide-react'
+import { signOut } from 'next-auth/react'
+import React, { FormEventHandler, useEffect, useState } from 'react'
import {
Table,
TableHeader,
@@ -11,182 +11,182 @@ import {
TableHead,
TableBody,
TableCell,
-} from "@/components/ui/table";
-import toast from "react-hot-toast";
-import { useRouter } from "next/navigation";
-import Updateingredient from "./UpdateIngredient";
-import Deleteingredient from "./DeleteIngredient";
-import { X } from "lucide-react";
-import UpdateRecipe from "./UpdateRecipe";
-import DeleteRecipe from "./DeleteRecipe";
+} from '@/components/ui/table'
+import toast from 'react-hot-toast'
+import { useRouter } from 'next/navigation'
+import Updateingredient from './UpdateIngredient'
+import Deleteingredient from './DeleteIngredient'
+import { X } from 'lucide-react'
+import UpdateRecipe from './UpdateRecipe'
+import DeleteRecipe from './DeleteRecipe'
type Ingredient = Prisma.IngredientGetPayload<{
select: {
- id: true;
- name: true;
- category: true;
- categoryId: true;
- };
-}>;
+ id: true
+ name: true
+ category: true
+ categoryId: true
+ }
+}>
type Category = Prisma.CategoryGetPayload<{
select: {
- id: true;
- name: true;
- img: true;
- ingredients: true;
- };
-}>;
+ id: true
+ name: true
+ img: true
+ ingredients: true
+ }
+}>
type Recipe = Prisma.RecipeGetPayload<{
select: {
- id: true;
- name: true;
- img: true;
- desc: true;
- ingredients: true;
- price: true;
- step: true;
- };
-}>;
+ id: true
+ name: true
+ img: true
+ desc: true
+ ingredients: true
+ price: true
+ step: true
+ }
+}>
type Order = Prisma.OrderGetPayload<{
select: {
- id: true;
- foodId: true;
+ id: true
+ foodId: true
food: {
select: {
- name: true;
- };
- };
- userId: true;
+ name: true
+ }
+ }
+ userId: true
user: {
select: {
- name: true;
- };
- };
- totalPrice: true;
- isPaid: true;
- };
-}>;
+ name: true
+ }
+ }
+ totalPrice: true
+ isPaid: true
+ }
+}>
-const fetcher = (url: string) => axios.get(url).then((res) => res.data);
+const fetcher = (url: string) => axios.get(url).then((res) => res.data)
export default function AdminDashboard() {
- const router = useRouter();
+ const router = useRouter()
// Data fetching hooks
- const [ingredients, setIngredients] = useState
(null);
- const [categories, setCategories] = useState(null);
- const [recipes, setRecipes] = useState(null);
- const [orders, setOrders] = useState(null);
+ const [ingredients, setIngredients] = useState(null)
+ const [categories, setCategories] = useState(null)
+ const [recipes, setRecipes] = useState(null)
+ const [orders, setOrders] = useState(null)
// Navigation hooks
- const [activeTab, setActiveTab] = useState(1);
+ const [activeTab, setActiveTab] = useState(1)
const handleTabChange = (tabNo: number) => {
- setActiveTab(tabNo);
- };
+ setActiveTab(tabNo)
+ }
// Ingredient add modal
- const [isIngredientAddOpen, setIsIngredientAddOpen] = useState(false);
+ const [isIngredientAddOpen, setIsIngredientAddOpen] = useState(false)
const handleIngredientAddModal = () => {
- setIsIngredientAddOpen(!isIngredientAddOpen);
- };
+ setIsIngredientAddOpen(!isIngredientAddOpen)
+ }
// Recipe add modal
- const [isRecipeAddOpen, setIsRecipeAddOpen] = useState(false);
+ const [isRecipeAddOpen, setIsRecipeAddOpen] = useState(false)
const handleRecipeAddModal = () => {
- setIsRecipeAddOpen(!isRecipeAddOpen);
- };
+ setIsRecipeAddOpen(!isRecipeAddOpen)
+ }
// Page load
- const [isLoading, setIsLoading] = useState(false);
+ const [isLoading, setIsLoading] = useState(false)
// CRUD hooks
// Ingredient CRUD
const [newIngredient, setNewIngredient] = useState({
id: 0,
- name: "",
+ name: '',
categoryId: 1,
- });
+ })
const addIngredient: FormEventHandler = async (e) => {
- e.preventDefault();
+ e.preventDefault()
- setIsLoading(true);
+ setIsLoading(true)
await axios
- .post("/api/ingredient", {
+ .post('/api/ingredient', {
id: newIngredient.id,
name: newIngredient.name,
categoryId: newIngredient.categoryId,
})
- .then(() => toast.success("Ingredient Add Success"))
- .catch(() => toast.error("Something went wrong!"));
+ .then(() => toast.success('Ingredient Add Success'))
+ .catch(() => toast.error('Something went wrong!'))
- setIsLoading(false);
+ setIsLoading(false)
setNewIngredient({
id: 0,
- name: "",
+ name: '',
categoryId: 1,
- });
+ })
- router.refresh;
+ router.refresh
- setIsIngredientAddOpen(false);
- };
+ setIsIngredientAddOpen(false)
+ }
// Recipe CRUD
const [newRecipe, setNewRecipe] = useState({
id: 0,
- name: "",
- desc: "",
+ name: '',
+ desc: '',
price: 0,
- step: [""],
- });
+ step: [''],
+ })
const addRecipe: FormEventHandler = async (e) => {
- e.preventDefault();
+ e.preventDefault()
- setIsLoading(true);
+ setIsLoading(true)
await axios
- .post("/api/recipe", {
+ .post('/api/recipe', {
id: newRecipe.id,
name: newRecipe.name,
desc: newRecipe.desc,
price: newRecipe.price,
step: newRecipe.step,
})
- .then(() => toast.success("Recipe Add Success"))
- .catch(() => toast.error("Something went wrong!"));
+ .then(() => toast.success('Recipe Add Success'))
+ .catch(() => toast.error('Something went wrong!'))
- setIsLoading(false);
+ setIsLoading(false)
setNewRecipe({
id: 0,
- name: "",
- desc: "",
+ name: '',
+ desc: '',
price: 0,
- step: [""],
- });
+ step: [''],
+ })
- setIsRecipeAddOpen(false);
+ setIsRecipeAddOpen(false)
- router.refresh();
- };
+ router.refresh()
+ }
const removeStep = (index: number) => {
- const updatedStep = [...newRecipe.step];
- updatedStep.splice(index, 1);
+ const updatedStep = [...newRecipe.step]
+ updatedStep.splice(index, 1)
setNewRecipe({
...newRecipe,
step: updatedStep,
- });
- };
+ })
+ }
// Fetch data
useEffect(() => {
@@ -198,22 +198,22 @@ export default function AdminDashboard() {
recipeResponse,
orderResponse,
] = await Promise.all([
- fetcher("/api/ingredient"),
- fetcher("/api/category"),
- fetcher("/api/recipe"),
- fetcher("/api/adminOrder"),
- ]);
- setIngredients(ingredientResponse);
- setCategories(categoryResponse);
- setRecipes(recipeResponse);
- setOrders(orderResponse);
+ fetcher('/api/ingredient'),
+ fetcher('/api/category'),
+ fetcher('/api/recipe'),
+ fetcher('/api/adminOrder'),
+ ])
+ setIngredients(ingredientResponse)
+ setCategories(categoryResponse)
+ setRecipes(recipeResponse)
+ setOrders(orderResponse)
} catch (error) {
- console.error("Error:", error);
+ console.error('Error:', error)
}
- };
+ }
- fetchData();
- }, []);
+ fetchData()
+ }, [])
// Loader
if (!ingredients || !categories || !recipes || !orders) {
@@ -240,7 +240,7 @@ export default function AdminDashboard() {
Loading...
- );
+ )
}
return (
@@ -271,7 +271,7 @@ export default function AdminDashboard() {