Skip to content

Commit

Permalink
chore: Route tidyups
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 24, 2023
1 parent 8a886ea commit 85ce7e1
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions editor.planx.uk/src/routes/pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { publicClient } from "lib/graphql";
import { getRetentionPeriod } from "lib/pay";
import {
compose,
map,
mount,
NaviRequest,
redirect,
Expand Down Expand Up @@ -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: (
<ErrorPage title={"Sorry, we can’t find that payment link"}>
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.
<br />
<br />
Please contact the person who invited you to pay.
</ErrorPage>
),
};
}
return {
if (!paymentRequest) return redirect("./not-found");

return route({
title: makeTitle("Make a payment"),
view: <MakePayment {...paymentRequest} />,
};
});
}),
"/not-found": route({
title: makeTitle("Sorry, we can’t find that payment link"),
view: (
<ErrorPage title={"Sorry, we can’t find that payment link"}>
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.
<br />
<br />
Please contact the person who invited you to pay.
</ErrorPage>
),
}),
"/invite": route(async (req) => {
"/invite": map(async (req) => {
const paymentRequest = await getPaymentRequest(req);
if (!paymentRequest) {
return {
title: makeTitle("Failed to generate payment request"),
view: <ErrorPage title={"Failed to generate payment request"} />,
};
}
return {
if (!paymentRequest) return redirect("./failed");

return route({
title: makeTitle("Invite to pay"),
view: <InviteToPay {...paymentRequest} />,
};
});
}),
"/invite/failed": route({
title: makeTitle("Failed to generate payment request"),
view: <ErrorPage title={"Failed to generate payment request"} />,
}),
"/pages/:page": redirect(
(req) => `../../../preview/pages/${req.params.page}`,
Expand All @@ -84,7 +84,7 @@ const payRoutes = compose(
const getPaymentRequest = async (
req: NaviRequest,
): Promise<PaymentRequest | undefined> => {
const paymentRequestId = req.params["paymentRequestId"];
const paymentRequestId = req.query["paymentRequestId"];
if (paymentRequestId) {
const paymentRequest = await fetchPaymentRequest(paymentRequestId);
return paymentRequest;
Expand Down

0 comments on commit 85ce7e1

Please sign in to comment.