Skip to content

Commit

Permalink
add expiry logic in client
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-joseph committed Oct 28, 2024
1 parent 035b406 commit 493f3ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions ticketing/client/pages/orders/[orderId].js
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
const OrderShow = () => {
import {useEffect, useState} from 'react'
const OrderShow = ({order}) => {

const [timeLeft, setTimeLeft] = useState('');

useEffect(()=>{
const findTimeLeft = () => {
const msLeft = new Date(order.expiresAt) - new Date();
setTimeLeft(Math.round(msLeft/1000))
}
findTimeLeft();
const timerId = setInterval(findTimeLeft, 1000);

return () => {
clearInterval(timerId);
}
},[order]);

if(timeLeft<0) {
return <div>Order expired</div>
}

return (
<div>
Order Show
<div>Tme letf to pay: {timeLeft} seconds</div>
</div>
)
}

OrderShow.getInitialProps = async (context, client) => {
const {orderId} = context.query;
const {data} = await client.get(`/api/orders/${orderId}`);
return {order: data};
};

export default OrderShow;
2 changes: 1 addition & 1 deletion ticketing/orders/src/routes/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { natsWrapper } from '../nats-wrapper';

const router = express.Router();

const EXPIRATION_WINDOW_SECONDS = 15 * 60;
const EXPIRATION_WINDOW_SECONDS = 1 * 60;

router.post('/api/orders', requireAuth, [
body('ticketId')
Expand Down

0 comments on commit 493f3ac

Please sign in to comment.