@egovernments/digit-ui-module-core 2.0.0-dev-20 → 2.0.0-dev-22

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.
@@ -0,0 +1,643 @@
1
+ "use strict";
2
+ this["webpackHotUpdate_egovernments_digit_ui_module_core"]("main",{
3
+
4
+ /***/ "./src/pages/employee/Login/login.js":
5
+ /*!*******************************************!*\
6
+ !*** ./src/pages/employee/Login/login.js ***!
7
+ \*******************************************/
8
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9
+
10
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
11
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
12
+ /* harmony export */ });
13
+ /* harmony import */ var _egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @egovernments/digit-ui-components */ "@egovernments/digit-ui-components");
14
+ /* harmony import */ var _egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__);
15
+ /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prop-types */ "../../../node_modules/prop-types/index.js");
16
+ /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_1__);
17
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react");
18
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__);
19
+ /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react-router-dom */ "react-router-dom");
20
+ /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_3__);
21
+ /* harmony import */ var _components_Background__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../components/Background */ "./src/components/Background.js");
22
+ /* harmony import */ var _components_Header__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../components/Header */ "./src/components/Header.js");
23
+ /* harmony import */ var _Carousel_Carousel__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Carousel/Carousel */ "./src/pages/employee/Login/Carousel/Carousel.js");
24
+ /* harmony import */ var _components_ImageComponent__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../../components/ImageComponent */ "./src/components/ImageComponent.js");
25
+ /* harmony import */ var _hoc_withAutoFocusMain__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../../hoc/withAutoFocusMain */ "./src/hoc/withAutoFocusMain.js");
26
+ /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! react/jsx-runtime */ "../../../node_modules/react/jsx-runtime.js");
27
+ var _excluded = ["UserRequest"],
28
+ _excluded2 = ["UserRequest"],
29
+ _excluded3 = ["UserRequest"];
30
+ 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); }
31
+ 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); }); }; }
32
+ 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; }
33
+ 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; }
34
+ 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; }
35
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
36
+ 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); }
37
+ 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; }
38
+ 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; }
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ // import SkipToMainContent from "../SkipToMainContent/SkipToMainContent";
48
+
49
+
50
+ var setEmployeeDetail = (userObject, token) => {
51
+ var _JSON$parse;
52
+ if (Digit.Utils.getMultiRootTenant() && "development" !== "development") // removed by dead control flow
53
+ {}
54
+ var locale = ((_JSON$parse = JSON.parse(sessionStorage.getItem("Digit.locale"))) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.value) || Digit.Utils.getDefaultLanguage();
55
+ localStorage.setItem("Employee.tenant-id", userObject === null || userObject === void 0 ? void 0 : userObject.tenantId);
56
+ localStorage.setItem("tenant-id", userObject === null || userObject === void 0 ? void 0 : userObject.tenantId);
57
+ localStorage.setItem("citizen.userRequestObject", JSON.stringify(userObject));
58
+ localStorage.setItem("locale", locale);
59
+ localStorage.setItem("Employee.locale", locale);
60
+ localStorage.setItem("token", token);
61
+ localStorage.setItem("Employee.token", token);
62
+ localStorage.setItem("user-info", JSON.stringify(userObject));
63
+ localStorage.setItem("Employee.user-info", JSON.stringify(userObject));
64
+ };
65
+ var Login = _ref => {
66
+ var _Digit$ComponentRegis, _Digit2, _propsConfig$inputs, _config$, _config$2;
67
+ var {
68
+ config: propsConfig,
69
+ t,
70
+ isDisabled,
71
+ loginOTPBased
72
+ } = _ref;
73
+ var {
74
+ data: cities,
75
+ isLoading
76
+ } = Digit.Hooks.useTenants();
77
+ var {
78
+ data: storeData,
79
+ isLoading: isStoreLoading
80
+ } = Digit.Hooks.useStore.getInitData();
81
+ var {
82
+ data: ssoMDMSData,
83
+ isLoading: isSSOMDMSLoading
84
+ } = Digit.Hooks.useSSOConfig(Digit.ULBService.getStateId(), {
85
+ select: data => {
86
+ var _data$MdmsRes, _data$SSO;
87
+ 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"]) || [];
88
+ return Array.isArray(config) ? config : [];
89
+ }
90
+ });
91
+ var {
92
+ stateInfo
93
+ } = storeData || {};
94
+ var [user, setUser] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(null);
95
+ var [showToast, setShowToast] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(null);
96
+ var [disable, setDisable] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(false);
97
+ var [loginLoader, setLoginLoader] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(false);
98
+ var navigate = (0,react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useNavigate)();
99
+ var DynamicLoginComponent = (_Digit$ComponentRegis = Digit.ComponentRegistryService) === null || _Digit$ComponentRegis === void 0 ? void 0 : _Digit$ComponentRegis.getComponent("DynamicLoginComponent");
100
+
101
+ /* Generic SSO Callback Handler - runs on mount / when disable/user/stateInfo change */
102
+ (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => {
103
+ var hashParams = new URLSearchParams(window.location.hash.slice(1));
104
+ var searchParams = new URLSearchParams(window.location.search);
105
+ var idToken = hashParams.get("id_token") || searchParams.get("id_token");
106
+ var accessToken = hashParams.get("access_token") || searchParams.get("access_token");
107
+ var code = searchParams.get("code");
108
+ var error = searchParams.get("error") || hashParams.get("error");
109
+ var errorDescription = searchParams.get("error_description") || hashParams.get("error_description") || searchParams.get("errorDescription") || hashParams.get("errorDescription");
110
+
111
+ // If we are not on an SSO callback URL, never keep the SSO overlay loader.
112
+ // Important: we intentionally don't set the loader before redirecting to the provider,
113
+ // so browser back (including bfcache restores) won't get stuck with a stale loader.
114
+ // Note: do NOT reset `disable` here — it is also used for form-validation gating and
115
+ // resetting it would fight FormComposerV2's onFormValueChange, causing an infinite loop.
116
+ if (!idToken && !code && !error) {
117
+ if (loginLoader) setLoginLoader(false);
118
+ return;
119
+ }
120
+ if (error && !showToast) {
121
+ setShowToast(errorDescription || "SSO Login Failed!");
122
+ setTimeout(closeToast, 5000);
123
+ setLoginLoader(false);
124
+ setDisable(false);
125
+ return;
126
+ }
127
+ if (!(stateInfo !== null && stateInfo !== void 0 && stateInfo.code)) {
128
+ // Tenant/state not ready yet; wait and retry when stateInfo arrives.
129
+ return;
130
+ }
131
+ if ((idToken || code) && !user && !disable) {
132
+ if (idToken) {
133
+ handleDigitLogin(idToken, accessToken);
134
+ } else if (code) {
135
+ setDisable(true);
136
+ setLoginLoader(true);
137
+ Digit.UserService.microsoftAuthenticate({
138
+ code
139
+ }).then(_ref2 => {
140
+ var {
141
+ UserRequest: info
142
+ } = _ref2,
143
+ tokens = _objectWithoutProperties(_ref2, _excluded);
144
+ Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId);
145
+ setUser(_objectSpread({
146
+ info
147
+ }, tokens));
148
+ setDisable(false);
149
+ setLoginLoader(false);
150
+ }).catch(err => {
151
+ var _err$response;
152
+ 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!");
153
+ setTimeout(closeToast, 5000);
154
+ setDisable(false);
155
+ setLoginLoader(false);
156
+ });
157
+ }
158
+ }
159
+ }, [user, disable, stateInfo, loginLoader, showToast]);
160
+
161
+ /* Post-login redirect and user setup */
162
+ (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => {
163
+ var _user$info, _user$info2, _window, _window2, _user$info3, _user$info4, _user$info5, _user$info6;
164
+ if (!user) {
165
+ return;
166
+ }
167
+ Digit.SessionStorage.set("citizen.userRequestObject", user);
168
+ 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"));
169
+ 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;
170
+ Digit.UserService.setUser(user);
171
+ setEmployeeDetail(user === null || user === void 0 ? void 0 : user.info, user === null || user === void 0 ? void 0 : user.access_token);
172
+ var redirectPath = "/".concat((_window = window) === null || _window === void 0 ? void 0 : _window.contextPath, "/employee");
173
+
174
+ /* logic to redirect back to same screen where we left off */
175
+ if ((_window2 = window) !== null && _window2 !== void 0 && (_window2 = _window2.location) !== null && _window2 !== void 0 && (_window2 = _window2.href) !== null && _window2 !== void 0 && _window2.includes("from=")) {
176
+ var _window3, _window4;
177
+ 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");
178
+ }
179
+
180
+ /* RAIN-6489 Logic to navigate to National DSS home in case user has only one role [NATADMIN]*/
181
+ 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")) {
182
+ var _window5;
183
+ redirectPath = "/".concat((_window5 = window) === null || _window5 === void 0 ? void 0 : _window5.contextPath, "/employee/dss/landing/NURT_DASHBOARD");
184
+ }
185
+
186
+ /* RAIN-6489 Logic to navigate to National DSS home incase user has only one role [NATADMIN]*/
187
+ 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")) {
188
+ var _window6;
189
+ redirectPath = "/".concat((_window6 = window) === null || _window6 === void 0 ? void 0 : _window6.contextPath, "/employee/dss/landing/home");
190
+ }
191
+ navigate(redirectPath, {
192
+ replace: true
193
+ });
194
+ }, [user]);
195
+
196
+ /* Generic Token Exchange with DIGIT Backend */
197
+ var handleDigitLogin = /*#__PURE__*/function () {
198
+ var _ref3 = _asyncToGenerator(function* (idToken) {
199
+ var accessToken = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
200
+ setDisable(true);
201
+ setLoginLoader(true);
202
+ try {
203
+ var _window7;
204
+ var response = yield fetch("/user/oauth/token", {
205
+ method: "POST",
206
+ headers: {
207
+ Authorization: "Basic ".concat(((_window7 = window) === null || _window7 === void 0 || (_window7 = _window7.globalConfigs) === null || _window7 === void 0 ? void 0 : _window7.getConfig("JWT_TOKEN")) || "ZWdvdi11c2VyLWNsaWVudDo="),
208
+ "Content-Type": "application/x-www-form-urlencoded"
209
+ },
210
+ body: new URLSearchParams(_objectSpread(_objectSpread({
211
+ grant_type: "jwt_exchange",
212
+ scope: "read",
213
+ userType: "EMPLOYEE",
214
+ assertion: idToken
215
+ }, accessToken && {
216
+ access_token: accessToken
217
+ }), {}, {
218
+ tenantId: stateInfo === null || stateInfo === void 0 ? void 0 : stateInfo.code
219
+ }))
220
+ });
221
+ if (!response.ok) {
222
+ var _parsed, _parsed2, _parsed3, _parsed4;
223
+ var raw = yield response.text();
224
+ var parsed;
225
+ try {
226
+ parsed = raw ? JSON.parse(raw) : null;
227
+ } catch (e) {
228
+ parsed = null;
229
+ }
230
+ 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";
231
+ throw new Error(message);
232
+ }
233
+ var data = yield response.json();
234
+ var {
235
+ UserRequest: info
236
+ } = data,
237
+ tokens = _objectWithoutProperties(data, _excluded2);
238
+ Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId);
239
+ setUser(_objectSpread({
240
+ info
241
+ }, tokens));
242
+ } catch (error) {
243
+ console.error("DIGIT Login Error:", error);
244
+ setShowToast((error === null || error === void 0 ? void 0 : error.message) || "DIGIT Login Failed");
245
+ setTimeout(closeToast, 5000);
246
+
247
+ // If token exchange fails, force Microsoft to prompt credentials on next SSO click.
248
+ try {
249
+ window.sessionStorage.setItem("sso.force.prompt.login", "true");
250
+ } catch (e) {
251
+ // no-op
252
+ }
253
+
254
+ // Prevent retry loop: clear `id_token`/`code` from URL (stay on same page).
255
+ try {
256
+ window.history.replaceState({}, document.title, window.location.pathname);
257
+ } catch (e) {
258
+ // no-op
259
+ }
260
+ }
261
+ setDisable(false);
262
+ setLoginLoader(false);
263
+ });
264
+ return function handleDigitLogin(_x) {
265
+ return _ref3.apply(this, arguments);
266
+ };
267
+ }();
268
+ var buildOIDCAuthorizeUrl = uiConfig => {
269
+ var _window8;
270
+ var {
271
+ authorizeUrl,
272
+ clientId,
273
+ scopes = ["openid", "profile", "email"],
274
+ responseType = "id_token",
275
+ responseMode = "fragment",
276
+ nonceRequired = true,
277
+ redirectPath = "employee/user/login",
278
+ resource,
279
+ provider,
280
+ prompt
281
+ } = uiConfig || {};
282
+ if (!authorizeUrl || !clientId) {
283
+ throw new Error("Missing authorizeUrl or clientId for OIDC login");
284
+ }
285
+ var nonce = nonceRequired ? Math.random().toString(36).substring(2) : undefined;
286
+ var redirectUri = "".concat(window.location.origin, "/").concat((_window8 = window) === null || _window8 === void 0 ? void 0 : _window8.contextPath, "/").concat(redirectPath);
287
+ var params = new URLSearchParams();
288
+ params.set("client_id", clientId);
289
+ params.set("response_type", responseType);
290
+ params.set("redirect_uri", redirectUri);
291
+ if (nonce) params.set("nonce", nonce);
292
+ if (responseMode) params.set("response_mode", responseMode);
293
+ if (scopes && scopes.length) params.set("scope", scopes.join(" "));
294
+ if (resource) params.set("resource", resource);
295
+
296
+ // Handle prompt parameter with priority:
297
+ // 1. Use configured prompt from SSO config (respects admin configuration)
298
+ // 2. Fall back to forced login only if no prompt is configured AND a previous login failed
299
+ try {
300
+ var forcePromptLogin = window.sessionStorage.getItem("sso.force.prompt.login") === "true";
301
+ if (prompt) {
302
+ // Respect configured prompt (e.g., "select_account", "consent")
303
+ params.set("prompt", prompt);
304
+ // Clear the force flag since we're using configured prompt
305
+ if (forcePromptLogin) {
306
+ window.sessionStorage.removeItem("sso.force.prompt.login");
307
+ }
308
+ } else if (forcePromptLogin) {
309
+ // Only force login if no prompt is configured
310
+ params.set("prompt", "login");
311
+ window.sessionStorage.removeItem("sso.force.prompt.login");
312
+ }
313
+ } catch (e) {
314
+ // If prompt is configured, still set it even if sessionStorage fails
315
+ if (prompt) {
316
+ params.set("prompt", prompt);
317
+ }
318
+ }
319
+ return "".concat(authorizeUrl, "?").concat(params.toString());
320
+ };
321
+ var onSSOLogin = /*#__PURE__*/function () {
322
+ var _ref4 = _asyncToGenerator(function* (ssoConfig) {
323
+ // For OIDC-like providers (MICROSOFT, GOOGLE, etc.), use generic OIDC login
324
+ var ui = (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.ui) || {};
325
+ var hasOidcConfig = Boolean((ui.authorizeUrl || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.authorizeUrl)) && ui.clientId);
326
+ if (ui.authStrategy === "OIDC_POPUP" || ui.provider === "MICROSOFT" || hasOidcConfig) {
327
+ return onOIDCLogin(ssoConfig);
328
+ }
329
+
330
+ // If the config doesn't match any known SSO strategy, don't leave the overlay loader stuck.
331
+ setShowToast("SSO configuration is invalid or unsupported");
332
+ setTimeout(closeToast, 5000);
333
+ });
334
+ return function onSSOLogin(_x2) {
335
+ return _ref4.apply(this, arguments);
336
+ };
337
+ }();
338
+ var onOIDCLogin = /*#__PURE__*/function () {
339
+ var _ref5 = _asyncToGenerator(function* (ssoConfig) {
340
+ try {
341
+ var ui = _objectSpread({}, (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.ui) || {});
342
+ // Backward-compatibility for older configs where authorizeUrl/resource
343
+ // might be on the top level instead of inside ui.
344
+ ui.authorizeUrl = ui.authorizeUrl || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.authorizeUrl);
345
+ ui.resource = ui.resource || (ssoConfig === null || ssoConfig === void 0 ? void 0 : ssoConfig.resource);
346
+ // For Microsoft, if resource is not explicitly provided, default it to clientId (v1 behavior).
347
+ if (ui.provider === "MICROSOFT" && !ui.resource) {
348
+ ui.resource = ui.clientId;
349
+ }
350
+ // Persist provider + logout-relevant info for later use during logout
351
+ if (ui.provider) {
352
+ localStorage.setItem("sso-provider", ui.provider);
353
+ }
354
+ if (ui.logoutUrl) {
355
+ localStorage.setItem("sso-logout-url", ui.logoutUrl);
356
+ }
357
+ if (ui.logoutRedirectParam) {
358
+ localStorage.setItem("sso-logout-redirect-param", ui.logoutRedirectParam);
359
+ }
360
+ if (ui.tenantId) {
361
+ localStorage.setItem("sso-tenant-id", ui.tenantId);
362
+ }
363
+ if (ui.authority) {
364
+ localStorage.setItem("sso-authority", ui.authority);
365
+ }
366
+ var url = buildOIDCAuthorizeUrl(ui);
367
+ // Simple implementation: redirect for OIDC if no library is present
368
+ // For a better experience, a popup and message bridge should be used
369
+ window.location.href = url;
370
+ } catch (error) {
371
+ console.error("OIDC Login Error:", error);
372
+ setShowToast(error.message || "OIDC Login Failed");
373
+ setTimeout(closeToast, 5000);
374
+ setLoginLoader(false);
375
+ }
376
+ });
377
+ return function onOIDCLogin(_x3) {
378
+ return _ref5.apply(this, arguments);
379
+ };
380
+ }();
381
+ var onLogin = /*#__PURE__*/function () {
382
+ var _ref6 = _asyncToGenerator(function* (data) {
383
+ var _requestData$city, _Digit;
384
+ // if (!data.city) {
385
+ // alert("Please Select City!");
386
+ // return;
387
+ // }
388
+ if (data !== null && data !== void 0 && data.username) {
389
+ data.username = data.username.trim();
390
+ }
391
+ if (data !== null && data !== void 0 && data.password) {
392
+ data.password = data.password.trim();
393
+ }
394
+ setDisable(true);
395
+ setLoginLoader(true);
396
+ var requestData = _objectSpread(_objectSpread(_objectSpread({}, data), defaultValues), {}, {
397
+ userType: "EMPLOYEE"
398
+ });
399
+ 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());
400
+ delete requestData.city;
401
+ try {
402
+ var _yield$Digit$UserServ = yield Digit.UserService.authenticate(requestData),
403
+ {
404
+ UserRequest: info
405
+ } = _yield$Digit$UserServ,
406
+ tokens = _objectWithoutProperties(_yield$Digit$UserServ, _excluded3);
407
+ Digit.SessionStorage.set("Employee.tenantId", info === null || info === void 0 ? void 0 : info.tenantId);
408
+ setUser(_objectSpread({
409
+ info
410
+ }, tokens));
411
+ } catch (err) {
412
+ var _err$response2;
413
+ 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"));
414
+ setTimeout(closeToast, 5000);
415
+ }
416
+ setDisable(false);
417
+ setLoginLoader(false);
418
+ });
419
+ return function onLogin(_x4) {
420
+ return _ref6.apply(this, arguments);
421
+ };
422
+ }();
423
+ var reqCreate = {
424
+ url: "/user-otp/v1/_send",
425
+ params: {
426
+ tenantId: (_Digit2 = Digit) === null || _Digit2 === void 0 || (_Digit2 = _Digit2.ULBService) === null || _Digit2 === void 0 ? void 0 : _Digit2.getStateId()
427
+ },
428
+ body: {},
429
+ config: {
430
+ enable: false
431
+ }
432
+ };
433
+ var mutation = Digit.Hooks.useCustomAPIMutationHook(reqCreate);
434
+ var onOtpLogin = /*#__PURE__*/function () {
435
+ var _ref7 = _asyncToGenerator(function* (data) {
436
+ var _Digit3;
437
+ var inputEmail = data.email;
438
+ yield mutation.mutate({
439
+ body: {
440
+ otp: {
441
+ userName: data.email,
442
+ type: "login",
443
+ tenantId: (_Digit3 = Digit) === null || _Digit3 === void 0 || (_Digit3 = _Digit3.ULBService) === null || _Digit3 === void 0 ? void 0 : _Digit3.getStateId(),
444
+ userType: "EMPLOYEE"
445
+ }
446
+ },
447
+ config: {
448
+ enable: true
449
+ }
450
+ }, {
451
+ onError: (error, variables) => {
452
+ var _error$response, _error$response2;
453
+ 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");
454
+ setTimeout(closeToast, 5000);
455
+ },
456
+ onSuccess: function () {
457
+ var _onSuccess = _asyncToGenerator(function* (data) {
458
+ var _window9, _Digit4;
459
+ navigate("/".concat((_window9 = window) === null || _window9 === void 0 ? void 0 : _window9.contextPath, "/employee/user/login/otp"), {
460
+ state: {
461
+ email: inputEmail,
462
+ tenant: (_Digit4 = Digit) === null || _Digit4 === void 0 || (_Digit4 = _Digit4.ULBService) === null || _Digit4 === void 0 ? void 0 : _Digit4.getStateId()
463
+ }
464
+ });
465
+ });
466
+ function onSuccess(_x6) {
467
+ return _onSuccess.apply(this, arguments);
468
+ }
469
+ return onSuccess;
470
+ }()
471
+ });
472
+ });
473
+ return function onOtpLogin(_x5) {
474
+ return _ref7.apply(this, arguments);
475
+ };
476
+ }();
477
+ var closeToast = () => {
478
+ setShowToast(null);
479
+ };
480
+ var onForgotPassword = () => {
481
+ var _window0;
482
+ navigate("/".concat((_window0 = window) === null || _window0 === void 0 ? void 0 : _window0.contextPath, "/employee/user/forgot-password"));
483
+ };
484
+ var defaultTenant = Digit.ULBService.getStateId();
485
+ var defaultValue = {
486
+ code: defaultTenant,
487
+ name: Digit.Utils.locale.getTransformedLocale("TENANT_TENANTS_".concat(defaultTenant))
488
+ };
489
+ var ssoConfigs = ssoMDMSData === null || ssoMDMSData === void 0 ? void 0 : ssoMDMSData.map(sso => {
490
+ var _sso$ui, _sso$ui2, _sso$ui3, _sso$ui4, _sso$ui5, _sso$ui6;
491
+ return _objectSpread(_objectSpread({}, sso), {}, {
492
+ provider: ((_sso$ui = sso.ui) === null || _sso$ui === void 0 ? void 0 : _sso$ui.provider) || sso.provider || "sso",
493
+ label: t("SSO_PROVIDER_".concat(((_sso$ui2 = sso.ui) === null || _sso$ui2 === void 0 ? void 0 : _sso$ui2.name) || sso.id)),
494
+ icon: (_sso$ui3 = sso.ui) !== null && _sso$ui3 !== void 0 && _sso$ui3.logo ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("img", {
495
+ src: sso.ui.logo,
496
+ alt: (_sso$ui4 = sso.ui) === null || _sso$ui4 === void 0 ? void 0 : _sso$ui4.name,
497
+ className: "employee-login-sso-logo"
498
+ }) : ((_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,
499
+ onLogin: ssoConfig => {
500
+ onSSOLogin(ssoConfig);
501
+ }
502
+ });
503
+ });
504
+ var config = [{
505
+ 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), {}, {
506
+ customProps: _objectSpread(_objectSpread({}, field.customProps), {}, {
507
+ ssoConfigs
508
+ })
509
+ }) : field)
510
+ }];
511
+ var {
512
+ mode
513
+ } = Digit.Hooks.useQueryParams();
514
+ 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) {
515
+ config[0].body[2].disable = true;
516
+ config[0].body[2].isMandatory = false;
517
+ config[0].body[2].populators.defaultValue = defaultValue;
518
+ }
519
+ var defaultValues = (0,react__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => Object.fromEntries(config[0].body.filter(field => {
520
+ var _field$populators, _field$populators2;
521
+ 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);
522
+ }).map(field => [field.populators.name, field.populators.defaultValue])), []);
523
+ var onFormValueChange = (setValue, formData, formState) => {
524
+ // Extract keys from the config
525
+ 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);
526
+ var hasEmptyFields = keys.some(key => {
527
+ var value = formData[key];
528
+ return value == null || value === "" || value === false;
529
+ });
530
+ setDisable(hasEmptyFields);
531
+ };
532
+ var renderLoginForm = function renderLoginForm() {
533
+ var _propsConfig$texts, _propsConfig$texts2, _propsConfig$texts3;
534
+ var extraClasses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
535
+ var cardClassName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
536
+ var wrapperClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
537
+ return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.FormComposerV2, {
538
+ onSubmit: loginOTPBased ? onOtpLogin : onLogin,
539
+ isDisabled: isDisabled || disable,
540
+ noBoxShadow: true,
541
+ inline: true,
542
+ submitInForm: true,
543
+ config: config,
544
+ label: propsConfig === null || propsConfig === void 0 || (_propsConfig$texts = propsConfig.texts) === null || _propsConfig$texts === void 0 ? void 0 : _propsConfig$texts.submitButtonLabel,
545
+ 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") ? "?" : ""),
546
+ onSecondayActionClick: onForgotPassword,
547
+ onFormValueChange: onFormValueChange,
548
+ heading: propsConfig === null || propsConfig === void 0 || (_propsConfig$texts3 = propsConfig.texts) === null || _propsConfig$texts3 === void 0 ? void 0 : _propsConfig$texts3.header,
549
+ className: "".concat(wrapperClass),
550
+ cardSubHeaderClassName: "loginCardSubHeaderClassName",
551
+ cardClassName: cardClassName,
552
+ buttonClassName: "buttonClassName",
553
+ defaultValues: defaultValues,
554
+ 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"], {
555
+ showTenant: false
556
+ })
557
+ });
558
+ };
559
+ var renderFooter = footerClassName => {
560
+ var _window1, _window1$getConfig;
561
+ return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", {
562
+ className: footerClassName,
563
+ style: {
564
+ backgroundColor: "unset"
565
+ },
566
+ children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_components_ImageComponent__WEBPACK_IMPORTED_MODULE_7__["default"], {
567
+ alt: "Powered by DIGIT",
568
+ 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"),
569
+ style: {
570
+ cursor: "pointer"
571
+ },
572
+ onClick: () => {
573
+ var _window10, _window10$getConfig;
574
+ 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();
575
+ }
576
+ })
577
+ });
578
+ };
579
+ if (isLoading || isStoreLoading) {
580
+ return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Loader, {
581
+ page: true,
582
+ variant: "PageLoader"
583
+ });
584
+ }
585
+ return propsConfig !== null && propsConfig !== void 0 && propsConfig.bannerImages ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)("div", {
586
+ className: "login-container",
587
+ children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_Carousel_Carousel__WEBPACK_IMPORTED_MODULE_6__["default"], {
588
+ bannerImages: propsConfig === null || propsConfig === void 0 ? void 0 : propsConfig.bannerImages
589
+ }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)("div", {
590
+ className: "login-form-container",
591
+ 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, {
592
+ type: "error",
593
+ label: t(showToast),
594
+ onClose: closeToast
595
+ }), renderFooter("EmployeeLoginFooter")]
596
+ })]
597
+ }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_components_Background__WEBPACK_IMPORTED_MODULE_4__["default"], {
598
+ children: [loginLoader && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", {
599
+ style: {
600
+ position: "fixed",
601
+ top: 0,
602
+ left: 0,
603
+ width: "100vw",
604
+ height: "100vh",
605
+ background: "rgba(0,0,0,0.35)",
606
+ display: "flex",
607
+ alignItems: "center",
608
+ justifyContent: "center",
609
+ zIndex: 9999
610
+ },
611
+ children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.Loader, {})
612
+ }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", {
613
+ className: "employeeBackbuttonAlign",
614
+ children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_egovernments_digit_ui_components__WEBPACK_IMPORTED_MODULE_0__.BackLink, {
615
+ onClick: () => window.history.back()
616
+ })
617
+ }), 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, {
618
+ type: "error",
619
+ label: t(showToast),
620
+ onClose: closeToast
621
+ }), renderFooter("employee-login-home-footer")]
622
+ });
623
+ };
624
+ Login.propTypes = {
625
+ loginParams: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().any)
626
+ };
627
+ Login.defaultProps = {
628
+ loginParams: null
629
+ };
630
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_hoc_withAutoFocusMain__WEBPACK_IMPORTED_MODULE_8__["default"])(Login, ".login-form-container"));
631
+
632
+ /***/ })
633
+
634
+ },
635
+ /******/ function(__webpack_require__) { // webpackRuntimeModules
636
+ /******/ /* webpack/runtime/getFullHash */
637
+ /******/ (() => {
638
+ /******/ __webpack_require__.h = () => ("5a340d1659238e20c0b3")
639
+ /******/ })();
640
+ /******/
641
+ /******/ }
642
+ );
643
+ //# sourceMappingURL=main.08f8755983b7134bc9cd.hot-update.js.map