@mseva/digit-ui-module-core 1.0.66-dev.1.2 → 1.0.66-dev.1.3

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.
@@ -11754,6 +11754,69 @@ const Header = () => {
11754
11754
  });
11755
11755
  };
11756
11756
 
11757
+ const OtpInput = ({
11758
+ otp,
11759
+ onOtpChange,
11760
+ onVerifyOtp,
11761
+ onResendOtp,
11762
+ canSubmit,
11763
+ isOtpValid
11764
+ }) => {
11765
+ const {
11766
+ t
11767
+ } = useTranslation();
11768
+ const [timeLeft, setTimeLeft] = useState(30);
11769
+ useEffect(() => {
11770
+ if (timeLeft === 0) return;
11771
+ const timer = setInterval(() => {
11772
+ setTimeLeft(prev => {
11773
+ if (prev <= 1) {
11774
+ clearInterval(timer);
11775
+ return 0;
11776
+ }
11777
+ return prev - 1;
11778
+ });
11779
+ }, 1000);
11780
+ return () => clearInterval(timer);
11781
+ }, [timeLeft]);
11782
+ const handleResendOtp = () => {
11783
+ onResendOtp && onResendOtp();
11784
+ setTimeLeft(30);
11785
+ };
11786
+ return /*#__PURE__*/React.createElement("div", {
11787
+ className: "input-wrapper"
11788
+ }, /*#__PURE__*/React.createElement("div", {
11789
+ style: {
11790
+ paddingLeft: "20px"
11791
+ },
11792
+ className: "label"
11793
+ }, t("CS_LOGIN_OTP")), /*#__PURE__*/React.createElement(FormStep, {
11794
+ onSelect: onVerifyOtp,
11795
+ config: {
11796
+ texts: {
11797
+ submitBarLabel: t("CS_COMMON_SUBMIT")
11798
+ }
11799
+ },
11800
+ t: t,
11801
+ isDisabled: !((otp === null || otp === void 0 ? void 0 : otp.length) === 6 && canSubmit),
11802
+ cardStyle: {
11803
+ backgroundColor: "transparent",
11804
+ boxShadow: "none",
11805
+ WebkitBoxShadow: "none",
11806
+ padding: "20px"
11807
+ }
11808
+ }, /*#__PURE__*/React.createElement(OTPInput, {
11809
+ length: 6,
11810
+ onChange: onOtpChange,
11811
+ value: otp
11812
+ }), timeLeft > 0 ? /*#__PURE__*/React.createElement("div", {
11813
+ className: "resendIn"
11814
+ }, t("CS_RESEND_ANOTHER_OTP"), " ", /*#__PURE__*/React.createElement("span", null, timeLeft), " ", t("CS_RESEND_SECONDS")) : /*#__PURE__*/React.createElement("div", {
11815
+ className: "card-text-button resend",
11816
+ onClick: handleResendOtp
11817
+ }, t("CS_RESEND_OTP")), !isOtpValid && /*#__PURE__*/React.createElement(CardLabelError$1, null, t("CS_INVALID_OTP"))));
11818
+ };
11819
+
11757
11820
  const setEmployeeDetail = (userObject, token) => {
11758
11821
  var _JSON$parse;
11759
11822
  let locale = ((_JSON$parse = JSON.parse(sessionStorage.getItem("Digit.locale"))) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.value) || "en_IN";
@@ -11784,9 +11847,13 @@ const Login = ({
11784
11847
  const [showToast, setShowToast] = useState(null);
11785
11848
  const [disable, setDisable] = useState(false);
11786
11849
  const [isForgotPasswordView, setIsForgotPasswordView] = useState(false);
11850
+ const [showOTP, setShowOTP] = useState(false);
11851
+ const [otp, setOtp] = useState("");
11852
+ const [isOtpValid, setIsOtpValid] = useState(true);
11853
+ const [canSubmit, setCanSubmit] = useState(true);
11787
11854
  const history = useHistory();
11788
11855
  useEffect(() => {
11789
- var _user$info, _user$info$roles, _user$info2, _user$info2$roles, _window, _window$location, _window$location$href, _user$info3, _user$info4, _user$info4$roles, _user$info5, _user$info5$roles, _user$info6, _user$info7, _user$info7$roles, _user$info8, _user$info8$roles;
11856
+ var _user$info, _user$info$roles, _user$info2, _user$info2$roles, _window, _window$location, _window$location$href;
11790
11857
  if (!user) {
11791
11858
  return;
11792
11859
  }
@@ -11800,20 +11867,12 @@ const Login = ({
11800
11867
  var _window2, _window2$location, _window2$location$hre, _window2$location$hre2;
11801
11868
  redirectPath = decodeURIComponent((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$location = _window2.location) === null || _window2$location === void 0 ? void 0 : (_window2$location$hre = _window2$location.href) === null || _window2$location$hre === void 0 ? void 0 : (_window2$location$hre2 = _window2$location$hre.split("from=")) === null || _window2$location$hre2 === void 0 ? void 0 : _window2$location$hre2[1]) || "/digit-ui/employee";
11802
11869
  }
11803
- if (user !== null && user !== void 0 && (_user$info3 = user.info) !== null && _user$info3 !== void 0 && _user$info3.roles && (user === null || user === void 0 ? void 0 : (_user$info4 = user.info) === null || _user$info4 === void 0 ? void 0 : (_user$info4$roles = _user$info4.roles) === null || _user$info4$roles === void 0 ? void 0 : _user$info4$roles.length) > 0 && user !== null && user !== void 0 && (_user$info5 = user.info) !== null && _user$info5 !== void 0 && (_user$info5$roles = _user$info5.roles) !== null && _user$info5$roles !== void 0 && _user$info5$roles.every(e => e.code === "NATADMIN")) {
11804
- redirectPath = "/digit-ui/employee/dss/landing/NURT_DASHBOARD";
11805
- }
11806
- if (user !== null && user !== void 0 && (_user$info6 = user.info) !== null && _user$info6 !== void 0 && _user$info6.roles && (user === null || user === void 0 ? void 0 : (_user$info7 = user.info) === null || _user$info7 === void 0 ? void 0 : (_user$info7$roles = _user$info7.roles) === null || _user$info7$roles === void 0 ? void 0 : _user$info7$roles.length) > 0 && user !== null && user !== void 0 && (_user$info8 = user.info) !== null && _user$info8 !== void 0 && (_user$info8$roles = _user$info8.roles) !== null && _user$info8$roles !== void 0 && _user$info8$roles.every(e => e.code === "STADMIN")) {
11807
- redirectPath = "/digit-ui/employee/dss/landing/home";
11808
- }
11809
- history.replace(redirectPath);
11810
11870
  }, [user]);
11811
11871
  const onLogin = async data => {
11812
11872
  if (!data.city) {
11813
11873
  alert("Please Select City!");
11814
11874
  return;
11815
11875
  }
11816
- setDisable(true);
11817
11876
  const requestData = {
11818
11877
  ...data,
11819
11878
  userType: "EMPLOYEE"
@@ -11825,6 +11884,16 @@ const Login = ({
11825
11884
  UserRequest: info,
11826
11885
  ...tokens
11827
11886
  } = await Digit.UserService.authenticate(requestData);
11887
+ const _data = {
11888
+ mobileNumber: info === null || info === void 0 ? void 0 : info.mobileNumber,
11889
+ tenantId: info === null || info === void 0 ? void 0 : info.tenantId,
11890
+ userType: "EMPLOYEE",
11891
+ type: "login"
11892
+ };
11893
+ setShowOTP(true);
11894
+ sendOtp({
11895
+ otp: _data
11896
+ });
11828
11897
  Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId);
11829
11898
  setUser({
11830
11899
  info,
@@ -11832,10 +11901,10 @@ const Login = ({
11832
11901
  });
11833
11902
  } catch (err) {
11834
11903
  var _err$response, _err$response$data;
11904
+ setDisable(false);
11835
11905
  setShowToast((err === null || err === void 0 ? void 0 : (_err$response = err.response) === null || _err$response === void 0 ? void 0 : (_err$response$data = _err$response.data) === null || _err$response$data === void 0 ? void 0 : _err$response$data.error_description) || "Invalid login credentials!");
11836
11906
  setTimeout(closeToast, 5000);
11837
11907
  }
11838
- setDisable(false);
11839
11908
  };
11840
11909
  const closeToast = () => {
11841
11910
  setShowToast(null);
@@ -11886,6 +11955,65 @@ const Login = ({
11886
11955
  script.async = true;
11887
11956
  document.body.appendChild(script);
11888
11957
  }, []);
11958
+ const resendOtp = async () => {
11959
+ var _user$info3, _user$info4;
11960
+ const data = {
11961
+ mobileNumber: user === null || user === void 0 ? void 0 : (_user$info3 = user.info) === null || _user$info3 === void 0 ? void 0 : _user$info3.mobileNumber,
11962
+ tenantId: user === null || user === void 0 ? void 0 : (_user$info4 = user.info) === null || _user$info4 === void 0 ? void 0 : _user$info4.tenantId,
11963
+ userType: "employee",
11964
+ type: "login"
11965
+ };
11966
+ const [res, err] = await sendOtp({
11967
+ otp: data
11968
+ });
11969
+ };
11970
+ async function onVerifyOtp() {
11971
+ try {
11972
+ var _user$info5, _user$info6;
11973
+ setIsOtpValid(true);
11974
+ setCanSubmit(false);
11975
+ const requestData = {
11976
+ username: user === null || user === void 0 ? void 0 : (_user$info5 = user.info) === null || _user$info5 === void 0 ? void 0 : _user$info5.userName,
11977
+ password: otp,
11978
+ tenantId: user === null || user === void 0 ? void 0 : (_user$info6 = user.info) === null || _user$info6 === void 0 ? void 0 : _user$info6.tenantId,
11979
+ userType: "EMPLOYEE"
11980
+ };
11981
+ const {
11982
+ ResponseInfo,
11983
+ UserRequest: info,
11984
+ ...tokens
11985
+ } = await Digit.UserService.authenticate(requestData);
11986
+ setUser({
11987
+ info,
11988
+ ...tokens
11989
+ });
11990
+ history.push("/digit-ui/employee");
11991
+ } catch (e) {
11992
+ setCanSubmit(true);
11993
+ setIsOtpValid(false);
11994
+ }
11995
+ }
11996
+ const sendOtp = async data => {
11997
+ try {
11998
+ var _user$info7;
11999
+ const res = await Digit.UserService.sendOtp(data, user === null || user === void 0 ? void 0 : (_user$info7 = user.info) === null || _user$info7 === void 0 ? void 0 : _user$info7.tenantId);
12000
+ setDisable(true);
12001
+ return [res, null];
12002
+ } catch (err) {
12003
+ return [null, err];
12004
+ }
12005
+ };
12006
+ const prevRef = React.useRef({});
12007
+ const onFormValueChange = (setValue, data) => {
12008
+ var _prev$city, _data$city;
12009
+ const prev = prevRef.current;
12010
+ const isChanged = (prev === null || prev === void 0 ? void 0 : (_prev$city = prev.city) === null || _prev$city === void 0 ? void 0 : _prev$city.code) !== (data === null || data === void 0 ? void 0 : (_data$city = data.city) === null || _data$city === void 0 ? void 0 : _data$city.code) || (prev === null || prev === void 0 ? void 0 : prev.username) !== (data === null || data === void 0 ? void 0 : data.username) || (prev === null || prev === void 0 ? void 0 : prev.password) !== (data === null || data === void 0 ? void 0 : data.password);
12011
+ if (isChanged) {
12012
+ setDisable(false);
12013
+ setShowOTP(false);
12014
+ }
12015
+ prevRef.current = data;
12016
+ };
11889
12017
  return isLoading || isStoreLoading ? /*#__PURE__*/React.createElement(Loader, null) :
11890
12018
  /*#__PURE__*/
11891
12019
  React.createElement(Background, null, /*#__PURE__*/React.createElement("div", {
@@ -11910,9 +12038,9 @@ const Login = ({
11910
12038
  onClick: onBackToLogin,
11911
12039
  className: "employee-back-button",
11912
12040
  type: "button"
11913
- }, "\u2190 Back to Login"), !isForgotPasswordView ? /*#__PURE__*/React.createElement(FormComposer, {
12041
+ }, "\u2190 Back to Login"), !isForgotPasswordView ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormComposer, {
11914
12042
  onSubmit: onLogin,
11915
- isDisabled: isDisabled || disable,
12043
+ isDisabled: disable,
11916
12044
  noBoxShadow: true,
11917
12045
  inline: true,
11918
12046
  submitInForm: true,
@@ -11921,6 +12049,7 @@ const Login = ({
11921
12049
  secondaryActionLabel: propsConfig.texts.secondaryButtonLabel,
11922
12050
  onSecondayActionClick: onForgotPassword,
11923
12051
  heading: propsConfig.texts.header,
12052
+ onFormValueChange: onFormValueChange,
11924
12053
  description: "Enter your details to access your account",
11925
12054
  headingStyle: {
11926
12055
  textAlign: "left",
@@ -11936,7 +12065,14 @@ const Login = ({
11936
12065
  borderRadius: "8px",
11937
12066
  padding: "12px"
11938
12067
  }
11939
- }) : /*#__PURE__*/React.createElement("div", {
12068
+ }), showOTP && /*#__PURE__*/React.createElement(OtpInput, {
12069
+ otp: otp,
12070
+ onOtpChange: setOtp,
12071
+ onVerifyOtp: onVerifyOtp,
12072
+ onResendOtp: resendOtp,
12073
+ canSubmit: canSubmit,
12074
+ isOtpValid: isOtpValid
12075
+ })) : /*#__PURE__*/React.createElement("div", {
11940
12076
  className: "employee-forgot-password-content"
11941
12077
  }, /*#__PURE__*/React.createElement("h2", {
11942
12078
  style: {
@@ -14522,8 +14658,8 @@ const UserProfile = ({
14522
14658
  const {
14523
14659
  t
14524
14660
  } = useTranslation();
14525
- const location = useLocation();
14526
14661
  const url = window.location.href;
14662
+ const location = useLocation();
14527
14663
  const stateId = Digit.ULBService.getStateId();
14528
14664
  const tenant = Digit.ULBService.getCurrentTenantId();
14529
14665
  const userInfo = ((_Digit$UserService$ge = Digit.UserService.getUser()) === null || _Digit$UserService$ge === void 0 ? void 0 : _Digit$UserService$ge.info) || {};
@@ -14559,7 +14695,6 @@ const UserProfile = ({
14559
14695
  const [selectedCorrespondentDistrict, setSelectedCorrespondentDistrict] = useState();
14560
14696
  const [pinCodeCorrespondent, setPinCodeCorrespondent] = useState();
14561
14697
  const isUserArchitect = window.location.href.includes("citizen") && (userInfo === null || userInfo === void 0 ? void 0 : (_userInfo$roles = userInfo.roles) === null || _userInfo$roles === void 0 ? void 0 : _userInfo$roles.some(role => role.code.includes("BPA_ARCHITECT")));
14562
- console.log("location", location);
14563
14698
  const getUserInfo = async () => {
14564
14699
  const uuid = userInfo === null || userInfo === void 0 ? void 0 : userInfo.uuid;
14565
14700
  if (uuid) {
@@ -14572,9 +14707,6 @@ const UserProfile = ({
14572
14707
  setLoading(false);
14573
14708
  }
14574
14709
  };
14575
- useEffect(() => {
14576
- console.log("userDetails", userDetails);
14577
- }, [userDetails]);
14578
14710
  React.useEffect(() => {
14579
14711
  window.addEventListener("resize", () => setWindowWidth(window.innerWidth));
14580
14712
  return () => {
@@ -14654,7 +14786,7 @@ const UserProfile = ({
14654
14786
  setSelectedCorrespondentDistrict(userDetails === null || userDetails === void 0 ? void 0 : userDetails.correspondenceDistrict);
14655
14787
  setCorrespondenceAddress(userDetails === null || userDetails === void 0 ? void 0 : userDetails.correspondenceAddress);
14656
14788
  setSelectedCorrespondentState(userDetails === null || userDetails === void 0 ? void 0 : userDetails.correspondenceState);
14657
- setSelectedState(userDetails === null || userDetails === void 0 ? void 0 : userDetails.permanentState);
14789
+ setSelectedState((userDetails === null || userDetails === void 0 ? void 0 : userDetails.permanentState) || "Punjab");
14658
14790
  if (userDetails !== null && userDetails !== void 0 && userDetails.isAddressSame) {
14659
14791
  setIsAddressSame(userDetails === null || userDetails === void 0 ? void 0 : userDetails.isAddressSame);
14660
14792
  }
@@ -15077,20 +15209,12 @@ const UserProfile = ({
15077
15209
  }
15078
15210
  };
15079
15211
  if (loading) return /*#__PURE__*/React.createElement(Loader, null);
15212
+ console.log("stateOptions", stateOptions);
15080
15213
  return /*#__PURE__*/React.createElement("div", {
15081
15214
  className: "user-profile"
15082
15215
  }, /*#__PURE__*/React.createElement("section", {
15083
15216
  className: `user-profile-section-wrapper ${userType === "employee" ? "employee" : ""}`
15084
- }, userType === "citizen" ? /*#__PURE__*/React.createElement("h6", {
15085
- onClick: () => history.push("/digit-ui/citizen"),
15086
- style: {
15087
- marginTop: "60px",
15088
- paddingLeft: "13px",
15089
- fontSize: "16px",
15090
- fontWeight: "bolder",
15091
- cursor: "pointer"
15092
- }
15093
- }, "Home") : /*#__PURE__*/React.createElement(BreadCrumb, {
15217
+ }, userType === "citizen" ? /*#__PURE__*/React.createElement(BackButton, null) : /*#__PURE__*/React.createElement(BreadCrumb, {
15094
15218
  crumbs: [{
15095
15219
  path: "/digit-ui/employee",
15096
15220
  content: t("ES_COMMON_HOME"),
@@ -15166,7 +15290,7 @@ const UserProfile = ({
15166
15290
  className: "user-profile-field-wrapper"
15167
15291
  }, /*#__PURE__*/React.createElement(CardLabel$1, {
15168
15292
  className: "user-profile-label"
15169
- }, `${t("CORE_COMMON_PROFILE_EMAIL")}`), /*#__PURE__*/React.createElement(TextInput$1, {
15293
+ }, `${t("CORE_COMMON_PROFILE_EMAIL")}`, "*"), /*#__PURE__*/React.createElement(TextInput$1, {
15170
15294
  t: t,
15171
15295
  type: "email",
15172
15296
  isMandatory: false,
@@ -15222,7 +15346,7 @@ const UserProfile = ({
15222
15346
  option: (stateOptions === null || stateOptions === void 0 ? void 0 : stateOptions.sort((a, b) => a.state_name.localeCompare(b.state_name))) || [],
15223
15347
  selected: selectedState,
15224
15348
  select: SelectState,
15225
- disable: editScreen
15349
+ disable: true
15226
15350
  })), /*#__PURE__*/React.createElement("div", {
15227
15351
  className: "user-profile-field-wrapper"
15228
15352
  }, /*#__PURE__*/React.createElement(CardLabel$1, {
@@ -16824,7 +16948,7 @@ const MobileInput = ({
16824
16948
  }))));
16825
16949
  };
16826
16950
 
16827
- const OtpInput = ({
16951
+ const OtpInput$1 = ({
16828
16952
  otp,
16829
16953
  onOtpChange,
16830
16954
  onVerifyOtp,
@@ -17069,6 +17193,15 @@ const NewLogin = ({
17069
17193
  selectedCity: selectedCity
17070
17194
  });
17071
17195
  };
17196
+ useEffect(() => {
17197
+ var _window2;
17198
+ localStorage.clear();
17199
+ if ((_window2 = window) !== null && _window2 !== void 0 && _window2.caches) {
17200
+ caches.keys().then(names => {
17201
+ names.forEach(name => caches.delete(name));
17202
+ });
17203
+ }
17204
+ }, []);
17072
17205
  return (
17073
17206
  /*#__PURE__*/
17074
17207
  React.createElement("div", {
@@ -17157,7 +17290,7 @@ const NewLogin = ({
17157
17290
  onSendOtp: onSendOtp,
17158
17291
  canSubmit: canSubmit && (lastSubmittedMobile ? mobileNumber !== lastSubmittedMobile : true),
17159
17292
  step: step
17160
- }), step === "OTP" && /*#__PURE__*/React.createElement(OtpInput, {
17293
+ }), step === "OTP" && /*#__PURE__*/React.createElement(OtpInput$1, {
17161
17294
  otp: otp,
17162
17295
  onOtpChange: setOtp,
17163
17296
  onVerifyOtp: onVerifyOtp,
@@ -17582,14 +17715,14 @@ const NewRegistration = ({
17582
17715
  id: "name",
17583
17716
  selected: getGender,
17584
17717
  select: setGender,
17585
- placeholder: t("COMMON_TABLE_SEARCH")
17718
+ placeholder: t("CORE_COMMON_GENDER")
17586
17719
  })), step === "FORM" && /*#__PURE__*/React.createElement(RegistrationForm, {
17587
17720
  onRegisterSubmit: onRegisterSubmit,
17588
17721
  onAgeError: onAgeError,
17589
17722
  selectedLanguage: selectedLanguage,
17590
17723
  selectedCity: selectedCity,
17591
17724
  mobileNumber: (_location$state4 = location.state) === null || _location$state4 === void 0 ? void 0 : _location$state4.mobileNumber
17592
- }), step === "OTP" && /*#__PURE__*/React.createElement(OtpInput, {
17725
+ }), step === "OTP" && /*#__PURE__*/React.createElement(OtpInput$1, {
17593
17726
  otp: otp,
17594
17727
  onOtpChange: setOtp,
17595
17728
  onVerifyOtp: onVerifyOtp,