feat(ui): replace end date field with '...' button toggle

- Hide end date by default; reveal via '...' button in both modes
- Keep state/validation/API logic unchanged
- Normalize labels to use MUI TextField labels across modes
- Align button with fields; constrain widths for expanded mode
This commit is contained in:
lenhanphung
2025-10-28 15:57:47 +07:00
committed by Benoit TELLIER
parent 5078128e10
commit 61358c081a
4 changed files with 187 additions and 62 deletions
+62
View File
@@ -0,0 +1,62 @@
// Date rules helpers to normalize end date/time behavior
import { combineDateTime } from "./dateTimeHelpers";
/** Adds a number of days to a YYYY-MM-DD string and returns YYYY-MM-DD */
export function addDays(dateStr: string, days: number): string {
const d = new Date(dateStr);
d.setDate(d.getDate() + days);
return d.toISOString().split("T")[0];
}
/**
* Compute endDate (YYYY-MM-DD) when startDate changes
* - If all-day: endDate = startDate + 1 day
* - Else: endDate = startDate
*/
export function getEndDateForStartChange(
startDate: string,
isAllDay: boolean
): string {
if (!startDate) return "";
return isAllDay ? addDays(startDate, 1) : startDate;
}
/**
* Compute new start/end (ISO-like strings) when toggling all-day
* - nextAllDay = true:
* - If fromAllDaySlot: endDate = startDate
* - Else: endDate = startDate + 1 day
* - Times are cleared (date-only)
* - nextAllDay = false:
* - end restored from originalEndDate if any, else previousEndDate, else start
*/
export function getEndDateForToggle(params: {
nextAllDay: boolean;
fromAllDaySlot?: boolean;
startDate: string;
previousEndDate: string;
originalEndDate?: string;
}): string {
const {
nextAllDay,
fromAllDaySlot,
startDate,
previousEndDate,
originalEndDate,
} = params;
if (nextAllDay) {
return fromAllDaySlot ? startDate : addDays(startDate, 1);
}
return originalEndDate || previousEndDate || startDate;
}
/** Utility to combine date with a fallback time (HH:mm) safely */
export function combineWithFallback(
dateStr: string,
timeHHmm: string | undefined,
fallbackTime: string
): string {
const time = timeHHmm && timeHHmm.trim() ? timeHHmm : fallbackTime;
return combineDateTime(dateStr, time);
}