Update 404 page

This commit is contained in:
2024-06-13 04:29:58 +00:00
parent ae5fd1102b
commit 3862aa4e22
10 changed files with 80 additions and 40 deletions

View File

@ -49,12 +49,14 @@ export default function Header() {
</div> </div>
<Show when={store.auth}> <Show when={store.auth}>
<div class="flex items-center justify-end"> <div class="flex items-center justify-end">
<div class="avatar hidden lg:block"> <div class="avatar">
<div class="w-9 rounded-full"> <div class="w-9 rounded-full">
<img <A href="/me" class="hidden lg:block">
src={`https://ui-avatars.com/api/?name=${store.userInfo?.name}`} <img
alt="avatar" src={`https://ui-avatars.com/api/?name=${store.userInfo?.name}`}
/> alt="avatar"
/>
</A>
</div> </div>
</div> </div>
<A <A

View File

@ -3,20 +3,16 @@ import useAuth from '@hooks/useAuth'
import useLanguage from '@hooks/useLanguage' import useLanguage from '@hooks/useLanguage'
import { A } from '@solidjs/router' import { A } from '@solidjs/router'
import { IconDashboard, IconLogout, IconTriangle } from '@tabler/icons-solidjs' import { IconDashboard, IconLogout, IconTriangle } from '@tabler/icons-solidjs'
import UserHelper from '@utils/auth'
import { For, Show, mergeProps } from 'solid-js' import { For, Show, mergeProps } from 'solid-js'
import { Dynamic } from 'solid-js/web' import { Dynamic } from 'solid-js/web'
import './navbar.scss' import './navbar.scss'
const language = useLanguage() const language = useLanguage()
const userHelper = new UserHelper()
console.log(userHelper.isAdmin) export const NAV_ITEM = (admin = false) => [
const NAV_ITEM = [
{ {
path: '/dashboard', path: '/dashboard',
show: true, show: admin,
icon: IconDashboard, icon: IconDashboard,
text: language?.ui.dashboard, text: language?.ui.dashboard,
}, },
@ -30,6 +26,12 @@ const NAV_ITEM = [
icon: IconDashboard, icon: IconDashboard,
text: 'Test', text: 'Test',
children: [ children: [
{
path: '/dashboard',
show: true,
icon: IconDashboard,
text: language?.ui.dashboard,
},
{ {
path: '/test', path: '/test',
show: true, show: true,
@ -142,7 +144,7 @@ export default function Navbar() {
</div> </div>
</Show> </Show>
<ul class="menu w-80 text-base-content pt-3 px-3 pb-6"> <ul class="menu w-80 text-base-content pt-3 px-3 pb-6">
<For each={NAV_ITEM}> <For each={NAV_ITEM(store?.userInfo?.isAdmin)}>
{(item) => { {(item) => {
if (!item.show) return if (!item.show) return
if (item.children) { if (item.children) {

View File

@ -1 +1,2 @@
export * from './Navbar'
export { default } from './Navbar' export { default } from './Navbar'

View File

@ -26,7 +26,7 @@ export default function useAuth(setAuth) {
await getLogout() await getLogout()
Helpers.clearStorage() Helpers.clearStorage()
setAuth({ auth: false, user: null }) setAuth({ auth: false, user: null })
navigate('/login', { replace: false }) navigate('/login', { replace: true })
} }
return { return {

View File

@ -14,13 +14,15 @@ render(
<Route path="/login" component={lazy(() => import('@pages/Login'))} /> <Route path="/login" component={lazy(() => import('@pages/Login'))} />
<Route path="/" component={Layout}> <Route path="/" component={Layout}>
<For each={ROUTES}> <For each={ROUTES}>
{(route) => ( {(route) =>
<Route route.show && (
path={route.path} <Route
component={route.components} path={route.path}
matchFilters={route.filter} component={route.components}
/> matchFilters={route.filter}
)} />
)
}
</For> </For>
</Route> </Route>
<Route path="*" component={lazy(() => import('@pages/NotFound'))} /> <Route path="*" component={lazy(() => import('@pages/NotFound'))} />

View File

@ -1,12 +1,23 @@
import { NAV_ITEM } from '@components/Navbar'
import { useSiteContext } from '@context/SiteContext'
import { useNavigate } from '@solidjs/router' import { useNavigate } from '@solidjs/router'
import { onMount } from 'solid-js' import { onMount } from 'solid-js'
function getFirstItem(array) {
const first = array.filter((item) => item.show)[0]
if (first.children) {
return getFirstItem(first.children)
}
return first
}
export default function Home() { export default function Home() {
const { store } = useSiteContext()
const navigate = useNavigate() const navigate = useNavigate()
onMount(() => { onMount(() => {
// const first = NAV_ROUTES.filter((item) => item.show)[0]?.path || '/me' const first = getFirstItem(NAV_ITEM(store?.userInfo?.isAdmin))
navigate('/me', { replace: true }) navigate(first ? first.path : '/me', { replace: true })
}) })
return <></> return <></>

View File

@ -1,3 +0,0 @@
export default function NotFound() {
return <>404</>
}

View File

@ -0,0 +1,25 @@
import { A } from '@solidjs/router'
export default function NotFound() {
return (
<div class="flex items-center justify-center min-h-screen bg-fu-green bg-fixed bg-cover bg-bottom error-bg">
<div class="flex flex-col items-center text-white">
<div class="relative text-center">
<h1 class="relative text-9xl tracking-tighter-less text-shadow font-sans font-bold">
<span>4</span>
<span>0</span>
<span>4</span>
</h1>
<span class="absolute top-0 -ml-12 font-semibold">Oops!</span>
</div>
<h5 class="font-semibold">Page not found</h5>
<p class="mt-2 mb-6">
we are sorry, but the page you requested was not found
</p>
<A href="/" class="btn btn-secondary btn-sm hover:text-white">
Got to Home
</A>
</div>
</div>
)
}

View File

@ -0,0 +1 @@
export { default } from './NotFound'

View File

@ -5,25 +5,24 @@ export const ROUTES = [
path: '/', path: '/',
components: lazy(() => import('@pages/Home')), components: lazy(() => import('@pages/Home')),
filter: {}, filter: {},
}, show: true,
{
path: '/dashboard',
components: lazy(() => import('@pages/Dashboard')),
filter: {},
},
{
path: '/profile',
components: lazy(() => import('@pages/Profile')),
filter: {},
},
{
path: '/ware-house',
components: lazy(() => import('@pages/WareHouse')),
filter: {},
}, },
{ {
path: '/me', path: '/me',
components: lazy(() => import('@pages/Profile')), components: lazy(() => import('@pages/Profile')),
filter: {}, filter: {},
show: true,
},
{
path: '/dashboard',
components: lazy(() => import('@pages/Dashboard')),
filter: {},
show: true,
},
{
path: '/ware-house',
components: lazy(() => import('@pages/WareHouse')),
filter: {},
show: true,
}, },
] ]