"Thank You for Your Order" Page
The last thing we need to do is add a thank you message to the customer for their order and indicate what they should do next.
To do this, we'll use the familiar method app.html
. In the address of this method, we will use the order ID.
const orderPage = app.html('/order/:id', async(ctx, req) => {
const order = await orderTable.getById(ctx, req.params.id!)
const item = await order.item.get(ctx)
return <Layout title='Order'>
<h1 class={"mb-4"}>Thank you for your order!</h1>
<div>
You ordered "{item.title}"
</div>
<div>
We will contact you to confirm the delivery details.
</div>
</Layout>
})
After that, we will add the final line in the buyAction
form handler, which will redirect to the order page after adding to the table, specifying the ID of the newly created order:
return ctx.resp.redirect(orderPage({id: order.id}).url())
Final Code
You can see the code for this example here, and you can view the demo here.