Compare commits

..

No commits in common. "68c6aa532778494b51fdb7841008d6b15bf14b06" and "e90bb1ed11e078c462d588ca280a77f2b420a1f6" have entirely different histories.

5 changed files with 82 additions and 57 deletions

View File

@ -1,8 +1,12 @@
.calendar-component { .calendar-component {
position: relative; position: relative;
margin: 30px 0; margin-top: 30px;
margin-bottom: 60px;
background-color: #f9f9f9; background-color: #f9f9f9;
padding: 20px 30px; padding-left: 68px;
padding-right: 54px;
padding-top: 48px;
padding-bottom: 40px;
font-family: "LabGrotesque", sans-serif; font-family: "LabGrotesque", sans-serif;
&__header { &__header {
@ -94,7 +98,7 @@
} }
&__rectangle { &__rectangle {
margin: 20px 0; margin: 36px 0;
img { img {
width: 100%; width: 100%;
@ -118,7 +122,7 @@
} }
} }
margin: 20px 0 20px; margin-bottom: 60px;
} }
&__form { &__form {
@ -199,7 +203,8 @@
} }
@media (max-width: 968px) { @media (max-width: 968px) {
.calendar-component { .calendar-component {
padding: 28px 10px; margin-bottom: 40px;
padding: 28px 10px 48px 10px;
&__header { &__header {
&-box { &-box {
@ -295,15 +300,3 @@
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,7 +25,6 @@ export function calendarHelper(value) {
} }
export function getReports(value) { export function getReports(value) {
// получение отчетов с видимой области
const startDay = value const startDay = value
.clone() .clone()
.startOf("month") .startOf("month")
@ -57,7 +56,12 @@ export function getCreatedDate(day) {
} }
} }
export const correctDay = (day) => (day < 10 ? `0${day}` : day); export function correctDay(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,6 +41,18 @@ 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())));
}, []); }, []);
@ -56,19 +68,14 @@ export const ProfileCalendar = () => {
)}` )}`
).then((reports) => { ).then((reports) => {
let spendTime = 0; let spendTime = 0;
for (const report of reports) {
reports report.task.map((task) => {
.filter( if (task.hours_spent) {
(item) => new Date(item.created_at).getMonth() === value.month() spendTime += Number(task.hours_spent);
) }
.map((report) => {
spendTime += report.task.reduce(
(acc, task) => acc + task.hours_spent,
0
);
}); });
}
setTotalHours(Math.floor(spendTime)); setTotalHours(spendTime);
setReports(reports); setReports(reports);
setLoader(false); setLoader(false);
}); });
@ -117,14 +124,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={(value) => setValue(value)} setValueHandler={setValueHandler}
value={value} value={value}
reports={reports} reports={reports}
totalHours={totalHours} totalHours={totalHours}
startRangeDays={startRangeDays} startRangeDays={startRangeDays}
toggleRangeDays={() => setStartRangeDays(!startRangeDays)} toggleRangeDays={toggleStartRangeDays}
startDate={startDate} startDate={startDate}
setStartDateRange={(date) => setStartDate(date)} setStartDateRange={setStartDateRange}
/> />
</div> </div>
</div> </div>

View File

@ -20,8 +20,7 @@ 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";
@ -31,6 +30,7 @@ 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,6 +44,7 @@ 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);
@ -73,8 +74,15 @@ 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 (moment() < day) return `block`; if (currentDay < 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(
@ -102,9 +110,13 @@ export const ProfileCalendarComponent = React.memo(
return "../../report"; return "../../report";
} }
const prevMonth = () => value.clone().subtract(1, "month"); function prevMonth() {
return value.clone().subtract(1, "month");
}
const nextMonth = () => value.clone().add(1, "month"); function nextMonth() {
return value.clone().add(1, "month");
}
function reportsByDate(endDay) { function reportsByDate(endDay) {
const requestDates = const requestDates =
@ -121,16 +133,25 @@ export const ProfileCalendarComponent = React.memo(
)}` )}`
).then((reports) => { ).then((reports) => {
let spendTime = 0; let spendTime = 0;
reports.map((report) => { for (const report of reports) {
spendTime += report.task.reduce( report.task.map((task) => {
(acc, task) => acc + task.hours_spent, if (task.hours_spent) {
0 spendTime += Number(task.hours_spent);
); }
}); });
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);
@ -287,7 +308,7 @@ export const ProfileCalendarComponent = React.memo(
onClick={() => { onClick={() => {
if (startRangeDays) resetRangeDays(); if (startRangeDays) resetRangeDays();
toggleRangeDays(); toggleRangeDays();
setActivePeriod(!activePeriod); toggleActivePeriod();
}} }}
> >
{endDate {endDate
@ -295,22 +316,22 @@ export const ProfileCalendarComponent = React.memo(
? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}` ? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}`
: `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}` : `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}`
: activePeriod : activePeriod
? "Выберите диапазон на календаре" ? "Выберите диапазон на календаре"
: "Выбрать диапазон"} : "Выбрать диапазон"}
</span> </span>
<span> <span>
{totalRangeHours {totalRangeHours
? `${totalRangeHours} ${hourOfNum(totalRangeHours)}` ? `${totalRangeHours} ${hourOfNum(totalRangeHours)}`
: endDate : endDate
? "0 часов" ? "0 часов"
: ""} : ""}
</span> </span>
{endDate && ( {endDate && (
<BaseButton <BaseButton
styles={"clear-days"} styles={"clear-days"}
onClick={() => { onClick={() => {
resetRangeDays(); resetRangeDays();
setActivePeriod(false); toggleActivePeriod();
toggleRangeDays(); toggleRangeDays();
}} }}
> >

View File

@ -16,8 +16,8 @@
&__content { &__content {
background: #ffffff; background: #ffffff;
border-radius: 12px; border-radius: 12px;
margin: 20px 0 30px; margin: 25px 0 80px;
padding: 20px 30px; padding: 50px 40px;
@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: 20px; margin-top: 30px;
margin-bottom: 5px; margin-bottom: 10px;
@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: 10px; margin-top: 30px;
margin-bottom: 20px; margin-bottom: 20px;
width: 460px; width: 460px;
height: 42px; height: 42px;