@comicrelief/component-library 7.2.0 → 7.3.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.
@@ -65,6 +65,17 @@ var Signup = function Signup(_ref) {
65
65
  moneyBuyCopy = _useState8[0],
66
66
  setMoneyBuyCopy = _useState8[1];
67
67
 
68
+ var _useState9 = (0, _react.useState)(false),
69
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
70
+ popOpen = _useState10[0],
71
+ setPopOpen = _useState10[1]; // In order to keep track of whether the user has ever been shown the popup
72
+
73
+
74
+ var _useState11 = (0, _react.useState)(false),
75
+ _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
76
+ popUpShown = _useState12[0],
77
+ setPopUpShown = _useState12[1];
78
+
68
79
  (0, _react.useEffect)(function () {
69
80
  var givingData = givingType === 'single' ? singleGiving : regularGiving; // Check the 2nd moneybuy exists before using it;
70
81
  // 'philantrophy' carts have been set up to use a single moneybuy.
@@ -91,13 +102,18 @@ var Signup = function Signup(_ref) {
91
102
  if (errorMsg) setErrorMsg(false);
92
103
  setMoneyBuyCopy(moneyBuyNewDescription);
93
104
  }
94
- }, [errorMsg, moneyBuyCopy, singleGiving, regularGiving, givingType, amountDonate, otherDescription]);
105
+ }, [errorMsg, moneyBuyCopy, singleGiving, regularGiving, givingType, amountDonate, otherDescription]); // Updates our flag that differentiates between the popup
106
+ // being *currently* open and it *ever* having been shown to user
107
+
108
+ (0, _react.useEffect)(function () {
109
+ if (popOpen && !popUpShown) setPopUpShown(true);
110
+ }, [popOpen, popUpShown]);
95
111
 
96
112
  var submitDonation = function submitDonation(event, amount, clientId, cartId, mbshipId, donateURL) {
97
113
  event.preventDefault();
98
114
 
99
115
  if ((0, _Membership.isAmountValid)(amount) && !errorMsg) {
100
- (0, _Membership.handleDonateSubmission)(amount, clientId, cartId, mbshipId, donateURL, givingType);
116
+ (0, _Membership.handleDonateSubmission)(amount, clientId, cartId, mbshipId, donateURL, givingType, popUpShown);
101
117
  } else {
102
118
  setErrorMsg(true);
103
119
  setMoneyBuyCopy(false);
@@ -107,12 +123,6 @@ var Signup = function Signup(_ref) {
107
123
 
108
124
  var givingData = givingType === 'single' ? singleGiving : regularGiving;
109
125
  var showGivingSelector = singleGiving !== null && regularGiving !== null;
110
-
111
- var _useState9 = (0, _react.useState)(false),
112
- _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
113
- popOpen = _useState10[0],
114
- setPopOpen = _useState10[1];
115
-
116
126
  return /*#__PURE__*/_react.default.createElement(_Donate.FormWrapper, null, showGivingSelector && /*#__PURE__*/_react.default.createElement(_GivingSelector.default, {
117
127
  givingType: givingType,
118
128
  changeGivingType: function changeGivingType(data) {
@@ -121,7 +131,8 @@ var Signup = function Signup(_ref) {
121
131
  setPopOpen: setPopOpen,
122
132
  mbshipID: mbshipID
123
133
  }), popOpen && /*#__PURE__*/_react.default.createElement(_PopUpComponent.default, {
124
- PopUpText: PopUpText
134
+ PopUpText: PopUpText,
135
+ setPopOpen: setPopOpen
125
136
  }), /*#__PURE__*/_react.default.createElement(_Donate.Form, {
126
137
  onSubmit: function onSubmit(e) {
127
138
  return submitDonation(e, amountDonate, clientID, cartID, mbshipID, donateLink);
@@ -23,7 +23,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
23
23
 
24
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
25
 
26
- /* eslint-disable */
26
+ var closeDuration = 0.6;
27
27
  var fadeClose = (0, _styledComponents.keyframes)(["0%{opacity:1;max-height:350px;}100%{opacity:0;max-height:0px;display:none;margin-top:-16px;}"]);
28
28
  var fadeOpen = (0, _styledComponents.keyframes)(["0%{opacity:0;max-height:0px;display:none;margin-top:-16px;}100%{opacity:1;max-height:350px;}"]);
29
29
 
@@ -31,7 +31,7 @@ var StyledPopUp = _styledComponents.default.div.withConfig({
31
31
  displayName: "PopUpComponent__StyledPopUp",
32
32
  componentId: "sc-1d7imlo-0"
33
33
  })(["display:grid;overflow:hidden;max-height:350px;opacity:1;animation:0.4s ", " ease;", " background-color:", ";box-shadow:0px 0px 16px rgba(0,0,0,0.15);border-radius:10px;", "{width:450px;margin-right:auto;margin-left:auto;}"], fadeOpen, function (props) {
34
- return props.isClosed && (0, _styledComponents.css)(["animation:0.6s ", " ease forwards;"], fadeClose);
34
+ return props.isClosed && (0, _styledComponents.css)(["animation:", "s ", " ease forwards;"], closeDuration, fadeClose);
35
35
  }, function (_ref) {
36
36
  var theme = _ref.theme;
37
37
  return theme.color('blue_light');
@@ -51,18 +51,28 @@ var Button = _styledComponents.default.button.withConfig({
51
51
  });
52
52
 
53
53
  var PopUpComponent = function PopUpComponent(_ref3) {
54
- var PopUpText = _ref3.PopUpText;
54
+ var PopUpText = _ref3.PopUpText,
55
+ setPopOpen = _ref3.setPopOpen;
55
56
 
56
57
  var _useState = (0, _react.useState)(false),
57
58
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
58
59
  isClosed = _useState2[0],
59
- setIsClosed = _useState2[1];
60
+ setIsClosed = _useState2[1]; // Only update centralised state - which renders
61
+ // this component - once the closing animation is complete
62
+
63
+
64
+ var handleCloser = function handleCloser() {
65
+ setIsClosed(true);
66
+ setTimeout(function () {
67
+ setPopOpen(false);
68
+ }, closeDuration * 1000);
69
+ };
60
70
 
61
71
  return /*#__PURE__*/_react.default.createElement(StyledPopUp, {
62
72
  isClosed: isClosed
63
73
  }, /*#__PURE__*/_react.default.createElement(Button, {
64
74
  onClick: function onClick() {
65
- return setIsClosed(true);
75
+ return handleCloser();
66
76
  },
67
77
  "aria-label": "Close"
68
78
  }, /*#__PURE__*/_react.default.createElement("img", {
@@ -16,6 +16,15 @@ var GivingSelector = function GivingSelector(_ref) {
16
16
  changeGivingType = _ref.changeGivingType,
17
17
  setPopOpen = _ref.setPopOpen,
18
18
  mbshipID = _ref.mbshipID;
19
+
20
+ // Only updates giving type and popup status when appropriate
21
+ var handleGivingTypeChange = function handleGivingTypeChange(thisButtonType, currentGivingType) {
22
+ if (currentGivingType !== thisButtonType) {
23
+ changeGivingType(thisButtonType);
24
+ setPopOpen(thisButtonType === 'single');
25
+ }
26
+ };
27
+
19
28
  return /*#__PURE__*/_react.default.createElement(_GivingSelector.Wrapper, null, /*#__PURE__*/_react.default.createElement(_GivingSelector.MoneyBox, null, /*#__PURE__*/_react.default.createElement("input", {
20
29
  className: "give-once",
21
30
  "aria-label": "Single",
@@ -26,8 +35,7 @@ var GivingSelector = function GivingSelector(_ref) {
26
35
  errormsg: "",
27
36
  checked: givingType === 'single',
28
37
  onClick: function onClick() {
29
- changeGivingType('single');
30
- setPopOpen(true);
38
+ return handleGivingTypeChange('single', givingType);
31
39
  }
32
40
  }), /*#__PURE__*/_react.default.createElement(_GivingSelector.Label, {
33
41
  active: givingType === 'single',
@@ -42,8 +50,7 @@ var GivingSelector = function GivingSelector(_ref) {
42
50
  errormsg: "",
43
51
  checked: givingType === 'monthly',
44
52
  onClick: function onClick() {
45
- changeGivingType('monthly');
46
- setPopOpen(false);
53
+ return handleGivingTypeChange('monthly', givingType);
47
54
  }
48
55
  }), /*#__PURE__*/_react.default.createElement(_GivingSelector.Label, {
49
56
  active: givingType === 'monthly',
@@ -42,6 +42,7 @@ exports.isInputMatchBoxValue = isInputMatchBoxValue;
42
42
 
43
43
  var handleDonateSubmission = function handleDonateSubmission(amount, clientID, cartID, mbshipID, donateLink) {
44
44
  var givingType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'monthly';
45
+ var popUpShown = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
45
46
  var currentpageUrl = window.location.href;
46
47
  var affiliateValue = getUrlParameter(currentpageUrl);
47
48
  var reg = /[#?|[\]\\]/g;
@@ -52,7 +53,7 @@ var handleDonateSubmission = function handleDonateSubmission(amount, clientID, c
52
53
  }
53
54
 
54
55
  var givingTypeUrl = givingType === 'single' ? 'single' : 'monthly';
55
- window.location.href = "".concat(donateLink, "?clientOverride=").concat(clientID, "&amount=").concat(amount, "&currency=GBP&givingType=").concat(givingTypeUrl, "&cartId=").concat(cartID, "&affiliate=").concat(affiliateValue, "&siteurl=").concat(currentpageUrl, "&rowID=").concat(mbshipID);
56
+ window.location.href = "".concat(donateLink, "?clientOverride=").concat(clientID, "&amount=").concat(amount, "&currency=GBP&givingType=").concat(givingTypeUrl, "&cartId=").concat(cartID, "&affiliate=").concat(affiliateValue, "&siteurl=").concat(currentpageUrl, "&rowID=").concat(mbshipID, "&popUpShown=").concat(popUpShown);
56
57
  };
57
58
 
58
59
  exports.handleDonateSubmission = handleDonateSubmission;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@comicrelief/component-library",
3
3
  "author": "Comic Relief Engineering Team",
4
- "version": "7.2.0",
4
+ "version": "7.3.0",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -39,6 +39,9 @@ const Signup = ({
39
39
  const [errorMsg, setErrorMsg] = useState(false);
40
40
  const [amountDonate, setAmountDonate] = useState(' ');
41
41
  const [moneyBuyCopy, setMoneyBuyCopy] = useState(true);
42
+ const [popOpen, setPopOpen] = useState(false);
43
+ // In order to keep track of whether the user has ever been shown the popup
44
+ const [popUpShown, setPopUpShown] = useState(false);
42
45
 
43
46
  useEffect(() => {
44
47
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
@@ -88,6 +91,12 @@ const Signup = ({
88
91
  otherDescription
89
92
  ]);
90
93
 
94
+ // Updates our flag that differentiates between the popup
95
+ // being *currently* open and it *ever* having been shown to user
96
+ useEffect(() => {
97
+ if (popOpen && !popUpShown) setPopUpShown(true);
98
+ }, [popOpen, popUpShown]);
99
+
91
100
  const submitDonation = (
92
101
  event,
93
102
  amount,
@@ -104,7 +113,8 @@ const Signup = ({
104
113
  cartId,
105
114
  mbshipId,
106
115
  donateURL,
107
- givingType
116
+ givingType,
117
+ popUpShown
108
118
  );
109
119
  } else {
110
120
  setErrorMsg(true);
@@ -116,8 +126,6 @@ const Signup = ({
116
126
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
117
127
  const showGivingSelector = singleGiving !== null && regularGiving !== null;
118
128
 
119
- const [popOpen, setPopOpen] = useState(false);
120
-
121
129
  return (
122
130
  <FormWrapper>
123
131
  {showGivingSelector && (
@@ -129,7 +137,7 @@ const Signup = ({
129
137
  />
130
138
  )}
131
139
 
132
- { popOpen && <PopUpComponent PopUpText={PopUpText} /> }
140
+ { popOpen && <PopUpComponent PopUpText={PopUpText} setPopOpen={setPopOpen} /> }
133
141
 
134
142
  <Form
135
143
  onSubmit={e => submitDonation(
@@ -1,11 +1,12 @@
1
- /* eslint-disable */
2
1
  import React, { useState } from 'react';
3
2
  import styled, { css, keyframes } from 'styled-components';
3
+ import PropTypes from 'prop-types';
4
4
  import Text from '../../../Atoms/Text/Text';
5
5
  import { media } from '../../../../theme/shared/size';
6
- import PropTypes from 'prop-types';
7
6
  import CloseCross from '../assets/close.svg';
8
7
 
8
+ const closeDuration = 0.6;
9
+
9
10
  const fadeClose = keyframes`
10
11
  0% {
11
12
  opacity: 1;
@@ -39,7 +40,7 @@ const StyledPopUp = styled.div`
39
40
  opacity: 1;
40
41
  animation: 0.4s ${fadeOpen} ease;
41
42
  ${props => props.isClosed && css`
42
- animation: 0.6s ${fadeClose} ease forwards;
43
+ animation: ${closeDuration}s ${fadeClose} ease forwards;
43
44
  `}
44
45
  background-color: ${({ theme }) => theme.color('blue_light')};
45
46
  box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.15);
@@ -78,23 +79,33 @@ const Button = styled.button`
78
79
  }
79
80
  `;
80
81
 
81
- const PopUpComponent = ({ PopUpText }) => {
82
+ const PopUpComponent = ({ PopUpText, setPopOpen }) => {
82
83
  const [isClosed, setIsClosed] = useState(false);
83
84
 
85
+ // Only update centralised state - which renders
86
+ // this component - once the closing animation is complete
87
+ const handleCloser = () => {
88
+ setIsClosed(true);
89
+ setTimeout(() => {
90
+ setPopOpen(false);
91
+ }, closeDuration * 1000);
92
+ };
93
+
84
94
  return (
85
95
  <StyledPopUp isClosed={isClosed}>
86
- <Button onClick={() => setIsClosed(true)} aria-label="Close">
87
- <img src={CloseCross} alt="Close cross icon"/>
96
+ <Button onClick={() => handleCloser()} aria-label="Close">
97
+ <img src={CloseCross} alt="Close cross icon" />
88
98
  </Button>
89
99
  <TextWrapper>
90
100
  <Text>{ PopUpText }</Text>
91
101
  </TextWrapper>
92
102
  </StyledPopUp>
93
- )
103
+ );
94
104
  };
95
105
 
96
106
  PopUpComponent.propTypes = {
97
- PopUpText: PropTypes.string.isRequired
107
+ PopUpText: PropTypes.string.isRequired,
108
+ setPopOpen: PropTypes.func.isRequired
98
109
  };
99
110
 
100
111
  export default PopUpComponent;
@@ -7,47 +7,51 @@ import {
7
7
 
8
8
  const GivingSelector = ({
9
9
  givingType, changeGivingType, setPopOpen, mbshipID
10
- }) => (
11
- <Wrapper>
12
- <MoneyBox>
13
- <input
14
- className="give-once"
15
- aria-label="Single"
16
- id={`give-once--${mbshipID}`}
17
- value="Single"
18
- type="radio"
19
- label=""
20
- errormsg=""
21
- checked={givingType === 'single'}
22
- onClick={() => {
23
- changeGivingType('single');
24
- setPopOpen(true);
25
- }}
26
- />
27
- <Label active={givingType === 'single'} htmlFor={`give-once--${mbshipID}`}>
28
- Single
29
- </Label>
30
- <input
31
- className="give-monthly"
32
- aria-label="Monthly"
33
- id={`give-monthly--${mbshipID}`}
34
- value="Monthly"
35
- type="radio"
36
- label=""
37
- errormsg=""
38
- checked={givingType === 'monthly'}
39
- onClick={() => {
40
- changeGivingType('monthly');
41
- setPopOpen(false);
42
- }}
43
- />
44
- <Label active={givingType === 'monthly'} htmlFor={`give-monthly--${mbshipID}`}>
45
- Monthly
46
- </Label>
47
- <Switch />
48
- </MoneyBox>
49
- </Wrapper>
50
- );
10
+ }) => {
11
+ // Only updates giving type and popup status when appropriate
12
+ const handleGivingTypeChange = (thisButtonType, currentGivingType) => {
13
+ if (currentGivingType !== thisButtonType) {
14
+ changeGivingType(thisButtonType);
15
+ setPopOpen(thisButtonType === 'single');
16
+ }
17
+ };
18
+
19
+ return (
20
+ <Wrapper>
21
+ <MoneyBox>
22
+ <input
23
+ className="give-once"
24
+ aria-label="Single"
25
+ id={`give-once--${mbshipID}`}
26
+ value="Single"
27
+ type="radio"
28
+ label=""
29
+ errormsg=""
30
+ checked={givingType === 'single'}
31
+ onClick={() => handleGivingTypeChange('single', givingType)}
32
+ />
33
+ <Label active={givingType === 'single'} htmlFor={`give-once--${mbshipID}`}>
34
+ Single
35
+ </Label>
36
+ <input
37
+ className="give-monthly"
38
+ aria-label="Monthly"
39
+ id={`give-monthly--${mbshipID}`}
40
+ value="Monthly"
41
+ type="radio"
42
+ label=""
43
+ errormsg=""
44
+ checked={givingType === 'monthly'}
45
+ onClick={() => handleGivingTypeChange('monthly', givingType)}
46
+ />
47
+ <Label active={givingType === 'monthly'} htmlFor={`give-monthly--${mbshipID}`}>
48
+ Monthly
49
+ </Label>
50
+ <Switch />
51
+ </MoneyBox>
52
+ </Wrapper>
53
+ );
54
+ };
51
55
 
52
56
  GivingSelector.propTypes = {
53
57
  givingType: PropTypes.string.isRequired,
@@ -42,7 +42,8 @@ const handleDonateSubmission = (
42
42
  cartID,
43
43
  mbshipID,
44
44
  donateLink,
45
- givingType = 'monthly'
45
+ givingType = 'monthly',
46
+ popUpShown = null
46
47
  ) => {
47
48
  let currentpageUrl = window.location.href;
48
49
  const affiliateValue = getUrlParameter(currentpageUrl);
@@ -56,7 +57,7 @@ const handleDonateSubmission = (
56
57
  }
57
58
  const givingTypeUrl = givingType === 'single' ? 'single' : 'monthly';
58
59
 
59
- window.location.href = `${donateLink}?clientOverride=${clientID}&amount=${amount}&currency=GBP&givingType=${givingTypeUrl}&cartId=${cartID}&affiliate=${affiliateValue}&siteurl=${currentpageUrl}&rowID=${mbshipID}`;
60
+ window.location.href = `${donateLink}?clientOverride=${clientID}&amount=${amount}&currency=GBP&givingType=${givingTypeUrl}&cartId=${cartID}&affiliate=${affiliateValue}&siteurl=${currentpageUrl}&rowID=${mbshipID}&popUpShown=${popUpShown}`;
60
61
  };
61
62
 
62
63
  export {