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
7fb56c62
Commit
7fb56c62
authored
Nov 07, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#28
Создал редюсер и экшен на получение задач
parent
0e93993f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
4 deletions
+65
-4
MonthCalendar.js
planner-front/src/containers/MonthCalendar/MonthCalendar.js
+8
-1
index.js
planner-front/src/index.js
+2
-0
tasksTypes.js
planner-front/src/store/actionTypes/tasksTypes.js
+3
-0
tasksActions.js
planner-front/src/store/actions/tasksActions.js
+27
-0
tasksReducer.js
planner-front/src/store/reducers/tasksReducer.js
+22
-0
usersReducer.js
planner-front/src/store/reducers/usersReducer.js
+3
-3
No files found.
planner-front/src/containers/MonthCalendar/MonthCalendar.js
View file @
7fb56c62
import
{
Container
}
from
'@mui/material'
;
import
{
Container
}
from
'@mui/material'
;
import
{
useEffect
,
useState
}
from
'react'
;
import
{
useEffect
,
useState
}
from
'react'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
MonthCalendarBody
from
'../../components/MonthCalendarBody/MonthCalendarBody'
;
import
MonthCalendarBody
from
'../../components/MonthCalendarBody/MonthCalendarBody'
;
import
MonthCalendarHeader
from
'../../components/MonthCalendarHeader/MonthCalendarHeader'
;
import
MonthCalendarHeader
from
'../../components/MonthCalendarHeader/MonthCalendarHeader'
;
import
{
fetchTasks
}
from
'../../store/actions/tasksActions'
;
function
MonthCalendar
()
{
function
MonthCalendar
()
{
const
dispatch
=
useDispatch
();
const
{
tasks
}
=
useSelector
(
state
=>
state
.
tasks
);
const
[
month
,
setMonth
]
=
useState
(
''
)
const
[
month
,
setMonth
]
=
useState
(
''
)
const
[
year
,
setYear
]
=
useState
(
''
)
const
[
year
,
setYear
]
=
useState
(
''
)
const
[
worker
,
setWorker
]
=
useState
(
''
);
const
[
worker
,
setWorker
]
=
useState
(
''
);
...
@@ -13,7 +18,9 @@ function MonthCalendar() {
...
@@ -13,7 +18,9 @@ function MonthCalendar() {
useEffect
(()
=>
{
useEffect
(()
=>
{
setMonth
(
new
Date
().
getMonth
())
setMonth
(
new
Date
().
getMonth
())
setYear
(
new
Date
().
getFullYear
())
setYear
(
new
Date
().
getFullYear
())
},[])
dispatch
(
fetchTasks
())
},
[
dispatch
])
console
.
log
(
tasks
)
const
onChangeWorkerHandler
=
(
event
)
=>
{
const
onChangeWorkerHandler
=
(
event
)
=>
{
setWorker
(
event
.
target
.
value
);
setWorker
(
event
.
target
.
value
);
};
};
...
...
planner-front/src/index.js
View file @
7fb56c62
...
@@ -5,6 +5,7 @@ import App from './App';
...
@@ -5,6 +5,7 @@ import App from './App';
import
{
configureStore
}
from
'@reduxjs/toolkit'
;
import
{
configureStore
}
from
'@reduxjs/toolkit'
;
import
{
Provider
}
from
'react-redux'
;
import
{
Provider
}
from
'react-redux'
;
import
usersReducer
from
'./store/reducers/usersReducer'
;
import
usersReducer
from
'./store/reducers/usersReducer'
;
import
tasksReducer
from
'./store/reducers/tasksReducer'
;
import
axios
from
'axios'
;
import
axios
from
'axios'
;
const
localStorageMiddleware
=
({
getState
})
=>
(
next
)
=>
(
action
)
=>
{
const
localStorageMiddleware
=
({
getState
})
=>
(
next
)
=>
(
action
)
=>
{
...
@@ -31,6 +32,7 @@ axios.interceptors.request.use(config=>{
...
@@ -31,6 +32,7 @@ axios.interceptors.request.use(config=>{
const
store
=
configureStore
({
const
store
=
configureStore
({
reducer
:
{
reducer
:
{
users
:
usersReducer
,
users
:
usersReducer
,
tasks
:
tasksReducer
},
},
preloadedState
:
loadFromLocalStorage
(),
preloadedState
:
loadFromLocalStorage
(),
middleware
:
(
getDefaultMiddleware
)
=>
getDefaultMiddleware
().
concat
(
localStorageMiddleware
)
middleware
:
(
getDefaultMiddleware
)
=>
getDefaultMiddleware
().
concat
(
localStorageMiddleware
)
...
...
planner-front/src/store/actionTypes/tasksTypes.js
0 → 100644
View file @
7fb56c62
export
const
FETCH_TASKS_REQUEST
=
"FETCH_TASKS_REQUEST"
;
export
const
FETCH_TASKS_SUCCESS
=
"FETCH_TASKS_SUCCESS"
;
export
const
FETCH_TASKS_FAILURE
=
"FETCH_TASKS_FAILURE"
;
\ No newline at end of file
planner-front/src/store/actions/tasksActions.js
0 → 100644
View file @
7fb56c62
import
{
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
}
from
"../actionTypes/tasksTypes"
;
import
axios
from
'../../axiosPlanner'
const
fetchTasksRequest
=
()
=>
{
return
{
type
:
FETCH_TASKS_REQUEST
}
};
const
fetchTasksSuccess
=
(
tasks
)
=>
{
return
{
type
:
FETCH_TASKS_SUCCESS
,
tasks
}
};
const
fetchTasksFailure
=
(
error
)
=>
{
return
{
type
:
FETCH_TASKS_FAILURE
,
error
}
};
export
const
fetchTasks
=
()
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
fetchTasksRequest
());
try
{
const
response
=
await
axios
.
get
(
"/tasks"
);
console
.
log
(
response
.
data
)
dispatch
(
fetchTasksSuccess
(
response
.
data
))
}
catch
(
error
)
{
dispatch
(
fetchTasksFailure
(
error
.
response
.
data
));
}
}
}
planner-front/src/store/reducers/tasksReducer.js
0 → 100644
View file @
7fb56c62
import
{
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
}
from
"../actionTypes/tasksTypes"
;
const
initialState
=
{
tasks
:
[],
loading
:
false
,
error
:
null
};
const
tasksRedu
с
er
=
(
state
=
initialState
,
action
)
=>
{
switch
(
action
.
type
)
{
case
FETCH_TASKS_REQUEST
:
return
{...
state
,
loading
:
true
};
case
FETCH_TASKS_SUCCESS
:
return
{...
state
,
loading
:
false
,
tasks
:
action
.
tasks
};
case
FETCH_TASKS_FAILURE
:
return
{...
state
,
loading
:
false
,
error
:
action
.
error
};
default
:
return
state
;
}
};
export
default
tasksRedu
с
er
;
\ No newline at end of file
planner-front/src/store/reducers/usersReducer.js
View file @
7fb56c62
...
@@ -5,14 +5,14 @@ const initialState = {
...
@@ -5,14 +5,14 @@ const initialState = {
name
:
'Ivan'
,
name
:
'Ivan'
,
surname
:
'Petrov'
,
surname
:
'Petrov'
,
email
:
'test@gmail.com'
,
email
:
'test@gmail.com'
,
role
:
'user'
role
:
'
super
user'
},
},
registerError
:
null
,
registerError
:
null
,
loginError
:
null
,
loginError
:
null
,
loading
:
false
loading
:
false
};
};
const
usersRedu
s
er
=
(
state
=
initialState
,
action
)
=>
{
const
usersRedu
c
er
=
(
state
=
initialState
,
action
)
=>
{
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
REGISTER_USER_REQUEST
:
case
REGISTER_USER_REQUEST
:
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
...
@@ -31,4 +31,4 @@ const usersReduser = (state = initialState, action) => {
...
@@ -31,4 +31,4 @@ const usersReduser = (state = initialState, action) => {
}
}
};
};
export
default
usersRedu
s
er
;
export
default
usersRedu
c
er
;
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