diff --git a/frontend/app/routes/payment-confirmation.tsx b/frontend/app/routes/payment-confirmation.tsx index e50ed33c..a2f0316f 100644 --- a/frontend/app/routes/payment-confirmation.tsx +++ b/frontend/app/routes/payment-confirmation.tsx @@ -11,7 +11,7 @@ import { validatePaymentParams } from '~/utils/validate.server' export const meta: MetaFunction = () => { return [ { title: 'Grant Interaction' }, - { name: 'description', content: 'Interaction success' }, + { name: 'description', content: 'Grant interaction result' }, ] } @@ -20,6 +20,19 @@ export async function loader({ request, context }: LoaderFunctionArgs) { const url = new URL(request.url) const params = Object.fromEntries([...url.searchParams]) + // Check for interaction result parameters (e.g., result=grant_rejected) + const interactionResult = params.result + if (interactionResult && interactionResult !== 'grant_approved') { + return data({ + success: false, + error: + interactionResult === 'grant_rejected' + ? 'The grant request was declined.' + : `Interaction failed: ${interactionResult}`, + params, + }) + } + const validation = validatePaymentParams(params) if (!validation.success) { return data({ @@ -58,19 +71,64 @@ export async function loader({ request, context }: LoaderFunctionArgs) { } } -export default function PaymentComplete() { - const { params } = useLoaderData() +export default function GrantInteraction() { + const loaderData = useLoaderData() const hasPostedMessage = useRef(false) + const isSuccess = loaderData.success useEffect(() => { if (hasPostedMessage.current) return hasPostedMessage.current = true if (window.opener) { - window.opener.postMessage({ type: 'GRANT_INTERACTION', ...params }, '*') + window.opener.postMessage( + { type: 'GRANT_INTERACTION', ...loaderData.params }, + '*', + ) } }, []) + if (!isSuccess) { + return ( +
+
+
+
+ + + +
+ +

+ Interaction Failed +

+ +

+ {'error' in loaderData && loaderData.error + ? loaderData.error + : 'Something went wrong. Please try again.'} +

+ +

+ You can close this window. +

+
+
+
+ ) + } + return (