@visns-studio/visns-components 3.2.4 → 3.2.5
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/components/crm/Fetch.jsx +7 -1
- package/components/crm/generic/GenericAuth.jsx +150 -0
- package/index.js +2 -0
- package/package.json +1 -1
package/components/crm/Fetch.jsx
CHANGED
|
@@ -77,7 +77,13 @@ const CustomFetch = (
|
|
|
77
77
|
if (errorCallback) {
|
|
78
78
|
errorCallback(errorMessage);
|
|
79
79
|
} else {
|
|
80
|
-
|
|
80
|
+
if (errorMessage !== 'Unauthenticated.') {
|
|
81
|
+
toast.error(<div>{parse(errorMessage)}</div>);
|
|
82
|
+
} else {
|
|
83
|
+
console.info(
|
|
84
|
+
'You are not authenticated into the system.'
|
|
85
|
+
);
|
|
86
|
+
}
|
|
81
87
|
}
|
|
82
88
|
reject(error);
|
|
83
89
|
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useNavigate,
|
|
4
|
+
useLocation,
|
|
5
|
+
Routes,
|
|
6
|
+
Route,
|
|
7
|
+
Navigate,
|
|
8
|
+
Outlet,
|
|
9
|
+
} from 'react-router-dom';
|
|
10
|
+
import { ToastContainer } from 'react-toastify';
|
|
11
|
+
import { Tooltip } from 'react-tooltip';
|
|
12
|
+
import 'react-tooltip/dist/react-tooltip.css';
|
|
13
|
+
import 'react-toastify/dist/ReactToastify.css';
|
|
14
|
+
|
|
15
|
+
import CustomFetch from '../Fetch';
|
|
16
|
+
import Login from '../auth/Login';
|
|
17
|
+
import Reset from '../auth/Reset';
|
|
18
|
+
import Verify from '../auth/Verify';
|
|
19
|
+
|
|
20
|
+
import Main from './main';
|
|
21
|
+
import logo from '../images/logo.svg';
|
|
22
|
+
|
|
23
|
+
const ProtectedRoute = ({ user, loading, redirectPath = '/login' }) => {
|
|
24
|
+
return loading ? null : !user.id ? (
|
|
25
|
+
<Navigate to={redirectPath} replace />
|
|
26
|
+
) : (
|
|
27
|
+
<Outlet />
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Auth = () => {
|
|
32
|
+
const navigate = useNavigate();
|
|
33
|
+
const location = useLocation();
|
|
34
|
+
const [userProfile, setUserProfile] = useState({});
|
|
35
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
36
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
37
|
+
|
|
38
|
+
const updateAuthStatus = async () => {
|
|
39
|
+
try {
|
|
40
|
+
const { data } = await CustomFetch('/ajax/user/profile', 'GET');
|
|
41
|
+
setUserProfile(data);
|
|
42
|
+
setIsAuthenticated(true);
|
|
43
|
+
setIsLoading(false);
|
|
44
|
+
|
|
45
|
+
if (location.pathname.split('/')[1] === 'login') {
|
|
46
|
+
navigate('/', { replace: true });
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
setIsLoading(false);
|
|
50
|
+
if (['Unauthenticatdata.'].includes(error)) {
|
|
51
|
+
setIsAuthenticated(false);
|
|
52
|
+
navigate('/login');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
updateAuthStatus();
|
|
59
|
+
}, [isAuthenticated]);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<Routes>
|
|
64
|
+
<Route
|
|
65
|
+
path="login"
|
|
66
|
+
element={
|
|
67
|
+
<LoginComponent
|
|
68
|
+
setIsAuthenticated={setIsAuthenticated}
|
|
69
|
+
setUserProfile={setUserProfile}
|
|
70
|
+
/>
|
|
71
|
+
}
|
|
72
|
+
/>
|
|
73
|
+
<Route
|
|
74
|
+
path="reset"
|
|
75
|
+
element={
|
|
76
|
+
<ResetComponent
|
|
77
|
+
setIsAuthenticated={setIsAuthenticated}
|
|
78
|
+
/>
|
|
79
|
+
}
|
|
80
|
+
/>
|
|
81
|
+
<Route
|
|
82
|
+
path="verify/:code"
|
|
83
|
+
element={
|
|
84
|
+
<VerifyComponent
|
|
85
|
+
setIsAuthenticated={setIsAuthenticated}
|
|
86
|
+
/>
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
<Route
|
|
90
|
+
element={
|
|
91
|
+
<ProtectedRoute
|
|
92
|
+
user={userProfile}
|
|
93
|
+
loading={isLoading}
|
|
94
|
+
/>
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
<Route
|
|
98
|
+
path="/*"
|
|
99
|
+
element={
|
|
100
|
+
<MainComponent
|
|
101
|
+
checkAuthStatus={updateAuthStatus}
|
|
102
|
+
setUserProfile={setUserProfile}
|
|
103
|
+
userProfile={userProfile}
|
|
104
|
+
setSystemAuth={setIsAuthenticated}
|
|
105
|
+
/>
|
|
106
|
+
}
|
|
107
|
+
/>
|
|
108
|
+
</Route>
|
|
109
|
+
</Routes>
|
|
110
|
+
<ToastContainer
|
|
111
|
+
theme="light"
|
|
112
|
+
position="bottom-center"
|
|
113
|
+
style={{ width: '600px' }}
|
|
114
|
+
/>
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const LoginComponent = React.memo(({ setIsAuthenticated, setUserProfile }) => (
|
|
120
|
+
<Login
|
|
121
|
+
logo={logo}
|
|
122
|
+
providers={['azure']}
|
|
123
|
+
setSystemAuth={setIsAuthenticated}
|
|
124
|
+
setUserProfile={setUserProfile}
|
|
125
|
+
/>
|
|
126
|
+
));
|
|
127
|
+
|
|
128
|
+
const ResetComponent = React.memo(({ setIsAuthenticated }) => (
|
|
129
|
+
<Reset logo={logo} setSystemAuth={setIsAuthenticated} />
|
|
130
|
+
));
|
|
131
|
+
|
|
132
|
+
const VerifyComponent = React.memo(({ setIsAuthenticated }) => (
|
|
133
|
+
<Verify logo={logo} setSystemAuth={setIsAuthenticated} />
|
|
134
|
+
));
|
|
135
|
+
|
|
136
|
+
const MainComponent = React.memo(
|
|
137
|
+
({ checkAuthStatus, setUserProfile, userProfile, setSystemAuth }) => (
|
|
138
|
+
<>
|
|
139
|
+
<Main
|
|
140
|
+
checkAuthStatus={checkAuthStatus}
|
|
141
|
+
setSystemAuth={setSystemAuth}
|
|
142
|
+
userProfile={userProfile}
|
|
143
|
+
setUserProfile={setUserProfile}
|
|
144
|
+
/>
|
|
145
|
+
<Tooltip id="system-tooltip" />
|
|
146
|
+
</>
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
export default Auth;
|
package/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import CmsIndex from './components/cms/generic/CmsIndex';
|
|
|
34
34
|
import CmsSort from './components/cms/generic/CmsSort';
|
|
35
35
|
|
|
36
36
|
/** CRM Generic Components */
|
|
37
|
+
import GenericAuth from './components/crm/generic/GenericAuth';
|
|
37
38
|
import GenericDetail from './components/crm/generic/GenericDetail';
|
|
38
39
|
import GenericIndex from './components/crm/generic/GenericIndex';
|
|
39
40
|
import GenericSort from './components/crm/generic/GenericSort';
|
|
@@ -54,6 +55,7 @@ export {
|
|
|
54
55
|
DropZone,
|
|
55
56
|
Field,
|
|
56
57
|
Form,
|
|
58
|
+
GenericAuth,
|
|
57
59
|
GenericDetail,
|
|
58
60
|
GenericIndex,
|
|
59
61
|
GenericSort,
|
package/package.json
CHANGED