@nibssplc/cams-sdk-react 0.0.1-beta.77 → 0.0.1-beta.79

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.
package/dist/index.esm.js CHANGED
@@ -6,13 +6,13 @@ import { MsalProvider, useMsal, useAccount } from '@azure/msal-react';
6
6
  import { PublicClientApplication, InteractionStatus } from '@azure/msal-browser';
7
7
  import z$1, { z } from 'zod';
8
8
  import { OTPInput, OTPInputContext, REGEXP_ONLY_DIGITS } from 'input-otp';
9
- import { RectangleEllipsis, XIcon, CheckCircle, Mail, Shield, ShieldCheck, ShieldClose } from 'lucide-react';
9
+ import { RectangleEllipsis, XIcon, CheckCircle, Mail, Shield, ShieldCheck, ShieldClose, KeyIcon, Loader2 } from 'lucide-react';
10
10
  import { appendErrors, FormProvider, Controller, useFormContext, useFormState, useForm } from 'react-hook-form';
11
11
  import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
12
12
  import { clsx } from 'clsx';
13
13
  import { twMerge } from 'tailwind-merge';
14
14
  import { Slot } from '@radix-ui/react-slot';
15
- import '@radix-ui/react-label';
15
+ import * as LabelPrimitive from '@radix-ui/react-label';
16
16
  import { cva } from 'class-variance-authority';
17
17
  import * as DialogPrimitive from '@radix-ui/react-dialog';
18
18
  import { toast } from 'sonner';
@@ -114,15 +114,17 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
114
114
 
115
115
  function useCAMSAuth(options) {
116
116
  var _this = this;
117
+ var _a;
117
118
  if (options === void 0) { options = {
118
119
  appCode: "",
120
+ loginExpiry: 1,
119
121
  storageKey: "CAMS-AUTH-SDK",
120
122
  }; }
121
- var _a = useState(false), isAuthenticated = _a[0], setIsAuthenticated = _a[1];
122
- var _b = useState(false), isLoading = _b[0], setIsLoading = _b[1];
123
- var _c = useState(null), error = _c[0], setError = _c[1];
124
- var _d = useState(""), token = _d[0], setToken = _d[1];
125
- var _e = useState(null), profile = _e[0], setProfile = _e[1];
123
+ var _b = useState(false), isAuthenticated = _b[0], setIsAuthenticated = _b[1];
124
+ var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
125
+ var _d = useState(null), error = _d[0], setError = _d[1];
126
+ var _e = useState(""), token = _e[0], setToken = _e[1];
127
+ var _f = useState(null), profile = _f[0], setProfile = _f[1];
126
128
  var sessionManagerRef = useRef(null);
127
129
  useEffect(function () {
128
130
  var _a, _b;
@@ -133,7 +135,7 @@ function useCAMSAuth(options) {
133
135
  if (isPopupWindow()) {
134
136
  initializePopupAuth();
135
137
  }
136
- (_a = sessionManagerRef.current) !== null && _a !== void 0 ? _a : (sessionManagerRef.current = new CAMSSessionManager(localStorage, options.storageKey || "CAMS-SDK", {
138
+ (_a = sessionManagerRef.current) !== null && _a !== void 0 ? _a : (sessionManagerRef.current = new CAMSSessionManager(localStorage, options.storageKey || "CAMS-AUTH-SDK", {
137
139
  onAuthSuccess: function (res) {
138
140
  var _a;
139
141
  setToken(res.userProfile.tokens.Bearer);
@@ -169,40 +171,53 @@ function useCAMSAuth(options) {
169
171
  }
170
172
  }, [options.storageKey]);
171
173
  var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
172
- var loginConfig, userProfile, err_1;
173
- var _a;
174
- return __generator(this, function (_b) {
175
- switch (_b.label) {
174
+ var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
175
+ var _a, _b, _c;
176
+ return __generator(this, function (_d) {
177
+ switch (_d.label) {
176
178
  case 0:
177
179
  if (!sessionManagerRef.current)
178
180
  return [2 /*return*/];
179
181
  setIsLoading(true);
180
182
  setError(null);
181
- _b.label = 1;
183
+ _d.label = 1;
182
184
  case 1:
183
- _b.trys.push([1, 4, 5, 6]);
184
- loginConfig = __assign(__assign({}, config), {
185
- // autoClose: options.autoClose ?? config.autoClose,
186
- idleTimeout: (_a = options.idleTimeout) !== null && _a !== void 0 ? _a : config.idleTimeout });
185
+ _d.trys.push([1, 4, 8, 9]);
186
+ loginConfig = __assign(__assign({}, config), { idleTimeout: options.idleTimeout });
187
187
  return [4 /*yield*/, sessionManagerRef.current.login(loginConfig)];
188
188
  case 2:
189
- _b.sent();
189
+ _d.sent();
190
190
  return [4 /*yield*/, sessionManagerRef.current.getProfile()];
191
191
  case 3:
192
- userProfile = _b.sent();
192
+ userProfile = _d.sent();
193
193
  setProfile(userProfile);
194
- return [3 /*break*/, 6];
194
+ return [3 /*break*/, 9];
195
195
  case 4:
196
- err_1 = _b.sent();
196
+ err_1 = _d.sent();
197
+ e = err_1;
198
+ isPopupClosedError = ((_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.includes("Authentication window was closed")) ||
199
+ (e === null || e === void 0 ? void 0 : e.error) === "Authentication window was closed";
200
+ if (!(isPopupClosedError && sessionManagerRef.current.isAuthenticated())) return [3 /*break*/, 6];
201
+ restoredToken = (_b = sessionManagerRef.current.getAccessToken()) !== null && _b !== void 0 ? _b : "";
202
+ setToken(restoredToken);
203
+ setIsAuthenticated(true);
204
+ return [4 /*yield*/, sessionManagerRef.current.getProfile()];
205
+ case 5:
206
+ userProfile = _d.sent();
207
+ setProfile(userProfile);
208
+ (_c = options.onAuthSuccess) === null || _c === void 0 ? void 0 : _c.call(options, restoredToken);
209
+ return [3 /*break*/, 7];
210
+ case 6:
197
211
  setError(err_1);
198
212
  setIsAuthenticated(false);
199
213
  setToken("");
200
214
  setProfile(null);
201
- return [3 /*break*/, 6];
202
- case 5:
215
+ _d.label = 7;
216
+ case 7: return [3 /*break*/, 9];
217
+ case 8:
203
218
  setIsLoading(false);
204
219
  return [7 /*endfinally*/];
205
- case 6: return [2 /*return*/];
220
+ case 9: return [2 /*return*/];
206
221
  }
207
222
  });
208
223
  }); }, [options.idleTimeout]);
@@ -231,8 +246,9 @@ function useCAMSAuth(options) {
231
246
  error: error,
232
247
  token: token,
233
248
  profile: profile,
249
+ loginExpiry: (_a = options.loginExpiry) !== null && _a !== void 0 ? _a : 1,
234
250
  appCode: options.appCode,
235
- storageKey: options.storageKey || "CAMS-SDK",
251
+ storageKey: options.storageKey || "CAMS-AUTH-SDK",
236
252
  };
237
253
  }
238
254
 
@@ -1398,6 +1414,11 @@ function InputOTPSlot(_a) {
1398
1414
  return (jsxRuntimeExports.jsxs("div", __assign({ "data-slot": "input-otp-slot", "data-active": isActive, className: cn("data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-12 w-12 items-center justify-center border-y border-r text-lg font-semibold shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]", className) }, props, { children: [char, hasFakeCaret && (jsxRuntimeExports.jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center", children: jsxRuntimeExports.jsx("div", { className: "animate-caret-blink bg-foreground h-4 w-px duration-1000" }) }))] })));
1399
1415
  }
1400
1416
 
1417
+ function Label(_a) {
1418
+ var className = _a.className, props = __rest(_a, ["className"]);
1419
+ return (jsxRuntimeExports.jsx(LabelPrimitive.Root, __assign({ "data-slot": "label", className: cn("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className) }, props)));
1420
+ }
1421
+
1401
1422
  var Form = FormProvider;
1402
1423
  var FormFieldContext = React.createContext({});
1403
1424
  var FormField = function (_a) {
@@ -1422,6 +1443,11 @@ function FormItem(_a) {
1422
1443
  var id = React.useId();
1423
1444
  return (jsxRuntimeExports.jsx(FormItemContext.Provider, { value: { id: id }, children: jsxRuntimeExports.jsx("div", __assign({ "data-slot": "form-item", className: cn("grid gap-2", className) }, props)) }));
1424
1445
  }
1446
+ function FormLabel(_a) {
1447
+ var className = _a.className, props = __rest(_a, ["className"]);
1448
+ var _b = useFormField(), error = _b.error, formItemId = _b.formItemId;
1449
+ return (jsxRuntimeExports.jsx(Label, __assign({ "data-slot": "form-label", "data-error": !!error, className: cn("data-[error=true]:text-destructive", className), htmlFor: formItemId }, props)));
1450
+ }
1425
1451
  function FormControl(_a) {
1426
1452
  var props = __rest(_a, []);
1427
1453
  var _b = useFormField(), error = _b.error, formItemId = _b.formItemId, formDescriptionId = _b.formDescriptionId, formMessageId = _b.formMessageId;
@@ -1686,7 +1712,7 @@ var useOTPHandler = function (_a) {
1686
1712
  });
1687
1713
  }
1688
1714
  else {
1689
- onAuthComplete(false, response);
1715
+ onAuthComplete(false, response.response.data);
1690
1716
  }
1691
1717
  return [2 /*return*/, false];
1692
1718
  }
@@ -1696,12 +1722,12 @@ var useOTPHandler = function (_a) {
1696
1722
  currentAttempt = attemptCount + 1;
1697
1723
  if (currentAttempt >= MAX_ATTEMPTS) {
1698
1724
  setIsMaxAttemptsReached(true);
1699
- onAuthComplete(false, error_1);
1725
+ onAuthComplete(false, error_1.response.data);
1700
1726
  }
1701
1727
  else {
1702
- onAuthComplete(false, error_1);
1728
+ onAuthComplete(false, error_1.response.data);
1703
1729
  }
1704
- onAuthComplete(false, error_1);
1730
+ onAuthComplete(false, error_1.response.data);
1705
1731
  return [2 /*return*/, false];
1706
1732
  case 4:
1707
1733
  setLoading(false);
@@ -1739,16 +1765,15 @@ var MFAOptions = function (_a) {
1739
1765
  var _d = useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1740
1766
  var _e = useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
1741
1767
  var _f = useState(null), authType = _f[0], setAuthType = _f[1];
1742
- var _g = useState(""); _g[0]; var setLastOTPCode = _g[1];
1743
1768
  var context = useCAMSContext$1();
1744
- var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1769
+ var _g = context.authMode === "MSAL" && "sendEmailOTP" in context
1745
1770
  ? context
1746
1771
  : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
1747
1772
  return [2 /*return*/];
1748
- }); }); } }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA, logout = _h.logout;
1773
+ }); }); } }, sendEmailOTP = _g.sendEmailOTP, completeMFA = _g.completeMFA, logout = _g.logout;
1749
1774
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1750
1775
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1751
- var _j = useOTPHandler({
1776
+ var _h = useOTPHandler({
1752
1777
  accessToken: accessToken || "",
1753
1778
  idToken: idToken || "",
1754
1779
  provider: "MSAL",
@@ -1766,11 +1791,11 @@ var MFAOptions = function (_a) {
1766
1791
  });
1767
1792
  }
1768
1793
  setShowSuccessAnimation(true);
1769
- toast.success(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
1794
+ toast.success(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
1770
1795
  setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1771
1796
  }
1772
1797
  else {
1773
- toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
1798
+ toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
1774
1799
  if (isMaxAttemptsReached) {
1775
1800
  setTimeout(function () {
1776
1801
  logout().then(function () {
@@ -1781,7 +1806,7 @@ var MFAOptions = function (_a) {
1781
1806
  }
1782
1807
  }
1783
1808
  },
1784
- }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1809
+ }), handleSubmitOTP = _h.handleSubmitOTP, loading = _h.loading, setLoading = _h.setLoading, attemptCount = _h.attemptCount, remainingAttempts = _h.remainingAttempts, isMaxAttemptsReached = _h.isMaxAttemptsReached, resetAttempts = _h.resetAttempts;
1785
1810
  var handleGoBack = function () {
1786
1811
  setAuthType(null);
1787
1812
  setOtpVisible(false);
@@ -1828,16 +1853,10 @@ var MFAOptions = function (_a) {
1828
1853
  setAuthType(null);
1829
1854
  setOtpVisible(false);
1830
1855
  setValue("");
1831
- }, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Email OTP" }) }), jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
1832
- setLastOTPCode(code);
1833
- return handleSubmitOTP(code);
1834
- }, fieldName: "EmailOTP", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] })] }) }));
1856
+ }, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Email OTP" }) }), jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) { return handleSubmitOTP(code); }, fieldName: "EmailOTP", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] })] }) }));
1835
1857
  }
1836
1858
  else if (authType === "AuthenticatorCode") {
1837
- content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Authenticator App" }) }), loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 h-full flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(CardDescription, { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
1838
- setLastOTPCode(code);
1839
- return handleSubmitOTP(code);
1840
- }, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] }))] }) }));
1859
+ content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Authenticator App" }) }), loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 h-full flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(CardDescription, { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) { return handleSubmitOTP(code); }, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] }))] }) }));
1841
1860
  }
1842
1861
  return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsxs(Card, { className: "space-y-6 p-6 rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("div", { className: "flex justify-center items", children: jsxRuntimeExports.jsx("img", { src: OTPAuthenticationImg, alt: "NIBSS Logo", width: 365, height: 365 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold mb-6 text-center", children: "Two-Factor Authentication" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-300 text-base -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { children: content }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }));
1843
1862
  };
@@ -1848,9 +1867,80 @@ var AuthLogo = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2
1848
1867
 
1849
1868
  var MicrosoftLogo = "data:image/svg+xml,%3Csvg%20width%3D%2225%22%20height%3D%2225%22%20viewBox%3D%220%200%2025%2025%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20id%3D%22microsoft_svgrepo.com%22%3E%3Cpath%20id%3D%22Vector%22%20d%3D%22M20.75%2013.25H13.25V20.75H20.75V13.25Z%22%20fill%3D%22%23FEBA08%22%2F%3E%3Cpath%20id%3D%22Vector_2%22%20d%3D%22M11.75%2013.25H4.25V20.75H11.75V13.25Z%22%20fill%3D%22%2305A6F0%22%2F%3E%3Cpath%20id%3D%22Vector_3%22%20d%3D%22M20.75%204.25H13.25V11.75H20.75V4.25Z%22%20fill%3D%22%2380BC06%22%2F%3E%3Cpath%20id%3D%22Vector_4%22%20d%3D%22M11.75%204.25H4.25V11.75H11.75V4.25Z%22%20fill%3D%22%23F25325%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E";
1850
1869
 
1870
+ var Input = React.forwardRef(function (_a, ref) {
1871
+ var className = _a.className, type = _a.type, props = __rest(_a, ["className", "type"]);
1872
+ return (jsxRuntimeExports.jsx("input", __assign({ type: type, className: cn("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref }, props)));
1873
+ });
1874
+ Input.displayName = "Input";
1875
+
1876
+ var credentialsSchema = z.object({
1877
+ username: z.string().min(1, "Username is required"),
1878
+ password: z.string().min(1, "Password is required"),
1879
+ });
1880
+ var ADLoginModal = function (_a) {
1881
+ var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
1882
+ var _b = useState("credentials"), step = _b[0], setStep = _b[1];
1883
+ var _c = useState({ username: "", password: "" }), credentials = _c[0], setCredentials = _c[1];
1884
+ var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
1885
+ var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
1886
+ var form = useForm({
1887
+ resolver: a$1(credentialsSchema),
1888
+ defaultValues: { username: "", password: "" },
1889
+ });
1890
+ var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
1891
+ return __generator(this, function (_a) {
1892
+ setCredentials(values);
1893
+ setStep("mfa");
1894
+ return [2 /*return*/];
1895
+ });
1896
+ }); };
1897
+ var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
1898
+ var error_1;
1899
+ return __generator(this, function (_a) {
1900
+ switch (_a.label) {
1901
+ case 0:
1902
+ setIsLoading(true);
1903
+ _a.label = 1;
1904
+ case 1:
1905
+ _a.trys.push([1, 3, 4, 5]);
1906
+ return [4 /*yield*/, onLogin(credentials.username, credentials.password, code)];
1907
+ case 2:
1908
+ _a.sent();
1909
+ onOpenChange(false);
1910
+ setStep("credentials");
1911
+ form.reset();
1912
+ setMfaCode("");
1913
+ return [3 /*break*/, 5];
1914
+ case 3:
1915
+ error_1 = _a.sent();
1916
+ console.error("AD login failed:", error_1);
1917
+ return [3 /*break*/, 5];
1918
+ case 4:
1919
+ setIsLoading(false);
1920
+ return [7 /*endfinally*/];
1921
+ case 5: return [2 /*return*/];
1922
+ }
1923
+ });
1924
+ }); };
1925
+ var handleClose = function () {
1926
+ onOpenChange(false);
1927
+ setStep("credentials");
1928
+ form.reset();
1929
+ setMfaCode("");
1930
+ };
1931
+ return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-md", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-5 h-5 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1932
+ var field = _a.field;
1933
+ return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
1934
+ } }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
1935
+ var field = _a.field;
1936
+ return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
1937
+ } }), jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntimeExports.jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1938
+ };
1939
+
1851
1940
  var DefaultLoginPage = function () {
1852
1941
  var context = useCAMSContext$1();
1853
1942
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1943
+ var _a = useState(false), showADModal = _a[0], setShowADModal = _a[1];
1854
1944
  var handleLogin = function () {
1855
1945
  if (authMode === "MSAL") {
1856
1946
  login();
@@ -1870,11 +1960,21 @@ var DefaultLoginPage = function () {
1870
1960
  },
1871
1961
  exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
1872
1962
  };
1873
- return (jsxRuntimeExports.jsx("main", { className: "min-h-screen bg-gray-50", children: jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-4", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Kindly use the below identity providers to authenticate"] }), jsxRuntimeExports.jsx("div", { className: "space-y-4", children: jsxRuntimeExports.jsxs(Button
1874
- // variant="outline"
1875
- , {
1876
- // variant="outline"
1877
- className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { children: isLoading ? 'Logging in...' : "Sign in with Microsoft" })] }) }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing") }));
1963
+ return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-4", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Kindly use the below identity providers to authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
1964
+ // variant="outline"
1965
+ , {
1966
+ // variant="outline"
1967
+ className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), jsxRuntimeExports.jsxs(Button
1968
+ // variant="outline"
1969
+ , {
1970
+ // variant="outline"
1971
+ className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, {}), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with AD" })] })] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, onLogin: function (username, password, mfaCode) { return __awaiter(void 0, void 0, void 0, function () {
1972
+ return __generator(this, function (_a) {
1973
+ // Implement your AD login logic here
1974
+ console.log("AD Login:", { username: username, password: password, mfaCode: mfaCode });
1975
+ return [2 /*return*/];
1976
+ });
1977
+ }); } })] }));
1878
1978
  };
1879
1979
 
1880
1980
  var ErrorFallback = function (_a) {