@codebit-programando-solucoes/codebit-web-antd 1.1.23 → 1.1.24

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.
@@ -35,7 +35,9 @@ export interface CodebitConfigContextType {
35
35
  */
36
36
  menuItems: (user?: LoggedUser) => MenuItem[];
37
37
  /** Indicates if the user is currently logged in. */
38
- isLogged: boolean;
38
+ isLogged: boolean | null;
39
+ /** Sets the logged-in state manually. */
40
+ setIsLogged: React.Dispatch<React.SetStateAction<boolean | null>>;
39
41
  /** The current user object, null when not logged in. */
40
42
  user: LoggedUser | null;
41
43
  /** Logs out the current user and resets session state. */
package/dist/index.cjs CHANGED
@@ -294,21 +294,23 @@ var __webpack_exports__ = {};
294
294
  __webpack_require__.d(__webpack_exports__, {
295
295
  TableContainer: ()=>TableContainer,
296
296
  CssTokenBridge: ()=>CssTokenBridge,
297
+ LocalLoginAuthenticationEnum: ()=>LocalLoginAuthenticationEnum,
297
298
  LoggedMainContainer: ()=>LoggedMainContainer,
298
- Login: ()=>Login,
299
299
  CodebitThemeProvider: ()=>CodebitThemeProvider,
300
+ Login: ()=>Login,
300
301
  useErrorModal: ()=>useErrorModal,
302
+ LocalLoginChangePasswordResult: ()=>LocalLoginChangePasswordResult,
301
303
  ErrorRetry: ()=>ErrorRetry,
302
304
  CodebitThemeContext: ()=>CodebitThemeContext,
305
+ ChangePassword: ()=>ChangePassword,
303
306
  CodebitConfigContext: ()=>CodebitConfigContext,
304
- ListCard: ()=>ListCard,
305
307
  ForgotPassword: ()=>ForgotPassword,
308
+ ListCard: ()=>ListCard,
306
309
  LoginContainer: ()=>LoginContainer,
307
310
  useErrorMessage: ()=>useErrorMessage,
308
311
  LocalLoginRecoveryPasswordResult: ()=>LocalLoginRecoveryPasswordResult,
309
312
  FilterContainer: ()=>FilterContainer,
310
313
  HandleError: ()=>HandleError,
311
- LocalLoginAuthenticationResult: ()=>LocalLoginAuthenticationResult,
312
314
  CodebitConfigProvider: ()=>CodebitConfigProvider,
313
315
  ThemeToggle: ()=>ThemeToggle
314
316
  });
@@ -360,6 +362,7 @@ var __webpack_exports__ = {};
360
362
  const contextValue = (0, external_react_.useMemo)(()=>({
361
363
  menuItems,
362
364
  isLogged,
365
+ setIsLogged,
363
366
  user,
364
367
  logout,
365
368
  version,
@@ -453,7 +456,6 @@ var __webpack_exports__ = {};
453
456
  passwordRequired: 'Por favor, insira sua senha!',
454
457
  separator: 'ou',
455
458
  errorTitle: 'Erro ao autenticar',
456
- genericError: 'Ocorreu um erro. Por favor, tente novamente.',
457
459
  invalidPassword: 'A senha está incorreta.',
458
460
  invalidEmailOrPassword: 'O e-mail ou senha estão incorretos.',
459
461
  userDisabled: 'Sua conta foi desativada. Por favor, entre em contato com o suporte.',
@@ -482,7 +484,7 @@ var __webpack_exports__ = {};
482
484
  passwordLowerCase: 'uma letra minúscula',
483
485
  passwordNumbers: 'um número',
484
486
  passwordSpecialChars: 'um caractere especial (!@#$%^&*)',
485
- passwordWeak: 'Senha fraca: Deve ter pelo menos {requirements}',
487
+ passwordWeak: 'Senha fraca: Deve ter pelo menos {{requirements}}',
486
488
  passwordsNotMatch: 'As senhas digitadas não coincidem!',
487
489
  tokenInvalidTitle: 'Token inválido',
488
490
  tokenInvalidOrExpired: 'O token informado é inválido ou está expirado. Inicie o processo de recuperação de senha e tente novamente.',
@@ -505,6 +507,7 @@ var __webpack_exports__ = {};
505
507
  Common: {
506
508
  ok: 'Ok',
507
509
  close: 'Fechar',
510
+ genericError: 'Ocorreu um erro. Por favor, tente novamente.',
508
511
  invalidEmail: 'O e-mail é inválido ou não está registrado.',
509
512
  recaptchaFailed: 'Validação reCAPTCHA falhou. Por favor, tente novamente.'
510
513
  }
@@ -583,7 +586,7 @@ var __webpack_exports__ = {};
583
586
  passwordLowerCase: 'a lowercase letter',
584
587
  passwordNumbers: 'a number',
585
588
  passwordSpecialChars: 'a special character (!@#$%^&*)',
586
- passwordWeak: 'Weak password: Must have at least {requirements}',
589
+ passwordWeak: 'Weak password: Must have at least {{requirements}}',
587
590
  passwordsNotMatch: 'The passwords do not match!',
588
591
  tokenInvalidTitle: 'Invalid Token',
589
592
  tokenInvalidOrExpired: 'The provided token is invalid or expired. Start the password recovery process and try again.',
@@ -1286,7 +1289,7 @@ var __webpack_exports__ = {};
1286
1289
  children: external_prop_types_default().node
1287
1290
  };
1288
1291
  const Login_logger = new codebit_web_namespaceObject.Logger('Login');
1289
- const LocalLoginAuthenticationResult = Object.freeze({
1292
+ const LocalLoginAuthenticationEnum = Object.freeze({
1290
1293
  INVALID_EMAIL: 'INVALID_EMAIL',
1291
1294
  INVALID_PASSWORD: 'INVALID_PASSWORD',
1292
1295
  INVALID_EMAIL_OR_PASSWORD: 'INVALID_EMAIL_OR_PASSWORD',
@@ -1297,6 +1300,7 @@ var __webpack_exports__ = {};
1297
1300
  function Login({ title, oauthCallbackUrl, navigateToForgotPassword, submitAuthenticateLocalUser }) {
1298
1301
  const [localLoading, setLocalLoading] = (0, external_react_.useState)(false);
1299
1302
  const [googleLoading, setGoogleLoading] = (0, external_react_.useState)(false);
1303
+ const { setIsLogged } = (0, external_react_.useContext)(CodebitConfigContext);
1300
1304
  const [form] = external_antd_namespaceObject.Form.useForm();
1301
1305
  const { t } = useCodebitWebAntdTranslation();
1302
1306
  const { modal } = external_antd_namespaceObject.App.useApp();
@@ -1317,9 +1321,10 @@ var __webpack_exports__ = {};
1317
1321
  const { email, password } = values;
1318
1322
  const result = await submitAuthenticateLocalUser(email, password, context);
1319
1323
  switch(result){
1320
- case LocalLoginAuthenticationResult.SUCCESS:
1324
+ case LocalLoginAuthenticationEnum.SUCCESS:
1325
+ setIsLogged(null);
1321
1326
  break;
1322
- case LocalLoginAuthenticationResult.INVALID_EMAIL:
1327
+ case LocalLoginAuthenticationEnum.INVALID_EMAIL:
1323
1328
  form.setFields([
1324
1329
  {
1325
1330
  name: 'email',
@@ -1329,7 +1334,7 @@ var __webpack_exports__ = {};
1329
1334
  }
1330
1335
  ]);
1331
1336
  break;
1332
- case LocalLoginAuthenticationResult.INVALID_PASSWORD:
1337
+ case LocalLoginAuthenticationEnum.INVALID_PASSWORD:
1333
1338
  form.setFields([
1334
1339
  {
1335
1340
  name: 'password',
@@ -1339,7 +1344,7 @@ var __webpack_exports__ = {};
1339
1344
  }
1340
1345
  ]);
1341
1346
  break;
1342
- case LocalLoginAuthenticationResult.INVALID_EMAIL_OR_PASSWORD:
1347
+ case LocalLoginAuthenticationEnum.INVALID_EMAIL_OR_PASSWORD:
1343
1348
  form.setFields([
1344
1349
  {
1345
1350
  name: 'email',
@@ -1355,14 +1360,14 @@ var __webpack_exports__ = {};
1355
1360
  }
1356
1361
  ]);
1357
1362
  break;
1358
- case LocalLoginAuthenticationResult.RECAPTCHA_VALIDATION_FAIL:
1363
+ case LocalLoginAuthenticationEnum.RECAPTCHA_VALIDATION_FAIL:
1359
1364
  modal.error({
1360
1365
  title: t('Login.authenticationFailed'),
1361
1366
  content: t('Common.recaptchaFailed'),
1362
1367
  okText: t('Common.ok')
1363
1368
  });
1364
1369
  break;
1365
- case LocalLoginAuthenticationResult.USER_DISABLED:
1370
+ case LocalLoginAuthenticationEnum.USER_DISABLED:
1366
1371
  modal.error({
1367
1372
  title: t('Login.authenticationFailed'),
1368
1373
  content: t('Login.userDisabled'),
@@ -1373,7 +1378,7 @@ var __webpack_exports__ = {};
1373
1378
  Login_logger.warn('Unhandled authentication result:', result);
1374
1379
  modal.error({
1375
1380
  title: t('Login.authenticationFailed'),
1376
- content: t('Common.genericError'),
1381
+ content: result,
1377
1382
  okText: t('Common.ok')
1378
1383
  });
1379
1384
  }
@@ -1401,13 +1406,14 @@ var __webpack_exports__ = {};
1401
1406
  children: t('LoginContainer.signIn')
1402
1407
  }),
1403
1408
  /*#__PURE__*/ (0, jsx_runtime.jsxs)(external_antd_namespaceObject.Space, {
1404
- direction: 'vertical',
1409
+ orientation: 'vertical',
1405
1410
  size: 'large',
1406
1411
  style: {
1407
1412
  width: '100%'
1408
1413
  },
1409
1414
  children: [
1410
1415
  submitAuthenticateLocalUser && /*#__PURE__*/ (0, jsx_runtime.jsxs)(external_antd_namespaceObject.Form, {
1416
+ form: form,
1411
1417
  name: 'login-form',
1412
1418
  layout: 'vertical',
1413
1419
  onFinish: handleLocalLogin,
@@ -1699,6 +1705,203 @@ var __webpack_exports__ = {};
1699
1705
  navigateToLogin: external_prop_types_default().func,
1700
1706
  submitRecoveryPassword: external_prop_types_default().func.isRequired
1701
1707
  };
1708
+ const ChangePassword_logger = new codebit_web_namespaceObject.Logger('ChangePassword');
1709
+ const LocalLoginChangePasswordResult = Object.freeze({
1710
+ INVALID_TOKEN: 'INVALID_TOKEN',
1711
+ SUCCESS: 'SUCCESS'
1712
+ });
1713
+ const ChangePassword = ({ navigateToLogin, checkToken, submitChangePassword })=>{
1714
+ const navigate = (0, external_react_router_namespaceObject.useNavigate)();
1715
+ const [form] = external_antd_namespaceObject.Form.useForm();
1716
+ const { modal } = external_antd_namespaceObject.App.useApp();
1717
+ const [loading, setLoading] = (0, external_react_.useState)(false);
1718
+ const [checkingToken, setCheckingToken] = (0, external_react_.useState)(true);
1719
+ const { t } = useCodebitWebAntdTranslation();
1720
+ t('');
1721
+ const params = (0, external_react_router_namespaceObject.useParams)();
1722
+ const context = {
1723
+ navigate,
1724
+ params
1725
+ };
1726
+ const handleChangePassword = async (values)=>{
1727
+ try {
1728
+ setLoading(true);
1729
+ const result = await submitChangePassword(values.password, context);
1730
+ switch(result){
1731
+ case LocalLoginChangePasswordResult.SUCCESS:
1732
+ modal.success({
1733
+ title: t('ForgotPassword.title'),
1734
+ content: t('ChangePassword.passwordChangedSuccess'),
1735
+ onOk: handleNavigateToLogin,
1736
+ okText: t('Common.close')
1737
+ });
1738
+ break;
1739
+ case LocalLoginChangePasswordResult.INVALID_TOKEN:
1740
+ modal.error({
1741
+ title: t('ForgotPassword.title'),
1742
+ content: t('ChangePassword.tokenInvalidRecovery'),
1743
+ onOk: handleNavigateToLogin,
1744
+ okText: t('Common.close')
1745
+ });
1746
+ break;
1747
+ }
1748
+ } catch (error) {
1749
+ ChangePassword_logger.error(error);
1750
+ react_namespaceObject.captureException(error);
1751
+ modal.error({
1752
+ title: t('ForgotPassword.title'),
1753
+ content: t('Common.genericError'),
1754
+ okText: t('Common.ok')
1755
+ });
1756
+ } finally{
1757
+ setLoading(false);
1758
+ }
1759
+ };
1760
+ const handleNavigateToLogin = async ()=>{
1761
+ ChangePassword_logger.debug('Navigate to login.');
1762
+ await navigateToLogin(context);
1763
+ };
1764
+ async function handleCheckToken() {
1765
+ ChangePassword_logger.debug('Processing change password token.');
1766
+ setCheckingToken(false);
1767
+ try {
1768
+ const isValidToken = await checkToken(context);
1769
+ if (!isValidToken) {
1770
+ const message = t('ChangePassword.tokenInvalidOrExpired');
1771
+ modal.warning({
1772
+ title: t('ChangePassword.tokenInvalidTitle'),
1773
+ content: message,
1774
+ onOk: handleNavigateToLogin,
1775
+ okText: t('Common.close')
1776
+ });
1777
+ }
1778
+ } catch (error) {
1779
+ ChangePassword_logger.error(error);
1780
+ react_namespaceObject.captureException(error);
1781
+ modal.error({
1782
+ title: t('ChangePassword.title'),
1783
+ content: t('Common.genericError'),
1784
+ okText: t('Common.ok')
1785
+ });
1786
+ } finally{
1787
+ setCheckingToken(false);
1788
+ }
1789
+ }
1790
+ (0, external_react_.useEffect)(()=>{
1791
+ setCheckingToken(true);
1792
+ handleCheckToken().then();
1793
+ }, []);
1794
+ return /*#__PURE__*/ (0, jsx_runtime.jsx)(LoginContainer, {
1795
+ title: t('ChangePassword.title'),
1796
+ children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Spin, {
1797
+ spinning: checkingToken,
1798
+ children: /*#__PURE__*/ (0, jsx_runtime.jsxs)(external_antd_namespaceObject.Form, {
1799
+ form: form,
1800
+ name: 'change-password-form',
1801
+ onFinish: handleChangePassword,
1802
+ initialValues: {
1803
+ password: '',
1804
+ confirmPassword: ''
1805
+ },
1806
+ style: {
1807
+ width: '100%'
1808
+ },
1809
+ children: [
1810
+ /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Typography.Paragraph, {
1811
+ style: {
1812
+ textAlign: 'center'
1813
+ },
1814
+ children: t('ChangePassword.passwordInstructions')
1815
+ }),
1816
+ /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Form.Item, {
1817
+ name: 'password',
1818
+ rules: [
1819
+ {
1820
+ required: true,
1821
+ message: t('ChangePassword.passwordRequired')
1822
+ },
1823
+ {
1824
+ validator: (_, value)=>{
1825
+ const strengthChecks = {
1826
+ length: value.length >= 8,
1827
+ hasUpperCase: /[A-Z]/.test(value),
1828
+ hasLowerCase: /[a-z]/.test(value),
1829
+ hasNumbers: /\d/.test(value),
1830
+ hasSpecialChars: /[!@#$%^&*(),.?":{}|<>]/.test(value)
1831
+ };
1832
+ const failedChecks = Object.entries(strengthChecks).filter(([, passes])=>!passes).map(([key])=>key);
1833
+ if (0 === failedChecks.length) return Promise.resolve();
1834
+ const errorMessages = {
1835
+ length: t('ChangePassword.passwordLength'),
1836
+ hasUpperCase: t('ChangePassword.passwordUpperCase'),
1837
+ hasLowerCase: t('ChangePassword.passwordLowerCase'),
1838
+ hasNumbers: t('ChangePassword.passwordNumbers'),
1839
+ hasSpecialChars: t('ChangePassword.passwordSpecialChars')
1840
+ };
1841
+ const errorMessage = failedChecks.map((check)=>errorMessages[check]).join(', ');
1842
+ return Promise.reject(new Error(t('ChangePassword.passwordWeak', {
1843
+ requirements: errorMessage
1844
+ })));
1845
+ }
1846
+ }
1847
+ ],
1848
+ children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Input.Password, {
1849
+ prefix: /*#__PURE__*/ (0, jsx_runtime.jsx)(icons_namespaceObject.LockOutlined, {}),
1850
+ placeholder: t('ChangePassword.newPassword'),
1851
+ size: 'large'
1852
+ })
1853
+ }),
1854
+ /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Form.Item, {
1855
+ name: 'confirmPassword',
1856
+ rules: [
1857
+ {
1858
+ required: true,
1859
+ message: t('ChangePassword.passwordRequired')
1860
+ },
1861
+ ({ getFieldValue })=>({
1862
+ validator (_, value) {
1863
+ if (!value || getFieldValue('password') === value) return Promise.resolve();
1864
+ return Promise.reject(new Error(t('ChangePassword.passwordsNotMatch')));
1865
+ }
1866
+ })
1867
+ ],
1868
+ children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Input.Password, {
1869
+ prefix: /*#__PURE__*/ (0, jsx_runtime.jsx)(icons_namespaceObject.LockOutlined, {}),
1870
+ placeholder: t('ChangePassword.confirmPassword'),
1871
+ size: 'large'
1872
+ })
1873
+ }),
1874
+ /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Form.Item, {
1875
+ children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Button, {
1876
+ type: 'primary',
1877
+ htmlType: 'submit',
1878
+ size: 'large',
1879
+ loading: loading,
1880
+ style: {
1881
+ width: '100%'
1882
+ },
1883
+ children: t('ChangePassword.submit')
1884
+ })
1885
+ }),
1886
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("div", {
1887
+ style: {
1888
+ textAlign: 'center'
1889
+ },
1890
+ children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Typography.Link, {
1891
+ onClick: handleNavigateToLogin,
1892
+ children: t('ChangePassword.backToLogin')
1893
+ })
1894
+ })
1895
+ ]
1896
+ })
1897
+ })
1898
+ });
1899
+ };
1900
+ ChangePassword.propTypes = {
1901
+ navigateToLogin: external_prop_types_default().func.isRequired,
1902
+ checkToken: external_prop_types_default().func.isRequired,
1903
+ submitChangePassword: external_prop_types_default().func.isRequired
1904
+ };
1702
1905
  const useErrorModal_logger = new codebit_web_namespaceObject.Logger('useErrorModal');
1703
1906
  function useErrorModal() {
1704
1907
  const { modal } = external_antd_namespaceObject.App.useApp();
@@ -1727,6 +1930,7 @@ var __webpack_exports__ = {};
1727
1930
  };
1728
1931
  }
1729
1932
  })();
1933
+ exports.ChangePassword = __webpack_exports__.ChangePassword;
1730
1934
  exports.CodebitConfigContext = __webpack_exports__.CodebitConfigContext;
1731
1935
  exports.CodebitConfigProvider = __webpack_exports__.CodebitConfigProvider;
1732
1936
  exports.CodebitThemeContext = __webpack_exports__.CodebitThemeContext;
@@ -1737,7 +1941,8 @@ exports.FilterContainer = __webpack_exports__.FilterContainer;
1737
1941
  exports.ForgotPassword = __webpack_exports__.ForgotPassword;
1738
1942
  exports.HandleError = __webpack_exports__.HandleError;
1739
1943
  exports.ListCard = __webpack_exports__.ListCard;
1740
- exports.LocalLoginAuthenticationResult = __webpack_exports__.LocalLoginAuthenticationResult;
1944
+ exports.LocalLoginAuthenticationEnum = __webpack_exports__.LocalLoginAuthenticationEnum;
1945
+ exports.LocalLoginChangePasswordResult = __webpack_exports__.LocalLoginChangePasswordResult;
1741
1946
  exports.LocalLoginRecoveryPasswordResult = __webpack_exports__.LocalLoginRecoveryPasswordResult;
1742
1947
  exports.LoggedMainContainer = __webpack_exports__.LoggedMainContainer;
1743
1948
  exports.Login = __webpack_exports__.Login;
@@ -1747,6 +1952,7 @@ exports.ThemeToggle = __webpack_exports__.ThemeToggle;
1747
1952
  exports.useErrorMessage = __webpack_exports__.useErrorMessage;
1748
1953
  exports.useErrorModal = __webpack_exports__.useErrorModal;
1749
1954
  for(var __rspack_i in __webpack_exports__)if (-1 === [
1955
+ "ChangePassword",
1750
1956
  "CodebitConfigContext",
1751
1957
  "CodebitConfigProvider",
1752
1958
  "CodebitThemeContext",
@@ -1757,7 +1963,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
1757
1963
  "ForgotPassword",
1758
1964
  "HandleError",
1759
1965
  "ListCard",
1760
- "LocalLoginAuthenticationResult",
1966
+ "LocalLoginAuthenticationEnum",
1967
+ "LocalLoginChangePasswordResult",
1761
1968
  "LocalLoginRecoveryPasswordResult",
1762
1969
  "LoggedMainContainer",
1763
1970
  "Login",
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
+ import { NavigateFunction } from 'react-router';
2
3
 
3
4
  /** Enumeration of possible authentication result codes. */
4
- export enum LocalLoginAuthenticationResult {
5
+ export enum LocalLoginAuthenticationEnum {
5
6
  INVALID_EMAIL = 'INVALID_EMAIL',
6
7
  INVALID_PASSWORD = 'INVALID_PASSWORD',
7
8
  INVALID_EMAIL_OR_PASSWORD = 'INVALID_EMAIL_OR_PASSWORD',
@@ -10,14 +11,19 @@ export enum LocalLoginAuthenticationResult {
10
11
  SUCCESS = 'SUCCESS',
11
12
  }
12
13
 
14
+ /**
15
+ * Result type for local login authentication.
16
+ *
17
+ * It can be either one of the predefined values from {@link LocalLoginAuthenticationEnum} or a custom string message.
18
+ */
19
+ export type LocalLoginAuthenticationResult =
20
+ | LocalLoginAuthenticationEnum
21
+ | string;
22
+
13
23
  /** Context object passed to navigation and authentication callback functions. */
14
24
  export interface LocalLoginConfContext {
15
- /**
16
- * Function to navigate to another route.
17
- *
18
- * @param path - The path to navigate to.
19
- */
20
- navigate: (path: string) => void;
25
+ /** Function to navigate to another route. */
26
+ navigate: NavigateFunction;
21
27
  }
22
28
 
23
29
  /** Props for the Login component. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebit-programando-solucoes/codebit-web-antd",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "types": "./src/index.d.ts",