-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdonation-form-express-only.js
146 lines (134 loc) · 3.2 KB
/
donation-form-express-only.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(RaiselyComponents, React) => {
const { DonationForm } = RaiselyComponents.Molecules;
const clsx = (...classes) =>
classes.filter((value) => value && typeof value === 'string').join(' ');
function CustomRenderStep({
mainHeading,
currencySelection,
giftAidEnabled,
giftAidFields,
thankYouTitle,
thankYouMessage,
customShareUrl,
recurring,
amount,
onTokenSuccess,
// callback handles
afterPaymentSelect,
// built-in iternals
builtIns: {
// internal components
FrequencySelect,
AmountSelect,
MissingProviderNotice,
OptIn,
CurrencySelect,
PaymentMethodSelect,
GiftAidOptIn,
AnonymousToggle,
ErrorFeedback,
PostDonateModal,
ThankYouScreen,
StepSelect,
// hooks
useDonationFormContext,
},
}) {
const { campaign, isEmbed } = useRaisely();
const { values } = useDonationFormContext();
// Determine which steps to show based off props
const stepConditions = {
amount: !amount,
thankyou: true,
};
// Verify which steps available based on the above conditions
const steps = Object.keys(stepConditions).filter(
(s) => stepConditions[s]
);
const currentStep = steps[values.step];
/**
* Because components of the donation form are modular, we can create different
* layouts based on the state of the donation form.
*/
if (currentStep === 'amount') {
// Detect missing express config
if (!campaign.config.donation?.express) {
return (
<div className="donation-form__body">
<ErrorFeedback customError="Please enable express donations" />
</div>
);
}
return (
<div className="donation-form__body">
<MissingProviderNotice />
{mainHeading && (
<h2 className="donation-form__title">{mainHeading}</h2>
)}
{recurring && <FrequencySelect />}
<AmountSelect />
<OptIn />
{giftAidEnabled ? (
<GiftAidOptIn giftAidFields={giftAidFields} />
) : null}
<CurrencySelect currencySelection={currencySelection} />
<PaymentMethodSelect
afterSelect={(nextState, paymentRequest) =>
afterPaymentSelect(
nextState,
paymentRequest,
steps.length - 1
)
}
hideManual
hidePaypal={Boolean(onTokenSuccess)}
/>
<AnonymousToggle />
<ErrorFeedback />
</div>
);
}
if (currentStep === 'thankyou') {
// confirmation/thank you
return (
<div>
<div className="donation-form__header">
<StepSelect stepCount={steps.length - 1} />
</div>
<div
className={clsx(
'donation-form__body',
'donation-form__body--success'
)}
>
<ThankYouScreen
title={thankYouTitle}
message={thankYouMessage}
customShareUrl={customShareUrl}
/>
</div>
{!isEmbed && (
<PostDonateModal
title={thankYouTitle}
message={thankYouMessage}
customShareUrl={customShareUrl}
/>
)}
</div>
);
}
return null;
}
return () => {
const { user } = useRaisely();
const configuration = {
// Ensure that form tries to figure itself out
autoconfigure: true,
// pass in user (required)
user,
};
return (
<DonationForm {...configuration} renderStep={CustomRenderStep} />
);
};
};