From 6bc74348f4b5bdcab8e670bd8529b7eec562b9af Mon Sep 17 00:00:00 2001 From: paolosantarsiero Date: Thu, 2 Jan 2025 12:16:25 +0100 Subject: [PATCH] refactor: change various files --- .gitignore | 1 + .../route.ts} | 0 app/api/customer/route.ts | 15 ++ app/checkout/page.tsx | 179 +------------- app/login/page.tsx | 2 +- app/not-found.tsx | 8 +- app/product/[name]/page.tsx | 9 + app/profile/orders/[id]/page.tsx | 2 +- app/profile/orders/page.tsx | 6 +- app/profile/page.tsx | 229 +++++++----------- app/search/layout.tsx | 2 +- app/signup/page.tsx | 2 +- components/button/logout.tsx | 3 +- components/cart/modal.tsx | 4 +- components/product/product-description.tsx | 4 +- components/shipping/form.tsx | 115 +++++++++ tsconfig.json | 9 +- 17 files changed, 252 insertions(+), 338 deletions(-) rename app/api/auth/{[...nextauth].ts => [...nextauth]/route.ts} (100%) create mode 100644 components/shipping/form.tsx diff --git a/.gitignore b/.gitignore index 0298027e4..e82a0f9db 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts +.env*.local diff --git a/app/api/auth/[...nextauth].ts b/app/api/auth/[...nextauth]/route.ts similarity index 100% rename from app/api/auth/[...nextauth].ts rename to app/api/auth/[...nextauth]/route.ts diff --git a/app/api/customer/route.ts b/app/api/customer/route.ts index 2f05476d5..e8c6349f9 100644 --- a/app/api/customer/route.ts +++ b/app/api/customer/route.ts @@ -1,6 +1,21 @@ +import { authOptions } from 'lib/auth/config'; import { woocommerce } from 'lib/woocomerce/woocommerce'; +import { getServerSession } from 'next-auth'; import { NextRequest, NextResponse } from 'next/server'; +export async function GET(req: NextRequest) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.store_id) { + return NextResponse.json({ error: 'User not logged' }, { status: 401 }); + } + const cart = await woocommerce.get('customers', { id: session?.user.store_id }); + return NextResponse.json(cart, { status: 200 }); + } catch (error) { + return NextResponse.json({ error: JSON.stringify(error) }, { status: 500 }); + } +} + export async function POST(req: NextRequest) { try { const data = await req.json(); diff --git a/app/checkout/page.tsx b/app/checkout/page.tsx index 632852f4f..fd3c29f44 100644 --- a/app/checkout/page.tsx +++ b/app/checkout/page.tsx @@ -2,6 +2,7 @@ import { useCart } from 'components/cart/cart-context'; import CartItemView from 'components/cart/cart-item'; +import ShippingForm from 'components/shipping/form'; import { OrderPayload } from 'lib/woocomerce/storeApi'; import { useState } from 'react'; @@ -37,18 +38,12 @@ export default function CheckoutPage() { payment_data: [] }; const [formData, setFormData] = useState(initialState); - const handleChangeShipping = (e: React.ChangeEvent) => { - setFormData((prev) => ({ - ...prev, - shipping_address: { ...prev.shipping_address, [e.target.name]: e.target.value } - })); + const handleChangeShipping = (e: any) => { + setFormData(e); }; - const handleChangeBilling = (e: React.ChangeEvent) => { - setFormData((prev) => ({ - ...prev, - billing_address: { ...prev.billing_address, [e.target.name]: e.target.value } - })); + const handleChangeBilling = (e: any) => { + setFormData(e); }; return ( @@ -72,169 +67,15 @@ export default function CheckoutPage() { ); })} - -

Shipping info

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
-

Billing info

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
+ +
+ +
+
diff --git a/app/login/page.tsx b/app/login/page.tsx index e99b7b1bd..432410575 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -23,7 +23,7 @@ export default function LoginPage() { return (

Login

-
+
{error &&

{error}

}
diff --git a/app/not-found.tsx b/app/not-found.tsx index c3632361e..ed413d294 100644 --- a/app/not-found.tsx +++ b/app/not-found.tsx @@ -1,5 +1,5 @@ -import Link from 'next/link' - +import Link from 'next/link'; + export default function NotFound() { return (
@@ -7,5 +7,5 @@ export default function NotFound() {

Could not find requested resource

Return Home
- ) -} \ No newline at end of file + ); +} diff --git a/app/product/[name]/page.tsx b/app/product/[name]/page.tsx index 9d65d78f4..bb00d9195 100644 --- a/app/product/[name]/page.tsx +++ b/app/product/[name]/page.tsx @@ -7,6 +7,7 @@ import { Gallery } from 'components/product/gallery'; import { ProductProvider } from 'components/product/product-context'; import { ProductDescription } from 'components/product/product-description'; import { VariantSelector } from 'components/product/variant-selector'; +import Prose from 'components/prose'; import { HIDDEN_PRODUCT_TAG } from 'lib/constants'; import { Image } from 'lib/woocomerce/models/base'; import { Product, ProductVariations } from 'lib/woocomerce/models/product'; @@ -91,6 +92,14 @@ export default async function ProductPage(props: { params: Promise<{ name: strin }))} /> +
+ {product.description ? ( + + ) : null} +
diff --git a/app/profile/orders/[id]/page.tsx b/app/profile/orders/[id]/page.tsx index a77ebc30b..e7bd1e616 100644 --- a/app/profile/orders/[id]/page.tsx +++ b/app/profile/orders/[id]/page.tsx @@ -17,7 +17,7 @@ export default async function OrderPage(props: { params: Promise<{ id: number }> return (

Order

-
+