Skip to content

Commit f1b0e19

Browse files
🐛 fix: resizing all day events issues (#1033)
* fix: ensure start date and end date is not the same when resizing allday events * fix: diffDays being incorrectly computed * fix: ensure allday start-end date patch applies only to allday events * fix(web): correct diffDays calculation for all-day events * fix(web): enable resizing of all-day events by restoring scaler mouse down functionality * fix(web): remove redundant check
1 parent 5e82182 commit f1b0e19

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

packages/web/src/views/Calendar/components/Draft/hooks/actions/useDraftActions.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,20 @@ export const useDraftActions = (
438438
(currTime: dayjs.Dayjs) => {
439439
if (!draft || !dateBeingChanged) return false;
440440

441-
const _currTime = draft.isAllDay
442-
? currTime.format(YEAR_MONTH_DAY_FORMAT)
443-
: currTime.format();
441+
if (draft.isAllDay) {
442+
return true;
443+
}
444+
445+
const _currTime = currTime.format();
444446
const noChange = draft[dateBeingChanged] === _currTime;
445447

446448
if (noChange) return false;
447449

448-
// For timed events, restrict to same day
449-
if (!draft.isAllDay) {
450-
const diffDay = currTime.day() !== dayjs(draft.startDate).day();
451-
if (diffDay) return false;
450+
const diffDay = currTime.day() !== dayjs(draft.startDate).day();
451+
if (diffDay) return false;
452452

453-
const sameStart = currTime.format() === draft.startDate;
454-
if (sameStart) return false;
455-
}
453+
const sameStart = currTime.format() === draft.startDate;
454+
if (sameStart) return false;
456455

457456
return true;
458457
},
@@ -461,8 +460,11 @@ export const useDraftActions = (
461460

462461
const resize = useCallback(
463462
(e: MouseEvent) => {
463+
if (!draft || !reduxDraft) return; // TS Guard
464+
465+
const _dateBeingChanged = dateBeingChanged as "startDate" | "endDate";
464466
const oppositeKey =
465-
dateBeingChanged === "startDate" ? "endDate" : "startDate";
467+
_dateBeingChanged === "startDate" ? "endDate" : "startDate";
466468

467469
const flipIfNeeded = (currTime: Dayjs) => {
468470
let startDate = draft?.startDate;
@@ -529,7 +531,7 @@ export const useDraftActions = (
529531

530532
const x = getX(e, isSidebarOpen);
531533
// For all-day events, use a fixed Y coordinate (0) because Y positioning is irrelevant:
532-
const y = draft?.isAllDay ? 0 : e.clientY;
534+
const y = draft.isAllDay ? 0 : e.clientY;
533535
const currTime = dateCalcs.getDateByXY(
534536
x,
535537
y,
@@ -541,18 +543,18 @@ export const useDraftActions = (
541543
}
542544

543545
const justFlipped = flipIfNeeded(currTime);
544-
const dateChanged = justFlipped ? oppositeKey : dateBeingChanged;
546+
const dateChanged = justFlipped ? oppositeKey : _dateBeingChanged;
545547

546-
const origTime = dayjs(dateChanged ? draft?.[dateChanged] : null);
548+
const origTime = dayjs(reduxDraft[dateChanged]).add(-1, "day");
547549

548550
let updatedTime: string;
549551
let hasMoved: boolean;
550552

551553
if (draft?.isAllDay) {
552554
// For all-day events, work with day differences
553-
const diffDays = currTime.diff(origTime, "day");
554-
updatedTime = origTime
555-
.add(diffDays, "days")
555+
const diffDays = currTime.diff(origTime, "day", true);
556+
updatedTime = currTime
557+
.add(dateChanged === "endDate" ? 1 : 0, "day")
556558
.format(YEAR_MONTH_DAY_FORMAT);
557559
hasMoved = diffDays !== 0;
558560
} else {
@@ -578,6 +580,7 @@ export const useDraftActions = (
578580
dateBeingChanged,
579581
dateCalcs,
580582
draft,
583+
reduxDraft,
581584
isResizing,
582585
isSidebarOpen,
583586
isValidMovement,

packages/web/src/views/Calendar/components/Grid/AllDayRow/AllDayEvents.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ export const AllDayEvents = ({
9494
}
9595
onMouseDown(e, event);
9696
}}
97-
// onScalerMouseDown={(
98-
// event,
99-
// e,
100-
// dateToChange: "startDate" | "endDate",
101-
// ) => {
102-
// e.stopPropagation();
103-
// e.preventDefault();
104-
// resizeAllDayEvent(event, dateToChange);
105-
// }}
97+
onScalerMouseDown={(
98+
event,
99+
e,
100+
dateToChange: "startDate" | "endDate",
101+
) => {
102+
e.stopPropagation();
103+
e.preventDefault();
104+
resizeAllDayEvent(event, dateToChange);
105+
}}
106106
/>
107107
);
108108
});

0 commit comments

Comments
 (0)