From f482a8614a8cdf4c1d6892e66d47f9adc6572fec Mon Sep 17 00:00:00 2001 From: albin-joseph Date: Mon, 28 Oct 2024 17:25:03 +0530 Subject: [PATCH] complete all the flow --- ticketing/client/components/header.js | 2 ++ ticketing/client/hooks/use-request.js | 4 +-- ticketing/client/package-lock.json | 36 +++++++++++++++++++- ticketing/client/package.json | 4 ++- ticketing/client/pages/orders/[orderId].js | 26 ++++++++++++-- ticketing/client/pages/orders/index.js | 20 +++++++++++ ticketing/client/pages/tickets/[ticketId].js | 2 +- ticketing/tickets/src/routes/index.ts | 2 +- 8 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 ticketing/client/pages/orders/index.js diff --git a/ticketing/client/components/header.js b/ticketing/client/components/header.js index d937dd7..d7fd54d 100644 --- a/ticketing/client/components/header.js +++ b/ticketing/client/components/header.js @@ -4,6 +4,8 @@ export default ({ currentUser }) => { const links = [ !currentUser && { label: 'Sign Up', href: '/auth/signup' }, !currentUser && { label: 'Sign In', href: '/auth/signin' }, + currentUser && {label: 'Sell Tickets', href: '/tickets/new'}, + currentUser && {label: 'My Orders', href: '/orders'}, currentUser && { label: 'Sign Out', href: '/auth/signout' }, ] .filter((linkConfig) => linkConfig) diff --git a/ticketing/client/hooks/use-request.js b/ticketing/client/hooks/use-request.js index 7819a75..2e56d93 100644 --- a/ticketing/client/hooks/use-request.js +++ b/ticketing/client/hooks/use-request.js @@ -4,10 +4,10 @@ import { useState } from "react"; const useRequest = ({url, method, body, onSuccess}) => { const [errors, setErrors] = useState(null); - const doRequest = async () => { + const doRequest = async (props = {}) => { try { setErrors(null); - const response = await axios[method](url, body); + const response = await axios[method](url,{...body, ...props}); if(onSuccess) { onSuccess(response.data); } diff --git a/ticketing/client/package-lock.json b/ticketing/client/package-lock.json index f5e3a1d..c9272d7 100644 --- a/ticketing/client/package-lock.json +++ b/ticketing/client/package-lock.json @@ -12,8 +12,10 @@ "axios": "^1.7.7", "bootstrap": "^5.3.3", "next": "^13.5.7", + "prop-types": "^15.8.1", "react": "^18.3.1", - "react-dom": "^18.3.1" + "react-dom": "^18.3.1", + "react-stripe-checkout": "^2.6.3" } }, "node_modules/@next/env": { @@ -429,6 +431,15 @@ } } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/picocolors": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.0.tgz", @@ -463,6 +474,17 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/prop-types": { + "version": "15.8.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", + "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.13.1" + } + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -494,6 +516,18 @@ "react": "^18.3.1" } }, + "node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "license": "MIT" + }, + "node_modules/react-stripe-checkout": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/react-stripe-checkout/-/react-stripe-checkout-2.6.3.tgz", + "integrity": "sha512-lnsCaAdlmwPGGMbQoI8FXtQUgEm+ktzPZ/ipAw4j0HYf80kef7CivGx6QitmgEn99/aa5hI/dmVXwfVZW/Mzfg==", + "license": "MIT" + }, "node_modules/scheduler": { "version": "0.23.2", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", diff --git a/ticketing/client/package.json b/ticketing/client/package.json index 1b1932c..459336b 100644 --- a/ticketing/client/package.json +++ b/ticketing/client/package.json @@ -13,7 +13,9 @@ "axios": "^1.7.7", "bootstrap": "^5.3.3", "next": "^13.5.7", + "prop-types": "^15.8.1", "react": "^18.3.1", - "react-dom": "^18.3.1" + "react-dom": "^18.3.1", + "react-stripe-checkout": "^2.6.3" } } diff --git a/ticketing/client/pages/orders/[orderId].js b/ticketing/client/pages/orders/[orderId].js index 0313ba3..a990962 100644 --- a/ticketing/client/pages/orders/[orderId].js +++ b/ticketing/client/pages/orders/[orderId].js @@ -1,7 +1,19 @@ -import {useEffect, useState} from 'react' -const OrderShow = ({order}) => { +import {useEffect, useState} from 'react'; +import StripeCheckout from 'react-stripe-checkout'; +import Router from 'next/router'; +import userRequest from '../../hooks/use-request'; + +const OrderShow = ({order, currentUser}) => { const [timeLeft, setTimeLeft] = useState(''); + const {doRequest, errors} = userRequest({ + url: '/api/payments', + method: 'post', + body: { + orderId: order.id + }, + onSuccess: (payment) => Router.push('/orders') + }) useEffect(()=>{ const findTimeLeft = () => { @@ -22,7 +34,15 @@ const OrderShow = ({order}) => { return (
-
Tme letf to pay: {timeLeft} seconds
+
Tme letf to pay: {timeLeft} seconds + doRequest({token: id})} + stripeKey='' + amount={order.ticket.price * 100} + email={currentUser.email} + /> + {errors} +
) } diff --git a/ticketing/client/pages/orders/index.js b/ticketing/client/pages/orders/index.js new file mode 100644 index 0000000..55c6d4f --- /dev/null +++ b/ticketing/client/pages/orders/index.js @@ -0,0 +1,20 @@ +const OrderIndex = ({orders}) => { + return ( +
+ +
+ ) +} + +OrderIndex.getInitialProps = async (context, client) => { + const {data} = await client.get('/api/orders') + return {orders: data}; +} + +export default OrderIndex; \ No newline at end of file diff --git a/ticketing/client/pages/tickets/[ticketId].js b/ticketing/client/pages/tickets/[ticketId].js index 6d36053..bcd99ae 100644 --- a/ticketing/client/pages/tickets/[ticketId].js +++ b/ticketing/client/pages/tickets/[ticketId].js @@ -17,7 +17,7 @@ const TicketShow = ({ticket}) => {

{ticket.title}

Price: {ticket.price}

{errors} - + ) diff --git a/ticketing/tickets/src/routes/index.ts b/ticketing/tickets/src/routes/index.ts index 0352978..7667e70 100644 --- a/ticketing/tickets/src/routes/index.ts +++ b/ticketing/tickets/src/routes/index.ts @@ -4,7 +4,7 @@ import { Ticket } from '../models/ticket'; const router = express.Router(); router.get('/api/tickets', async (req: Request, res: Response) => { - const tickets = await Ticket.find({}); + const tickets = await Ticket.find({orderId: undefined}); res.send(tickets); });