From 1f4572bdb91a805f6858622e1c957b77b018e0f5 Mon Sep 17 00:00:00 2001 From: Alexander Thiel Date: Wed, 20 Jan 2021 18:00:05 +0100 Subject: [PATCH 1/2] feat: allows to select donation recipient --- components/Payment/Payment.js | 25 +++++++++++++++++++++---- data/de.json | 5 ++++- hooks/index.js | 2 +- hooks/usePayment.js | 33 ++++++++++++++++++++++++--------- pages/api/payment.js | 14 +++++++++----- 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/components/Payment/Payment.js b/components/Payment/Payment.js index dc798ef..2201dc1 100644 --- a/components/Payment/Payment.js +++ b/components/Payment/Payment.js @@ -1,6 +1,8 @@ -import { useState } from 'react'; - -import { usePayment, useTrip, useTranslation } from '../../hooks'; +import { + createContext, + useContext, +} from 'react'; +import { usePayment, useTrip, useTranslation, usePaymentTranslations } from '../../hooks'; import { Select } from '../Select'; @@ -11,6 +13,7 @@ import { button, } from './Payment.module.css'; +const PaymentContext = createContext({}); export default function Payment() { const { t, formatNumber } = useTranslation(); @@ -18,12 +21,26 @@ export default function Payment() { trip: { cost }, } = useTrip(); const { process } = usePayment(); + const { recipients } = usePaymentTranslations(); + + // Destination is view-only and we'll individually reach out to donors + let { recipient } = useContext(PaymentContext); + recipient = Object.keys(recipients)[0]; return (

{t('paymentHeadline')}

{formatNumber(cost, 2)} €

-