From d4ec833a31216b94c7da4635c236587edb7aa762 Mon Sep 17 00:00:00 2001 From: kurpfish Date: Tue, 7 Dec 2021 09:58:19 +0200 Subject: [PATCH] calendar routes --- src/components/Calendar/Calendar.js | 36 +++++++++---------- src/components/Calendar/CalendarComponent.js | 19 ++++------ src/components/Calendar/calendarHelper.js | 2 +- src/components/Candidate/Candidate.js | 4 +-- .../CandidateSidebar/CandidateSidebar.js | 5 +++ .../CandidateSidebar/candidateSidebar.scss | 2 +- src/pages/CalendarPage.js | 4 ++- src/redux/reportSlice.js | 21 +++++++++++ src/store/store.js | 4 ++- 9 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 src/redux/reportSlice.js diff --git a/src/components/Calendar/Calendar.js b/src/components/Calendar/Calendar.js index 7677e21b..1e4dbf20 100644 --- a/src/components/Calendar/Calendar.js +++ b/src/components/Calendar/Calendar.js @@ -17,7 +17,7 @@ const getDateParamString = ({ paramName, value }) => { return value ? `${paramName}=${value}` : '' } -const Calendar = () => { +const Calendar = ({ onSelect }) => { const dispatch = useDispatch() const candidateForCalendar = useSelector(selectCurrentCandidate) const role = useSelector(getRole) @@ -28,22 +28,22 @@ const Calendar = () => { const history = useHistory() - useEffect(() => { - fetchReportList({ - link: `${ - process.env.REACT_APP_API_URL - }/api/reports/index?user_id=${userId}${getDateParamString({ - paramName: 'fromDate', - value: fromDate - })}${getDateParamString({ - paramName: 'toDate', - value: toDate - })}`, - history, - role, - logout: () => dispatch(auth(false)) - }) - }, []) + // useEffect(() => { + // fetchReportList({ + // link: `${ + // process.env.REACT_APP_API_URL + // }/api/reports/index?user_id=${userId}${getDateParamString({ + // paramName: 'fromDate', + // value: fromDate + // })}${getDateParamString({ + // paramName: 'toDate', + // value: toDate + // })}`, + // history, + // role, + // logout: () => {} + // }) + // }, []) useEffect(() => { setMonth(currentMonth) @@ -78,7 +78,7 @@ const Calendar = () => {
- +

{month} : 60 часов

diff --git a/src/components/Calendar/CalendarComponent.js b/src/components/Calendar/CalendarComponent.js index 24a26e8d..ddf41a3a 100644 --- a/src/components/Calendar/CalendarComponent.js +++ b/src/components/Calendar/CalendarComponent.js @@ -4,11 +4,11 @@ import rectangle from '../../images/rectangle__calendar.png' import calendarIcon from '../../images/calendar_icon.png' import moment from 'moment' import 'moment/locale/ru' -import { calendarHelper, currentMonthAndDay } from './calendarHelper' +import { calendarHelper, currentMonthAndDay, } from './calendarHelper' import './calendarComponent.scss' -const CalendarComponent = () => { +const CalendarComponent = ({ onSelect }) => { const [value, setValue] = useState(moment()) const [calendar, setCalendar] = useState([]) @@ -36,14 +36,7 @@ const CalendarComponent = () => { } function nextMonth() { - return value.clone().subtract(2, 'month') - } - - const prevMonthFirst = () => { - return moment().subtract(1, 'month').format('MMMM') - } - const prevMonthSecond = () => { - return moment().subtract(2, 'month').format('MMMM') + return value.clone().add(1, 'month'); } return ( @@ -52,11 +45,11 @@ const CalendarComponent = () => {

Мои отчеты

- setValue(prevMonth())}>{prevMonthFirst()} + setValue(prevMonth())}>{prevMonth().format('MMMM')}
- setValue(nextMonth())}>{prevMonthSecond()} + setValue(nextMonth())}>{nextMonth().format('MMMM')}
@@ -79,7 +72,7 @@ const CalendarComponent = () => { {calendar.map((week) => week.map((day) => ( + + +
{candidate && candidate.achievements && diff --git a/src/components/CandidateSidebar/candidateSidebar.scss b/src/components/CandidateSidebar/candidateSidebar.scss index 4b7938c3..c9af894f 100644 --- a/src/components/CandidateSidebar/candidateSidebar.scss +++ b/src/components/CandidateSidebar/candidateSidebar.scss @@ -85,7 +85,7 @@ line-height: normal; text-align: center; margin-top: 20px; - margin-bottom: 40px; + margin-bottom: 10px; } .candidate-sidebar__select:hover { diff --git a/src/pages/CalendarPage.js b/src/pages/CalendarPage.js index 9e730a7b..789c89c1 100644 --- a/src/pages/CalendarPage.js +++ b/src/pages/CalendarPage.js @@ -1,9 +1,11 @@ import React from 'react'; +import { useHistory } from 'react-router'; import { WithLogout } from '../hoc/withLogout'; import Calendar from '../components/Calendar/Calendar'; const CalendarPage = () => { - return ; + const history = useHistory(); + return { history.push('/report/0') }} />; }; export default CalendarPage; diff --git a/src/redux/reportSlice.js b/src/redux/reportSlice.js new file mode 100644 index 00000000..9146e9dc --- /dev/null +++ b/src/redux/reportSlice.js @@ -0,0 +1,21 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const initialState = { + dateSelected: '', +}; + +export const reportSlice = createSlice({ + name: 'report', + initialState, + reducers: { + dateSelected: (state, action) => { + state.dateSelected = action.payload; + }, + }, +}); + +export const { dateSelected, } = reportSlice.actions; + +export const selectDate = (state) => state.report.dateSelected; + +export default reportSlice.reducer; diff --git a/src/store/store.js b/src/store/store.js index 7de953b4..07959342 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -2,11 +2,13 @@ import { configureStore } from '@reduxjs/toolkit'; import outstaffingReducer from '../redux/outstaffingSlice'; import loaderReducer from '../redux/loaderSlice'; import roleReducer from '../redux/roleSlice'; +import reportReducer from '../redux/reportSlice'; export const store = configureStore({ reducer: { outstaffing: outstaffingReducer, loader: loaderReducer, - role: roleReducer + role: roleReducer, + report: reportReducer, }, });