Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
8132aceb
Commit
8132aceb
authored
May 25, 2022
by
Michal Čížek
Browse files
added sidebar, switched to hash router
parent
32191843
Changes
4
Show whitespace changes
Inline
Side-by-side
frontend/src/app.tsx
View file @
8132aceb
import
{
MantineProvider
}
from
"
@mantine/core
"
;
import
{
QueryClientProvider
,
QueryClient
}
from
"
react-query
"
;
import
{
Browser
Router
}
from
"
react-router-dom
"
;
import
{
Hash
Router
}
from
"
react-router-dom
"
;
import
axios
from
"
axios
"
;
import
{
AuthProvider
}
from
"
context/auth/auth-provider
"
;
...
...
@@ -13,7 +13,7 @@ axios.defaults.withCredentials = true;
export
const
App
=
()
=>
{
return
(
<
Browser
Router
<
Hash
Router
basename
=
{
process
.
env
.
NODE_ENV
===
"
development
"
?
undefined
:
"
/pa165
"
}
>
<
MantineProvider
>
...
...
@@ -27,6 +27,6 @@ export const App = () => {
</
NotificationProvider
>
</
QueryClientProvider
>
</
MantineProvider
>
</
Browser
Router
>
</
Hash
Router
>
);
};
frontend/src/components/header/header.tsx
View file @
8132aceb
import
{
use
Callback
,
useMemo
,
useState
}
from
"
react
"
;
import
{
Coin
,
Menu2
,
Logout
}
from
"
tabler-icons-react
"
;
import
{
use
Memo
}
from
"
react
"
;
import
{
Coin
,
Logout
}
from
"
tabler-icons-react
"
;
import
{
ActionIcon
,
Avatar
,
Button
,
Center
,
Drawer
,
Grid
,
Group
,
Paper
,
...
...
@@ -14,11 +12,8 @@ import {
import
{
useAuth
}
from
"
context/auth/auth-context
"
;
import
{
Navigation
}
from
"
./navigation
"
;
export
const
Header
=
()
=>
{
const
{
user
,
logout
,
isLoggedIn
}
=
useAuth
();
const
[
isOpen
,
setIsOpen
]
=
useState
(
false
);
const
initials
=
useMemo
(()
=>
{
const
parts
=
user
?.
name
.
trim
().
split
(
"
"
);
...
...
@@ -32,17 +27,10 @@ export const Header = () => {
return
result
??
"
UN
"
;
},
[
user
?.
name
]);
const
openDrawer
=
useCallback
(()
=>
setIsOpen
(
true
),
[]);
const
closeDrawer
=
useCallback
(()
=>
setIsOpen
(
false
),
[]);
return
(
<
Paper
shadow
=
"sm"
sx
=
{
{
padding
:
"
0.5rem
"
}
}
>
<
Grid
align
=
"center"
>
<
Grid
.
Col
xs
=
{
6
}
md
=
{
4
}
>
<
ActionIcon
onClick
=
{
openDrawer
}
>
<
Menu2
/>
</
ActionIcon
>
</
Grid
.
Col
>
<
Grid
.
Col
xs
=
{
6
}
md
=
{
4
}
/>
<
Grid
.
Col
xs
=
{
4
}
sx
=
{
(
theme
)
=>
({
...
...
@@ -72,19 +60,6 @@ export const Header = () => {
</
Group
>
</
Grid
.
Col
>
</
Grid
>
<
Drawer
opened
=
{
isOpen
}
onClose
=
{
closeDrawer
}
title
=
{
<
Text
size
=
"md"
weight
=
"bold"
>
Navigation
</
Text
>
}
size
=
"lg"
padding
=
"md"
>
<
Navigation
onClick
=
{
closeDrawer
}
/>
</
Drawer
>
</
Paper
>
);
};
frontend/src/components/
header/navigation
.tsx
→
frontend/src/components/
sidebar/sidebar
.tsx
View file @
8132aceb
import
{
ReactNode
}
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
Stack
,
Button
}
from
"
@mantine/core
"
;
import
{
Stack
,
Button
,
Paper
,
Sx
}
from
"
@mantine/core
"
;
import
{
BuildingStore
,
CalendarEvent
,
Home
,
Location
,
Login
,
UserPlus
,
}
from
"
tabler-icons-react
"
;
import
{
User
}
from
"
models
"
;
import
{
useAuth
}
from
"
../../context/auth/auth-context
"
;
type
NavItem
=
{
label
:
string
;
to
:
string
;
icon
:
ReactNode
;
showPermission
:
string
;
show
?:
((
user
?:
User
)
=>
boolean
)
|
boolean
;
sx
?:
Sx
;
};
const
navItems
:
NavItem
[]
=
[
...
...
@@ -21,25 +27,36 @@ const navItems: NavItem[] = [
label
:
"
Home
"
,
to
:
"
/
"
,
icon
:
<
Home
/>,
showPermission
:
"
ALL
"
,
},
{
label
:
"
Events
"
,
to
:
"
/events
"
,
icon
:
<
CalendarEvent
/>,
showPermission
:
"
ALL
"
,
},
{
label
:
"
Locations
"
,
to
:
"
/locations
"
,
icon
:
<
Location
/>,
show
Permission
:
"
MANAGER
"
,
show
:
(
user
)
=>
user
?.
userRole
===
"
MANAGER
"
,
},
{
label
:
"
My reservations
"
,
to
:
"
/my-reservations
"
,
icon
:
<
BuildingStore
/>,
showPermission
:
"
SELLER
"
,
show
:
(
user
)
=>
user
?.
userRole
===
"
SELLER
"
,
},
{
label
:
"
Login
"
,
to
:
"
/login
"
,
icon
:
<
Login
/>,
show
:
(
user
)
=>
!
user
,
sx
:
{
marginTop
:
"
auto
"
},
},
{
label
:
"
Register
"
,
to
:
"
/register
"
,
icon
:
<
UserPlus
/>,
show
:
(
user
)
=>
!
user
,
},
];
...
...
@@ -47,20 +64,24 @@ interface Props {
onClick
?:
()
=>
void
;
}
export
const
Navigation
=
({
onClick
}:
Props
)
=>
{
export
const
Sidebar
=
({
onClick
}:
Props
)
=>
{
const
{
user
}
=
useAuth
();
const
showPermission
=
user
?
user
.
userRole
:
"
ALL
"
;
return
(
<
Stack
spacing
=
{
5
}
>
{
navItems
.
filter
(
(
item
)
=>
item
.
showPermission
===
showPermission
||
item
.
showPermission
===
"
ALL
"
)
.
map
(({
icon
,
label
,
to
})
=>
(
<
Paper
withBorder
sx
=
{
{
flexGrow
:
1
,
minWidth
:
250
,
maxWidth
:
350
,
position
:
"
relative
"
,
padding
:
"
1rem
"
,
}
}
>
<
Stack
spacing
=
{
5
}
sx
=
{
{
position
:
"
sticky
"
,
top
:
"
1rem
"
}
}
>
{
navItems
.
map
(
({
icon
,
label
,
to
,
show
=
true
,
sx
})
=>
(
show
instanceof
Function
?
show
?.(
user
)
:
show
)
&&
(
<
Button
variant
=
"subtle"
leftIcon
=
{
icon
}
...
...
@@ -68,10 +89,13 @@ export const Navigation = ({ onClick }: Props) => {
component
=
{
Link
}
to
=
{
to
}
onClick
=
{
onClick
}
sx
=
{
sx
}
>
{
label
}
</
Button
>
))
}
)
)
}
</
Stack
>
</
Paper
>
);
};
frontend/src/modules/app-routes.tsx
View file @
8132aceb
...
...
@@ -5,6 +5,7 @@ import { Header } from "components/header/header";
import
{
useAuth
}
from
"
context/auth/auth-context
"
;
import
{
ProtectedRoute
}
from
"
components/protected-route/protected-route
"
;
import
{
EntryRoute
}
from
"
components/entry-route/entry-route
"
;
import
{
Sidebar
}
from
"
components/sidebar/sidebar
"
;
import
{
Home
}
from
"
./home/home
"
;
import
{
StandReservation
}
from
"
./stand-reservation/stand-reservation
"
;
...
...
@@ -28,8 +29,11 @@ export const AppRoutes = () => {
sx
=
{
(
theme
)
=>
({
flexGrow
:
1
,
backgroundColor
:
theme
.
fn
.
rgba
(
theme
.
colors
.
dark
[
1
],
0.1
),
display
:
"
flex
"
,
})
}
>
<
Sidebar
/>
<
Box
sx
=
{
{
flexGrow
:
1
}
}
>
{
isFetchedAfterMount
&&
(
<
Routes
>
<
Route
path
=
"/"
element
=
{
<
Home
/>
}
/>
...
...
@@ -42,7 +46,10 @@ export const AppRoutes = () => {
<
Route
path
=
"/events/:id/edit"
element
=
{
<
CreateUpdateEvent
/>
}
/>
<
Route
element
=
{
<
ProtectedRoute
/>
}
>
<
Route
path
=
"/locations"
element
=
{
<
Locations
/>
}
/>
<
Route
path
=
"/stands/list/events/:id"
element
=
{
<
EventStands
/>
}
/>
<
Route
path
=
"/stands/list/events/:id"
element
=
{
<
EventStands
/>
}
/>
</
Route
>
<
Route
path
=
"*"
element
=
{
<
NotFound
/>
}
/>
<
Route
...
...
@@ -54,5 +61,6 @@ export const AppRoutes = () => {
)
}
</
Box
>
</
Box
>
</
Box
>
);
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment