@influenzanet/case-web-app-core 2.7.5-staging.3 → 2.7.5-staging.4

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,5 +1,5 @@
1
- import React from 'react';
2
- import { DefaultRoutes } from '../../../types/routing';
1
+ import React from "react";
2
+ import { DefaultRoutes } from "../../../types/routing";
3
3
  interface LoginProps {
4
4
  defaultRoutes: DefaultRoutes;
5
5
  }
package/build/index.es.js CHANGED
@@ -19800,11 +19800,11 @@ var getErrorMsg = function (err) {
19800
19800
 
19801
19801
  var marginBottomClass$1 = "mb-2";
19802
19802
  var marginTopClass = "mt-2";
19803
- var loginFormI18nPrefix = 'login.credentials';
19804
- var verificationFormI18nPrefix = 'login.verificationCode';
19805
- var signupDisabled = process.env.REACT_APP_DISABLE_SIGNUP === 'true';
19803
+ var loginFormI18nPrefix = "login.credentials";
19804
+ var verificationFormI18nPrefix = "login.verificationCode";
19805
+ var signupDisabled = process.env.REACT_APP_DISABLE_SIGNUP === "true";
19806
19806
  var LoginForm = function (props) {
19807
- var t = useTranslation(['dialogs']).t;
19807
+ var t = useTranslation(["dialogs"]).t;
19808
19808
  var _a = useState({
19809
19809
  email: props.email,
19810
19810
  password: props.password,
@@ -19825,11 +19825,11 @@ var LoginForm = function (props) {
19825
19825
  var isDisabled = function (loginData) {
19826
19826
  return loginData.email.length < 3 || loginData.password.length < 6;
19827
19827
  };
19828
- var rememberMeCheckbox = jsx(Checkbox, { id: "loginDialogRememberMe", className: marginBottomClass$1, name: "rememberMe", checked: loginData.rememberMe, label: t("".concat(loginFormI18nPrefix, ".rememberMeLabel")), onChange: function (checked) {
19828
+ var rememberMeCheckbox = (jsx(Checkbox, { id: "loginDialogRememberMe", className: marginBottomClass$1, name: "rememberMe", checked: loginData.rememberMe, label: t("".concat(loginFormI18nPrefix, ".rememberMeLabel")), onChange: function (checked) {
19829
19829
  setLoginData(function (prev) {
19830
19830
  return __assign(__assign({}, prev), { rememberMe: checked });
19831
19831
  });
19832
- } }, void 0);
19832
+ } }, void 0));
19833
19833
  var infoText = t("".concat(loginFormI18nPrefix, ".info"));
19834
19834
  var emailInputLabel = t("".concat(loginFormI18nPrefix, ".emailInputLabel"));
19835
19835
  var emailInputPlaceholder = t("".concat(loginFormI18nPrefix, ".emailInputPlaceholder"));
@@ -19838,45 +19838,46 @@ var LoginForm = function (props) {
19838
19838
  var loginBtn = t("".concat(loginFormI18nPrefix, ".btn"));
19839
19839
  var passwordForgottenBtn = t("".concat(loginFormI18nPrefix, ".passwordForgottenBtn"));
19840
19840
  var signupBtn = t("".concat(loginFormI18nPrefix, ".signupBtn"));
19841
- return (jsxs(React__default$1.Fragment, { children: [infoText && infoText.length > 0 ?
19842
- jsx(AlertBox, { type: "info", className: marginBottomClass$1, content: infoText }, void 0) : null, jsxs("form", __assign({ onSubmit: function (event) {
19841
+ return (jsxs(React__default$1.Fragment, { children: [infoText && infoText.length > 0 ? (jsx(AlertBox, { type: "info", className: marginBottomClass$1, content: infoText }, void 0)) : null, jsxs("form", __assign({ onSubmit: function (event) {
19843
19842
  event.preventDefault();
19844
19843
  props.onSubmit(loginData.email, loginData.password, loginData.rememberMe);
19845
- } }, { children: [jsx(AlertBox, { className: marginBottomClass$1, hide: !props.error, content: props.error ? props.error : '', type: "danger", useIcon: true, iconSize: "2rem", closable: true, onClose: function () { return props.clearError(); } }, void 0), jsx(TextField, { id: "loginDialogEmail", label: emailInputLabel, placeholder: emailInputPlaceholder, type: "email", name: "email", className: marginBottomClass$1, value: loginData.email, required: true, autoComplete: "email", onChange: function (event) {
19844
+ } }, { children: [jsx(AlertBox, { className: marginBottomClass$1, hide: !props.error, content: props.error ? props.error : "", type: "danger", useIcon: true, iconSize: "2rem", closable: true, onClose: function () { return props.clearError(); } }, void 0), jsx(TextField, { id: "loginDialogEmail", label: emailInputLabel, placeholder: emailInputPlaceholder, type: "email", name: "email", className: marginBottomClass$1, value: loginData.email, required: true, autoComplete: "email", onChange: function (event) {
19846
19845
  var value = event.target.value;
19847
- setLoginData(function (prev) { return __assign(__assign({}, prev), { email: value }); });
19846
+ setLoginData(function (prev) {
19847
+ return __assign(__assign({}, prev), { email: value });
19848
+ });
19848
19849
  } }, void 0), jsx(TextField, { id: "loginDialogPassword", label: passwordInputLabel, placeholder: passwordInputPlaceholder, type: "password", name: "password", className: marginBottomClass$1, value: loginData.password, required: true, disabled: false, autoComplete: "current-password", onChange: function (event) {
19849
19850
  var value = event.target.value;
19850
- setLoginData(function (prev) { return __assign(__assign({}, prev), { password: value }); });
19851
- } }, void 0), rememberMeCheckbox, jsx("div", __assign({ className: marginBottomClass$1 }, { children: jsx(DialogBtn, { type: "submit", label: loginBtn, disabled: isDisabled(loginData) || props.isLoading, loading: props.isLoading, loadingLabel: t('loadingMsg') }, void 0) }), void 0), jsx("div", { children: jsx("button", __assign({ type: "button", className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19851
+ setLoginData(function (prev) {
19852
+ return __assign(__assign({}, prev), { password: value });
19853
+ });
19854
+ } }, void 0), rememberMeCheckbox, jsx("div", __assign({ className: marginBottomClass$1 }, { children: jsx(DialogBtn, { type: "submit", label: loginBtn, disabled: isDisabled(loginData) || props.isLoading, loading: props.isLoading, loadingLabel: t("loadingMsg") }, void 0) }), void 0), jsx("div", { children: jsx("button", __assign({ type: "button", className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19855
+ event.preventDefault();
19856
+ props.onOpenDialog("passwordForgotten");
19857
+ } }, { children: passwordForgottenBtn }), void 0) }, void 0), !signupDisabled ? (jsx("div", __assign({ className: marginTopClass }, { children: jsx("button", __assign({ type: "button", className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19852
19858
  event.preventDefault();
19853
- props.onOpenDialog('passwordForgotten');
19854
- } }, { children: passwordForgottenBtn }), void 0) }, void 0), !signupDisabled ?
19855
- jsx("div", __assign({ className: marginTopClass }, { children: jsx("button", __assign({ type: "button", className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19856
- event.preventDefault();
19857
- props.onOpenDialog('signup');
19858
- } }, { children: signupBtn }), void 0) }), void 0)
19859
- : null] }), void 0)] }, void 0));
19859
+ props.onOpenDialog("signup");
19860
+ } }, { children: signupBtn }), void 0) }), void 0)) : null] }), void 0)] }, void 0));
19860
19861
  };
19861
19862
  var VerificationCodeForm = function (props) {
19862
19863
  var _a = useState(""), verificationCode = _a[0], setVerificationCode = _a[1];
19863
- var t = useTranslation(['dialogs']).t;
19864
+ var t = useTranslation(["dialogs"]).t;
19864
19865
  var onSubmit = function (e) {
19865
19866
  e.preventDefault();
19866
- props.onSubmit(verificationCode.replace('-', ''));
19867
+ props.onSubmit(verificationCode.replace("-", ""));
19867
19868
  };
19868
19869
  var submitButtonEnabled = function () {
19869
- return !props.isLoading && verificationCode.replace('-', '').length === 6;
19870
+ return !props.isLoading && verificationCode.replace("-", "").length === 6;
19870
19871
  };
19871
19872
  var submitBtnLabel = t("".concat(verificationFormI18nPrefix, ".submitBtn"));
19872
19873
  var resendBtnLabel = t("".concat(verificationFormI18nPrefix, ".resendBtn"));
19873
19874
  var infoText = t("".concat(verificationFormI18nPrefix, ".info"));
19874
19875
  var codeInputLabel = t("".concat(verificationFormI18nPrefix, ".codeInputLabel"));
19875
19876
  var codeInputPlaceholder = t("".concat(verificationFormI18nPrefix, ".codeInputPlaceholder"));
19876
- return (jsxs("form", __assign({ noValidate: true, onSubmit: onSubmit }, { children: [jsx(AlertBox, { className: marginBottomClass$1, hide: !props.error, content: props.error ? props.error : '', type: "danger", useIcon: true, iconSize: "2rem", closable: true, onClose: function () { return props.clearError(); } }, void 0), jsx(TextField, { id: "twoFACode", label: codeInputLabel, placeholder: codeInputPlaceholder, type: "text", name: "twoFACode", className: marginBottomClass$1, value: verificationCode, required: true, disabled: false, autoComplete: "off", onChange: function (event) {
19877
+ return (jsxs("form", __assign({ noValidate: true, onSubmit: onSubmit }, { children: [jsx(AlertBox, { className: marginBottomClass$1, hide: !props.error, content: props.error ? props.error : "", type: "danger", useIcon: true, iconSize: "2rem", closable: true, onClose: function () { return props.clearError(); } }, void 0), jsx(TextField, { id: "twoFACode", label: codeInputLabel, placeholder: codeInputPlaceholder, type: "text", name: "twoFACode", className: marginBottomClass$1, value: verificationCode, required: true, disabled: false, autoComplete: "off", onChange: function (event) {
19877
19878
  var value = event.target.value;
19878
19879
  setVerificationCode(value);
19879
- } }, void 0), jsx(DialogBtn, { className: marginBottomClass$1, type: "submit", label: submitBtnLabel, disabled: !submitButtonEnabled(), loading: props.isLoading, loadingLabel: t('loadingMsg') }, void 0), infoText ? jsx(AlertBox, { className: marginBottomClass$1, type: "info", content: infoText }, void 0) : null, jsx("div", { children: jsx("button", __assign({ type: "button", disabled: !props.resendEnabled, className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19880
+ } }, void 0), jsx(DialogBtn, { className: marginBottomClass$1, type: "submit", label: submitBtnLabel, disabled: !submitButtonEnabled(), loading: props.isLoading, loadingLabel: t("loadingMsg") }, void 0), infoText ? (jsx(AlertBox, { className: marginBottomClass$1, type: "info", content: infoText }, void 0)) : null, jsx("div", { children: jsx("button", __assign({ type: "button", disabled: !props.resendEnabled, className: "btn btn-link p-0 text-decoration-none text-start text-uppercase", onClick: function (event) {
19880
19881
  event.preventDefault();
19881
19882
  props.onResendVerificationCode();
19882
19883
  } }, { children: resendBtnLabel }), void 0) }, void 0)] }), void 0));
@@ -19890,27 +19891,35 @@ var Login = function (props) {
19890
19891
  var instanceId = useSelector(function (state) { return state.config.instanceId; });
19891
19892
  var persistState = useSelector(function (state) { return state.app.persistState; });
19892
19893
  var dialogState = useSelector(function (state) { return state.dialog; });
19893
- var open = ((_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.type) === 'login';
19894
- var initialLoginData = open ? dialogState.config.payload : undefined;
19895
- var preventNavigateOnSuccess = open ? (_b = dialogState.config.payload) === null || _b === void 0 ? void 0 : _b.preventNavigateOnSuccess : undefined;
19894
+ var open = ((_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.type) === "login";
19895
+ var initialLoginData = open
19896
+ ? dialogState.config.payload
19897
+ : undefined;
19898
+ var preventNavigateOnSuccess = open
19899
+ ? (_b = dialogState.config.payload) === null || _b === void 0 ? void 0 : _b.preventNavigateOnSuccess
19900
+ : undefined;
19896
19901
  var setAuthState = useSetAuthState();
19897
19902
  var logout = useLogout();
19898
19903
  var history = useHistory();
19899
19904
  var _c = useState(false), verificationStep = _c[0], setVerificationStep = _c[1];
19900
19905
  var _d = useState(false), loading = _d[0], setLoading = _d[1];
19901
- var _e = useState(''), errorMessage = _e[0], setErrorMessage = _e[1];
19906
+ var _e = useState(""), errorMessage = _e[0], setErrorMessage = _e[1];
19902
19907
  var _f = useState(false), resendEnabled = _f[0], setResetEnabled = _f[1];
19903
19908
  var _g = useState(initialLoginData ? initialLoginData.email : ""), emailAddress = _g[0], setEmailAddress = _g[1];
19904
19909
  var _h = useState(initialLoginData ? initialLoginData.password : ""), password = _h[0], setPassword = _h[1];
19905
- var _j = useState(initialLoginData && initialLoginData.verificationCode ? initialLoginData.verificationCode : ""), verificationCode = _j[0], setVerificationCode = _j[1];
19910
+ var _j = useState(initialLoginData && initialLoginData.verificationCode
19911
+ ? initialLoginData.verificationCode
19912
+ : ""), verificationCode = _j[0], setVerificationCode = _j[1];
19906
19913
  var dispatch = useDispatch();
19907
- var _k = useTranslation(['dialogs']), t = _k.t, i18n = _k.i18n;
19914
+ var _k = useTranslation(["dialogs"]), t = _k.t, i18n = _k.i18n;
19908
19915
  useEffect(function () {
19909
19916
  setResetEnabled(false);
19910
19917
  if (open && initialLoginData) {
19911
19918
  setEmailAddress(initialLoginData.email);
19912
19919
  setPassword(initialLoginData.password);
19913
- setVerificationCode(initialLoginData.verificationCode ? initialLoginData.verificationCode : '');
19920
+ setVerificationCode(initialLoginData.verificationCode
19921
+ ? initialLoginData.verificationCode
19922
+ : "");
19914
19923
  dispatch(setPersistState(initialLoginData.rememberMe));
19915
19924
  }
19916
19925
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -19930,14 +19939,14 @@ var Login = function (props) {
19930
19939
  var setAuthFields = function (email, password, rememberMe) {
19931
19940
  setEmailAddress(email);
19932
19941
  setPassword(password);
19933
- setErrorMessage('');
19942
+ setErrorMessage("");
19934
19943
  dispatch(setPersistState(rememberMe));
19935
19944
  };
19936
19945
  var handleClose = function () {
19937
19946
  setEmailAddress("");
19938
19947
  setPassword("");
19939
- setErrorMessage('');
19940
- setVerificationCode('');
19948
+ setErrorMessage("");
19949
+ setVerificationCode("");
19941
19950
  setVerificationStep(false);
19942
19951
  dispatch(dialogActions.closeDialog());
19943
19952
  };
@@ -19949,9 +19958,9 @@ var Login = function (props) {
19949
19958
  case 0:
19950
19959
  if (loading)
19951
19960
  return [2 /*return*/];
19961
+ logout(true);
19952
19962
  setAuthFields(creds.email, creds.password, creds.rememberMe);
19953
19963
  setLoading(true);
19954
- logout(true);
19955
19964
  _c.label = 1;
19956
19965
  case 1:
19957
19966
  _c.trys.push([1, 3, 4, 5]);
@@ -19968,20 +19977,29 @@ var Login = function (props) {
19968
19977
  setVerificationStep(true);
19969
19978
  }
19970
19979
  else {
19971
- response.user.account.accountConfirmedAt = +response.user.account.accountConfirmedAt;
19980
+ response.user.account.accountConfirmedAt =
19981
+ +response.user.account.accountConfirmedAt;
19972
19982
  setAuthState(response.token, response.user);
19973
19983
  currentLangauge = i18n.language;
19974
- if (response.user.account.preferredLanguage && response.user.account.preferredLanguage !== currentLangauge) {
19984
+ if (response.user.account.preferredLanguage &&
19985
+ response.user.account.preferredLanguage !== currentLangauge) {
19975
19986
  i18n.changeLanguage(response.user.account.preferredLanguage);
19976
19987
  }
19977
- if (!response.user.account.accountConfirmedAt || response.user.account.accountConfirmedAt <= 0) {
19978
- dispatch(dialogActions.openDialogWithoutPayload({ type: 'signupSuccess', origin: (_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.origin }));
19988
+ if (!response.user.account.accountConfirmedAt ||
19989
+ response.user.account.accountConfirmedAt <= 0) {
19990
+ dispatch(dialogActions.openDialogWithoutPayload({
19991
+ type: "signupSuccess",
19992
+ origin: (_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.origin,
19993
+ }));
19979
19994
  }
19980
19995
  /*
19981
- * We might already be in the defaultRoutes.auth path because of the change in state that occurs above, which triggers
19982
- * a redirect. The pathname check is to prevent racing conditions and avoid doing multiple api calls
19983
- */
19984
- if (history && history.location.pathname !== props.defaultRoutes.auth && ((_b = dialogState.config) === null || _b === void 0 ? void 0 : _b.origin) !== 'surveyFlow' && !preventNavigateOnSuccess) {
19996
+ * We might already be in the defaultRoutes.auth path because of the change in state that occurs above, which triggers
19997
+ * a redirect. The pathname check is to prevent racing conditions and avoid doing multiple api calls
19998
+ */
19999
+ if (history &&
20000
+ history.location.pathname !== props.defaultRoutes.auth &&
20001
+ ((_b = dialogState.config) === null || _b === void 0 ? void 0 : _b.origin) !== "surveyFlow" &&
20002
+ !preventNavigateOnSuccess) {
19985
20003
  history.push(props.defaultRoutes.auth);
19986
20004
  }
19987
20005
  handleClose();
@@ -20034,51 +20052,54 @@ var Login = function (props) {
20034
20052
  var handleError = function (errorResponse) {
20035
20053
  var error;
20036
20054
  switch (errorResponse) {
20037
- case 'invalid username and/or password':
20038
- error = t('dialogs:login.errors.accountOrPassword');
20055
+ case "invalid username and/or password":
20056
+ error = t("dialogs:login.errors.accountOrPassword");
20039
20057
  break;
20040
- case 'wrong verfication code':
20041
- error = t('dialogs:login.errors.wrongCode');
20058
+ case "wrong verfication code":
20059
+ error = t("dialogs:login.errors.wrongCode");
20042
20060
  break;
20043
- case 'new verfication code':
20044
- error = t('login.errors.newCodeSent');
20061
+ case "new verfication code":
20062
+ error = t("login.errors.newCodeSent");
20045
20063
  break;
20046
- case 'cannot generate verification code so often':
20047
- error = t('login.errors.rateLimit');
20064
+ case "cannot generate verification code so often":
20065
+ error = t("login.errors.rateLimit");
20048
20066
  break;
20049
20067
  default:
20050
- error = t('login.errors.unknown');
20068
+ error = t("login.errors.unknown");
20051
20069
  break;
20052
20070
  }
20053
20071
  setErrorMessage(error);
20054
20072
  };
20055
- return (jsx(Dialog, __assign({ open: open, title: verificationStep ? t("".concat(verificationFormI18nPrefix, ".title")) : t("".concat(loginFormI18nPrefix, ".title")), onClose: handleClose, ariaLabelledBy: "loginDialogTitle" }, { children: jsx("div", __assign({ className: clsx(defaultDialogPaddingXClass, 'py-3', 'bg-grey-1') }, { children: verificationStep ?
20056
- jsx(VerificationCodeForm, { isLoading: loading, onSubmit: function (code) {
20057
- login({
20058
- email: emailAddress,
20059
- password: password,
20060
- rememberMe: persistState,
20061
- verificationCode: code
20062
- });
20063
- }, onResendVerificationCode: function () {
20064
- if (!resendEnabled) {
20065
- console.log('resend not enabled, please wait');
20066
- return;
20067
- }
20068
- resendCode();
20069
- }, resendEnabled: !loading && resendEnabled, error: errorMessage, clearError: function () { return setErrorMessage(''); } }, void 0) :
20070
- jsx(LoginForm, { isLoading: loading, email: emailAddress, password: password, rememberMe: persistState, error: errorMessage, clearError: function () { return setErrorMessage(''); }, onSubmit: function (email, password, rememberMe) {
20071
- login({
20072
- email: email,
20073
- password: password,
20074
- rememberMe: rememberMe,
20075
- verificationCode: verificationCode,
20076
- });
20077
- }, onOpenDialog: function (dialog) {
20078
- var _a;
20079
- handleClose();
20080
- dispatch(dialogActions.openDialogWithoutPayload({ type: dialog, origin: (_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.origin }));
20081
- } }, void 0) }), void 0) }), void 0));
20073
+ return (jsx(Dialog, __assign({ open: open, title: verificationStep
20074
+ ? t("".concat(verificationFormI18nPrefix, ".title"))
20075
+ : t("".concat(loginFormI18nPrefix, ".title")), onClose: handleClose, ariaLabelledBy: "loginDialogTitle" }, { children: jsx("div", __assign({ className: clsx(defaultDialogPaddingXClass, "py-3", "bg-grey-1") }, { children: verificationStep ? (jsx(VerificationCodeForm, { isLoading: loading, onSubmit: function (code) {
20076
+ login({
20077
+ email: emailAddress,
20078
+ password: password,
20079
+ rememberMe: persistState,
20080
+ verificationCode: code,
20081
+ });
20082
+ }, onResendVerificationCode: function () {
20083
+ if (!resendEnabled) {
20084
+ console.log("resend not enabled, please wait");
20085
+ return;
20086
+ }
20087
+ resendCode();
20088
+ }, resendEnabled: !loading && resendEnabled, error: errorMessage, clearError: function () { return setErrorMessage(""); } }, void 0)) : (jsx(LoginForm, { isLoading: loading, email: emailAddress, password: password, rememberMe: persistState, error: errorMessage, clearError: function () { return setErrorMessage(""); }, onSubmit: function (email, password, rememberMe) {
20089
+ login({
20090
+ email: email,
20091
+ password: password,
20092
+ rememberMe: rememberMe,
20093
+ verificationCode: verificationCode,
20094
+ });
20095
+ }, onOpenDialog: function (dialog) {
20096
+ var _a;
20097
+ handleClose();
20098
+ dispatch(dialogActions.openDialogWithoutPayload({
20099
+ type: dialog,
20100
+ origin: (_a = dialogState.config) === null || _a === void 0 ? void 0 : _a.origin,
20101
+ }));
20102
+ } }, void 0)) }), void 0) }), void 0));
20082
20103
  };
20083
20104
 
20084
20105
  var getTranslatedMarkdownPath = function (markdownName, language) {
@@ -21724,7 +21745,7 @@ var initializeActiveSurveysThunk = createAsyncThunk("studies/initializeActiveSur
21724
21745
  return result;
21725
21746
  }, {});
21726
21747
  dispatch(initializeActiveSurveys(profilesToActiveSurveysMap));
21727
- dispatch(initializeActiveSurveyInfos(response.data.surveyInfos));
21748
+ dispatch(initializeActiveSurveyInfos(response.data.surveyInfos || []));
21728
21749
  return [2 /*return*/];
21729
21750
  }
21730
21751
  });