This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e6aaf1
commit 0f1df65
Showing
18 changed files
with
205 additions
and
23 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
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,22 @@ | ||
import { prisma } from "@/db/client"; | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const { userId } = await request.json(); | ||
try { | ||
const res = await prisma.order.findMany({ | ||
where: { | ||
userId: userId, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ data: res }); | ||
} catch (err) { | ||
console.log(err); | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} |
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,34 @@ | ||
import OrdersOrdersSection from "@/containers/orders-page/orders-section"; | ||
import OrdersTitleSection from "@/containers/orders-page/title-section"; | ||
import React, { FC } from "react"; | ||
import createClient from "@/db/client"; | ||
import axios from "axios"; | ||
import { redirect } from "next/navigation"; | ||
import { getOrders } from "@/libs/endpoints"; | ||
|
||
interface OrdersPageProps {} | ||
|
||
const getUserOrders = async (id: string) => { | ||
const { data } = await axios.post(getOrders, {}); | ||
return data; | ||
}; | ||
const OrdersPage: FC<OrdersPageProps> = async ({}) => { | ||
const supabase = createClient(); | ||
|
||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
if (!user) { | ||
redirect("/"); | ||
} | ||
const { data } = await getUserOrders(user.email ?? user.user_metadata.email); | ||
|
||
return ( | ||
<main> | ||
<OrdersTitleSection /> | ||
<OrdersOrdersSection orders={data} /> | ||
</main> | ||
); | ||
}; | ||
|
||
export default OrdersPage; |
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,23 @@ | ||
import { TOrder } from '@/types/Order'; | ||
import React, { FC } from 'react' | ||
|
||
interface OrderCardProps { | ||
order:TOrder | ||
} | ||
|
||
const OrderCard: FC<OrderCardProps> = ({ order }) => { | ||
return ( | ||
<div className='w-max h-max rounded-lg shadow-lg p-6'> | ||
<div> | ||
<h1 className='text-black text-base'>{order.date.toString( | ||
|
||
)}</h1> | ||
</div> | ||
<div> | ||
|
||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default OrderCard; |
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
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
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
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,24 @@ | ||
import OrderCard from '@/components/Cards/OrderCard'; | ||
import { TBasketItem } from '@/types/BasketItem'; | ||
import { TOrder } from '@/types/Order'; | ||
import React, { FC } from 'react' | ||
|
||
interface OrdersOrdersSectionProps { | ||
orders:TOrder[] | ||
} | ||
|
||
// WHAT A COMPONENT NAME LOL | ||
const OrdersOrdersSection: FC<OrdersOrdersSectionProps> = ({ orders }) => { | ||
console.log(orders) | ||
return ( | ||
<section className="flex w-full justify-center"> | ||
<div className="flex flex-col py-10 md:py-28 items-center gap-8 md:gap-24 w-full max-w-screen-xl mx-5 md:mx-20"> | ||
{orders.map((el,_i) => ( | ||
<OrderCard key={_i} order={el}/> | ||
))} | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
export default OrdersOrdersSection; |
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,17 @@ | ||
import React, { FC } from 'react' | ||
|
||
interface OrdersTitleSectionProps { | ||
|
||
} | ||
|
||
const OrdersTitleSection: FC<OrdersTitleSectionProps> = ({ }) => { | ||
return ( | ||
<section className="flex w-full justify-center"> | ||
<div className="flex flex-col py-10 md:py-28 items-center gap-8 md:gap-24 w-full max-w-screen-xl mx-5 md:mx-20"> | ||
<h1 className="text-2xl lg:text-6xl text-black font-bold">Your Orders</h1> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
export default OrdersTitleSection; |
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
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
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,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `date` to the `Order` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Order" ADD COLUMN "date" TIMESTAMP(3) NOT NULL; |
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Order" ALTER COLUMN "date" SET DATA TYPE TEXT; |
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,9 @@ | ||
/* | ||
Warnings: | ||
- Changed the type of `date` on the `Order` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Order" DROP COLUMN "date", | ||
ADD COLUMN "date" TIMESTAMP(3) NOT NULL; |
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
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,13 @@ | ||
export const formatDateToSQLDateTime = (date: Date) : string => { | ||
// Get the ISO string of the Date object | ||
const isoString = date.toISOString(); | ||
|
||
// Extract the date and time components | ||
const datePart = isoString.slice(0, 10); | ||
const timePart = isoString.slice(11, 19); | ||
|
||
// Combine them in the SQL datetime format | ||
const sqlDateTime = `${datePart} ${timePart}`; | ||
|
||
return sqlDateTime; | ||
} |
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,10 @@ | ||
import { TBasketItem } from "./BasketItem" | ||
|
||
|
||
export type TOrder = { | ||
id:number, | ||
userId:number, | ||
products:TBasketItem[], | ||
price:number, | ||
date:Date | ||
} |
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