From 52e7df0e7b4986f509546b3df61f2dded08b72f7 Mon Sep 17 00:00:00 2001 From: M1kola Date: Mon, 23 Jan 2023 23:51:18 +0300 Subject: [PATCH] switch report date --- src/pages/Summary/Summary.js | 2 +- src/pages/ViewReport/ViewReport.js | 85 +++++++++++++++++++--------- src/pages/ViewReport/viewReport.scss | 7 ++- 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/pages/Summary/Summary.js b/src/pages/Summary/Summary.js index b202f607..8c97f9d3 100644 --- a/src/pages/Summary/Summary.js +++ b/src/pages/Summary/Summary.js @@ -69,7 +69,7 @@ export const Summary = () => {
- {gitInfo.length && gitInfo.map((itemGit) => { + {Boolean(gitInfo.length) && gitInfo.map((itemGit) => { return
diff --git a/src/pages/ViewReport/ViewReport.js b/src/pages/ViewReport/ViewReport.js index 052269c4..5fa137af 100644 --- a/src/pages/ViewReport/ViewReport.js +++ b/src/pages/ViewReport/ViewReport.js @@ -1,6 +1,9 @@ import React, {useEffect, useState} from 'react' import {Link} from "react-router-dom"; import {useRequest} from "../../hooks/useRequest"; +import {useSelector} from "react-redux"; +import {getReportDate} from "../../redux/reportSlice"; +import {currentMonthAndDay} from "../../components/Calendar/calendarHelper"; import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader"; import {Footer} from "../../components/Footer/Footer"; @@ -10,26 +13,33 @@ import arrowSwitchDate from "../../images/arrowViewReport.svg"; import './viewReport.scss' -const getCreatedDate = () => { - const date = new Date(); - const dd = String(date.getDate()).padStart(2, '0'); - const mm = String(date.getMonth() + 1).padStart(2, '0'); - const yyyy = date.getFullYear(); - return `${yyyy}-${mm}-${dd}` -}; - export const ViewReport = () => { + const getCreatedDate = (day) => { + if (day) { + return `${new Date(day).getFullYear()}-${new Date(day).getMonth() + 1}-${new Date(day).getDate()}` + } else { + const date = new Date(); + const dd = String(date.getDate()).padStart(2, '0'); + const mm = String(date.getMonth() + 1).padStart(2, '0'); + const yyyy = date.getFullYear(); + return `${yyyy}-${mm}-${dd}` + } + }; const {apiRequest} = useRequest(); + const reportDate = useSelector(getReportDate); const [taskText, setTaskText] = useState([]); const [difficulties, setDifficulties] = useState([]) const [tomorrowTask, setTomorrowTask] = useState([]) const [totalHours, setTotalHours] = useState(0); - useEffect(() => { + const [reportDay, setReportDay] = useState(new Date (getCreatedDate(reportDate))) + const [currentDay, setCurrentDay] = useState(new Date ()) + + function getReportFromDate(day) { setTaskText([]) setDifficulties([]) setTomorrowTask([]) - apiRequest(`reports/find-by-date?user_card_id=${localStorage.getItem('cardId')}&date=2023-01-22`) + apiRequest(`reports/find-by-date?user_card_id=${localStorage.getItem('cardId')}&date=${day}`) .then(res => { let spendTime = 0 for (const item of res) { @@ -53,6 +63,21 @@ export const ViewReport = () => { } setTotalHours(spendTime) }) + } + + function nextDay() { + reportDay.setDate(reportDay.getDate() + 1); + getCreatedDate(reportDay) + getReportFromDate(getCreatedDate(reportDay)) + } + + function previousDay() { + reportDay.setDate(reportDay.getDate() - 1); + getReportFromDate(getCreatedDate(reportDay)) + } + + useEffect(() => { + getReportFromDate(getCreatedDate(reportDate)) }, []); return (
@@ -64,7 +89,7 @@ export const ViewReport = () => { arrow

Вернуться

-

{getCreatedDate()}

+

{getCreatedDate(reportDay)}

Вами потрачено на работу : {totalHours} часов

{/*
*/} {/* */} @@ -73,11 +98,11 @@ export const ViewReport = () => {
-
+
previousDay()}> arrow
-

{getCreatedDate()}

-
+

{getCreatedDate(reportDay)}

+
nextDay()}> arrow
@@ -112,20 +137,24 @@ export const ViewReport = () => {
-
-

Какие сложности возникли?

- {difficulties.length && difficulties.map((item, index) => { - return

{item}

- } - )} -
-
-

Что планируется сделать завтра?

- {tomorrowTask.length && tomorrowTask.map((item, index) => { - return

{item}

- } - )} -
+ {Boolean(difficulties.length) && +
+

Какие сложности возникли?

+ {difficulties.map((item, index) => { + return

{item}

+ } + )} +
+ } + {Boolean(tomorrowTask.length) && +
+

Что планируется сделать завтра?

+ {tomorrowTask.map((item, index) => { + return

{item}

+ } + )} +
+ }
:
diff --git a/src/pages/ViewReport/viewReport.scss b/src/pages/ViewReport/viewReport.scss index 5144485c..65f1f2ee 100644 --- a/src/pages/ViewReport/viewReport.scss +++ b/src/pages/ViewReport/viewReport.scss @@ -122,7 +122,7 @@ p { font-weight: 400; - font-size: 12px; + font-size: 18px; line-height: 32px; color: #000000; } @@ -143,6 +143,11 @@ } } + .disable { + pointer-events: none; + opacity: 0.5; + } + .table__container { margin: 0 -28px; overflow: hidden;