@popmenu/common-ui 0.125.0 → 0.126.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/build/index.es.js CHANGED
@@ -1116,6 +1116,13 @@ var useStyles$2 = makeStyles(function () { return ({
1116
1116
  gridGap: 16,
1117
1117
  },
1118
1118
  }); });
1119
+ var northAmericanPhoneRegex = /^(\()?[2-9]{1}\d{2}(\))?[-\s.]?[2-9]{1}\d{2}[-\s.]?\d{4}$/;
1120
+ var ukPhoneRegex = /^((\+?44\s?|0044\s?)(\s?\d{3,5}|\(\d{3,5}\))(\s?\d{3,4})(\s?\d{3,4})$|^07\d{9}$)/;
1121
+ var validatePhoneNumber = function (phone) {
1122
+ if (!phone)
1123
+ return false;
1124
+ return northAmericanPhoneRegex.test(phone) || ukPhoneRegex.test(phone);
1125
+ };
1119
1126
  var FollowerAuthenticationForm = function () {
1120
1127
  var _a = useFollowerAuthenticationDialogContext(), state = _a.state, messages = _a.messages, locationOptions = _a.locationOptions, onActionButtonClick = _a.onActionButtonClick, loading = _a.loading;
1121
1128
  var classes = useStyles$2();
@@ -1130,24 +1137,33 @@ var FollowerAuthenticationForm = function () {
1130
1137
  var checkFieldValidity = function (e) {
1131
1138
  var _a, _b;
1132
1139
  var fieldName = e.target.name;
1133
- var fieldValidity = (_b = (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.elements.namedItem(fieldName)) === null || _b === void 0 ? void 0 : _b.validity.valid;
1140
+ var fieldValue = e.target.value;
1134
1141
  switch (fieldName) {
1135
1142
  case 'phone':
1136
- setSignUpPhoneValue(e.target.value);
1137
- setShowPhoneErrorText(!fieldValidity);
1143
+ var isPhoneValid = validatePhoneNumber(fieldValue);
1144
+ setSignUpPhoneValue(fieldValue);
1145
+ setShowPhoneErrorText(!isPhoneValid && fieldValue.length > 0);
1138
1146
  break;
1139
1147
  case 'email':
1140
- setSignUpEmailValue(e.target.value);
1141
- setShowEmailErrorText(!fieldValidity);
1148
+ var emailField = (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.elements.namedItem(fieldName);
1149
+ var isEmailValid = (_b = emailField === null || emailField === void 0 ? void 0 : emailField.validity.valid) !== null && _b !== void 0 ? _b : false;
1150
+ setSignUpEmailValue(fieldValue);
1151
+ setShowEmailErrorText(!isEmailValid && fieldValue.length > 0);
1142
1152
  break;
1143
1153
  case 'location':
1144
- setShowLocationErrorText(!e.target.value);
1154
+ setShowLocationErrorText(!fieldValue);
1145
1155
  break;
1146
1156
  }
1147
1157
  };
1148
1158
  useEffect(function () {
1149
- setFormValidity(['phone', 'email', 'location'].every(function (fieldName) { var _a, _b; return (_b = (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.elements.namedItem(fieldName)) === null || _b === void 0 ? void 0 : _b.validity.valid; }));
1150
- }, [showPhoneErrorText, showEmailErrorText, showLocationErrorText, signUpPhoneValue, signUpEmailValue]);
1159
+ var _a;
1160
+ var hasValidPhone = Boolean(signUpPhoneValue) && !showPhoneErrorText;
1161
+ var hasValidEmail = Boolean(signUpEmailValue) && !showEmailErrorText;
1162
+ var locationField = (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.elements.namedItem('location');
1163
+ var hasValidLocation = locationField ? Boolean(locationField.value) : true;
1164
+ var hasValidContact = hasValidPhone || hasValidEmail;
1165
+ setFormValidity(hasValidContact && hasValidLocation);
1166
+ }, [signUpPhoneValue, signUpEmailValue, showPhoneErrorText, showEmailErrorText, showLocationErrorText]);
1151
1167
  var handleSubmit = function (e) {
1152
1168
  e.preventDefault();
1153
1169
  var form = e.target;
@@ -1170,7 +1186,6 @@ var FollowerAuthenticationForm = function () {
1170
1186
  e.preventDefault();
1171
1187
  } }),
1172
1188
  React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpPhoneInputLabel, key: "phone-input", id: "phone-input", name: "phone", onChange: checkFieldValidity, error: showPhoneErrorText, helperText: showPhoneErrorText && messages.signUpPhoneErrorText, inputProps: {
1173
- pattern: '^[0-9]{10}$',
1174
1189
  required: signUpEmailValue ? false : true,
1175
1190
  }, defaultValue: state.context.phone }),
1176
1191
  React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpNameInputLabel, key: "name-input", id: "name-input", name: "name", inputProps: { required: true } }),