Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pineylilly committed Oct 28, 2023
2 parents 81e0d1c + 7a97a4f commit 0abc175
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 151 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Introduction

## Getting Started
This is our project ChadMart

First, run the development server:
The beginning of this project came from a Hackathon called 10 days project where each teams have 10 days to build a product from a given problem.

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
This was the given problem

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
```
Problem Statement
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
Chulalongkorn University has a digital cash giveaway policy for all students, with each receiving 10,000 Bulbs to stimulate the economy within the country.
In this regard, Chulalongkorn University seeks to support a platform that enables the buying and selling of Bulbs to thrive in the Country. Therefore, we task everyone with creating a product that can promote the exchange of Bulbs between Chulalongkorn students.
```

## Learn More
So we created an E-Commerce product that uses digital money to buy stuff

To learn more about Next.js, take a look at the following resources:
## Tech Used

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
These are the techs that we used in this project

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
- [Next.js](https://nextjs.org/) - Feature rich framework for Frontend and Backed
- [Kinde](https://kinde.com) - Authentication as a service
- [Uploadthing](https://uploadthing.com/) - Files upload
- [Prisma](https://prisma.io) - Database ORM
- [PostgreSQL](https://www.postgresql.org/) - Open source database
- [shadcn UI](https://ui.shadcn.com) - Next.Js UI Library
- [TailwindCSS](https://tailwindcss.com) - Styling

## Deploy on Vercel
## Meet Our Team

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Our team is called ![Static Badge](https://img.shields.io/badge/Chad-GPT-orange)

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Here are the members
- [Justin](https://github.com/jusjira) - Full-Stack, UX&UI, PM
- [Nick](https://github.com/creampiney)- Full-Stack, UX&UI
- [V](https://github.com/hellp002)- Full-Stack, UX&UI
2 changes: 1 addition & 1 deletion app/(seller)/merchant/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async function account() {
<div className="flex flex-col items-center justify-center">
<Link
className="flex flex-col items-center justify-center"
href={"/wallet"}
href={"/money/wallet"}
>
<Button className="aspect-square h-full flex flex-col">
<Wallet size={32} />
Expand Down
1 change: 0 additions & 1 deletion app/(seller)/merchant/product/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Input } from "@/components/ui/input";
import React from "react";
import { toast } from "@/components/ui/use-toast";
import { Textarea } from "@/components/ui/textarea";
import { CldUploadButton } from "next-cloudinary";
import { UploadButton } from "@/utils/uploadthing";
import {useRouter} from "next/navigation"
import Image from "next/image";
Expand Down
181 changes: 114 additions & 67 deletions app/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import SignOutButton from "@/components/signOutButton";
import { Button, buttonVariants } from "@/components/ui/button";
import Link from "next/link";
import React from "react";
import {LoginLink, getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
import {
LoginLink,
getKindeServerSession,
} from "@kinde-oss/kinde-auth-nextjs/server";
import { Label } from "@/components/ui/label";
import { db } from "@/lib/db";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import Image from "next/image";
import { redirect } from "next/navigation";
import { Heart, Package, ShoppingBag, Wallet } from "lucide-react";
import { Clock, MapPin, User2 } from "lucide-react";

export default async function account() {
Expand All @@ -18,27 +22,26 @@ export default async function account() {
async function checkIfNew() {
const dbUser = await db.user.findUnique({
where: {
id: user?.id||""
}
})
id: user?.id || "",
},
});
if (!dbUser) {
// create user in db
await db.user.create({
data: {
id: user.id as string,
displayName: user.given_name as string

displayName: user.given_name as string,
},
});

redirect('/account/edit')
redirect("/account/edit");
}
// const newDbUser = await db.user.findUnique({
// where: {
// id: user?.id||""
// }
// })

return dbUser;
}
async function getUserData() {
Expand All @@ -54,73 +57,88 @@ export default async function account() {

// console.log(userData)



return (
<div className="relative flex min-h-full flex-col gap-3 bg-neutral-100 p-3 dark:bg-neutral-800">
<div className="px-5">
<h3 className="text-lg font-medium">Profile</h3>
</div>
<Separator />
{
(!user) && (
<div className="flex h-full min-h-full items-center justify-center rounded-md">
{!user && (
<div className="flex h-full min-h-full items-center justify-center rounded-md">
<Button asChild className="w-2/3 lg:w-48">
<LoginLink className={buttonVariants()}>Sign in</LoginLink>
</Button>
</div>
)}
{user && (
<div className="flex h-full min-h-full flex-col md:flex-row items-center justify-center gap-3 rounded-md">
<div className="flex w-full justify-center">
<DarkModeToggle />
</div>
)
}
{ (user) && (
<div className="flex h-full min-h-full flex-col md:flex-row items-center justify-center gap-3 rounded-md">
<div className="flex w-full justify-center">
<DarkModeToggle />
</div>
<div className="flex w-full justify-center">
<Link className={`${buttonVariants({ variant: "outline" })} w-2/3 lg:w-48 !border-black`} href="/merchant" prefetch={false}>
Merchant Page
</Link>
</div>
<div className="flex w-full justify-center">
<Link className={`${buttonVariants({ variant: "outline" })} w-2/3 lg:w-48 !border-black`} href="/account/edit" prefetch={false}>
Edit Profile
</Link>
</div>
<div className="flex w-full justify-center">
<SignOutButton />
</div>
<div className="flex w-full justify-center">
<SignOutButton />
</div>
<div className="flex w-full justify-center">
<Link
className={`${buttonVariants({
variant: "outline",
})} w-2/3 lg:w-48 !border-black`}
href="/merchant"
prefetch={false}
>
Merchant Page
</Link>
</div>
)
}
{
(user) && (
<div className="flex flex-col">
{/* Profile Avatar / Name / Role */}
<div className="flex flex-col md:flex-row items-center justify-center gap-2 p-2 -m-2 mt-2 mb-2 px-3 py-2 w-full">
<div className="inline-flex basis-32 items-center justify-center min-w-32 min-h-32 w-32 h-32 md:w-32 md:h-32 overflow-hidden bg-[#C3DCE3] rounded-full relative">
{
(<Image className='h-full !object-cover' src={userData?.image as string} alt="Profile Image" fill></Image>)
}
<div className="flex w-full justify-center">
<Link
className={`${buttonVariants({
variant: "outline",
})} w-2/3 lg:w-48 !border-black`}
href="/account/edit"
prefetch={false}
>
Edit Profile
</Link>
</div>
</div>
)}
{user && (
<div className="flex flex-col">
{/* Profile Avatar / Name / Role */}
<div className="flex flex-col md:flex-row items-center justify-center gap-2 p-2 -m-2 mt-2 mb-2 px-3 py-2 w-full">
<div className="inline-flex basis-32 items-center justify-center min-w-32 min-h-32 w-32 h-32 md:w-32 md:h-32 overflow-hidden bg-[#C3DCE3] rounded-full relative">
{
<Image
className="h-full !object-cover"
src={userData?.image as string}
alt="Profile Image"
fill
></Image>
}
</div>
<div className="flex flex-col items-center md:items-start space-y-3 md:pl-6">
<div className="max-w-sm text-center">
<Label className="font-bold text-md break-words">
{userData?.displayName}
</Label>
</div>
<div className="flex flex-col items-center md:items-start space-y-3 md:pl-6">
<div className="max-w-sm text-center">
<Label className="font-bold text-md break-words">{userData?.displayName}</Label>
</div>
<div className="max-w-sm">
<Label className="text-sm break-words">{userData?.bio}</Label>
</div>
<div className="max-w-sm">
<Label className="text-sm break-words">{userData?.bio}</Label>
</div>
</div>
</div>

{/* User Profile */}
<div className="flex flex-col gap-2 mt-2 mb-2 px-4 md:px-10 py-3 w-full">
<Card>
<CardHeader>
{/* User Profile */}
<div className="flex flex-col gap-2 mt-2 mb-2 px-4 md:px-10 py-3 w-full">
<Card>
<CardHeader>
<div className="w-full md:px-4 text-center md:text-left">
<Label className="font-bold text-lg break-words">Personal Profile</Label>
<Label className="font-bold text-lg break-words">
Personal Profile
</Label>
</div>
</CardHeader>
<CardContent>
</CardHeader>
<CardContent>
<div className="flex flex-col items-start space-y-4">
<div className="w-full flex flex-row space-x-4">
<User2 className="w-5 h-5"/>
Expand All @@ -135,16 +153,45 @@ export default async function account() {
<Label className="text-sm break-words"><span className="font-bold">Account Created At :</span> {userData?.createdAt.toString()}</Label>
</div>
</div>
</CardContent>
</Card>

</div>

</CardContent>
</Card>
</div>

{/* User Orders */}
<div className="flex flex-col gap-2 px-4 md:px-10 py-3 w-full">
<Card>
<CardContent className="!p-6 flex flex-row justify-center items-center gap-6">
<Link
className="flex flex-col items-center justify-center"
href={"/account/wishlist"}
>
<Button className="aspect-square h-full flex flex-col">
<Heart fill="red" color="red" size={32}/>
</Button>
<span>Wishlist</span>
</Link>
<div className="flex flex-col items-center justify-center">
<Button className="aspect-square h-full flex flex-col">
<ShoppingBag size={32} />
</Button>
<span>Orders</span>
</div>
<div className="flex flex-col items-center justify-center">
<Link
className="flex flex-col items-center justify-center"
href={"/money/wallet"}
>
<Button className="aspect-square h-full flex flex-col">
<Wallet size={32} />
</Button>
<span>Wallet</span>
</Link>
</div>
</CardContent>
</Card>
</div>

)
}

</div>
)}
</div>
);
}
51 changes: 51 additions & 0 deletions app/account/wishlist/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import ProductBox from "@/components/productBox";
import { db } from "@/lib/db";
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import React from "react";
import pluralize from "pluralize";

export default async function Page() {
const { getUser } = getKindeServerSession();
const user = await getUser();
const wished = await db.user.findUnique({
where: {
id: user.id as string,
},
select: {
wishlists: {
select: {
product: {
select: {
id: true,
price: true,
image: true,
name: true,
},
},
},
},
},
});

return (
<div className="relative flex min-h-full flex-col gap-3 bg-neutral-100 p-3 dark:bg-neutral-800">
<div>
<p>
There are {pluralize("product", wished?.wishlists.length, true)} is
your wishlist
</p>
</div>
<div className="grid-container">
{wished?.wishlists.map((p, index) => (
<ProductBox
key={index}
name={p.product.name}
id={p.product.id}
image={p.product.image}
price={p.product.price}
/>
))}
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion app/api/editProfile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NextRequest, NextResponse } from "next/server";

export async function PUT(req : NextRequest) {
const dbUser = await getdbUser();
if (!dbUser) return NextResponse.json({status : 204, message : "session failure"});
if (!dbUser) return NextResponse.json({status : 403, message : "session failure"});
// const {displayName , bio, image} = await req.json();
// console.log(await req.json())
const res = await db.user.update({where : {id : dbUser.id} , data : await req.json()});
Expand Down
Loading

0 comments on commit 0abc175

Please sign in to comment.