Compare commits

..

2 Commits

Author SHA1 Message Date
Victor Batischev
68c6aa5327 format 2023-12-20 16:15:14 +03:00
Victor Batischev
7a1eeb6886 fix hour calculation and report form 2023-12-20 16:14:30 +03:00
5 changed files with 57 additions and 82 deletions

View File

@ -1,12 +1,8 @@
.calendar-component { .calendar-component {
position: relative; position: relative;
margin-top: 30px; margin: 30px 0;
margin-bottom: 60px;
background-color: #f9f9f9; background-color: #f9f9f9;
padding-left: 68px; padding: 20px 30px;
padding-right: 54px;
padding-top: 48px;
padding-bottom: 40px;
font-family: "LabGrotesque", sans-serif; font-family: "LabGrotesque", sans-serif;
&__header { &__header {
@ -98,7 +94,7 @@
} }
&__rectangle { &__rectangle {
margin: 36px 0; margin: 20px 0;
img { img {
width: 100%; width: 100%;
@ -122,7 +118,7 @@
} }
} }
margin-bottom: 60px; margin: 20px 0 20px;
} }
&__form { &__form {
@ -203,8 +199,7 @@
} }
@media (max-width: 968px) { @media (max-width: 968px) {
.calendar-component { .calendar-component {
margin-bottom: 40px; padding: 28px 10px;
padding: 28px 10px 48px 10px;
&__header { &__header {
&-box { &-box {
@ -300,3 +295,15 @@
height: 14px; height: 14px;
} }
} }
@media (max-width: 575.98px) {
.selectDateRange {
font-size: 14px;
text-align: center;
column-gap: 8px;
.select {
padding: 4px;
}
}
}

View File

@ -25,6 +25,7 @@ export function calendarHelper(value) {
} }
export function getReports(value) { export function getReports(value) {
// получение отчетов с видимой области
const startDay = value const startDay = value
.clone() .clone()
.startOf("month") .startOf("month")
@ -56,12 +57,7 @@ export function getCreatedDate(day) {
} }
} }
export function correctDay(day) { export const correctDay = (day) => (day < 10 ? `0${day}` : day);
if (day < 10) {
return `0${day}`;
}
return day;
}
export function currentMonth() { export function currentMonth() {
const currentMonth = moment().format("MMMM"); const currentMonth = moment().format("MMMM");

View File

@ -41,18 +41,6 @@ export const ProfileCalendar = () => {
const [startRangeDays, setStartRangeDays] = useState(false); const [startRangeDays, setStartRangeDays] = useState(false);
const [startDate, setStartDate] = useState(null); const [startDate, setStartDate] = useState(null);
function setValueHandler(value) {
setValue(value);
}
function setStartDateRange(date) {
setStartDate(date);
}
function toggleStartRangeDays() {
setStartRangeDays(!startRangeDays);
}
useEffect(() => { useEffect(() => {
dispatch(setRequestDate(getReports(moment()))); dispatch(setRequestDate(getReports(moment())));
}, []); }, []);
@ -68,14 +56,19 @@ export const ProfileCalendar = () => {
)}` )}`
).then((reports) => { ).then((reports) => {
let spendTime = 0; let spendTime = 0;
for (const report of reports) {
report.task.map((task) => { reports
if (task.hours_spent) { .filter(
spendTime += Number(task.hours_spent); (item) => new Date(item.created_at).getMonth() === value.month()
} )
.map((report) => {
spendTime += report.task.reduce(
(acc, task) => acc + task.hours_spent,
0
);
}); });
}
setTotalHours(spendTime); setTotalHours(Math.floor(spendTime));
setReports(reports); setReports(reports);
setLoader(false); setLoader(false);
}); });
@ -124,14 +117,14 @@ export const ProfileCalendar = () => {
<div className="row calendar__wrapper"> <div className="row calendar__wrapper">
<div className="col-12 col-xl-12"> <div className="col-12 col-xl-12">
<ProfileCalendarComponent <ProfileCalendarComponent
setValueHandler={setValueHandler} setValueHandler={(value) => setValue(value)}
value={value} value={value}
reports={reports} reports={reports}
totalHours={totalHours} totalHours={totalHours}
startRangeDays={startRangeDays} startRangeDays={startRangeDays}
toggleRangeDays={toggleStartRangeDays} toggleRangeDays={() => setStartRangeDays(!startRangeDays)}
startDate={startDate} startDate={startDate}
setStartDateRange={setStartDateRange} setStartDateRange={(date) => setStartDate(date)}
/> />
</div> </div>
</div> </div>

View File

@ -20,7 +20,8 @@ import {
currentMonthAndDay, currentMonthAndDay,
getCorrectDate, getCorrectDate,
getReports, getReports,
hourOfNum hourOfNum,
correctDay
} from "@components/Calendar/calendarHelper"; } from "@components/Calendar/calendarHelper";
import BaseButton from "@components/Common/BaseButton/BaseButton"; import BaseButton from "@components/Common/BaseButton/BaseButton";
import ShortReport from "@components/ShortReport/ShortReport"; import ShortReport from "@components/ShortReport/ShortReport";
@ -30,7 +31,6 @@ import calendarIcon from "assets/icons/calendar.svg";
// import close from "assets/icons/closeProjectPersons.svg"; // import close from "assets/icons/closeProjectPersons.svg";
import rectangle from "assets/images/rectangle__calendar.png"; import rectangle from "assets/images/rectangle__calendar.png";
// eslint-disable-next-line react/display-name
export const ProfileCalendarComponent = React.memo( export const ProfileCalendarComponent = React.memo(
({ ({
value, value,
@ -44,7 +44,6 @@ export const ProfileCalendarComponent = React.memo(
}) => { }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [currentDay] = useState(moment());
const [calendar, setCalendar] = useState([]); const [calendar, setCalendar] = useState([]);
const [month, setMonth] = useState(""); const [month, setMonth] = useState("");
const [shortReport, setShortReport] = useState(false); const [shortReport, setShortReport] = useState(false);
@ -74,15 +73,8 @@ export const ProfileCalendarComponent = React.memo(
return day.isSame(new Date(), "day"); return day.isSame(new Date(), "day");
} }
function correctDay(day) {
if (day < 10) {
return `0${day}`;
}
return day;
}
function dayStyles(day) { function dayStyles(day) {
if (currentDay < day) return `block`; if (moment() < day) return `block`;
for (const date of reports) { for (const date of reports) {
if ( if (
`${new Date(day).getFullYear()}-${correctDay( `${new Date(day).getFullYear()}-${correctDay(
@ -110,13 +102,9 @@ export const ProfileCalendarComponent = React.memo(
return "../../report"; return "../../report";
} }
function prevMonth() { const prevMonth = () => value.clone().subtract(1, "month");
return value.clone().subtract(1, "month");
}
function nextMonth() { const nextMonth = () => value.clone().add(1, "month");
return value.clone().add(1, "month");
}
function reportsByDate(endDay) { function reportsByDate(endDay) {
const requestDates = const requestDates =
@ -133,25 +121,16 @@ export const ProfileCalendarComponent = React.memo(
)}` )}`
).then((reports) => { ).then((reports) => {
let spendTime = 0; let spendTime = 0;
for (const report of reports) { reports.map((report) => {
report.task.map((task) => { spendTime += report.task.reduce(
if (task.hours_spent) { (acc, task) => acc + task.hours_spent,
spendTime += Number(task.hours_spent); 0
} );
}); });
} setTotalRangeHours(Math.floor(spendTime));
setTotalRangeHours(spendTime);
}); });
} }
function toggleActivePeriod() {
if (!activePeriod) {
setActivePeriod(true);
} else {
setActivePeriod(false);
}
}
function rangeDays(day) { function rangeDays(day) {
if (!startDate) { if (!startDate) {
setStartDateRange(day); setStartDateRange(day);
@ -308,7 +287,7 @@ export const ProfileCalendarComponent = React.memo(
onClick={() => { onClick={() => {
if (startRangeDays) resetRangeDays(); if (startRangeDays) resetRangeDays();
toggleRangeDays(); toggleRangeDays();
toggleActivePeriod(); setActivePeriod(!activePeriod);
}} }}
> >
{endDate {endDate
@ -331,7 +310,7 @@ export const ProfileCalendarComponent = React.memo(
styles={"clear-days"} styles={"clear-days"}
onClick={() => { onClick={() => {
resetRangeDays(); resetRangeDays();
toggleActivePeriod(); setActivePeriod(false);
toggleRangeDays(); toggleRangeDays();
}} }}
> >

View File

@ -16,8 +16,8 @@
&__content { &__content {
background: #ffffff; background: #ffffff;
border-radius: 12px; border-radius: 12px;
margin: 25px 0 80px; margin: 20px 0 30px;
padding: 50px 40px; padding: 20px 30px;
@media (max-width: 555px) { @media (max-width: 555px) {
padding: 25px 20px; padding: 25px 20px;
@ -69,8 +69,8 @@
letter-spacing: normal; letter-spacing: normal;
line-height: 30px; line-height: 30px;
text-align: left; text-align: left;
margin-top: 30px; margin-top: 20px;
margin-bottom: 10px; margin-bottom: 5px;
@media (max-width: 555px) { @media (max-width: 555px) {
margin-top: 25px; margin-top: 25px;
@ -302,7 +302,7 @@
&__input-box { &__input-box {
input { input {
margin-left: 10px; margin-left: 10px;
margin-top: 30px; margin-top: 10px;
margin-bottom: 20px; margin-bottom: 20px;
width: 460px; width: 460px;
height: 42px; height: 42px;