@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.
@@ -42,7 +42,8 @@ const Donate = _ref => {
42
42
  isDesktopOverride,
43
43
  otherAmountValue,
44
44
  additionalSingleCopy,
45
- additionalMonthlyCopy
45
+ additionalMonthlyCopy,
46
+ defaultGivingType
46
47
  } = _ref;
47
48
  let isDesktop = (0, _reactResponsive.useMediaQuery)({
48
49
  query: "(min-width: ".concat(_size.screen.medium, ")")
@@ -111,7 +112,8 @@ const Donate = _ref => {
111
112
  submitButtonColor: submitButtonColor,
112
113
  otherAmountValue: otherAmountValue,
113
114
  additionalSingleCopy: additionalSingleCopy,
114
- additionalMonthlyCopy: additionalMonthlyCopy
115
+ additionalMonthlyCopy: additionalMonthlyCopy,
116
+ defaultGivingType: defaultGivingType
115
117
  })));
116
118
  };
117
119
  Donate.defaultProps = {
@@ -139,6 +141,7 @@ Donate.defaultProps = {
139
141
  otherAmountValue: null,
140
142
  title: null,
141
143
  additionalSingleCopy: null,
142
- additionalMonthlyCopy: null
144
+ additionalMonthlyCopy: null,
145
+ defaultGivingType: null
143
146
  };
144
147
  var _default = exports.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
  ```
@@ -31,9 +31,10 @@ const Signup = _ref => {
31
31
  otherAmountValue,
32
32
  additionalSingleCopy,
33
33
  additionalMonthlyCopy,
34
+ defaultGivingType,
34
35
  ...rest
35
36
  } = _ref;
36
- const [givingType, setGivingType] = (0, _react.useState)('single');
37
+ const [givingType, setGivingType] = (0, _react.useState)();
37
38
  const [errorMsg, setErrorMsg] = (0, _react.useState)(false);
38
39
  const [amountDonate, setAmountDonate] = (0, _react.useState)(10);
39
40
  const [moneyBuyCopy, setMoneyBuyCopy] = (0, _react.useState)(true);
@@ -45,7 +46,7 @@ const Signup = _ref => {
45
46
  // otherwise assign based on the associated moneybuys:
46
47
  if (otherAmountValue) {
47
48
  setAmountDonate(otherAmountValue);
48
- } else {
49
+ } else if (givingType) {
49
50
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
50
51
 
51
52
  // Check the 2nd moneybuy exists before using it;
@@ -56,20 +57,22 @@ const Signup = _ref => {
56
57
  }
57
58
  }, [givingType, singleGiving, regularGiving, otherAmountValue]);
58
59
  (0, _react.useEffect)(() => {
59
- const givingData = givingType === 'single' ? singleGiving : regularGiving;
60
- let moneyBuyNewDescription = otherAmountText;
61
- givingData.moneybuys.map((moneyBuy, index) => {
62
- if (moneyBuy.value === amountDonate) {
63
- moneyBuyNewDescription = moneyBuy.description;
60
+ if (givingType) {
61
+ const givingData = givingType === 'single' ? singleGiving : regularGiving;
62
+ let moneyBuyNewDescription = otherAmountText;
63
+ givingData.moneybuys.map((moneyBuy, index) => {
64
+ if (moneyBuy.value === amountDonate) {
65
+ moneyBuyNewDescription = moneyBuy.description;
66
+ }
67
+ return index === 1 && amountDonate === undefined && (setMoneyBuyCopy(moneyBuy.description), setAmountDonate(moneyBuy.value));
68
+ });
69
+ if (!(0, _Membership.isAmountValid)(amountDonate)) {
70
+ if (moneyBuyCopy) setMoneyBuyCopy(false);
71
+ if (!errorMsg) setErrorMsg(true);
72
+ } else {
73
+ if (errorMsg) setErrorMsg(false);
74
+ setMoneyBuyCopy(moneyBuyNewDescription);
64
75
  }
65
- return index === 1 && amountDonate === undefined && (setMoneyBuyCopy(moneyBuy.description), setAmountDonate(moneyBuy.value));
66
- });
67
- if (!(0, _Membership.isAmountValid)(amountDonate)) {
68
- if (moneyBuyCopy) setMoneyBuyCopy(false);
69
- if (!errorMsg) setErrorMsg(true);
70
- } else {
71
- if (errorMsg) setErrorMsg(false);
72
- setMoneyBuyCopy(moneyBuyNewDescription);
73
76
  }
74
77
  }, [errorMsg, moneyBuyCopy, singleGiving, regularGiving, givingType, amountDonate, otherAmountText]);
75
78
 
@@ -78,6 +81,18 @@ const Signup = _ref => {
78
81
  (0, _react.useEffect)(() => {
79
82
  if (popOpen && !popUpShown) setPopUpShown(true);
80
83
  }, [popOpen, popUpShown]);
84
+
85
+ // On load, determine what should actually be the default giving type
86
+ (0, _react.useEffect)(() => {
87
+ // Use any explicit setting
88
+ if (defaultGivingType) {
89
+ setGivingType(defaultGivingType);
90
+ } else {
91
+ // Else, use whatever's available
92
+ setGivingType(singleGiving !== null ? 'single' : 'monthly');
93
+ }
94
+ // eslint-disable-next-line react-hooks/exhaustive-deps
95
+ }, []);
81
96
  const submitDonation = (event, amount, clientId, cartId, mbshipId, donateURL) => {
82
97
  event.preventDefault();
83
98
  if ((0, _Membership.isAmountValid)(amount) && !errorMsg) {
@@ -117,7 +132,7 @@ const Signup = _ref => {
117
132
  const thisAmount = givingData.moneybuys[1] ? givingData.moneybuys[1].value : givingData.moneybuys[0].value;
118
133
  setAmountDonate(thisAmount);
119
134
  }
120
- }, [errorMsg, givingData.moneybuys]);
135
+ }, [errorMsg, givingData]);
121
136
 
122
137
  // Listen for click outside custom amount input if there is no value entered.
123
138
  (0, _react.useEffect)(() => {
@@ -156,7 +171,7 @@ const Signup = _ref => {
156
171
  tag: "span",
157
172
  size: "l",
158
173
  weight: "bold"
159
- }, chooseAmountText || "".concat(noMoneyBuys ? 'Enter' : 'Choose', " an amount to give"))), !noMoneyBuys && /*#__PURE__*/_react.default.createElement(_Donate.MoneyBuys, null, givingData.moneybuys.map((_ref2, index) => {
174
+ }, chooseAmountText || "".concat(noMoneyBuys ? 'Enter' : 'Choose', " an amount to give"))), !noMoneyBuys && givingType && /*#__PURE__*/_react.default.createElement(_Donate.MoneyBuys, null, givingData.moneybuys.map((_ref2, index) => {
160
175
  let {
161
176
  value
162
177
  } = _ref2;
@@ -212,6 +227,7 @@ Signup.defaultProps = {
212
227
  otherAmountValue: null,
213
228
  data: {},
214
229
  additionalSingleCopy: null,
215
- additionalMonthlyCopy: null
230
+ additionalMonthlyCopy: null,
231
+ defaultGivingType: null
216
232
  };
217
233
  var _default = exports.default = Signup;
@@ -47,4 +47,7 @@ const GivingSelector = _ref => {
47
47
  htmlFor: "give-monthly--".concat(mbshipID)
48
48
  }, "Monthly"), /*#__PURE__*/_react.default.createElement(_GivingSelector.Switch, null)));
49
49
  };
50
+ GivingSelector.defaultProps = {
51
+ givingType: null
52
+ };
50
53
  var _default = exports.default = GivingSelector;