From 3563a246fe4cf8c3ce211895c3c32d1a675ae66b Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 3 Jan 2022 11:32:15 -0330 Subject: [PATCH] Allow templates without alerts (#13150) The confirmation page template system allows templates to have alerts, but it throws an uncaught Promise rejection if a template has no alerts. This is the unintended side-effect of input validation. The `getTemplateAlerts` function was updated to always return an array. The one callsite was updated to expect an empty array if there were no alerts to render, rather than expecting `undefined`. --- ui/pages/confirmation/confirmation.js | 2 +- ui/pages/confirmation/templates/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/pages/confirmation/confirmation.js b/ui/pages/confirmation/confirmation.js index 532dc8209..684737168 100644 --- a/ui/pages/confirmation/confirmation.js +++ b/ui/pages/confirmation/confirmation.js @@ -83,7 +83,7 @@ function useAlertState(pendingConfirmation) { let isMounted = true; if (pendingConfirmation) { getTemplateAlerts(pendingConfirmation).then((alerts) => { - if (isMounted && alerts) { + if (isMounted && alerts.length > 0) { dispatch({ type: 'set', confirmationId: pendingConfirmation.id, diff --git a/ui/pages/confirmation/templates/index.js b/ui/pages/confirmation/templates/index.js index a4e873735..8c9a6997f 100644 --- a/ui/pages/confirmation/templates/index.js +++ b/ui/pages/confirmation/templates/index.js @@ -43,7 +43,7 @@ const ALLOWED_TEMPLATE_KEYS = [ */ export async function getTemplateAlerts(pendingApproval) { const fn = APPROVAL_TEMPLATES[pendingApproval.type]?.getAlerts; - const results = fn ? await fn(pendingApproval) : undefined; + const results = fn ? await fn(pendingApproval) : []; if (!Array.isArray(results)) { throw new Error(`Template alerts must be an array, received: ${results}`); }