@comicrelief/component-library 7.12.2 → 7.14.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.
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import { useMediaQuery } from 'react-responsive';
3
3
  import PropTypes from 'prop-types';
4
4
 
@@ -39,7 +39,8 @@ const Donate = ({
39
39
  noMoneyBuys,
40
40
  PopUpText,
41
41
  chooseAmountText,
42
- isDesktopOverride
42
+ isDesktopOverride,
43
+ otherAmountValue
43
44
  }) => {
44
45
  let isDesktop = useMediaQuery({ query: `(min-width: ${screen.medium})` });
45
46
 
@@ -47,7 +48,7 @@ const Donate = ({
47
48
  const [overrideValue, setOverrideValue] = useState(null);
48
49
 
49
50
  // Store the updated override value
50
- React.useEffect(() => {
51
+ useEffect(() => {
51
52
  setOverrideValue(isDesktopOverride);
52
53
  }, [isDesktopOverride]);
53
54
 
@@ -122,6 +123,7 @@ const Donate = ({
122
123
  PopUpText={PopUpText}
123
124
  chooseAmountText={chooseAmountText}
124
125
  submitButtonColor={submitButtonColor}
126
+ otherAmountValue={otherAmountValue}
125
127
  />
126
128
  </Wrapper>
127
129
  </Container>
@@ -153,7 +155,8 @@ Donate.propTypes = {
153
155
  noMoneyBuys: PropTypes.bool,
154
156
  PopUpText: PropTypes.string,
155
157
  chooseAmountText: PropTypes.string,
156
- isDesktopOverride: PropTypes.bool
158
+ isDesktopOverride: PropTypes.bool,
159
+ otherAmountValue: PropTypes.number
157
160
  };
158
161
 
159
162
  Donate.defaultProps = {
@@ -178,7 +181,8 @@ Donate.defaultProps = {
178
181
  noMoneyBuys: false,
179
182
  PopUpText: 'Help us deliver long-term impact by converting your single donation into a monthly gift.',
180
183
  chooseAmountText: '',
181
- isDesktopOverride: null
184
+ isDesktopOverride: null,
185
+ otherAmountValue: null
182
186
  };
183
187
 
184
188
  export default Donate;
@@ -103,6 +103,102 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
103
103
  />;
104
104
  ```
105
105
 
106
+ ## Single Giving "No Money Buys" with overridden manual input value
107
+
108
+ ```js
109
+ import data from './dev-data/data-single';
110
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
111
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
112
+ import { useState } from 'react';
113
+
114
+ // Simulating default state of a parent componenet
115
+ const [amountDonate, setAmountDonate] = useState(123.45);
116
+
117
+ // Simulating state update of a parent componenet
118
+ setTimeout(()=>{
119
+ setAmountDonate(567.89);
120
+ }, 3000);
121
+
122
+ <Donate
123
+ mobileBackgroundColor="blue_dark"
124
+ desktopOverlayColor="blue_dark"
125
+ formAlignRight={false}
126
+ imageLow={desktopPictures.imageLow}
127
+ images={desktopPictures.images}
128
+ mobileImageLow={mobilePictures.imageLow}
129
+ mobileImages={mobilePictures.images}
130
+ data={data}
131
+ mbshipID="mship-4"
132
+ donateLink="https://donation.comicrelief.com/"
133
+ clientID="donate"
134
+ cartID="default-comicrelief"
135
+ title="Donate Now"
136
+ noMoneyBuys
137
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
138
+ otherAmountValue={amountDonate}
139
+ />;
140
+ ```
141
+
142
+ ## Form align right, with red desktop overlay and purple mobile background colour, with a blue submit button, with overridden manual input value
143
+
144
+ ```js
145
+ import data from './dev-data/data';
146
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
147
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
148
+ import { useState } from 'react';
149
+
150
+ // Simulating default state of a parent componenet
151
+ const [amountDonate, setAmountDonate] = useState(111.22);
152
+
153
+ // Simulating state update of a parent componenet
154
+ setTimeout(()=>{
155
+ setAmountDonate(333.44);
156
+ }, 3000);
157
+
158
+ <Donate
159
+ alt="Background image"
160
+ formAlignRight={true}
161
+ imageLow={desktopPictures.imageLow}
162
+ images={desktopPictures.images}
163
+ mobileImageLow={mobilePictures.imageLow}
164
+ mobileImages={mobilePictures.images}
165
+ data={data}
166
+ mbshipID="mship-1"
167
+ donateLink="https://donation.comicrelief.com/"
168
+ clientID="donate"
169
+ cartID="default-comicrelief"
170
+ title="Donate Now"
171
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
172
+ otherAmountValue={amountDonate}
173
+ />;
174
+ ```
175
+
176
+ ## Form align left, with custom message after choosing an "Other amount" to donate, high value cart.
177
+ ```js
178
+ import data from './dev-data/data-high-value';
179
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
180
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
181
+
182
+ <Donate
183
+ mobileBackgroundColor="blue_dark"
184
+ desktopOverlayColor="blue_dark"
185
+ formAlignRight={false}
186
+ imageLow={desktopPictures.imageLow}
187
+ images={desktopPictures.images}
188
+ mobileImageLow={mobilePictures.imageLow}
189
+ mobileImages={mobilePictures.images}
190
+ data={data}
191
+ mbshipID="mship-2"
192
+ donateLink="https://donation.comicrelief.com/"
193
+ clientID="donate"
194
+ cartID="default-comicrelief"
195
+ title="Donate Now"
196
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
197
+ otherAmountText="Overridden via the 'Other amount text' prop"
198
+ />;
199
+ ```
200
+
201
+
106
202
  ## Form align right - no subtitle
107
203
 
108
204
  ```js
@@ -72,3 +72,26 @@ it('Single donation with no Money Buys renders correctly', () => {
72
72
 
73
73
  expect(tree).toMatchSnapshot();
74
74
  });
75
+
76
+ it('"Single Giving, No Money Buys, with overridden manual input value" renders correctly', () => {
77
+ const tree = renderWithTheme(
78
+ <Donate
79
+ mobileBackgroundColor="blue_dark"
80
+ desktopOverlayColor="blue_dark"
81
+ formAlignRight={false}
82
+ imageLow={defaultData.pictures.imageLow}
83
+ images={defaultData.pictures.images}
84
+ data={data}
85
+ mbshipID="mship-4"
86
+ donateLink="https://donation.comicrelief.com/"
87
+ clientID="donate"
88
+ cartID="default-comicrelief"
89
+ title="Donate Now"
90
+ noMoneyBuys
91
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
92
+ otherAmountValue={345.67}
93
+ />
94
+ ).toJSON();
95
+
96
+ expect(tree).toMatchSnapshot();
97
+ });
@@ -35,6 +35,7 @@ const Signup = ({
35
35
  PopUpText,
36
36
  chooseAmountText,
37
37
  submitButtonColor,
38
+ otherAmountValue,
38
39
  ...rest
39
40
  }) => {
40
41
  const [givingType, setGivingType] = useState('single');
@@ -46,17 +47,23 @@ const Signup = ({
46
47
  const [popUpShown, setPopUpShown] = useState(false);
47
48
 
48
49
  useEffect(() => {
49
- const givingData = givingType === 'single' ? singleGiving : regularGiving;
50
+ // If a specific 'other amount' has been passed down, use it,
51
+ // otherwise assign based on the associated moneybuys:
52
+ if (otherAmountValue) {
53
+ setAmountDonate(parseFloat(otherAmountValue));
54
+ } else {
55
+ const givingData = givingType === 'single' ? singleGiving : regularGiving;
50
56
 
51
- // Check the 2nd moneybuy exists before using it;
52
- // 'philantrophy' carts have been set up to use a single moneybuy.
53
- // See ENG-1685 for more details
54
- const thisAmount = givingData.moneybuys[1]
55
- ? givingData.moneybuys[1].value
56
- : givingData.moneybuys[0].value;
57
+ // Check the 2nd moneybuy exists before using it;
58
+ // 'philantrophy' carts have been set up to use a single moneybuy.
59
+ // See ENG-1685 for more details
60
+ const thisAmount = givingData.moneybuys[1]
61
+ ? givingData.moneybuys[1].value
62
+ : givingData.moneybuys[0].value;
57
63
 
58
- setAmountDonate(parseFloat(thisAmount));
59
- }, [givingType, singleGiving, regularGiving]);
64
+ setAmountDonate(parseFloat(thisAmount));
65
+ }
66
+ }, [givingType, singleGiving, regularGiving, otherAmountValue]);
60
67
 
61
68
  useEffect(() => {
62
69
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
@@ -124,6 +131,13 @@ const Signup = ({
124
131
  }
125
132
  };
126
133
 
134
+ // Update the local state if the prop has been set and changed
135
+ useEffect(() => {
136
+ if (otherAmountValue) {
137
+ setAmountDonate(parseFloat(otherAmountValue));
138
+ }
139
+ }, [otherAmountValue, setAmountDonate]);
140
+
127
141
  // Create money buy boxes
128
142
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
129
143
  const showGivingSelector = singleGiving !== null && regularGiving !== null;
@@ -239,7 +253,8 @@ Signup.propTypes = {
239
253
  data: PropTypes.objectOf(PropTypes.shape),
240
254
  PopUpText: PropTypes.string.isRequired,
241
255
  chooseAmountText: PropTypes.string.isRequired,
242
- submitButtonColor: PropTypes.string.isRequired
256
+ submitButtonColor: PropTypes.string.isRequired,
257
+ otherAmountValue: PropTypes.number.isRequired
243
258
  };
244
259
 
245
260
  Signup.defaultProps = {