@ssplib/react-components 0.0.82 → 0.0.84

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export default function NavBar({ links, title, img, pos, next, el, menuItems, }: {
2
+ export default function NavBar({ links, title, img, pos, next, el, menuItems, logoutMsg, logoutURL, }: {
3
3
  links: {
4
4
  name: string;
5
5
  path: string;
@@ -9,5 +9,7 @@ export default function NavBar({ links, title, img, pos, next, el, menuItems, }:
9
9
  menuItems: JSX.Element | JSX.Element[];
10
10
  next?: boolean;
11
11
  el?: JSX.Element;
12
+ logoutMsg?: string;
13
+ logoutURL?: string;
12
14
  pos?: 'fixed' | 'inherit';
13
15
  }): JSX.Element;
@@ -37,7 +37,7 @@ const link_1 = __importDefault(require("next/link"));
37
37
  const router_1 = require("next/router");
38
38
  const react_1 = __importStar(require("react"));
39
39
  const auth_1 = require("../../context/auth");
40
- function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems, }) {
40
+ function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems, logoutMsg = 'Sair', logoutURL = '/', }) {
41
41
  let router = undefined;
42
42
  if (next)
43
43
  router = (0, router_1.useRouter)();
@@ -107,11 +107,11 @@ function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems,
107
107
  menuItems,
108
108
  react_1.default.createElement(material_1.MenuItem, { onClick: (e) => {
109
109
  setAvatarAnchor(null);
110
- logout();
110
+ logout(logoutURL);
111
111
  } },
112
112
  react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
113
113
  react_1.default.createElement(LogoutOutlined_1.default, { sx: { fill: '#545454' } }),
114
- react_1.default.createElement(material_1.Typography, { textTransform: 'capitalize' }, "Sair"))))),
114
+ react_1.default.createElement(material_1.Typography, { textTransform: 'capitalize' }, logoutMsg))))),
115
115
  react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 0.4, alignItems: 'center', onClick: (e) => setAvatarAnchor(e.currentTarget), sx: { userSelect: 'none' } },
116
116
  react_1.default.createElement(material_1.Typography, null, "Ol\u00E1,"),
117
117
  react_1.default.createElement(material_1.Typography, { fontWeight: 600 }, user.name),
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
- export declare function Login({ imgURL, name, children, loginURL }: {
2
+ export declare function Login({ imgURL, name, children, loginURL, captchaSiteKey, }: {
3
3
  imgURL?: string;
4
4
  loginURL: string;
5
5
  children: JSX.Element | JSX.Element[];
6
6
  name?: string;
7
+ captchaSiteKey?: string;
7
8
  }): JSX.Element;
@@ -36,12 +36,16 @@ const React = __importStar(require("react"));
36
36
  const react_1 = require("react");
37
37
  const auth_1 = require("../../context/auth");
38
38
  const FormProvider_1 = __importDefault(require("../providers/FormProvider"));
39
- function Login({ imgURL = '', name = 'Login', children, loginURL }) {
39
+ const react_google_recaptcha_1 = __importDefault(require("react-google-recaptcha"));
40
+ function Login({ imgURL = '', name = 'Login', children, loginURL, captchaSiteKey, }) {
40
41
  const [loading, setLoading] = (0, react_1.useState)(false);
41
42
  const [error, setError] = (0, react_1.useState)(false);
43
+ const [captchaSolved, setCaptchaSolved] = (0, react_1.useState)(false);
44
+ const [captchaToken, setCaptchaToken] = (0, react_1.useState)('');
45
+ const captcha = (0, react_1.useRef)(null);
42
46
  const { adLogin } = (0, react_1.useContext)(auth_1.AuthContext);
43
47
  function onLogin(data) {
44
- adLogin(loginURL, data, setLoading, setError);
48
+ adLogin(loginURL, data, setLoading, setError, captchaToken);
45
49
  }
46
50
  return (React.createElement(FormProvider_1.default, { onSubmit: onLogin },
47
51
  React.createElement(Container_1.default, { component: 'main', maxWidth: 'xs' },
@@ -55,7 +59,10 @@ function Login({ imgURL = '', name = 'Login', children, loginURL }) {
55
59
  React.createElement(Typography_1.default, { component: 'h1', variant: 'h5', paddingY: 3 }, name),
56
60
  React.createElement(material_1.Stack, { spacing: 3, width: 300 },
57
61
  React.createElement(material_1.Stack, { spacing: 1 }, children),
58
- React.createElement(lab_1.LoadingButton, { type: 'submit', fullWidth: true, variant: 'contained', loading: loading }, "Login"),
62
+ captchaSiteKey && (React.createElement(react_google_recaptcha_1.default, { ref: captcha, hl: 'pt', sitekey: captchaSiteKey, onExpired: () => setCaptchaSolved(false), onChange: (e) => {
63
+ setCaptchaToken(e), e && setCaptchaSolved(true);
64
+ } })),
65
+ React.createElement(lab_1.LoadingButton, { type: 'submit', fullWidth: true, variant: 'contained', loading: loading, disabled: !captchaSolved }, "Login"),
59
66
  error && (React.createElement(Box_1.default, { bgcolor: '#ce4257', padding: 2, borderRadius: 2, color: 'white' },
60
67
  React.createElement(Typography_1.default, null, "Dados incorretos. Tente novamente!"))))))));
61
68
  }
@@ -72,11 +72,11 @@ function LoginProvider({ children, AUTH_URL, redirectURL = '/', validateTokenRou
72
72
  }
73
73
  });
74
74
  }, []);
75
- function adLogin(loginURL, data, setLoading, setError) {
75
+ function adLogin(loginURL, data, setLoading, setError, captchaToken) {
76
76
  setLoading(true);
77
77
  fetch(loginURL, {
78
78
  method: 'POST',
79
- body: JSON.stringify(Object.assign(Object.assign({}, data), { cpf: data.cpf.replaceAll(/[.-]/g, '') })),
79
+ body: JSON.stringify(Object.assign(Object.assign({}, data), { cpf: data.cpf.replaceAll(/[.-]/g, ''), captchaToken })),
80
80
  headers: {
81
81
  'Content-Type': 'application/json',
82
82
  },
@@ -62,7 +62,7 @@ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTo
62
62
  },
63
63
  }).then((res) => {
64
64
  if (!res.ok) {
65
- logout();
65
+ logout('/');
66
66
  return;
67
67
  }
68
68
  else {
@@ -124,12 +124,12 @@ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTo
124
124
  router.replace(redirectURL).finally(() => setUserLoaded(true));
125
125
  });
126
126
  }
127
- function logout() {
127
+ function logout(url) {
128
128
  setUserLoaded(false);
129
129
  setUser(null);
130
130
  (0, cookies_next_1.deleteCookie)(exports.cookieName);
131
131
  localStorage.removeItem(userImgName);
132
- router.replace(redirectURL).finally(() => setUserLoaded(true));
132
+ router.replace(url).finally(() => setUserLoaded(true));
133
133
  }
134
134
  return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, adLogin: () => { }, logout, saveUserData, type: 'govbr' } }, children);
135
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",
package/types/auth.d.ts CHANGED
@@ -67,7 +67,7 @@ export interface AuthReturnData {
67
67
  user: User | null | undefined;
68
68
  userLoaded: boolean;
69
69
  login: () => void;
70
- adLogin: (loginURL: string, data: any, setLoading: React.Dispatch<React.SetStateAction<boolean>>, setError: React.Dispatch<React.SetStateAction<boolean>>) => void;
70
+ adLogin: (loginURL: string, data: any, setLoading: React.Dispatch<React.SetStateAction<boolean>>, setError: React.Dispatch<React.SetStateAction<boolean>>, captchaToken: string) => void;
71
71
  saveUserData: (token: AuthReturn) => void;
72
- logout: () => void;
72
+ logout: (url: string) => void;
73
73
  }