372 drag and drop multiple days event to use normal mode instead of extended mode (#407)

- When dragging from allday slot: open normal mode with allday checked, show start date and end date
- When dragging from week/month view grid: open normal mode with allday checked, show 4 fields (start date, start time, end date, end time)
- Update DateTimeFields logic to support displaying time fields when allday=true and hasEndDateChanged=true for multiple days events

Add setHasEndDateChanged(false) to resetAllStateToDefault function to prevent stale state when:
- User creates multi-day event from grid (sets hasEndDateChanged = true)
- Closes the modal
- Opens modal again for a single-day event

This ensures hasEndDateChanged is properly reset to false when modal is closed or reset.

Fix drag and drop logic: keep allday=false when dragging from week view

- Remove setAllDay(true) when dragging multiple days from week view grid
- Keep allday=false to show time fields for week view drag scenarios
- Add comprehensive test cases for drag and drop scenarios
- Test cases cover allday slot and week view drag scenarios
- Prevent regressions with test coverage for display logic
This commit is contained in:
lenhanphung
2025-12-17 16:28:11 +07:00
committed by GitHub
parent 89103b5787
commit a935d2bc43
4 changed files with 233 additions and 10 deletions
@@ -104,10 +104,26 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
});
}, [startDate, endDate, startTime, endTime, getCurrentDuration]);
const spansMultipleDays = React.useMemo(() => {
return startDate !== endDate;
}, [startDate, endDate]);
const isExpanded = showMore;
const shouldShowEndDateNormal = allday || showEndDate;
const showSingleDateField = !isExpanded && !shouldShowEndDateNormal;
const showFourFieldsNormal = !isExpanded && showEndDate && !allday;
// Show full 4 fields when:
// 1. Non-allday with hasEndDateChanged
// 2. Multiple days with hasEndDateChanged (supports drag from week/month view grid with allday checked)
// 3. Multiple days without allday (original behavior)
const shouldShowFullFieldsInNormal =
(!allday && hasEndDateChanged) ||
(hasEndDateChanged && spansMultipleDays) ||
(spansMultipleDays && !allday);
const showSingleDateField =
!isExpanded && !shouldShowEndDateNormal && !shouldShowFullFieldsInNormal;
// When shouldShowFullFieldsInNormal is true, show time fields even if allday is true
// This supports the case: drag from week/month view grid with multiple days
const shouldShowTimeFields = !allday || shouldShowFullFieldsInNormal;
const startDateLabel = showSingleDateField
? t("dateTimeFields.date")
@@ -328,7 +344,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
flexDirection="column"
sx={{ maxWidth: showMore ? "calc(100% - 145px)" : "100%" }}
>
{isExpanded || showFourFieldsNormal ? (
{isExpanded || shouldShowFullFieldsInNormal ? (
<>
<Box display="flex" gap={1} flexDirection="row" alignItems="center">
<Box sx={{ maxWidth: "300px", width: "48%" }}>
@@ -351,7 +367,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
}}
/>
</Box>
{!allday && (
{shouldShowTimeFields && (
<Box sx={{ width: "110px" }}>
<TimePicker
ampm={false}
@@ -397,7 +413,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
}}
/>
</Box>
{!allday && (
{shouldShowTimeFields && (
<Box sx={{ width: "110px" }}>
<TimePicker
ampm={false}
+29 -5
View File
@@ -181,6 +181,7 @@ function EventPopover({
setTimezone(resolvedCalendarTimezone);
setHasVideoConference(false);
setMeetingLink(null);
setHasEndDateChanged(false);
}, [resolvedCalendarTimezone, defaultCalendarId]);
// Track if we should sync from selectedRange (only on initial selection, not on toggle)
@@ -286,11 +287,22 @@ function EventPopover({
setStart(startValue);
setEnd(endValue);
// If start date != end date, open extended mode
// Check if multiple days event
const startDateOnly = startValue.slice(0, 10);
const endDateOnly = endValue.slice(0, 10);
if (startDateOnly !== endDateOnly) {
setShowMore(true);
const isMultipleDays = startDateOnly !== endDateOnly;
if (isMultipleDays) {
// Keep normal mode (showMore = false) for multiple days events
setShowMore(false);
if (selectedRange.allDay) {
// Dragged from allday slot: allday already set to true at line 234
// Will show start date and end date (handled by showEndDate logic)
} else {
// Dragged from week/month view grid: keep allday=false to show time fields, trigger 4 fields display
setHasEndDateChanged(true);
}
}
} else {
// Fallback: format Date objects using local time components
@@ -337,8 +349,19 @@ function EventPopover({
if (formattedStart && formattedEnd) {
const startDateOnly = formattedStart.slice(0, 10);
const endDateOnly = formattedEnd.slice(0, 10);
if (startDateOnly !== endDateOnly) {
setShowMore(true);
const isMultipleDays = startDateOnly !== endDateOnly;
if (isMultipleDays) {
// Keep normal mode (showMore = false) for multiple days events
setShowMore(false);
if (selectedRange.allDay) {
// Dragged from allday slot: allday already set to true at line 234
// Will show start date and end date (handled by showEndDate logic)
} else {
// Dragged from week/month view grid: keep allday=false to show time fields, trigger 4 fields display
setHasEndDateChanged(true);
}
}
}
}
@@ -493,6 +516,7 @@ function EventPopover({
setBusy("OPAQUE");
setHasVideoConference(false);
setMeetingLink(null);
setHasEndDateChanged(false);
}
if (!isCreatingNew) {