@ssplib/react-components 0.0.44 → 0.0.46
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.
|
@@ -116,7 +116,7 @@ function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems,
|
|
|
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),
|
|
118
118
|
react_1.default.createElement(KeyboardArrowDown_1.default, null)))) : type === 'govbr' ? (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: login, sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
119
|
-
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Entrar com o gov.br"))) : (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: login, sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
119
|
+
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Entrar com o gov.br"))) : (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: () => router === null || router === void 0 ? void 0 : router.push('/login'), sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
120
120
|
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Login"))))))),
|
|
121
121
|
loading && react_1.default.createElement(LinearProgress_1.default, null)),
|
|
122
122
|
react_1.default.createElement(material_1.Box, { paddingBottom: 9 })));
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare function Login({ imgURL, name,
|
|
2
|
+
export declare function Login({ imgURL, name, children, loginURL, onSuccess, onFail, }: {
|
|
3
3
|
imgURL?: string;
|
|
4
|
-
|
|
4
|
+
loginURL: string;
|
|
5
|
+
children: JSX.Element | JSX.Element[];
|
|
5
6
|
name?: string;
|
|
7
|
+
onSuccess: () => void;
|
|
8
|
+
onFail: () => void;
|
|
6
9
|
}): JSX.Element;
|
package/components/page/Login.js
CHANGED
|
@@ -27,24 +27,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Login = void 0;
|
|
30
|
+
const lab_1 = require("@mui/lab");
|
|
30
31
|
const material_1 = require("@mui/material");
|
|
31
32
|
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
32
|
-
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
33
33
|
const Container_1 = __importDefault(require("@mui/material/Container"));
|
|
34
34
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
35
35
|
const React = __importStar(require("react"));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
const react_1 = require("react");
|
|
37
|
+
const FormProvider_1 = __importDefault(require("../providers/FormProvider"));
|
|
38
|
+
const auth_1 = require("../../context/auth");
|
|
39
|
+
function Login({ imgURL = '', name = 'Login', children, loginURL, onSuccess, onFail, }) {
|
|
40
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
41
|
+
const { adLogin } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
42
|
+
function onLogin(data) {
|
|
43
|
+
adLogin(loginURL, data);
|
|
44
|
+
}
|
|
45
|
+
return (React.createElement(FormProvider_1.default, { onSubmit: onLogin },
|
|
46
|
+
React.createElement(Container_1.default, { component: 'main', maxWidth: 'xs' },
|
|
47
|
+
React.createElement(Box_1.default, { sx: {
|
|
48
|
+
marginTop: 8,
|
|
49
|
+
display: 'flex',
|
|
50
|
+
flexDirection: 'column',
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
} },
|
|
53
|
+
imgURL && React.createElement("img", { src: imgURL, alt: '', height: 100, width: 100 }),
|
|
54
|
+
React.createElement(Typography_1.default, { component: 'h1', variant: 'h5', paddingY: 3 }, name),
|
|
55
|
+
React.createElement(material_1.Stack, { spacing: 3, width: 300 },
|
|
56
|
+
React.createElement(material_1.Stack, { spacing: 1 }, children),
|
|
57
|
+
React.createElement(lab_1.LoadingButton, { type: 'submit', fullWidth: true, variant: 'contained', loading: loading }, "Login"))))));
|
|
49
58
|
}
|
|
50
59
|
exports.Login = Login;
|
|
@@ -72,24 +72,31 @@ function LoginProvider({ children, AUTH_URL, redirectURL = '/', validateTokenRou
|
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
}, []);
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
function adLogin(loginURL, data) {
|
|
76
|
+
fetch(loginURL, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
body: JSON.stringify(Object.assign(Object.assign({}, data), { cpf: data.cpf.replaceAll(/[.-]/g, '') })),
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
},
|
|
82
|
+
}).then((res) => {
|
|
83
|
+
if (res.ok) {
|
|
84
|
+
res.json().then((j) => {
|
|
85
|
+
const token = j.accessToken;
|
|
86
|
+
const user = (0, jwt_decode_1.default)(token);
|
|
87
|
+
setUser({
|
|
88
|
+
name: user.name,
|
|
89
|
+
image: '',
|
|
90
|
+
roles: user.roles.map((x) => x.code),
|
|
91
|
+
token: token,
|
|
92
|
+
});
|
|
93
|
+
(0, cookies_next_1.setCookie)(exports.cookieName, token);
|
|
94
|
+
router.replace(redirectURL).finally(() => setUserLoaded(true));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
setUserLoaded(true);
|
|
99
|
+
});
|
|
93
100
|
}
|
|
94
101
|
// chamado no callback de login
|
|
95
102
|
function saveUserData(authData) {
|
|
@@ -106,6 +113,6 @@ function LoginProvider({ children, AUTH_URL, redirectURL = '/', validateTokenRou
|
|
|
106
113
|
localStorage.removeItem(userImgName);
|
|
107
114
|
router.replace(redirectURL).finally(() => setUserLoaded(true));
|
|
108
115
|
}
|
|
109
|
-
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, logout, saveUserData, type: 'ad' } }, children);
|
|
116
|
+
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login: () => { }, adLogin, logout, saveUserData, type: 'ad' } }, children);
|
|
110
117
|
}
|
|
111
118
|
exports.LoginProvider = LoginProvider;
|
|
@@ -131,6 +131,6 @@ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTo
|
|
|
131
131
|
localStorage.removeItem(userImgName);
|
|
132
132
|
router.replace(redirectURL).finally(() => setUserLoaded(true));
|
|
133
133
|
}
|
|
134
|
-
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, logout, saveUserData, type: 'govbr' } }, children);
|
|
134
|
+
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, adLogin: () => { }, logout, saveUserData, type: 'govbr' } }, children);
|
|
135
135
|
}
|
|
136
136
|
exports.OAuthProvider = OAuthProvider;
|
package/package.json
CHANGED
package/types/auth.d.ts
CHANGED