Add src
This commit is contained in:
0
src/App.css
Normal file
0
src/App.css
Normal file
57
src/App.jsx
Normal file
57
src/App.jsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||||
|
import SignIn from './pages/auth/SignIn';
|
||||||
|
import { ProtectedRoute } from './ProtectedRoute';
|
||||||
|
import NotFound from './pages/blank/NotFound';
|
||||||
|
import { getSessionData } from './components/Global/Formatter';
|
||||||
|
|
||||||
|
// dashboard
|
||||||
|
import Home from './pages/home/Home';
|
||||||
|
import Blank from './pages/blank/Blank';
|
||||||
|
|
||||||
|
// master
|
||||||
|
import IndexDevice from './pages/master/device/IndexDevice';
|
||||||
|
|
||||||
|
// Setting
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
const session = getSessionData();
|
||||||
|
// console.log(session);
|
||||||
|
|
||||||
|
const isAdmin =
|
||||||
|
session?.user?.role_id != `${import.meta.env.VITE_ROLE_VENDOR}` &&
|
||||||
|
session?.user?.role_id &&
|
||||||
|
session?.user?.role_id != null &&
|
||||||
|
session?.user?.role_id != 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BrowserRouter
|
||||||
|
future={{
|
||||||
|
v7_startTransition: true,
|
||||||
|
v7_relativeSplatPath: true,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Routes>
|
||||||
|
{isAdmin ? (
|
||||||
|
<Route path="/" element={<Navigate to="/dashboard/home" />} />
|
||||||
|
) : (
|
||||||
|
<Route path="/" element={<Navigate to="/dashboard/home-vendor" />} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Route path="/signin" element={<SignIn />} />
|
||||||
|
<Route path="/dashboard" element={<ProtectedRoute />}>
|
||||||
|
<Route path="home" element={<Home />} />
|
||||||
|
<Route path="blank" element={<Blank />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
|
<Route path="/master" element={<ProtectedRoute />}>
|
||||||
|
<Route path="device" element={<IndexDevice />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
|
<Route path="*" element={<NotFound />} />
|
||||||
|
</Routes>
|
||||||
|
</BrowserRouter>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default App;
|
||||||
20
src/ProtectedRoute.jsx
Normal file
20
src/ProtectedRoute.jsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Navigate, Outlet } from 'react-router-dom';
|
||||||
|
import MainLayout from './layout/MainLayout';
|
||||||
|
|
||||||
|
import { getSessionData } from './components/Global/Formatter';
|
||||||
|
|
||||||
|
export const ProtectedRoute = () => {
|
||||||
|
const session = getSessionData();
|
||||||
|
// console.log(session);
|
||||||
|
|
||||||
|
const isAuthenticated = session?.auth ?? false;
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
return <Navigate to="/signin" replace />;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<MainLayout>
|
||||||
|
<Outlet />
|
||||||
|
</MainLayout>
|
||||||
|
);
|
||||||
|
};
|
||||||
7
src/Utils/Auth/Logout.jsx
Normal file
7
src/Utils/Auth/Logout.jsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const handleLogOut = () => {
|
||||||
|
localStorage.removeItem('Auth');
|
||||||
|
localStorage.removeItem('session');
|
||||||
|
window.location.replace('/signin');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default handleLogOut;
|
||||||
32
src/Utils/Auth/SignIn.jsx
Normal file
32
src/Utils/Auth/SignIn.jsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { login } from '../../api/auth';
|
||||||
|
import { encryptData } from '../../components/Global/Formatter';
|
||||||
|
import { NotifAlert } from '../../components/Global/ToastNotif';
|
||||||
|
|
||||||
|
const handleSignIn = async (values) => {
|
||||||
|
|
||||||
|
const response = await login(values);
|
||||||
|
|
||||||
|
// return false
|
||||||
|
if (response?.status == 200) {
|
||||||
|
/* you can change this according to your authentication protocol */
|
||||||
|
let token = JSON.stringify(response.data?.token);
|
||||||
|
let role = JSON.stringify(response.data?.user?.role_id);
|
||||||
|
|
||||||
|
localStorage.setItem('token', token);
|
||||||
|
response.data.auth = true;
|
||||||
|
localStorage.setItem('session', encryptData(response?.data));
|
||||||
|
if (role === `${import.meta.env.VITE_ROLE_VENDOR}`) {
|
||||||
|
window.location.replace('/dashboard/home-vendor');
|
||||||
|
} else {
|
||||||
|
window.location.replace('/dashboard/home');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Gagal',
|
||||||
|
message: response?.data?.message || 'Terjadi kesalahan saat menyimpan data.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default handleSignIn;
|
||||||
21
src/index.css
Normal file
21
src/index.css
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
:root {
|
||||||
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
/* color-scheme: light dark;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
background-color: #242424; */
|
||||||
|
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
margin: 0;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
html body {
|
||||||
|
margin: 0;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
13
src/main.jsx
Normal file
13
src/main.jsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/client'
|
||||||
|
import App from './App.jsx'
|
||||||
|
import './index.css'
|
||||||
|
import { BreadcrumbProvider } from './layout/LayoutBreadcrumb.jsx';
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<BreadcrumbProvider>
|
||||||
|
<App />
|
||||||
|
</BreadcrumbProvider>
|
||||||
|
</React.StrictMode>,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user