generated from ngyngcphu/react-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): create router template and change return type of /api/user
- Loading branch information
Showing
23 changed files
with
186 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_BACKEND_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,75 @@ | ||
import { AuthLayout } from '@layouts'; | ||
import { AuthPage } from '@pages'; | ||
import { useEffect } from 'react'; | ||
import { HomeIcon } from '@heroicons/react/24/outline'; | ||
import { AppLayout, AuthLayout } from '@layouts'; | ||
import { AuthPage, HomePage } from '@pages'; | ||
import { useUserStore } from '@states'; | ||
import { AppSkeleton } from '@components'; | ||
|
||
export default function App() { | ||
const { userStatus, getUserData } = useUserStore(); | ||
|
||
useEffect(() => { | ||
getUserData(); | ||
}, [getUserData]); | ||
|
||
if (userStatus === 'UNINIT' || userStatus === 'PENDING') { | ||
return <AppSkeleton />; | ||
} | ||
|
||
if (userStatus === 'REJECT') { | ||
return ( | ||
<AuthLayout> | ||
<AuthPage /> | ||
</AuthLayout> | ||
); | ||
} | ||
|
||
return ( | ||
<AuthLayout> | ||
<AuthPage /> | ||
</AuthLayout> | ||
<AppLayout | ||
menu={[ | ||
{ | ||
type: 'item', | ||
icon: <HomeIcon className='h-5 w-5' />, | ||
path: '/home', | ||
name: 'Trang chủ', | ||
element: <HomePage /> | ||
} | ||
// { | ||
// type: 'list', | ||
// icon: <CurrencyDollarIcon className='h-5 w-5' />, | ||
// name: 'Quỹ lab', | ||
// routes: [ | ||
// { | ||
// type: 'item', | ||
// name: 'Thống kê', | ||
// icon: <ChartBarSquareIcon strokeWidth={2} className='h-4 w-4' />, | ||
// path: '/finance/statistic', | ||
// element: <></> | ||
// }, | ||
// { | ||
// type: 'item', | ||
// icon: <CreditCardIcon strokeWidth={2} className='h-4 w-4' />, | ||
// name: 'Giao dịch', | ||
// path: '/finance/transaction', | ||
// element: <></> | ||
// } | ||
// ] | ||
// }, | ||
// 'divider', | ||
// { | ||
// type: 'item', | ||
// icon: <UserCircleIcon className='h-5 w-5' />, | ||
// path: '/user', | ||
// name: 'Cá nhân', | ||
// element: <></> | ||
// }, | ||
// { | ||
// type: 'logout-btn', | ||
// icon: <PowerIcon className='h-5 w-5' />, | ||
// name: 'Đăng xuất', | ||
// //onClick: () => authService.logout().then(() => getData()) | ||
// } | ||
]} | ||
/> | ||
); | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
This file was deleted.
Oops, something went wrong.
File renamed without changes
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
export function AppLayout() { | ||
return <></>; | ||
} | ||
import { useMemo } from 'react'; | ||
import { Routes, Route } from 'react-router-dom'; | ||
|
||
export const AppLayout: Component<{ menu: RouteMenu }> = ({ menu }) => { | ||
const routeItems = useMemo(() => { | ||
const items: { path: string; element: React.ReactElement }[] = []; | ||
for (const menuItem of menu) { | ||
if (menuItem === 'divider' || menuItem.type === 'logout-btn') continue; | ||
if (menuItem.type === 'list') { | ||
for (const route of menuItem.routes) { | ||
items.push({ path: route.path, element: route.element }); | ||
} | ||
} else { | ||
items.push({ path: menuItem.path, element: menuItem.element }); | ||
} | ||
} | ||
|
||
return items; | ||
}, [menu]); | ||
|
||
return ( | ||
<div className='flex flex-col h-screen sm:min-h-screen'> | ||
<div className='lg:p-4 flex-1 h-full'> | ||
<Routes> | ||
{routeItems.map((item) => ( | ||
<Route path={item.path} element={item.element} key={item.path} /> | ||
))} | ||
</Routes> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
import './index.css'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { ToastContainer } from 'react-toastify'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import { ThemeProvider } from '@material-tailwind/react'; | ||
import './index.css'; | ||
import App from './App'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<ThemeProvider> | ||
<ToastContainer limit={1} /> | ||
<App /> | ||
</ThemeProvider> | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<ToastContainer limit={1} /> | ||
<App /> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function HomePage() { | ||
return <div>Đăng nhập thành công</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { server, invoke } from './common'; | ||
|
||
export const userService = { | ||
getInfo: () => invoke<string[]>(server.get('/api/user')) | ||
getInfo: () => invoke<UserReturnValue>(server.get('/api/user')) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
type BaseRoute = { | ||
icon: React.ReactElement; | ||
name: string; | ||
}; | ||
|
||
type RoutesList = BaseRoute & { | ||
type: 'list'; | ||
routes: RouteItem[]; | ||
}; | ||
|
||
type RouteItem = BaseRoute & { | ||
type: 'item'; | ||
path: string; | ||
element: React.ReactElement; | ||
}; | ||
|
||
type LogoutBtn = BaseRoute & { | ||
type: 'logout-btn'; | ||
onClick: () => void; | ||
}; | ||
|
||
type RouteMenuItem = RouteItem | RoutesList | 'divider' | LogoutBtn; | ||
|
||
type RouteMenu = RouteMenuItem[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
type UserReturnValue = { | ||
id: string; | ||
email: string; | ||
}; | ||
|
||
type UserStore = { | ||
userStatus: StoreStatus; | ||
userData: string[]; | ||
userData: UserReturnValue; | ||
getUserData: () => Promise<void>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters