@popmenu/common-ui 0.98.0 → 0.100.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.
@@ -31,6 +31,10 @@ export declare type ReducerEvent = {
31
31
  type: 'click-google-continue';
32
32
  } | {
33
33
  type: 'click-sign-up';
34
+ } | {
35
+ type: 'click-email-sign-up';
36
+ } | {
37
+ type: 'click-phone-sign-up';
34
38
  } | {
35
39
  type: 'click-get-code';
36
40
  context: {
@@ -59,7 +63,7 @@ export declare type ReducerEvent = {
59
63
  } | {
60
64
  type: 'start-facebook-auth';
61
65
  };
62
- declare type MessageKey = `${ReducerStateValue}Title` | `${ReducerStateValue}Info` | `${ReducerStateValue}GraphicAlt` | 'indirectUserFoundLabel' | 'indirectUserFoundCtaButtonLabel' | 'indirectUserFoundCtaButtonLabelAlt' | 'signUpPhoneInputLabel' | 'signUpNameInputLabel' | 'signUpEmailInputLabel' | 'signUpLocationInputLabel' | 'signUpBirthdaySectionLabel' | 'signUpMonthInputLabel' | 'signUpDayInputLabel' | 'signUp' | 'signUpFinePrint' | 'emailFoundInputLabel' | 'emailFoundCtaButtonLabel' | 'phoneFoundInputLabel' | 'phoneFoundCtaButtonLabel' | 'emailAuthCodeInputLabel' | 'phoneAuthCodeInputLabel' | 'or' | 'popmenuLogoAlt' | 'continueWithFacebookButtonLabel' | 'continueWithGoogleButtonLabel' | 'initialCtaButtonLabel' | 'initialInputLabel' | 'passwordInputLabel' | 'poweredBy' | 'done' | 'signIn' | 'signInWithPassword';
66
+ declare type MessageKey = `${ReducerStateValue}Title` | `${ReducerStateValue}Info` | `${ReducerStateValue}GraphicAlt` | 'indirectUserFoundLabel' | 'indirectUserFoundCtaButtonLabel' | 'indirectUserFoundCtaButtonLabelAlt' | 'signUpPhoneErrorText' | 'signUpPhoneInputLabel' | 'signUpNameInputLabel' | 'signUpEmailErrorText' | 'signUpEmailInputLabel' | 'signUpLocationErrorText' | 'signUpLocationInputLabel' | 'signUpBirthdaySectionLabel' | 'signUpMonthInputLabel' | 'signUpDayInputLabel' | 'signUp' | 'signUpFinePrint' | 'emailFoundInputLabel' | 'emailFoundCtaButtonLabel' | 'phoneFoundInputLabel' | 'phoneFoundCtaButtonLabel' | 'emailAuthCodeInputLabel' | 'phoneAuthCodeInputLabel' | 'or' | 'popmenuLogoAlt' | 'continueWithFacebookButtonLabel' | 'continueWithGoogleButtonLabel' | 'initialCtaButtonLabel' | 'initialInputLabel' | 'passwordInputLabel' | 'poweredBy' | 'done' | 'signIn' | 'signInWithPassword';
63
67
  declare type LocationOption = {
64
68
  label: string;
65
69
  value: string;
package/build/index.es.js CHANGED
@@ -1105,6 +1105,35 @@ var useStyles$2 = makeStyles(function () { return ({
1105
1105
  var FollowerAuthenticationForm = function () {
1106
1106
  var _a = useFollowerAuthenticationDialogContext(), state = _a.state, messages = _a.messages, locationOptions = _a.locationOptions, dispatch = _a.dispatch, loading = _a.loading;
1107
1107
  var classes = useStyles$2();
1108
+ // sign-up form state
1109
+ var formRef = useRef(null);
1110
+ var _b = useState(false), formValidity = _b[0], setFormValidity = _b[1];
1111
+ var _c = useState(), showPhoneErrorText = _c[0], setShowPhoneErrorText = _c[1];
1112
+ var _d = useState(), showEmailErrorText = _d[0], setShowEmailErrorText = _d[1];
1113
+ var _e = useState(), showLocationErrorText = _e[0], setShowLocationErrorText = _e[1];
1114
+ var _f = useState(state.defaultFormValues.phone || ''), signUpPhoneValue = _f[0], setSignUpPhoneValue = _f[1];
1115
+ var _g = useState(state.defaultFormValues.email || ''), signUpEmailValue = _g[0], setSignUpEmailValue = _g[1];
1116
+ var checkFieldValidity = function (e) {
1117
+ var _a, _b;
1118
+ var fieldName = e.target.name;
1119
+ 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;
1120
+ switch (fieldName) {
1121
+ case 'phone':
1122
+ setSignUpPhoneValue(e.target.value);
1123
+ setShowPhoneErrorText(!fieldValidity);
1124
+ break;
1125
+ case 'email':
1126
+ setSignUpEmailValue(e.target.value);
1127
+ setShowEmailErrorText(!fieldValidity);
1128
+ break;
1129
+ case 'location':
1130
+ setShowLocationErrorText(!e.target.value);
1131
+ break;
1132
+ }
1133
+ };
1134
+ useEffect(function () {
1135
+ 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; }));
1136
+ }, [showPhoneErrorText, showEmailErrorText, showLocationErrorText, signUpPhoneValue, signUpEmailValue]);
1108
1137
  var handleSubmit = function (e) {
1109
1138
  e.preventDefault();
1110
1139
  var form = e.target;
@@ -1123,15 +1152,23 @@ var FollowerAuthenticationForm = function () {
1123
1152
  React__default.createElement(TextField$1, { disabled: loading, label: messages.initialInputLabel, key: "identifier-input", id: "identifier-input", name: "identifier" }),
1124
1153
  React__default.createElement(Button$1, { disabled: loading, type: "submit" }, messages.initialCtaButtonLabel)));
1125
1154
  case 'signUp':
1126
- return (React__default.createElement("form", __assign({}, formProps),
1127
- React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpPhoneInputLabel, key: "phone-input", id: "phone-input", name: "phone" }),
1128
- React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpNameInputLabel, key: "name-input", id: "name-input", name: "name" }),
1129
- React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpEmailInputLabel, key: "email-input", id: "email-input", name: "email" }),
1130
- React__default.createElement(TextField$1, { disabled: loading, select: true, label: messages.signUpLocationInputLabel, key: "location-input", id: "location-input", name: "location" }, locationOptions.map(function (locationOption) { return (React__default.createElement(MenuItem, { key: locationOption.value, value: locationOption.value }, locationOption.label)); })),
1155
+ return (React__default.createElement("form", __assign({ ref: formRef }, formProps, { onInvalid: function (e) {
1156
+ e.preventDefault();
1157
+ } }),
1158
+ 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: {
1159
+ pattern: '^[0-9]{10}$',
1160
+ required: signUpEmailValue ? false : true,
1161
+ } }),
1162
+ React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpNameInputLabel, key: "name-input", id: "name-input", name: "name", inputProps: { required: true } }),
1163
+ React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpEmailInputLabel, key: "email-input", id: "email-input", name: "email", error: showEmailErrorText, helperText: showEmailErrorText && messages.signUpEmailErrorText, onChange: checkFieldValidity, inputProps: {
1164
+ required: signUpPhoneValue ? false : true,
1165
+ type: 'email',
1166
+ } }),
1167
+ React__default.createElement(TextField$1, { disabled: loading, select: true, onChange: checkFieldValidity, label: messages.signUpLocationInputLabel, error: showLocationErrorText, helperText: showLocationErrorText && messages.signUpLocationErrorText, key: "location-input", id: "location-input", inputProps: { required: true }, name: "location" }, locationOptions.map(function (locationOption) { return (React__default.createElement(MenuItem, { "data-cy": 'option', key: locationOption.value, value: locationOption.value }, locationOption.label)); })),
1131
1168
  React__default.createElement(Typography$1, { style: { alignSelf: 'start' } }, messages.signUpBirthdaySectionLabel),
1132
1169
  React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpMonthInputLabel, key: "birthday-month-input", id: "birthday-month-input", name: "birthdayMonth" }),
1133
1170
  React__default.createElement(TextField$1, { disabled: loading, label: messages.signUpDayInputLabel, key: "birthday-date-input", id: "birthday-date-input", name: "birthdayDate" }),
1134
- React__default.createElement(Button$1, { disabled: loading, type: "submit" }, messages.signUp)));
1171
+ React__default.createElement(Button$1, { disabled: loading || !formValidity, type: "submit" }, messages.signUp)));
1135
1172
  case 'emailFound':
1136
1173
  return (React__default.createElement("form", __assign({}, formProps),
1137
1174
  React__default.createElement(TextField$1, { disabled: loading, label: messages.emailFoundInputLabel, key: "email-input", id: "email-input", name: "email", value: state.defaultFormValues.email }),
@@ -1230,7 +1267,7 @@ var FollowerAuthenticationAltActions = function () {
1230
1267
  } }, messages.phoneFoundCtaButtonLabel)));
1231
1268
  case 'welcome':
1232
1269
  return (React__default.createElement(Button$1, { onClick: function () {
1233
- dispatch({ type: 'click-sign-up' });
1270
+ dispatch({ type: 'click-done' });
1234
1271
  } }, messages.done));
1235
1272
  default:
1236
1273
  return null;