diff --git a/README.md b/README.md index 617cc07..9e029dc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ +# OpenBooking -![tw-banner](https://github.com/thirdweb-example/next-starter/assets/57885104/20c8ce3b-4e55-4f10-ae03-2fe4743a5ee8) - -# thirdweb-next-starter - -Starter template to build an onchain react native app with [thirdweb](https://thirdweb.com/) and [next](https://nextjs.org/). +## Overview ## Installation @@ -19,7 +16,7 @@ To run this project, you will need to add the following environment variables to `CLIENT_ID` -To learn how to create a client ID, refer to the [client documentation](https://portal.thirdweb.com/typescript/v5/client). +To learn how to create a client ID, refer to the [client documentation](https://portal.thirdweb.com/typescript/v5/client). ## Run locally diff --git a/src/app/customer/checkin/page.tsx b/src/app/customer/checkin/page.tsx new file mode 100644 index 0000000..0e79da8 --- /dev/null +++ b/src/app/customer/checkin/page.tsx @@ -0,0 +1,81 @@ +"use client"; + +import { useSearchParams, useRouter } from "next/navigation"; +import { Suspense, useEffect, useState } from "react"; +import { + ConnectButton, + TransactionButton, + useActiveAccount, +} from "thirdweb/react"; +import { client, contract } from "../../client"; +import { prepareContractCall } from "thirdweb"; + +function CheckInInnerPage() { + const router = useRouter(); + const searchParams = useSearchParams(); + const [reservationId, setReservationId] = useState(null); + const address = useActiveAccount(); + + useEffect(() => { + const id = searchParams.get("id"); + if (id) { + setReservationId(id); + console.log(id); + } + }, [searchParams]); + + const handleFinalizePayment = async () => { + if (!reservationId) throw new Error("Reservation ID is not found."); + + return prepareContractCall({ + contract, + method: "finalizePayment", + params: [BigInt(reservationId)], + }); + }; + + if (!reservationId) { + return
Now Loading...
; + } + + return ( +
+

Service Confirmation

+

Reservation ID: {reservationId}

+
+ + {address && ( + { + console.log("Sent Transaction:", result.transactionHash); + }} + onTransactionConfirmed={(receipt) => { + console.log("Confirmed Transaction:", receipt.transactionHash); + router.push("/customer"); + }} + onError={(error) => { + console.error("Transaction Error has occured:", error); + }} + > + Confirm the Service + + )} +
+
+ ); +} + +export default function CheckInPage() { + return ( + + + + ); +} diff --git a/src/app/customer/confirm-service/page.tsx b/src/app/customer/confirm-service/page.tsx deleted file mode 100644 index ae43660..0000000 --- a/src/app/customer/confirm-service/page.tsx +++ /dev/null @@ -1,81 +0,0 @@ -"use client"; - -import { useSearchParams, useRouter } from "next/navigation"; -import { Suspense, useEffect, useState } from "react"; -import { - ConnectButton, - TransactionButton, - useActiveAccount, -} from "thirdweb/react"; -import { client, contract } from "../../../app/client"; -import { prepareContractCall } from "thirdweb"; - -function ConfirmServiceInnerPage() { - const router = useRouter(); - const searchParams = useSearchParams(); - const [reservationId, setReservationId] = useState(null); - const address = useActiveAccount(); - - useEffect(() => { - const id = searchParams.get("id"); - if (id) { - setReservationId(id); - console.log(id); - } - }, [searchParams]); - - const handleFinalizePayment = async () => { - if (!reservationId) throw new Error("Reservation ID is not found."); - - return prepareContractCall({ - contract, - method: "finalizePayment", - params: [BigInt(reservationId)], - }); - }; - - if (!reservationId) { - return
Now Loading...
; - } - - return ( -
-

Service Confirmation

-

Reservation ID: {reservationId}

-
- - {address && ( - { - console.log("Sent Transaction:", result.transactionHash); - }} - onTransactionConfirmed={(receipt) => { - console.log("Confirmed Transaction:", receipt.transactionHash); - router.push("/customer"); - }} - onError={(error) => { - console.error("Transaction Error has occured:", error); - }} - > - Confirm the Service - - )} -
-
- ); -} - -export default function ConfirmServicePage() { - return ( - - - - ); -} diff --git a/src/app/customer/page.tsx b/src/app/customer/page.tsx index fad2af7..5eab81c 100644 --- a/src/app/customer/page.tsx +++ b/src/app/customer/page.tsx @@ -21,15 +21,20 @@ export default function CustomerPage() { } return ( -
+
+
+ +
+

Customer Page

- +

Select a store

+ setSelectedStore(storeId)} /> @@ -85,98 +90,4 @@ export default function CustomerPage() {
); -} - -// export default function Home() { -// return ( -//
-//
-//
- -//
-// -//
- -// -//
-//
-// ); -// } - -function Header() { - return ( -
- - -

- thirdweb SDK - + - Next.js -

- -

- Read the{" "} - - README.md - {" "} - file to get started. -

-
- ); -} - -function ThirdwebResources() { - return ( -
- - - - - -
- ); -} - -function ArticleCard(props: { - title: string; - href: string; - description: string; -}) { - return ( - -
-

{props.title}

-

{props.description}

-
-
- ); -} +} \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx index 7ee3910..b40cd6a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,29 +2,29 @@ import Link from 'next/link'; import Image from 'next/image'; export default function Home() { - return ( -
-
-

Reservation System

-
- - Customer Page - - - Store Management Page - -
-
- Thirdweb Logo -

Powered by Thirdweb

-
-
-
- ); + return ( +
+
+

OpenBooking

+
+ + Customer Page + + + Store Management Page + +
+
+ Thirdweb Logo +

Powered by Thirdweb

+
+
+
+ ); } \ No newline at end of file diff --git a/src/app/store/page.tsx b/src/app/store/page.tsx index 59f35f5..313f3e8 100644 --- a/src/app/store/page.tsx +++ b/src/app/store/page.tsx @@ -35,7 +35,17 @@ export default function StorePage() { return (
-

Store Page

+
+ +
+ +

ストアページ

@@ -55,57 +65,43 @@ export default function StorePage() { )}

-
- -
-
diff --git a/src/components/QRCodeGenerator.tsx b/src/components/QRCodeGenerator.tsx index f9082b4..791880b 100644 --- a/src/components/QRCodeGenerator.tsx +++ b/src/components/QRCodeGenerator.tsx @@ -1,8 +1,15 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import QRCode from "qrcode.react"; const QRCodeGenerator: React.FC<{ reservationId: bigint | null }> = ({ reservationId }) => { const [showQR, setShowQR] = useState(false); + const [baseUrl, setBaseUrl] = useState(process.env.NEXT_PUBLIC_VERCEL_URL || process.env.NEXT_PUBLIC_BASE_URL); + + useEffect(() => { + if (typeof window !== 'undefined') { + setBaseUrl(`${window.location.protocol}//${window.location.host}`); + } + }, []); return (
@@ -22,7 +29,7 @@ const QRCodeGenerator: React.FC<{ reservationId: bigint | null }> = ({ reservati { (() => { if (reservationId != null) { - let url = `http://localhost:3000/customer/confirm-service?id=${reservationId.toString()}` + let url = `${baseUrl}/customer/checkin?id=${reservationId.toString()}` return (