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}