From 85ce7e1adf3bfc0d170887c577f0428f22ae7b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 24 Oct 2023 16:29:12 +0100 Subject: [PATCH] chore: Route tidyups --- editor.planx.uk/src/routes/pay.tsx | 56 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/editor.planx.uk/src/routes/pay.tsx b/editor.planx.uk/src/routes/pay.tsx index ca0da6e521..65bb57bfab 100644 --- a/editor.planx.uk/src/routes/pay.tsx +++ b/editor.planx.uk/src/routes/pay.tsx @@ -4,6 +4,7 @@ import { publicClient } from "lib/graphql"; import { getRetentionPeriod } from "lib/pay"; import { compose, + map, mount, NaviRequest, redirect, @@ -37,40 +38,39 @@ const payRoutes = compose( }), mount({ - "/": route(async (req) => { + "/": map(async (req) => { const paymentRequest = await getPaymentRequest(req); - if (!paymentRequest) { - return { - title: makeTitle("Sorry, we can’t find that payment link"), - view: ( - - Please check you have the right link. If it still doesn’t work, it - may mean the payment link has expired or payment has already been - made. -
-
- Please contact the person who invited you to pay. -
- ), - }; - } - return { + if (!paymentRequest) return redirect("./not-found"); + + return route({ title: makeTitle("Make a payment"), view: , - }; + }); + }), + "/not-found": route({ + title: makeTitle("Sorry, we can’t find that payment link"), + view: ( + + Please check you have the right link. If it still doesn’t work, it may + mean the payment link has expired or payment has already been made. +
+
+ Please contact the person who invited you to pay. +
+ ), }), - "/invite": route(async (req) => { + "/invite": map(async (req) => { const paymentRequest = await getPaymentRequest(req); - if (!paymentRequest) { - return { - title: makeTitle("Failed to generate payment request"), - view: , - }; - } - return { + if (!paymentRequest) return redirect("./failed"); + + return route({ title: makeTitle("Invite to pay"), view: , - }; + }); + }), + "/invite/failed": route({ + title: makeTitle("Failed to generate payment request"), + view: , }), "/pages/:page": redirect( (req) => `../../../preview/pages/${req.params.page}`, @@ -84,7 +84,7 @@ const payRoutes = compose( const getPaymentRequest = async ( req: NaviRequest, ): Promise => { - const paymentRequestId = req.params["paymentRequestId"]; + const paymentRequestId = req.query["paymentRequestId"]; if (paymentRequestId) { const paymentRequest = await fetchPaymentRequest(paymentRequestId); return paymentRequest;