Fixed nextDay

This commit is contained in:
MaxOvs19 2023-05-18 18:21:20 +03:00
parent 0de6c43fe1
commit b45dc0283c
2 changed files with 13 additions and 30 deletions

View File

@ -65,19 +65,6 @@ export const ProfileCalendarComponent = React.memo(
return "pass"; return "pass";
} }
// function correctRoute(day) {
// for (const date of reports) {
// if (
// `${new Date(day).getFullYear()}-${correctDay(
// new Date(day).getMonth() + 1
// )}-${correctDay(new Date(day).getDate())}` === date.created_at
// ) {
// return `../view/${day}`;
// }
// }
// return "../../report";
// }
function correctRoute(day) { function correctRoute(day) {
for (const date of reports) { for (const date of reports) {
if ( if (

View File

@ -1,13 +1,11 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link, Navigate, useParams } from "react-router-dom"; import { Link, Navigate, useParams } from "react-router-dom";
import { useSelector } from "react-redux";
import { getReportDate } from "../../redux/reportSlice";
import { Loader } from "../../components/Loader/Loader"; import { Loader } from "../../components/Loader/Loader";
import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader"; import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader";
import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs"; import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs";
import { Footer } from "../../components/Footer/Footer"; import { Footer } from "../../components/Footer/Footer";
import { Navigation } from "../../components/Navigation/Navigation";
import { apiRequest } from "../../api/request"; import { apiRequest } from "../../api/request";
import { import {
@ -20,22 +18,20 @@ import arrow from "../../images/right-arrow.png";
import arrowSwitchDate from "../../images/arrowViewReport.png"; import arrowSwitchDate from "../../images/arrowViewReport.png";
import "./viewReport.scss"; import "./viewReport.scss";
import { Navigation } from "../../components/Navigation/Navigation";
export const ViewReport = () => { export const ViewReport = () => {
if (localStorage.getItem("role_status") === "18") { if (localStorage.getItem("role_status") === "18") {
return <Navigate to="/profile" replace />; return <Navigate to="/profile" replace />;
} }
const reportDate = useSelector(getReportDate); // :D
const dateReport = useParams(); const dateReport = useParams();
const [testReportDay] = useState(new Date(dateReport.id)); const [previousReportDay] = useState(new Date(dateReport.id));
const [nextReportDay] = useState(new Date(dateReport.id));
const [taskText, setTaskText] = useState([]); const [taskText, setTaskText] = useState([]);
const [difficulties, setDifficulties] = useState([]); const [difficulties, setDifficulties] = useState([]);
const [tomorrowTask, setTomorrowTask] = useState([]); const [tomorrowTask, setTomorrowTask] = useState([]);
const [totalHours, setTotalHours] = useState(0); const [totalHours, setTotalHours] = useState(0);
const [reportDay] = useState(new Date(getCreatedDate(reportDate))); ///
const [currentDay] = useState(new Date()); const [currentDay] = useState(new Date());
const [loader, setLoader] = useState(false); const [loader, setLoader] = useState(false);
@ -74,21 +70,22 @@ export const ViewReport = () => {
setTotalHours(spendTime); setTotalHours(spendTime);
setLoader(false); setLoader(false);
}); });
testReportDay.setDate(testReportDay.getDate() - 1); previousReportDay.setDate(previousReportDay.getDate() - 1);
nextReportDay.setDate(nextReportDay.getDate() + 1);
} }
function nextDay() { function nextDay() {
reportDay.setDate(reportDay.getDate() + 1); getReportFromDate(getCreatedDate(nextReportDay));
getReportFromDate(getCreatedDate(reportDay)); previousReportDay.setDate(previousReportDay.getDate() + 2);
} }
function previousDay() { function previousDay() {
getReportFromDate(getCreatedDate(testReportDay)); getReportFromDate(getCreatedDate(previousReportDay));
nextReportDay.setDate(nextReportDay.getDate() - 2);
} }
useEffect(() => { useEffect(() => {
getReportFromDate(dateReport.id); getReportFromDate(dateReport.id);
console.log(dateReport.id);
}, []); }, []);
return ( return (
@ -129,7 +126,7 @@ export const ViewReport = () => {
previousDay(); previousDay();
}} }}
> >
<Link to={`../view/${getCreatedDate(testReportDay)}`}> <Link to={`../view/${getCreatedDate(previousReportDay)}`}>
<div className="viewReport__switchDate__prev switchDate"> <div className="viewReport__switchDate__prev switchDate">
<img src={arrowSwitchDate} alt="arrow" /> <img src={arrowSwitchDate} alt="arrow" />
</div> </div>
@ -138,15 +135,14 @@ export const ViewReport = () => {
<p>{getCorrectDate(dateReport.id)}</p> <p>{getCorrectDate(dateReport.id)}</p>
<div> <div onClick={() => nextDay()}>
<Link to={`../view/${0}`}> <Link to={`../view/${getCreatedDate(nextReportDay)}`}>
<div <div
className={`viewReport__switchDate__next switchDate ${ className={`viewReport__switchDate__next switchDate ${
getCreatedDate(currentDay) === getCreatedDate(reportDay) getCreatedDate(currentDay) === getCreatedDate(nextReportDay)
? "disable" ? "disable"
: "" : ""
}`} }`}
onClick={() => nextDay()}
> >
<img src={arrowSwitchDate} alt="arrow" /> <img src={arrowSwitchDate} alt="arrow" />
</div> </div>