From ea7a91562b26439d9496fa3f04249cd0f836d96d Mon Sep 17 00:00:00 2001 From: Amir Angel <36531255+17Amir17@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:49:05 +0700 Subject: [PATCH] Better One Click Error Page (#2139) Better one click error page --------- Co-authored-by: or orsatti Co-authored-by: Richard Liu --- .../resources/one-click-page/error.html | 285 ++++++++++++++---- .../routing/routes/genericIssuanceRoutes.ts | 139 +++++---- 2 files changed, 296 insertions(+), 128 deletions(-) diff --git a/apps/passport-server/resources/one-click-page/error.html b/apps/passport-server/resources/one-click-page/error.html index ee3426602a..e8bca241b6 100644 --- a/apps/passport-server/resources/one-click-page/error.html +++ b/apps/passport-server/resources/one-click-page/error.html @@ -6,6 +6,13 @@ + + + + Missing ticket + .modal__button_container { + display: flex; + flex-direction: column; + width: 100%; + gap: 8px; + } + - - - - - - - - - - - - Whoops, looks like you don't have a ticket. - Go to Zupass + + + NO UPCOMING EVENTS + Don't see you ticket? Learn more + + Learn more + + + + + + + DON'T SEE YOUR TICKET? + + + The ticket that this link refers to either does not exist or was updated. + + + + Contact + support + Close + + + diff --git a/apps/passport-server/src/routing/routes/genericIssuanceRoutes.ts b/apps/passport-server/src/routing/routes/genericIssuanceRoutes.ts index aee707b059..4941058c9b 100644 --- a/apps/passport-server/src/routing/routes/genericIssuanceRoutes.ts +++ b/apps/passport-server/src/routing/routes/genericIssuanceRoutes.ts @@ -26,7 +26,7 @@ import { TicketPreviewResultValue } from "@pcd/passport-interface"; import { SerializedSemaphoreGroup } from "@pcd/semaphore-group-pcd"; -import { sleep } from "@pcd/util"; +import { ZUPASS_SUPPORT_EMAIL, sleep } from "@pcd/util"; import express from "express"; import { sha256 } from "js-sha256"; import Mustache from "mustache"; @@ -790,74 +790,87 @@ export function initGenericIssuanceRoutes( ); }; const absPath = path.resolve("./resources/one-click-page/index.html"); - const result = await genericIssuanceService.handleGetTicketPreview( - email, - code, - pipeline - ); - const main: TicketPreviewResultValue["tickets"] = []; - const addOns: TicketPreviewResultValue["tickets"] = []; + try { + const result = await genericIssuanceService.handleGetTicketPreview( + email, + code, + pipeline + ); + + const main: TicketPreviewResultValue["tickets"] = []; + const addOns: TicketPreviewResultValue["tickets"] = []; - for (const ticket of result.tickets) { - if (ticket.isAddOn) { - addOns.push(ticket); - } else { - main.push(ticket); + for (const ticket of result.tickets) { + if (ticket.isAddOn) { + addOns.push(ticket); + } else { + main.push(ticket); + } } - } - if (!main.length) { - throw new PCDHTTPError( - 400, - `No ticket found with order code ${code} and email ${email}. Please contact support@zupass.org immediately.` - ); - } + if (!main.length) { + throw new PCDHTTPError( + 400, + `No ticket found with order code ${code} and email ${email}. Please contact support@zupass.org immediately.` + ); + } - const file = await readFileWithCache(absPath); - const ticket = main[0]; - - // filter out add-ons - const ticketsCount = main.length; - - const tickets = await Promise.all( - main.map(async (ticket) => { - // Find all add-ons that belong to this main ticket - const ticketAddons = addOns - .filter((addon) => addon.parentTicketId === ticket.ticketId) - .map(async (addon) => ({ - image: await getTicketImage(addon), - name: addon.ticketName - })); - - return { - attendeeName: - ticket.attendeeName !== "" - ? ticket.attendeeName.toUpperCase() - : ticket.eventName.toUpperCase(), - attendeeEmail: ticket.attendeeEmail, - ticketName: ticket.ticketName, - qr: await getTicketImage(ticket), - showAddons: ticketAddons.length > 0, - id: ticket.ticketId, - moreThanOneAddon: ticketAddons.length > 1, - addonsCount: ticketAddons.length, - addons: await Promise.all(ticketAddons) - }; - }) - ); + const file = await readFileWithCache(absPath); + const ticket = main[0]; + + // filter out add-ons + const ticketsCount = main.length; + + const tickets = await Promise.all( + main.map(async (ticket) => { + // Find all add-ons that belong to this main ticket + const ticketAddons = addOns + .filter((addon) => addon.parentTicketId === ticket.ticketId) + .map(async (addon) => ({ + image: await getTicketImage(addon), + name: addon.ticketName + })); + + return { + attendeeName: + ticket.attendeeName !== "" + ? ticket.attendeeName.toUpperCase() + : ticket.eventName.toUpperCase(), + attendeeEmail: ticket.attendeeEmail, + ticketName: ticket.ticketName, + qr: await getTicketImage(ticket), + showAddons: ticketAddons.length > 0, + id: ticket.ticketId, + moreThanOneAddon: ticketAddons.length > 1, + addonsCount: ticketAddons.length, + addons: await Promise.all(ticketAddons) + }; + }) + ); - const rendered = Mustache.render(file, { - tickets, - eventName: ticket?.eventName.toUpperCase(), - eventLocation: ticket?.eventLocation, - backgroundImage: ticket?.imageUrl, - count: ticketsCount, - isMoreThanOne: ticketsCount > 1, - zupassUrl: process.env.PASSPORT_CLIENT_URL, - startDate: ticket?.eventStartDate - }); - res.send(rendered); + const rendered = Mustache.render(file, { + tickets, + eventName: ticket?.eventName.toUpperCase(), + eventLocation: ticket?.eventLocation, + backgroundImage: ticket?.imageUrl, + count: ticketsCount, + isMoreThanOne: ticketsCount > 1, + zupassUrl: process.env.PASSPORT_CLIENT_URL, + startDate: ticket?.eventStartDate + }); + res.send(rendered); + } catch { + const errorFilePath = path.resolve( + "./resources/one-click-page/error.html" + ); + const file = await readFileWithCache(errorFilePath); + const rendered = Mustache.render(file, { + zupassSupport: ZUPASS_SUPPORT_EMAIL, + email: email + }); + res.send(rendered); + } } ); }