@comicrelief/component-library 7.25.0 → 7.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Organisms/Donate/Donate.js +6 -3
- package/dist/components/Organisms/Donate/Donate.md +55 -0
- package/dist/components/Organisms/Donate/Form/Form.js +34 -18
- package/dist/components/Organisms/Donate/GivingSelector/GivingSelector.js +3 -0
- package/dist/components/Organisms/Donate/__snapshots__/Donate.test.js.snap +84 -300
- package/dist/components/Organisms/Donate/dev-data/data-monthly.js +22 -0
- package/package.json +1 -1
- package/src/components/Organisms/Donate/Donate.js +7 -3
- package/src/components/Organisms/Donate/Donate.md +55 -0
- package/src/components/Organisms/Donate/Form/Form.js +43 -26
- package/src/components/Organisms/Donate/GivingSelector/GivingSelector.js +5 -1
- package/src/components/Organisms/Donate/__snapshots__/Donate.test.js.snap +84 -300
- package/src/components/Organisms/Donate/dev-data/data-monthly.js +23 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
cartId: 'monthly-only',
|
|
9
|
+
singleGiving: null,
|
|
10
|
+
regularGiving: {
|
|
11
|
+
moneybuys: [{
|
|
12
|
+
description: 'a regular supply of toiletries for someone living in a refugee camp in Serbia.',
|
|
13
|
+
value: '5.50'
|
|
14
|
+
}, {
|
|
15
|
+
description: 'a potentially lifesaving call for a man at risk of suicide in the UK.',
|
|
16
|
+
value: '10'
|
|
17
|
+
}, {
|
|
18
|
+
description: 'the distribution of enough surplus food for a school breakfast club to feed 80 children.',
|
|
19
|
+
value: '20'
|
|
20
|
+
}]
|
|
21
|
+
}
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -42,7 +42,8 @@ const Donate = ({
|
|
|
42
42
|
isDesktopOverride,
|
|
43
43
|
otherAmountValue,
|
|
44
44
|
additionalSingleCopy,
|
|
45
|
-
additionalMonthlyCopy
|
|
45
|
+
additionalMonthlyCopy,
|
|
46
|
+
defaultGivingType
|
|
46
47
|
}) => {
|
|
47
48
|
let isDesktop = useMediaQuery({ query: `(min-width: ${screen.medium})` });
|
|
48
49
|
|
|
@@ -131,6 +132,7 @@ const Donate = ({
|
|
|
131
132
|
otherAmountValue={otherAmountValue}
|
|
132
133
|
additionalSingleCopy={additionalSingleCopy}
|
|
133
134
|
additionalMonthlyCopy={additionalMonthlyCopy}
|
|
135
|
+
defaultGivingType={defaultGivingType}
|
|
134
136
|
/>
|
|
135
137
|
</Wrapper>
|
|
136
138
|
</Container>
|
|
@@ -165,7 +167,8 @@ Donate.propTypes = {
|
|
|
165
167
|
isDesktopOverride: PropTypes.bool,
|
|
166
168
|
otherAmountValue: PropTypes.number,
|
|
167
169
|
additionalSingleCopy: PropTypes.string,
|
|
168
|
-
additionalMonthlyCopy: PropTypes.string
|
|
170
|
+
additionalMonthlyCopy: PropTypes.string,
|
|
171
|
+
defaultGivingType: PropTypes.string
|
|
169
172
|
};
|
|
170
173
|
|
|
171
174
|
Donate.defaultProps = {
|
|
@@ -194,7 +197,8 @@ Donate.defaultProps = {
|
|
|
194
197
|
otherAmountValue: null,
|
|
195
198
|
title: null,
|
|
196
199
|
additionalSingleCopy: null,
|
|
197
|
-
additionalMonthlyCopy: null
|
|
200
|
+
additionalMonthlyCopy: null,
|
|
201
|
+
defaultGivingType: null
|
|
198
202
|
};
|
|
199
203
|
|
|
200
204
|
export default Donate;
|
|
@@ -438,4 +438,59 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
|
|
|
438
438
|
subtitle="Please help us fund life-changing projects in the UK and around the world."
|
|
439
439
|
additionalSingleCopy="Some additional single giving copy - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa."
|
|
440
440
|
/>;
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Default monthly giving type
|
|
444
|
+
|
|
445
|
+
```js
|
|
446
|
+
import data from './dev-data/data';
|
|
447
|
+
const mobilePictures = require('../../../styleguide/data/data').mobileImages;
|
|
448
|
+
const desktopPictures = require('../../../styleguide/data/data').defaultData;
|
|
449
|
+
|
|
450
|
+
<Donate
|
|
451
|
+
alt="Background image"
|
|
452
|
+
mobileBackgroundColor="deep_violet_dark"
|
|
453
|
+
desktopOverlayColor="red"
|
|
454
|
+
submitButtonColor="blue_dark"
|
|
455
|
+
formAlignRight={true}
|
|
456
|
+
imageLow={desktopPictures.imageLow}
|
|
457
|
+
images={desktopPictures.images}
|
|
458
|
+
mobileImageLow={mobilePictures.imageLow}
|
|
459
|
+
mobileImages={mobilePictures.images}
|
|
460
|
+
data={data}
|
|
461
|
+
mbshipID="mship-14"
|
|
462
|
+
donateLink="https://donation.comicrelief.com/"
|
|
463
|
+
clientID="donate"
|
|
464
|
+
cartID="default-comicrelief"
|
|
465
|
+
title="Donate Now"
|
|
466
|
+
subtitle="Please help us fund life-changing projects in the UK and around the world."
|
|
467
|
+
defaultGivingType="monthly"
|
|
468
|
+
/>;
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Monthly ONLY
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
import data from './dev-data/data-monthly';
|
|
475
|
+
const mobilePictures = require('../../../styleguide/data/data').mobileImages;
|
|
476
|
+
const desktopPictures = require('../../../styleguide/data/data').defaultData;
|
|
477
|
+
|
|
478
|
+
<Donate
|
|
479
|
+
alt="Background image"
|
|
480
|
+
mobileBackgroundColor="deep_violet_dark"
|
|
481
|
+
desktopOverlayColor="red"
|
|
482
|
+
submitButtonColor="blue_dark"
|
|
483
|
+
formAlignRight={true}
|
|
484
|
+
imageLow={desktopPictures.imageLow}
|
|
485
|
+
images={desktopPictures.images}
|
|
486
|
+
mobileImageLow={mobilePictures.imageLow}
|
|
487
|
+
mobileImages={mobilePictures.images}
|
|
488
|
+
data={data}
|
|
489
|
+
mbshipID="mship-15"
|
|
490
|
+
donateLink="https://donation.comicrelief.com/"
|
|
491
|
+
clientID="donate"
|
|
492
|
+
cartID="default-comicrelief"
|
|
493
|
+
title="Donate Now"
|
|
494
|
+
subtitle="Please help us fund life-changing projects in the UK and around the world."
|
|
495
|
+
/>;
|
|
441
496
|
```
|
|
@@ -40,9 +40,10 @@ const Signup = ({
|
|
|
40
40
|
otherAmountValue,
|
|
41
41
|
additionalSingleCopy,
|
|
42
42
|
additionalMonthlyCopy,
|
|
43
|
+
defaultGivingType,
|
|
43
44
|
...rest
|
|
44
45
|
}) => {
|
|
45
|
-
const [givingType, setGivingType] = useState(
|
|
46
|
+
const [givingType, setGivingType] = useState();
|
|
46
47
|
const [errorMsg, setErrorMsg] = useState(false);
|
|
47
48
|
const [amountDonate, setAmountDonate] = useState(10);
|
|
48
49
|
const [moneyBuyCopy, setMoneyBuyCopy] = useState(true);
|
|
@@ -55,7 +56,7 @@ const Signup = ({
|
|
|
55
56
|
// otherwise assign based on the associated moneybuys:
|
|
56
57
|
if (otherAmountValue) {
|
|
57
58
|
setAmountDonate(otherAmountValue);
|
|
58
|
-
} else {
|
|
59
|
+
} else if (givingType) {
|
|
59
60
|
const givingData = givingType === 'single' ? singleGiving : regularGiving;
|
|
60
61
|
|
|
61
62
|
// Check the 2nd moneybuy exists before using it;
|
|
@@ -70,29 +71,31 @@ const Signup = ({
|
|
|
70
71
|
}, [givingType, singleGiving, regularGiving, otherAmountValue]);
|
|
71
72
|
|
|
72
73
|
useEffect(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let moneyBuyNewDescription = otherAmountText;
|
|
74
|
+
if (givingType) {
|
|
75
|
+
const givingData = givingType === 'single' ? singleGiving : regularGiving;
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
if (moneyBuy.value === amountDonate) {
|
|
79
|
-
moneyBuyNewDescription = moneyBuy.description;
|
|
80
|
-
}
|
|
77
|
+
let moneyBuyNewDescription = otherAmountText;
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
setAmountDonate(moneyBuy.value))
|
|
87
|
-
);
|
|
88
|
-
});
|
|
79
|
+
givingData.moneybuys.map((moneyBuy, index) => {
|
|
80
|
+
if (moneyBuy.value === amountDonate) {
|
|
81
|
+
moneyBuyNewDescription = moneyBuy.description;
|
|
82
|
+
}
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
return (
|
|
85
|
+
index === 1
|
|
86
|
+
&& amountDonate === undefined
|
|
87
|
+
&& (setMoneyBuyCopy(moneyBuy.description),
|
|
88
|
+
setAmountDonate(moneyBuy.value))
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!isAmountValid(amountDonate)) {
|
|
93
|
+
if (moneyBuyCopy) setMoneyBuyCopy(false);
|
|
94
|
+
if (!errorMsg) setErrorMsg(true);
|
|
95
|
+
} else {
|
|
96
|
+
if (errorMsg) setErrorMsg(false);
|
|
97
|
+
setMoneyBuyCopy(moneyBuyNewDescription);
|
|
98
|
+
}
|
|
96
99
|
}
|
|
97
100
|
}, [
|
|
98
101
|
errorMsg,
|
|
@@ -110,6 +113,18 @@ const Signup = ({
|
|
|
110
113
|
if (popOpen && !popUpShown) setPopUpShown(true);
|
|
111
114
|
}, [popOpen, popUpShown]);
|
|
112
115
|
|
|
116
|
+
// On load, determine what should actually be the default giving type
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
// Use any explicit setting
|
|
119
|
+
if (defaultGivingType) {
|
|
120
|
+
setGivingType(defaultGivingType);
|
|
121
|
+
} else {
|
|
122
|
+
// Else, use whatever's available
|
|
123
|
+
setGivingType(singleGiving !== null ? 'single' : 'monthly');
|
|
124
|
+
}
|
|
125
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
113
128
|
const submitDonation = (
|
|
114
129
|
event,
|
|
115
130
|
amount,
|
|
@@ -170,7 +185,7 @@ const Signup = ({
|
|
|
170
185
|
|
|
171
186
|
setAmountDonate(thisAmount);
|
|
172
187
|
}
|
|
173
|
-
}, [errorMsg, givingData
|
|
188
|
+
}, [errorMsg, givingData]);
|
|
174
189
|
|
|
175
190
|
// Listen for click outside custom amount input if there is no value entered.
|
|
176
191
|
useEffect(() => {
|
|
@@ -227,7 +242,7 @@ const Signup = ({
|
|
|
227
242
|
{chooseAmountText || `${noMoneyBuys ? 'Enter' : 'Choose'} an amount to give`}
|
|
228
243
|
</Text>
|
|
229
244
|
</Legend>
|
|
230
|
-
{!noMoneyBuys && (
|
|
245
|
+
{!noMoneyBuys && givingType && (
|
|
231
246
|
<MoneyBuys>
|
|
232
247
|
{givingData.moneybuys.map(({ value }, index) => (
|
|
233
248
|
<MoneyBuy
|
|
@@ -329,7 +344,8 @@ Signup.propTypes = {
|
|
|
329
344
|
submitButtonColor: PropTypes.string.isRequired,
|
|
330
345
|
otherAmountValue: PropTypes.number,
|
|
331
346
|
additionalSingleCopy: PropTypes.string,
|
|
332
|
-
additionalMonthlyCopy: PropTypes.string
|
|
347
|
+
additionalMonthlyCopy: PropTypes.string,
|
|
348
|
+
defaultGivingType: PropTypes.string
|
|
333
349
|
};
|
|
334
350
|
|
|
335
351
|
Signup.defaultProps = {
|
|
@@ -337,7 +353,8 @@ Signup.defaultProps = {
|
|
|
337
353
|
otherAmountValue: null,
|
|
338
354
|
data: {},
|
|
339
355
|
additionalSingleCopy: null,
|
|
340
|
-
additionalMonthlyCopy: null
|
|
356
|
+
additionalMonthlyCopy: null,
|
|
357
|
+
defaultGivingType: null
|
|
341
358
|
};
|
|
342
359
|
|
|
343
360
|
export default Signup;
|
|
@@ -51,8 +51,12 @@ const GivingSelector = ({
|
|
|
51
51
|
);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
GivingSelector.defaultProps = {
|
|
55
|
+
givingType: null
|
|
56
|
+
};
|
|
57
|
+
|
|
54
58
|
GivingSelector.propTypes = {
|
|
55
|
-
givingType: PropTypes.string
|
|
59
|
+
givingType: PropTypes.string,
|
|
56
60
|
changeGivingType: PropTypes.func.isRequired,
|
|
57
61
|
setPopOpen: PropTypes.func.isRequired,
|
|
58
62
|
mbshipID: PropTypes.string.isRequired
|