Skip to content

Commit 22c01b5

Browse files
committed
22. Back to the Client | 09. Creating an Order
1 parent b0eaaf3 commit 22c01b5

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

22_Back_to_the_Client.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ If chome will block page for security reasons, type: **thisisunsafe**
5252

5353
<br/>
5454

55+
### 08. Linking to Wildcard Routess
56+
57+
<br/>
58+
59+
### 09. Creating an Order
60+
61+
<br/>
62+
63+
![Application](/img/pic-22-04.png?raw=true)
64+
65+
<br/>
66+
5567
---
5668

5769
<br/>

22_Back_to_the_Client/app/client/pages/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import Link from 'next/link';
2+
13
const LandingPage = ({ currentUser, tickets }) => {
24
const ticketList = tickets.map((ticket) => {
35
return (
46
<tr key={ticket.id}>
57
<td>{ticket.title}</td>
68
<td>{ticket.price}</td>
9+
<td>
10+
<Link href="/tickets/[ticketId]" as={`/tickets/${ticket.id}`}>
11+
<a>View</a>
12+
</Link>
13+
</td>
714
</tr>
815
);
916
});
@@ -16,6 +23,7 @@ const LandingPage = ({ currentUser, tickets }) => {
1623
<tr>
1724
<th>Title</th>
1825
<th>Price</th>
26+
<th>Link</th>
1927
</tr>
2028
</thead>
2129
<tbody>{ticketList}</tbody>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import useRequest from '../../hooks/use-request';
2+
3+
const TicketShow = ({ ticket }) => {
4+
const { doRequest, errors } = useRequest({
5+
url: '/api/orders',
6+
method: 'post',
7+
body: {
8+
ticketId: ticket.id,
9+
},
10+
onSuccess: (order) => console.log(order),
11+
});
12+
13+
return (
14+
<div>
15+
<h1>{ticket.title}</h1>
16+
<h4>Price: {ticket.price}</h4>
17+
{errors}
18+
<button className="btn btn-primary" onClick={doRequest}>
19+
Purchase
20+
</button>
21+
</div>
22+
);
23+
};
24+
25+
TicketShow.getInitialProps = async (context, client) => {
26+
const { ticketId } = context.query;
27+
28+
const { data } = await client.get(`/api/tickets/${ticketId}`);
29+
30+
return { ticket: data };
31+
};
32+
33+
export default TicketShow;

img/pic-22-04.png

22 KB
Loading

0 commit comments

Comments
 (0)