Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
7520d64e
Commit
7520d64e
authored
Nov 05, 2022
by
Ibadullina Inabat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
реализовано слияние кода с основным
parent
f6ba2795
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
57 deletions
+60
-57
App.js
planner-front/src/App.js
+12
-8
AnonymousMenu.js
...front/src/components/Menus/AnonymousMenu/AnonymousMenu.js
+1
-1
AppToolbar.js
planner-front/src/components/UI/AppToolbar/AppToolbar.js
+21
-23
index.js
planner-front/src/index.js
+17
-22
actionTypes.js
planner-front/src/store/actionTypes/actionTypes.js
+0
-0
usersActionTypes.js
planner-front/src/store/actionTypes/usersActionTypes.js
+0
-0
usersActions.js
planner-front/src/store/actions/usersActions.js
+1
-1
usersReducer.js
planner-front/src/store/reducers/usersReducer.js
+8
-2
No files found.
planner-front/src/App.js
View file @
7520d64e
import
{
Routes
,
Route
,
Outlet
,
Navigate
,
BrowserRouter
}
from
"react-router-dom"
;
import
{
Routes
,
Route
,
Outlet
,
Navigate
,
BrowserRouter
}
from
"react-router-dom"
;
import
{
Container
}
from
"@mui/material"
;
import
{
Container
}
from
"@mui/material"
;
import
{
useSelector
}
from
"react-redux"
;
import
{
useSelector
}
from
"react-redux"
;
import
AppToolbar
from
"./components/UI/AppToolBar/AppToolBar"
;
import
AppToolbar
from
"./components/UI/AppToolbar/AppToolBar"
;
import
Login
from
"./containers/Login/Login"
;
import
Register
from
"./containers/Register/Register"
;
const
ProtectedRoute
=
({
isAllowed
,
roles
,
redirectUrl
,
children
})
=>
{
const
ProtectedRoute
=
({
isAllowed
,
roles
,
redirectUrl
,
children
})
=>
{
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
console
.
log
(
user
)
if
(
!
isAllowed
&&
!
roles
?.
includes
(
user
?.
role
))
{
if
(
!
isAllowed
&&
!
roles
?.
includes
(
user
?.
role
))
{
return
<
Navigate
to
=
{
redirectUrl
}
/
>
return
<
Navigate
to
=
{
redirectUrl
}
/
>
}
}
...
@@ -13,6 +16,7 @@ const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
...
@@ -13,6 +16,7 @@ const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const
App
=
()
=>
{
const
App
=
()
=>
{
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
console
.
log
(
user
)
return
(
return
(
<
BrowserRouter
>
<
BrowserRouter
>
<
Routes
>
<
Routes
>
...
@@ -30,7 +34,7 @@ const App = () => {
...
@@ -30,7 +34,7 @@ const App = () => {
<
Route
path
=
{
"/"
}
element
=
{
<
Route
path
=
{
"/"
}
element
=
{
<
ProtectedRoute
<
ProtectedRoute
isAllowed
=
{
user
}
isAllowed
=
{
user
}
redirectUrl
=
{
"/
log
-in"
}
redirectUrl
=
{
"/
sign
-in"
}
>
>
<
h1
>
week
page
<
/h1
>
<
h1
>
week
page
<
/h1
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
...
@@ -39,7 +43,7 @@ const App = () => {
...
@@ -39,7 +43,7 @@ const App = () => {
<
Route
path
=
{
"/week"
}
element
=
{
<
Route
path
=
{
"/week"
}
element
=
{
<
ProtectedRoute
<
ProtectedRoute
isAllowed
=
{
user
}
isAllowed
=
{
user
}
redirectUrl
=
{
"/
log
-in"
}
redirectUrl
=
{
"/
sign
-in"
}
>
>
<
h1
>
week
page
<
/h1
>
<
h1
>
week
page
<
/h1
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
...
@@ -48,7 +52,7 @@ const App = () => {
...
@@ -48,7 +52,7 @@ const App = () => {
<
Route
path
=
{
"/month"
}
element
=
{
<
Route
path
=
{
"/month"
}
element
=
{
<
ProtectedRoute
<
ProtectedRoute
isAllowed
=
{
user
}
isAllowed
=
{
user
}
redirectUrl
=
{
"/
log
-in"
}
redirectUrl
=
{
"/
sign
-in"
}
>
>
<
h1
>
month
page
<
/h1
>
<
h1
>
month
page
<
/h1
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
...
@@ -57,7 +61,7 @@ const App = () => {
...
@@ -57,7 +61,7 @@ const App = () => {
<
Route
path
=
{
"/my-tasks"
}
element
=
{
<
Route
path
=
{
"/my-tasks"
}
element
=
{
<
ProtectedRoute
<
ProtectedRoute
isAllowed
=
{
user
}
isAllowed
=
{
user
}
redirectUrl
=
{
"/
log
-in"
}
redirectUrl
=
{
"/
sign
-in"
}
>
>
<
h1
>
my
tasks
page
<
/h1
>
<
h1
>
my
tasks
page
<
/h1
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
...
@@ -66,7 +70,7 @@ const App = () => {
...
@@ -66,7 +70,7 @@ const App = () => {
<
Route
path
=
{
"/profile/:id"
}
element
=
{
<
Route
path
=
{
"/profile/:id"
}
element
=
{
<
ProtectedRoute
<
ProtectedRoute
isAllowed
=
{
user
}
isAllowed
=
{
user
}
redirectUrl
=
{
"/
log
-in"
}
redirectUrl
=
{
"/
sign
-in"
}
>
>
<
h1
>
profile
page
<
/h1
>
<
h1
>
profile
page
<
/h1
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
...
@@ -86,11 +90,11 @@ const App = () => {
...
@@ -86,11 +90,11 @@ const App = () => {
roles
=
{[
"superuser"
]}
roles
=
{[
"superuser"
]}
redirectUrl
=
{
"/"
}
redirectUrl
=
{
"/"
}
>
>
<
h1
>
sign
-
up
page
<
/h1
>
<
Register
/
>
<
/ProtectedRoute
>
<
/ProtectedRoute
>
}
/
>
}
/
>
<
Route
path
=
{
"/
log-in"
}
element
=
{
<
h1
>
log
-
in
page
<
/h1
>}/
>
<
Route
path
=
{
"/
sign-in"
}
element
=
{
<
Login
/
>
}
/
>
<
Route
path
=
'*'
element
=
{
<
h1
>
404
<
/h1>}/
>
<
Route
path
=
'*'
element
=
{
<
h1
>
404
<
/h1>}/
>
<
/Route
>
<
/Route
>
<
/Routes
>
<
/Routes
>
...
...
planner-front/src/components/Menus/AnonymousMenu/AnonymousMenu.js
View file @
7520d64e
...
@@ -6,7 +6,7 @@ const AnonymousMenu = () => {
...
@@ -6,7 +6,7 @@ const AnonymousMenu = () => {
<
Button
<
Button
component
=
{
NavLink
}
component
=
{
NavLink
}
color
=
"inherit"
color
=
"inherit"
to
=
"/
log
-in"
to
=
"/
sign
-in"
>
>
Вход
Вход
<
/Button
>
<
/Button
>
...
...
planner-front/src/components/UI/AppToolbar/AppToolbar.js
View file @
7520d64e
import
{
AppBar
,
Box
,
Toolbar
,
IconButton
,
Typography
}
from
"@mui/material"
;
import
{
AppBar
,
Box
,
Toolbar
,
Typography
}
from
"@mui/material"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
MenuIcon
from
'@mui/icons-material/Menu'
;
import
{
useSelector
}
from
"react-redux"
;
import
HasAccess
from
"../HasAccess/HasAccess"
;
import
HasAccess
from
"../HasAccess/HasAccess"
;
import
{
useSelector
}
from
"react-redux"
;
import
AnonymousMenu
from
"../../Menus/AnonymousMenu/AnonymousMenu"
;
import
AnonymousMenu
from
"../../Menus/AnonymousMenu/AnonymousMenu"
;
import
UserMenu
from
"../../Menus/UserMenu/UserMenu"
;
import
WorkerMenu
from
"../../Menus/WorkerMenu/WorkerMenu"
;
import
AdminMenu
from
"../../Menus/AdminMenu/AdminMenu"
;
const
AppToolbar
=
()
=>
{
const
AppToolbar
=
()
=>
{
const
user
=
useSelector
(
state
=>
state
.
users
.
user
);
const
user
=
useSelector
(
state
=>
state
.
users
.
user
);
return
<
Box
sx
=
{{
flexGrow
:
1
,
mb
:
"40px"
}}
>
return
<
Box
sx
=
{{
flexGrow
:
1
,
mb
:
"40px"
}}
>
<
AppBar
position
=
"static"
>
<
AppBar
position
=
"static"
>
<
Toolbar
>
<
Toolbar
>
<
IconButton
<
Typography
size
=
"large"
variant
=
"h4"
edge
=
"start"
component
=
"div"
color
=
"inherit"
sx
=
{{
flexGrow
:
1
}}
>
aria
-
label
=
"menu"
sx
=
{{
mr
:
2
}}
<
NavLink
to
=
'/'
style
=
{{
textDecoration
:
'none'
,
color
:
'inherit'
}}
>
Task
Manager
<
/NavLink
>
component
=
{
NavLink
}
to
=
"/"
>
<
MenuIcon
/>
<
/IconButton
>
<
Typography
variant
=
"h6"
component
=
"div"
sx
=
{{
flexGrow
:
1
}}
>
Planner
<
/Typography>
<
/Typography>
<
HasAccess
allowed
=
{
!!
user
}
>
<
UserMenu
user
=
{
user
}
/
>
<
/HasAccess>
<
HasAccess
allowed
=
{
!
user
}
>
<
HasAccess
allowed
=
{
!
user
}
>
<
AnonymousMenu
/>
<
AnonymousMenu
/>
<
/HasAccess
>
<
/HasAccess
>
<
HasAccess
roles
=
{[
'user'
]}
>
<
WorkerMenu
/>
<
/HasAccess
>
<
HasAccess
roles
=
{[
'superuser'
]}
>
<
AdminMenu
/>
<
/HasAccess
>
<
/Toolbar
>
<
/Toolbar
>
<
/AppBar
>
<
/AppBar
>
<
/Box
>
<
/Box
>
...
...
planner-front/src/index.js
View file @
7520d64e
import
ReactDOM
from
'react-dom'
;
import
React
from
'react'
;
import
{
configureStore
}
from
"@reduxjs/toolkit"
;
import
ReactDOM
from
'react-dom/client'
;
import
{
Provider
}
from
'react-redux'
;
import
'./index.css'
;
import
{
BrowserRouter
}
from
'react-router-dom'
;
import
"./index.css"
;
import
App
from
'./App'
;
import
App
from
'./App'
;
import
usersReduser
from
'./store/reducers/usersReducer'
;
import
{
configureStore
}
from
'@reduxjs/toolkit'
;
import
{
Provider
}
from
'react-redux'
;
import
usersReducer
from
'./store/reducers/usersReducer'
;
const
local
s
torageMiddleware
=
({
getState
})
=>
(
next
)
=>
(
action
)
=>
{
const
local
S
torageMiddleware
=
({
getState
})
=>
(
next
)
=>
(
action
)
=>
{
const
result
=
next
(
action
);
const
result
=
next
(
action
);
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
getState
().
users
.
user
));
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
getState
().
users
.
user
));
return
result
;
return
result
;
}
}
;
const
loadFromLocalStorage
=
()
=>
{
const
loadFromLocalStorage
=
()
=>
{
if
(
localStorage
.
getItem
(
"user"
)
!==
null
)
{
if
(
localStorage
.
getItem
(
"user"
)
!==
null
)
{
return
{
users
:
{
user
:
JSON
.
parse
(
localStorage
.
getItem
(
"user"
))}}
return
{
users
:
{
user
:
JSON
.
parse
(
localStorage
.
getItem
(
"user"
))}}
}
}
return
undefined
;
return
undefined
;
}
}
;
const
store
=
configureStore
({
const
store
=
configureStore
({
reducer
:
{
reducer
:
{
users
:
usersRedu
ser
users
:
usersRedu
cer
,
},
},
preloadedState
:
loadFromLocalStorage
(),
preloadedState
:
loadFromLocalStorage
(),
middleware
:
(
getDefaultMiddleware
)
=>
getDefaultMiddleware
().
concat
(
local
s
torageMiddleware
)
middleware
:
(
getDefaultMiddleware
)
=>
getDefaultMiddleware
().
concat
(
local
S
torageMiddleware
)
})
;
})
const
app
=
(
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
'root'
));
<
BrowserRouter
>
root
.
render
(
<
Provider
store
=
{
store
}
>
<
Provider
store
=
{
store
}
>
<
App
/>
<
App
/>
<
/Provider
>
<
/Provider
>
<
/BrowserRouter
>
);
);
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
'root'
));
root
.
render
(
app
);
\ No newline at end of file
planner-front/src/store/actionTypes.js
→
planner-front/src/store/actionTypes
/actionTypes
.js
View file @
7520d64e
File moved
planner-front/src/store/actionTypes/usersActionTypes.js
deleted
100644 → 0
View file @
f6ba2795
planner-front/src/store/actions/usersActions.js
View file @
7520d64e
import
axios
from
"../../axiosPlanner"
;
import
axios
from
"../../axiosPlanner"
;
import
{
LOGIN_USER_FAILURE
,
LOGIN_USER_SUCCESS
,
LOGOUT_USER_FAILURE
,
LOGOUT_USER_SUCCESS
,
REGISTER_USER_FAILURE
,
REGISTER_USER_REQUEST
,
REGISTER_USER_SUCCESS
}
from
"../actionTypes"
import
{
LOGIN_USER_FAILURE
,
LOGIN_USER_SUCCESS
,
LOGOUT_USER_FAILURE
,
LOGOUT_USER_SUCCESS
,
REGISTER_USER_FAILURE
,
REGISTER_USER_REQUEST
,
REGISTER_USER_SUCCESS
}
from
"../actionTypes
/actionTypes
"
import
{
showNotification
}
from
"./commonActions"
;
import
{
showNotification
}
from
"./commonActions"
;
const
registerUserRequest
=
()
=>
{
const
registerUserRequest
=
()
=>
{
...
...
planner-front/src/store/reducers/usersReducer.js
View file @
7520d64e
import
{
REGISTER_USER_REQUEST
,
REGISTER_USER_SUCCESS
,
REGISTER_USER_FAILURE
,
LOGIN_USER_SUCCESS
,
LOGIN_USER_FAILURE
,
LOGOUT_USER_SUCCESS
}
from
"../actionTypes"
;
import
{
REGISTER_USER_REQUEST
,
REGISTER_USER_SUCCESS
,
REGISTER_USER_FAILURE
,
LOGIN_USER_SUCCESS
,
LOGIN_USER_FAILURE
,
LOGOUT_USER_SUCCESS
}
from
"../actionTypes
/actionTypes
"
;
const
initialState
=
{
const
initialState
=
{
user
:
null
,
user
:
{
name
:
'Ivan'
,
surname
:
'Petrov'
,
email
:
'test@gmail.com'
,
role
:
'superuser'
},
registerError
:
null
,
registerError
:
null
,
loginError
:
null
,
loginError
:
null
,
loading
:
false
loading
:
false
...
@@ -17,6 +22,7 @@ const usersReduser = (state = initialState, action) => {
...
@@ -17,6 +22,7 @@ const usersReduser = (state = initialState, action) => {
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
case
LOGIN_USER_SUCCESS
:
case
LOGIN_USER_SUCCESS
:
return
{...
state
,
user
:
action
.
user
};
return
{...
state
,
user
:
action
.
user
};
case
LOGIN_USER_FAILURE
:
case
LOGIN_USER_FAILURE
:
return
{...
state
,
loginError
:
action
.
error
};
return
{...
state
,
loginError
:
action
.
error
};
case
LOGOUT_USER_SUCCESS
:
case
LOGOUT_USER_SUCCESS
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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