Skip to content

Commit

Permalink
create an order
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-joseph committed Oct 28, 2024
1 parent 606a95e commit c4686eb
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ticketing/client/pages/tickets/[ticketId].js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
const TicketShow = () => {
return <div>Ticket Show</div>
import useRequest from '../../hooks/use-request';

const TicketShow = ({ticket}) => {

const {doRequest, errors} = useRequest({
url: '/api/orders',
method: 'post',
body: {
ticketId: ticket.id
},
onSuccess: (order) => console.log(order)
});

return (
<div>
<h1>{ticket.title}</h1>
<h4>Price: {ticket.price}</h4>
{errors}
<button onClick={doRequest} className="btn btn-primary">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;

0 comments on commit c4686eb

Please sign in to comment.