Skip to content

Commit cdc427e

Browse files
authored
fix(web): prevent day agenda replacement form (#1831)
1 parent 348c576 commit cdc427e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/web/src/views/Day/components/Calendar/DayCalendarGrid.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ mock.module("@web/common/calendar-grid/hooks/useCalendarGridLayout", () => ({
8282
},
8383
}));
8484

85+
const floatingUi =
86+
require("@floating-ui/react") as typeof import("@floating-ui/react");
87+
const useDismissMock = mock(floatingUi.useDismiss);
88+
89+
mock.module("@floating-ui/react", () => ({
90+
...floatingUi,
91+
useDismiss: useDismissMock,
92+
}));
93+
8594
mock.module("@web/components/FloatingEventForm/FloatingEventForm", () => ({
8695
FloatingEventForm: () => null,
8796
}));
@@ -130,6 +139,7 @@ const setDraftEvent = (event: Schema_Event) => {
130139

131140
beforeEach(() => {
132141
store = createStoreWithEvents([]);
142+
useDismissMock.mockClear();
133143
});
134144

135145
afterEach(() => {
@@ -356,6 +366,18 @@ describe("DayCalendarGrid", () => {
356366
expect(getDraft()).toBeNull();
357367
});
358368

369+
it("dismisses the floating form after empty agenda mouse handlers run", () => {
370+
renderDayCalendarGrid();
371+
372+
expect(useDismissMock).toHaveBeenCalledWith(
373+
expect.anything(),
374+
expect.objectContaining({
375+
enabled: true,
376+
outsidePressEvent: "click",
377+
}),
378+
);
379+
});
380+
359381
it("dismisses an open draft when clicking empty Day all-day calendar space", () => {
360382
const existingDraft = createTimedEvent({
361383
_id: "open-all-day-draft",

packages/web/src/views/Day/components/Calendar/DayCalendarGrid.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ import {
5757
import { useDayTimedDraftCreation } from "./useDayTimedDraftCreation";
5858

5959
const isDayInteractionMotionActive = () => false;
60+
const DAY_EVENT_FORM_DISMISS_OPTIONS = {
61+
enabled: true,
62+
outsidePressEvent: "click",
63+
} as const;
6064

6165
export function DayCalendarGrid() {
6266
const dispatch = useAppDispatch();
@@ -90,7 +94,7 @@ export function DayCalendarGrid() {
9094
dispatch(draftSlice.actions.discard(undefined));
9195
}
9296
});
93-
const dismiss = useDismiss(floating.context, { enabled: true });
97+
const dismiss = useDismiss(floating.context, DAY_EVENT_FORM_DISMISS_OPTIONS);
9498
const interactions = useInteractions([dismiss]);
9599

96100
const getDayInteractionLayoutSources = useCallback(

0 commit comments

Comments
 (0)