UNPKG

@egovernments/digit-ui-module-core

Version:

## Version: 1.9.0 **Release Date:** October 23, 2025

643 lines (618 loc) 37.9 kB
"use strict"; this["webpackHotUpdate_egovernments_digit_ui_module_core"]("main",{ /***/ "./src/pages/employee/Login/login.js": /*!*******************************************!*\ !*** ./src/pages/employee/Login/login.js ***! \*******************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var _egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @egovernments/digit-ui-components */ "@egovernments/digit-ui-components"); /* harmony import */ var _egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prop-types */ "../../../node_modules/prop-types/index.js"); /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react"); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react-router-dom */ "react-router-dom"); /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _components_Background__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../components/Background */ "./src/components/Background.js"); /* harmony import */ var _components_Header__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../components/Header */ "./src/components/Header.js"); /* harmony import */ var _Carousel_Carousel__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Carousel/Carousel */ "./src/pages/employee/Login/Carousel/Carousel.js"); /* harmony import */ var _components_ImageComponent__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../../components/ImageComponent */ "./src/components/ImageComponent.js"); /* harmony import */ var _hoc_withAutoFocusMain__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../../hoc/withAutoFocusMain */ "./src/hoc/withAutoFocusMain.js"); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! react/jsx-runtime */ "../../../node_modules/react/jsx-runtime.js"); var _excluded = ["UserRequest"], _excluded2 = ["UserRequest"], _excluded3 = ["UserRequest"]; function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } // import SkipToMainContent from "../SkipToMainContent/SkipToMainContent"; var setEmployeeDetail = (userObject, token) => { var _JSON$parse; if (Digit.Utils.getMultiRootTenant() && "development" !== "development") // removed by dead control flow {} var locale = ((_JSON$parse = JSON.parse(sessionStorage.getItem("Digit.locale"))) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.value) || Digit.Utils.getDefaultLanguage(); localStorage.setItem("Employee.tenant-id", userObject === null || userObject === void 0 ? void 0 : userObject.tenantId); localStorage.setItem("tenant-id", userObject === null || userObject === void 0 ? void 0 : userObject.tenantId); localStorage.setItem("citizen.userRequestObject", JSON.stringify(userObject)); localStorage.setItem("locale", locale); localStorage.setItem("Employee.locale", locale); localStorage.setItem("token", token); localStorage.setItem("Employee.token", token); localStorage.setItem("user-info", JSON.stringify(userObject)); localStorage.setItem("Employee.user-info", JSON.stringify(userObject)); }; var Login = _ref => { var _Digit$ComponentRegis, _Digit2, _propsConfig$inputs, _config$, _config$2; var { config: propsConfig, t, isDisabled, loginOTPBased } = _ref; var { data: cities, isLoading } = Digit.Hooks.useTenants(); var { data: storeData, isLoading: isStoreLoading } = Digit.Hooks.useStore.getInitData(); var { data: ssoMDMSData, isLoading: isSSOMDMSLoading } = Digit.Hooks.useSSOConfig(Digit.ULBService.getStateId(), { select: data => { var _data$MdmsRes, _data$SSO; var config = (data === null || data === void 0 || (_data$MdmsRes = data.MdmsRes) === null || _data$MdmsRes === void 0 || (_data$MdmsRes = _data$MdmsRes["SSO"]) === null || _data$MdmsRes === void 0 ? void 0 : _data$MdmsRes.IdentityProviders) || (data === null || data === void 0 || (_data$SSO = data["SSO"]) === null || _data$SSO === void 0 ? void 0 : _data$SSO.IdentityProviders) || (data === null || data === void 0 ? void 0 : data["IdentityProviders"]) || []; return Array.isArray(config) ? config : []; } }); var { stateInfo } = storeData || {}; var [user, setUser] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(null); var [showToast, setShowToast] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(null); var [disable, setDisable] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(false); var [loginLoader, setLoginLoader] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(false); var navigate = (0,react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useNavigate)(); var DynamicLoginComponent = (_Digit$ComponentRegis = Digit.ComponentRegistryService) === null || _Digit$ComponentRegis === void 0 ? void 0 : _Digit$ComponentRegis.getComponent("DynamicLoginComponent"); /* Generic SSO Callback Handler - runs on mount / when disable/user/stateInfo change */ (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => { var hashParams = new URLSearchParams(window.location.hash.slice(1)); var searchParams = new URLSearchParams(window.location.search); var idToken = hashParams.get("id_token") || searchParams.get("id_token"); var accessToken = hashParams.get("access_token") || searchParams.get("access_token"); var code = searchParams.get("code"); var error = searchParams.get("error") || hashParams.get("error"); var errorDescription = searchParams.get("error_description") || hashParams.get("error_description") || searchParams.get("errorDescription") || hashParams.get("errorDescription"); // If we are not on an SSO callback URL, never keep the SSO overlay loader. // Important: we intentionally don't set the loader before redirecting to the provider, // so browser back (including bfcache restores) won't get stuck with a stale loader. // Note: do NOT reset `disable` here — it is also used for form-validation gating and // resetting it would fight FormComposerV2's onFormValueChange, causing an infinite loop. if (!idToken && !code && !error) { if (loginLoader) setLoginLoader(false); return; } if (error && !showToast) { setShowToast(errorDescription || "SSO Login Failed!"); setTimeout(closeToast, 5000); setLoginLoader(false); setDisable(false); return; } if (!(stateInfo !== null && stateInfo !== void 0 && stateInfo.code)) { // Tenant/state not ready yet; wait and retry when stateInfo arrives. return; } if ((idToken || code) && !user && !disable) { if (idToken) { handleDigitLogin(idToken, accessToken); } else if (code) { setDisable(true); setLoginLoader(true); Digit.UserService.microsoftAuthenticate({ code }).then(_ref2 => { var { UserRequest: info } = _ref2, tokens = _objectWithoutProperties(_ref2, _excluded); Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId); setUser(_objectSpread({ info }, tokens)); setDisable(false); setLoginLoader(false); }).catch(err => { var _err$response; setShowToast((err === null || err === void 0 || (_err$response = err.response) === null || _err$response === void 0 || (_err$response = _err$response.data) === null || _err$response === void 0 ? void 0 : _err$response.error_description) || "Login Failed!"); setTimeout(closeToast, 5000); setDisable(false); setLoginLoader(false); }); } } }, [user, disable, stateInfo, loginLoader, showToast]); /* Post-login redirect and user setup */ (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => { var _user$info, _user$info2, _window, _window2, _user$info3, _user$info4, _user$info5, _user$info6; if (!user) { return; } Digit.SessionStorage.set("citizen.userRequestObject", user); var filteredRoles = user === null || user === void 0 || (_user$info = user.info) === null || _user$info === void 0 || (_user$info = _user$info.roles) === null || _user$info === void 0 ? void 0 : _user$info.filter(role => role.tenantId === Digit.SessionStorage.get("Employee.tenantId")); if ((user === null || user === void 0 || (_user$info2 = user.info) === null || _user$info2 === void 0 || (_user$info2 = _user$info2.roles) === null || _user$info2 === void 0 ? void 0 : _user$info2.length) > 0) user.info.roles = filteredRoles; Digit.UserService.setUser(user); setEmployeeDetail(user === null || user === void 0 ? void 0 : user.info, user === null || user === void 0 ? void 0 : user.access_token); var redirectPath = "/".concat((_window = window) === null || _window === void 0 ? void 0 : _window.contextPath, "/employee"); /* logic to redirect back to same screen where we left off */ if ((_window2 = window) !== null && _window2 !== void 0 && (_window2 = _window2.location) !== null && _window2 !== void 0 && (_window2 = _window2.href) !== null && _window2 !== void 0 && _window2.includes("from=")) { var _window3, _window4; redirectPath = decodeURIComponent((_window3 = window) === null || _window3 === void 0 || (_window3 = _window3.location) === null || _window3 === void 0 || (_window3 = _window3.href) === null || _window3 === void 0 || (_window3 = _window3.split("from=")) === null || _window3 === void 0 ? void 0 : _window3[1]) || "/".concat((_window4 = window) === null || _window4 === void 0 ? void 0 : _window4.contextPath, "/employee"); } /* RAIN-6489 Logic to navigate to National DSS home in case user has only one role [NATADMIN]*/ if (user !== null && user !== void 0 && (_user$info3 = user.info) !== null && _user$info3 !== void 0 && _user$info3.roles && user !== null && user !== void 0 && (_user$info4 = user.info) !== null && _user$info4 !== void 0 && (_user$info4 = _user$info4.roles) !== null && _user$info4 !== void 0 && _user$info4.every(e => e.code === "NATADMIN")) { var _window5; redirectPath = "/".concat((_window5 = window) === null || _window5 === void 0 ? void 0 : _window5.contextPath, "/employee/dss/landing/NURT_DASHBOARD"); } /* RAIN-6489 Logic to navigate to National DSS home incase user has only one role [NATADMIN]*/ if (user !== null && user !== void 0 && (_user$info5 = user.info) !== null && _user$info5 !== void 0 && _user$info5.roles && user !== null && user !== void 0 && (_user$info6 = user.info) !== null && _user$info6 !== void 0 && (_user$info6 = _user$info6.roles) !== null && _user$info6 !== void 0 && _user$info6.every(e => e.code === "STADMIN")) { var _window6; redirectPath = "/".concat((_window6 = window) === null || _window6 === void 0 ? void 0 : _window6.contextPath, "/employee/dss/landing/home"); } navigate(redirectPath, { replace: true }); }, [user]); /* Generic Token Exchange with DIGIT Backend */ var handleDigitLogin = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator(function* (idToken) { var accessToken = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; setDisable(true); setLoginLoader(true); try { var _window7; var response = yield fetch("/user/oauth/token", { method: "POST", headers: { Authorization: "Basic ".concat(((_window7 = window) === null || _window7 === void 0 || (_window7 = _window7.globalConfigs) === null || _window7 === void 0 ? void 0 : _window7.getConfig("JWT_TOKEN")) || "ZWdvdi11c2VyLWNsaWVudDo="), "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(_objectSpread(_objectSpread({ grant_type: "jwt_exchange", scope: "read", userType: "EMPLOYEE", assertion: idToken }, accessToken && { access_token: accessToken }), {}, { tenantId: stateInfo === null || stateInfo === void 0 ? void 0 : stateInfo.code })) }); if (!response.ok) { var _parsed, _parsed2, _parsed3, _parsed4; var raw = yield response.text(); var parsed; try { parsed = raw ? JSON.parse(raw) : null; } catch (e) { parsed = null; } var message = ((_parsed = parsed) === null || _parsed === void 0 ? void 0 : _parsed.error_description) || ((_parsed2 = parsed) === null || _parsed2 === void 0 ? void 0 : _parsed2.errorDescription) || ((_parsed3 = parsed) === null || _parsed3 === void 0 ? void 0 : _parsed3.message) || ((_parsed4 = parsed) === null || _parsed4 === void 0 ? void 0 : _parsed4.error) || raw || "DIGIT Login Failed"; throw new Error(message); } var data = yield response.json(); var { UserRequest: info } = data, tokens = _objectWithoutProperties(data, _excluded2); Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId); setUser(_objectSpread({ info }, tokens)); } catch (error) { console.error("DIGIT Login Error:", error); setShowToast((error === null || error === void 0 ? void 0 : error.message) || "DIGIT Login Failed"); setTimeout(closeToast, 5000); // If token exchange fails, force Microsoft to prompt credentials on next SSO click. try { window.sessionStorage.setItem("sso.force.prompt.login", "true"); } catch (e) { // no-op } // Prevent retry loop: clear `id_token`/`code` from URL (stay on same page). try { window.history.replaceState({}, document.title, window.location.pathname); } catch (e) { // no-op } } setDisable(false); setLoginLoader(false); }); return function handleDigitLogin(_x) { return _ref3.apply(this, arguments); }; }(); var buildOIDCAuthorizeUrl = uiConfig => { var _window8; var { authorizeUrl, clientId, scopes = ["openid", "profile", "email"], responseType = "id_token", responseMode = "fragment", nonceRequired = true, redirectPath = "employee/user/login", resource, provider, prompt } = uiConfig || {}; if (!authorizeUrl || !clientId) { throw new Error("Missing authorizeUrl or clientId for OIDC login"); } var nonce = nonceRequired ? Math.random().toString(36).substring(2) : undefined; var redirectUri = "".concat(window.location.origin, "/").concat((_window8 = window) === null || _window8 === void 0 ? void 0 : _window8.contextPath, "/").concat(redirectPath); var params = new URLSearchParams(); params.set("client_id", clientId); params.set("response_type", responseType); params.set("redirect_uri", redirectUri); if (nonce) params.set("nonce", nonce); if (responseMode) params.set("response_mode", responseMode); if (scopes && scopes.length) params.set("scope", scopes.join(" ")); if (resource) params.set("resource", resource); // Handle prompt parameter with priority: // 1. Use configured prompt from SSO config (respects admin configuration) // 2. Fall back to forced login only if no prompt is configured AND a previous login failed try { var forcePromptLogin = window.sessionStorage.getItem("sso.force.prompt.login") === "true"; if (prompt) { // Respect configured prompt (e.g., "select_account", "consent") params.set("prompt", prompt); // Clear the force flag since we're using configured prompt if (forcePromptLogin) { window.sessionStorage.removeItem("sso.force.prompt.login"); } } else if (forcePromptLogin) { // Only force login if no prompt is configured params.set("prompt", "login"); window.sessionStorage.removeItem("sso.force.prompt.login"); } } catch (e) { // If prompt is configured, still set it even if sessionStorage fails if (prompt) { params.set("prompt", prompt); } } return "".concat(authorizeUrl, "?").concat(params.toString()); }; var onSSOLogin = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator(function* (ssoConfig) { // For OIDC-like providers (MICROSOFT, GOOGLE, etc.), use generic OIDC login var ui = (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.ui) || {}; var hasOidcConfig = Boolean((ui.authorizeUrl || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.authorizeUrl)) && ui.clientId); if (ui.authStrategy === "OIDC_POPUP" || ui.provider === "MICROSOFT" || hasOidcConfig) { return onOIDCLogin(ssoConfig); } // If the config doesn't match any known SSO strategy, don't leave the overlay loader stuck. setShowToast("SSO configuration is invalid or unsupported"); setTimeout(closeToast, 5000); }); return function onSSOLogin(_x2) { return _ref4.apply(this, arguments); }; }(); var onOIDCLogin = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator(function* (ssoConfig) { try { var ui = _objectSpread({}, (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.ui) || {}); // Backward-compatibility for older configs where authorizeUrl/resource // might be on the top level instead of inside ui. ui.authorizeUrl = ui.authorizeUrl || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.authorizeUrl); ui.resource = ui.resource || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.resource); // For Microsoft, if resource is not explicitly provided, default it to clientId (v1 behavior). if (ui.provider === "MICROSOFT" && !ui.resource) { ui.resource = ui.clientId; } // Persist provider + logout-relevant info for later use during logout if (ui.provider) { localStorage.setItem("sso-provider", ui.provider); } if (ui.logoutUrl) { localStorage.setItem("sso-logout-url", ui.logoutUrl); } if (ui.logoutRedirectParam) { localStorage.setItem("sso-logout-redirect-param", ui.logoutRedirectParam); } if (ui.tenantId) { localStorage.setItem("sso-tenant-id", ui.tenantId); } if (ui.authority) { localStorage.setItem("sso-authority", ui.authority); } var url = buildOIDCAuthorizeUrl(ui); // Simple implementation: redirect for OIDC if no library is present // For a better experience, a popup and message bridge should be used window.location.href = url; } catch (error) { console.error("OIDC Login Error:", error); setShowToast(error.message || "OIDC Login Failed"); setTimeout(closeToast, 5000); setLoginLoader(false); } }); return function onOIDCLogin(_x3) { return _ref5.apply(this, arguments); }; }(); var onLogin = /*#__PURE__*/function () { var _ref6 = _asyncToGenerator(function* (data) { var _requestData$city, _Digit; // if (!data.city) { // alert("Please Select City!"); // return; // } if (data !== null && data !== void 0 && data.username) { data.username = data.username.trim(); } if (data !== null && data !== void 0 && data.password) { data.password = data.password.trim(); } setDisable(true); setLoginLoader(true); var requestData = _objectSpread(_objectSpread(_objectSpread({}, data), defaultValues), {}, { userType: "EMPLOYEE" }); requestData.tenantId = (requestData === null || requestData === void 0 || (_requestData$city = requestData.city) === null || _requestData$city === void 0 ? void 0 : _requestData$city.code) || ((_Digit = Digit) === null || _Digit === void 0 || (_Digit = _Digit.ULBService) === null || _Digit === void 0 ? void 0 : _Digit.getStateId()); delete requestData.city; try { var _yield$Digit$UserServ = yield Digit.UserService.authenticate(requestData), { UserRequest: info } = _yield$Digit$UserServ, tokens = _objectWithoutProperties(_yield$Digit$UserServ, _excluded3); Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId); setUser(_objectSpread({ info }, tokens)); } catch (err) { var _err$response2; setShowToast((err === null || err === void 0 || (_err$response2 = err.response) === null || _err$response2 === void 0 || (_err$response2 = _err$response2.data) === null || _err$response2 === void 0 ? void 0 : _err$response2.error_description) || (err === null || err === void 0 ? void 0 : err.message) == "ES_ERROR_USER_NOT_PERMITTED" && t("ES_ERROR_USER_NOT_PERMITTED") || t("INVALID_LOGIN_CREDENTIALS")); setTimeout(closeToast, 5000); } setDisable(false); setLoginLoader(false); }); return function onLogin(_x4) { return _ref6.apply(this, arguments); }; }(); var reqCreate = { url: "/user-otp/v1/_send", params: { tenantId: (_Digit2 = Digit) === null || _Digit2 === void 0 || (_Digit2 = _Digit2.ULBService) === null || _Digit2 === void 0 ? void 0 : _Digit2.getStateId() }, body: {}, config: { enable: false } }; var mutation = Digit.Hooks.useCustomAPIMutationHook(reqCreate); var onOtpLogin = /*#__PURE__*/function () { var _ref7 = _asyncToGenerator(function* (data) { var _Digit3; var inputEmail = data.email; yield mutation.mutate({ body: { otp: { userName: data.email, type: "login", tenantId: (_Digit3 = Digit) === null || _Digit3 === void 0 || (_Digit3 = _Digit3.ULBService) === null || _Digit3 === void 0 ? void 0 : _Digit3.getStateId(), userType: "EMPLOYEE" } }, config: { enable: true } }, { onError: (error, variables) => { var _error$response, _error$response2; setShowToast(error !== null && error !== void 0 && (_error$response = error.response) !== null && _error$response !== void 0 && (_error$response = _error$response.data) !== null && _error$response !== void 0 && (_error$response = _error$response.Errors) !== null && _error$response !== void 0 && _error$response[0].code ? "SANDBOX_RESEND_OTP".concat(error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.data) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.Errors) === null || _error$response2 === void 0 || (_error$response2 = _error$response2[0]) === null || _error$response2 === void 0 ? void 0 : _error$response2.code) : "SANDBOX_RESEND_OTP_ERROR"); setTimeout(closeToast, 5000); }, onSuccess: function () { var _onSuccess = _asyncToGenerator(function* (data) { var _window9, _Digit4; navigate("/".concat((_window9 = window) === null || _window9 === void 0 ? void 0 : _window9.contextPath, "/employee/user/login/otp"), { state: { email: inputEmail, tenant: (_Digit4 = Digit) === null || _Digit4 === void 0 || (_Digit4 = _Digit4.ULBService) === null || _Digit4 === void 0 ? void 0 : _Digit4.getStateId() } }); }); function onSuccess(_x6) { return _onSuccess.apply(this, arguments); } return onSuccess; }() }); }); return function onOtpLogin(_x5) { return _ref7.apply(this, arguments); }; }(); var closeToast = () => { setShowToast(null); }; var onForgotPassword = () => { var _window0; navigate("/".concat((_window0 = window) === null || _window0 === void 0 ? void 0 : _window0.contextPath, "/employee/user/forgot-password")); }; var defaultTenant = Digit.ULBService.getStateId(); var defaultValue = { code: defaultTenant, name: Digit.Utils.locale.getTransformedLocale("TENANT_TENANTS_".concat(defaultTenant)) }; var ssoConfigs = ssoMDMSData === null || ssoMDMSData === void 0 ? void 0 : ssoMDMSData.map(sso => { var _sso$ui, _sso$ui2, _sso$ui3, _sso$ui4, _sso$ui5, _sso$ui6; return _objectSpread(_objectSpread({}, sso), {}, { provider: ((_sso$ui = sso.ui) === null || _sso$ui === void 0 ? void 0 : _sso$ui.provider) || sso.provider || "sso", label: t("SSO_PROVIDER_".concat(((_sso$ui2 = sso.ui) === null || _sso$ui2 === void 0 ? void 0 : _sso$ui2.name) || sso.id)), icon: (_sso$ui3 = sso.ui) !== null && _sso$ui3 !== void 0 && _sso$ui3.logo ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("img", { src: sso.ui.logo, alt: (_sso$ui4 = sso.ui) === null || _sso$ui4 === void 0 ? void 0 : _sso$ui4.name, className: "employee-login-sso-logo" }) : ((_sso$ui5 = sso.ui) === null || _sso$ui5 === void 0 ? void 0 : _sso$ui5.provider) === "MICROSOFT" ? "Microsoft" : (_sso$ui6 = sso.ui) === null || _sso$ui6 === void 0 ? void 0 : _sso$ui6.icon, onLogin: ssoConfig => { onSSOLogin(ssoConfig); } }); }); var config = [{ body: propsConfig === null || propsConfig === void 0 || (_propsConfig$inputs = propsConfig.inputs) === null || _propsConfig$inputs === void 0 ? void 0 : _propsConfig$inputs.map(field => (field === null || field === void 0 ? void 0 : field.component) === "EmployeeSSOLoginOptions" ? _objectSpread(_objectSpread({}, field), {}, { customProps: _objectSpread(_objectSpread({}, field.customProps), {}, { ssoConfigs }) }) : field) }]; var { mode } = Digit.Hooks.useQueryParams(); if (mode === "admin" && (config === null || config === void 0 || (_config$ = config[0]) === null || _config$ === void 0 || (_config$ = _config$.body) === null || _config$ === void 0 || (_config$ = _config$[2]) === null || _config$ === void 0 ? void 0 : _config$.disable) == false && (config === null || config === void 0 || (_config$2 = config[0]) === null || _config$2 === void 0 || (_config$2 = _config$2.body) === null || _config$2 === void 0 || (_config$2 = _config$2[2]) === null || _config$2 === void 0 || (_config$2 = _config$2.populators) === null || _config$2 === void 0 ? void 0 : _config$2.defaultValue) == undefined) { config[0].body[2].disable = true; config[0].body[2].isMandatory = false; config[0].body[2].populators.defaultValue = defaultValue; } var defaultValues = (0,react__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => Object.fromEntries(config[0].body.filter(field => { var _field$populators, _field$populators2; return (field === null || field === void 0 || (_field$populators = field.populators) === null || _field$populators === void 0 ? void 0 : _field$populators.defaultValue) && (field === null || field === void 0 || (_field$populators2 = field.populators) === null || _field$populators2 === void 0 ? void 0 : _field$populators2.name); }).map(field => [field.populators.name, field.populators.defaultValue])), []); var onFormValueChange = (setValue, formData, formState) => { // Extract keys from the config var keys = config[0].body.filter(field => field === null || field === void 0 ? void 0 : field.isMandatory).map(field => field === null || field === void 0 ? void 0 : field.key); var hasEmptyFields = keys.some(key => { var value = formData[key]; return value == null || value === "" || value === false; }); setDisable(hasEmptyFields); }; var renderLoginForm = function renderLoginForm() { var _propsConfig$texts, _propsConfig$texts2, _propsConfig$texts3; var extraClasses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; var cardClassName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; var wrapperClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ""; return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.FormComposerV2, { onSubmit: loginOTPBased ? onOtpLogin : onLogin, isDisabled: isDisabled || disable, noBoxShadow: true, inline: true, submitInForm: true, config: config, label: propsConfig === null || propsConfig === void 0 || (_propsConfig$texts = propsConfig.texts) === null || _propsConfig$texts === void 0 ? void 0 : _propsConfig$texts.submitButtonLabel, secondaryActionLabel: (propsConfig === null || propsConfig === void 0 || (_propsConfig$texts2 = propsConfig.texts) === null || _propsConfig$texts2 === void 0 ? void 0 : _propsConfig$texts2.secondaryButtonLabel) + (extraClasses.includes("login-form-container") ? "?" : ""), onSecondayActionClick: onForgotPassword, onFormValueChange: onFormValueChange, heading: propsConfig === null || propsConfig === void 0 || (_propsConfig$texts3 = propsConfig.texts) === null || _propsConfig$texts3 === void 0 ? void 0 : _propsConfig$texts3.header, className: "".concat(wrapperClass), cardSubHeaderClassName: "loginCardSubHeaderClassName", cardClassName: cardClassName, buttonClassName: "buttonClassName", defaultValues: defaultValues, children: stateInfo !== null && stateInfo !== void 0 && stateInfo.code ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_components_Header__WEBPACK_IMPORTED_MODULE_5__["default"], {}) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_components_Header__WEBPACK_IMPORTED_MODULE_5__["default"], { showTenant: false }) }); }; var renderFooter = footerClassName => { var _window1, _window1$getConfig; return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { className: footerClassName, style: { backgroundColor: "unset" }, children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_components_ImageComponent__WEBPACK_IMPORTED_MODULE_7__["default"], { alt: "Powered by DIGIT", src: (_window1 = window) === null || _window1 === void 0 || (_window1 = _window1.globalConfigs) === null || _window1 === void 0 || (_window1$getConfig = _window1.getConfig) === null || _window1$getConfig === void 0 ? void 0 : _window1$getConfig.call(_window1, "DIGIT_FOOTER_BW"), style: { cursor: "pointer" }, onClick: () => { var _window10, _window10$getConfig; window.open((_window10 = window) === null || _window10 === void 0 || (_window10 = _window10.globalConfigs) === null || _window10 === void 0 || (_window10$getConfig = _window10.getConfig) === null || _window10$getConfig === void 0 ? void 0 : _window10$getConfig.call(_window10, "DIGIT_HOME_URL"), "_blank").focus(); } }) }); }; if (isLoading || isStoreLoading) { return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Loader, { page: true, variant: "PageLoader" }); } return propsConfig !== null && propsConfig !== void 0 && propsConfig.bannerImages ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)("div", { className: "login-container", children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_Carousel_Carousel__WEBPACK_IMPORTED_MODULE_6__["default"], { bannerImages: propsConfig === null || propsConfig === void 0 ? void 0 : propsConfig.bannerImages }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)("div", { className: "login-form-container", children: [renderLoginForm("login-form-container", "", loginOTPBased ? "sandbox-onboarding-wrapper" : ""), DynamicLoginComponent && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(DynamicLoginComponent, {}), showToast && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Toast, { type: "error", label: t(showToast), onClose: closeToast }), renderFooter("EmployeeLoginFooter")] })] }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_components_Background__WEBPACK_IMPORTED_MODULE_4__["default"], { children: [loginLoader && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { style: { position: "fixed", top: 0, left: 0, width: "100vw", height: "100vh", background: "rgba(0,0,0,0.35)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 9999 }, children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Loader, {}) }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { className: "employeeBackbuttonAlign", children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.BackLink, { onClick: () => window.history.back() }) }), renderLoginForm("loginFormStyleEmployee", "loginCardClassName", loginOTPBased ? "sandbox-onboarding-wrapper" : ""), DynamicLoginComponent && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(DynamicLoginComponent, {}), showToast && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Toast, { type: "error", label: t(showToast), onClose: closeToast }), renderFooter("employee-login-home-footer")] }); }; Login.propTypes = { loginParams: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().any) }; Login.defaultProps = { loginParams: null }; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_hoc_withAutoFocusMain__WEBPACK_IMPORTED_MODULE_8__["default"])(Login, ".login-form-container")); /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ /* webpack/runtime/getFullHash */ /******/ (() => { /******/ __webpack_require__.h = () => ("5a340d1659238e20c0b3") /******/ })(); /******/ /******/ } ); //# sourceMappingURL=main.08f8755983b7134bc9cd.hot-update.js.map