calendar range days

This commit is contained in:
Mikola 2023-10-12 12:50:17 +03:00
parent 8b49a3a7c2
commit 95ba471e1f
2 changed files with 25 additions and 21 deletions

View File

@ -43,8 +43,8 @@ export const ProfileCalendar = () => {
setValue(value);
}
function setStartDateRange (date) {
setStartDate(date)
function setStartDateRange(date) {
setStartDate(date);
}
function toggleStartRangeDays() {

View File

@ -39,7 +39,7 @@ export const ProfileCalendarComponent = React.memo(
startRangeDays,
toggleRangeDays,
startDate,
setStartDateRange
setStartDateRange,
}) => {
const dispatch = useDispatch();
@ -60,7 +60,7 @@ export const ProfileCalendarComponent = React.memo(
}));
});
if (endDate) {
resetRangeDays()
resetRangeDays();
}
}, [value]);
@ -117,11 +117,14 @@ export const ProfileCalendarComponent = React.memo(
}
function reportsByDate(endDay) {
const requestDates = startDate < endDay ? `fromDate=${getCorrectYYMMDD(
const requestDates =
startDate < endDay
? `fromDate=${getCorrectYYMMDD(
startDate._d
)}&toDate=${getCorrectYYMMDD(endDay._d)}` : `fromDate=${getCorrectYYMMDD(
endDay._d
)}&toDate=${getCorrectYYMMDD(startDate._d)}`;
)}&toDate=${getCorrectYYMMDD(endDay._d)}`
: `fromDate=${getCorrectYYMMDD(endDay._d)}&toDate=${getCorrectYYMMDD(
startDate._d
)}`;
apiRequest(
`/reports/reports-by-date?${requestDates}&user_card_id=${localStorage.getItem(
"cardId"
@ -158,8 +161,7 @@ export const ProfileCalendarComponent = React.memo(
new Date(curDay) < day
) {
selectRange[curDay] = true;
}
else {
} else {
selectRange[curDay] = false;
}
} else {
@ -169,8 +171,7 @@ export const ProfileCalendarComponent = React.memo(
new Date(curDay) > day
) {
selectRange[curDay] = true;
}
else {
} else {
selectRange[curDay] = false;
}
}
@ -266,7 +267,8 @@ export const ProfileCalendarComponent = React.memo(
className={
startRangeDays
? `selectDays ${
String(startDate?._d) === String(day._d) || endDate === day
String(startDate?._d) === String(day._d) ||
endDate === day
? "selectedDay"
: ""
} ${endDate ? "disable" : ""} ${
@ -299,7 +301,9 @@ export const ProfileCalendarComponent = React.memo(
}}
>
{endDate
? startDate < endDate ? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}` : `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}`
? startDate < endDate
? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}`
: `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}`
: "Выбрать диапазон"}
</span>
<span>