-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from alwinsimon/v1
V1
- Loading branch information
Showing
19 changed files
with
356 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ========================================= Main Branch ::: CI - Tests - Auth Service ========================================= | ||
|
||
name: CI - Tests - Auth Service | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
Production-Branch-Pre-Integration-Tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: cd auth && npm install && npm run test:ci |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,34 +1,56 @@ | ||
import buildClient from "../api/build-client"; | ||
import Link from 'next/link'; | ||
|
||
const IndexPage = ({ currentUser }) => { | ||
const IndexPage = ({ currentUser, tickets }) => { | ||
if (!currentUser) { | ||
return ( | ||
<> | ||
<h1>Landing Page</h1> | ||
<br/> | ||
<br /> | ||
<h5>Signed Out</h5> | ||
</> | ||
); | ||
} | ||
|
||
let ticketList; | ||
if (currentUser) { | ||
ticketList = tickets.map((ticket) => { | ||
return ( | ||
<tr key={ticket.id}> | ||
<td>{ticket.title}</td> | ||
<td>{ticket.price}</td> | ||
<td> | ||
<Link href="/tickets/[ticketId]" as={`/tickets/${ticket.id}`}> | ||
View | ||
</Link> | ||
</td> | ||
</tr> | ||
); | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<h1>Landing Page</h1> | ||
<br /> | ||
<h5>Welcome {currentUser.email}</h5> | ||
|
||
<h1>Tickets</h1> | ||
<table className="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Title</th> | ||
<th>Price</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody>{currentUser && ticketList}</tbody> | ||
</table> | ||
</> | ||
); | ||
}; | ||
|
||
IndexPage.getInitialProps = async (context) => { | ||
try { | ||
const client = buildClient(context); | ||
const response = await client.get("/api/users/currentuser"); | ||
return response.data; | ||
} catch (err) { | ||
console.error("Error in making request to get current user:", err.message); | ||
return { currentUser: null }; | ||
} | ||
IndexPage.getInitialProps = async (context, client, currentUser) => { | ||
const { data } = await client.get("/api/tickets"); | ||
return { tickets: data }; | ||
}; | ||
|
||
export default IndexPage; |
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,66 @@ | ||
import { useEffect, useState } from "react"; | ||
import Router from "next/router"; | ||
import StripeCheckout from "react-stripe-checkout"; | ||
import useRequest from "../../hooks/use-request"; | ||
|
||
const OrderShow = ({ order, currentUser }) => { | ||
const [timeLeft, setTimeLeft] = useState(0); | ||
const [makeRequest, errors] = useRequest({ | ||
url: "/api/payments", | ||
method: "post", | ||
body: { | ||
orderId: order.id, | ||
}, | ||
onSuccess: (payment) => { | ||
Router.push("/orders"); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
const findTimeLeft = () => { | ||
const milliSecondsLeft = new Date(order.expiresAt) - new Date(); | ||
const secondsLeft = Math.round(milliSecondsLeft / 1000); | ||
|
||
setTimeLeft(secondsLeft); | ||
}; | ||
|
||
findTimeLeft(); | ||
const timer = setInterval(findTimeLeft, 1000); | ||
|
||
return () => { | ||
clearInterval(timer); | ||
}; | ||
}, [order]); | ||
|
||
if (timeLeft < 0) { | ||
return ( | ||
<div> | ||
<h3 className="text text-danger">Order Expired !!!</h3> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
Time left to complete payment: {timeLeft} seconds. | ||
<StripeCheckout | ||
token={(token) => { | ||
makeRequest({ token: token.id }); | ||
}} | ||
stripeKey="pk_test_51O53zRSJtuYafghXhYNZzaJqYAh6afqRduQ3UAMs6Wm4vkv30ayq09gBPgU3jYkQPXrofQa9aRbIlb4uuCp3FC6O000J86xaKc" | ||
amount={order.ticket.price * 100} | ||
email={currentUser.email} | ||
/> | ||
{errors} | ||
</div> | ||
); | ||
}; | ||
|
||
OrderShow.getInitialProps = async (context, client) => { | ||
const { orderId } = context.query; | ||
const { data } = await client.get(`/api/orders/${orderId}`); | ||
|
||
return { order: data }; | ||
}; | ||
|
||
export default OrderShow; |
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 @@ | ||
const OrderIndex = ({ orders }) => { | ||
return ( | ||
<> | ||
<ul> | ||
{orders.map((order) => { | ||
return ( | ||
<li key={orders.id}> | ||
{order.ticket.title} - {order.status} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
OrderIndex.getInitialProps = async (context, client) => { | ||
const response = await client.get("/api/orders"); | ||
|
||
return { orders: response.data }; | ||
}; | ||
|
||
export default OrderIndex; |
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,40 @@ | ||
import Router from "next/router"; | ||
import useRequest from "../../hooks/use-request"; | ||
|
||
const TicketShow = ({ ticket }) => { | ||
const [makeRequest, errors] = useRequest({ | ||
url: "/api/orders", | ||
method: "post", | ||
body: { | ||
ticketId: ticket.id, | ||
}, | ||
onSuccess: (orderData) => { | ||
Router.push("/orders/[orderId]", `/orders/${orderData.id}`); | ||
}, | ||
}); | ||
|
||
const handleClick = async () => { | ||
makeRequest(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>{ticket.title}</h1> | ||
<h4>Price: {ticket.price} INR</h4> | ||
{errors} | ||
<button className="btn btn-primary" onClick={handleClick}> | ||
Purchase | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
TicketShow.getInitialProps = async (context, client) => { | ||
const { ticketId } = context.query; | ||
|
||
const { data } = await client.get(`/api/tickets/${ticketId}`); | ||
|
||
return { ticket: data }; | ||
}; | ||
|
||
export default TicketShow; |
Oops, something went wrong.