diff --git a/src/locales/en/translationEn.json b/src/locales/en/translationEn.json index 147e494f..69a64415 100644 --- a/src/locales/en/translationEn.json +++ b/src/locales/en/translationEn.json @@ -1181,6 +1181,7 @@ "keepEditing": "Keep editing", "copied": "Copied to clipboard", "discard": "Discard", + "day": "day", "validations": { "informationRequired": "Information is required" }, diff --git a/src/locales/fr/transalationFr.json b/src/locales/fr/transalationFr.json index 409ce858..263d3c98 100644 --- a/src/locales/fr/transalationFr.json +++ b/src/locales/fr/transalationFr.json @@ -1179,6 +1179,7 @@ "unsavedChanges": "Vous avez des modifications non enregistrées. Voulez-vous les ignorer ?", "keepEditing": "Poursuivre l'édition", "discard": "Ignorer", + "day": "jour", "copied": "Copié dans le presse-papiers", "validations": { "informationRequired": "Des informations sont requises" diff --git a/src/pages/Dashboard/AddEvent/AddEvent.jsx b/src/pages/Dashboard/AddEvent/AddEvent.jsx index 3d9edca2..944ff7b8 100644 --- a/src/pages/Dashboard/AddEvent/AddEvent.jsx +++ b/src/pages/Dashboard/AddEvent/AddEvent.jsx @@ -110,6 +110,7 @@ import { isDataValid, placeHolderCollectionCreator } from '../../../utils/MultiL import MultiLingualTextEditor from '../../../components/MultilingualTextEditor/MultiLingualTextEditor'; import MultilingualInput from '../../../components/MultilingualInput'; import { contentLanguageKeyMap } from '../../../constants/contentLanguage'; +import { doesEventExceedNextDay } from '../../../utils/doesEventExceed'; import SortableTreeSelect from '../../../components/TreeSelectOption/SortableTreeSelect'; const { TextArea } = Input; @@ -119,8 +120,8 @@ function AddEvent() { const location = useLocation(); const dispatch = useDispatch(); const [form] = Form.useForm(); - Form.useWatch('startTime', form); - Form.useWatch('endTime', form); + const start_Time = Form.useWatch('startTime', form); + const end_Time = Form.useWatch('endTime', form); const timestampRef = useRef(Date.now()).current; const { calendarId, eventId } = useParams(); let [searchParams] = useSearchParams(); @@ -283,6 +284,18 @@ function AddEvent() { }, { label: t('dashboard.events.addEditEvent.otherInformation.contact.email'), value: 'email' }, ]; + + const adjustEndDateTimeIfBeforeStart = (startDateTime, endDateTime, timezone) => { + const start = moment.tz(startDateTime, timezone); + let end = moment.tz(endDateTime, timezone); + + if (end.isBefore(start)) { + end.add(1, 'days'); + } + + return end.toISOString(); + }; + const hasSubEventConfigChanges = (customDates = [], subEventConfig = []) => { // Convert both arrays to a simpler format for easier comparison const formatCustomDates = customDates.flatMap(({ startDate, customTimes = [] }) => @@ -676,7 +689,11 @@ function AddEvent() { startDateTime = moment .tz(datePickerValue, eventData?.scheduleTimezone ?? 'Canada/Eastern') .format('YYYY-MM-DD'); - if (endTimeValue) endDateTime = dateTimeConverter(datePickerValue, endTimeValue, customTimeFlag); + if (endTimeValue) { + endDateTime = dateTimeConverter(datePickerValue, endTimeValue, customTimeFlag); + if (startDateTime && endDateTime) + endDateTime = adjustEndDateTimeIfBeforeStart(startDateTime, endDateTime, eventData?.scheduleTimezone); + } } if (dateTypeValue === dateTypes.RANGE) { @@ -2606,6 +2623,7 @@ function AddEvent() { ? moment.tz(eventData?.endDateTime, eventData?.scheduleTimezone ?? 'Canada/Eastern') : undefined } + dependencies={['startTime']} data-cy="form-item-single-date-end-time-label"> +1 {t('common.day')} + } data-cy="single-date-end-time" /> diff --git a/src/pages/Dashboard/EventReadOnly/EventReadOnly.jsx b/src/pages/Dashboard/EventReadOnly/EventReadOnly.jsx index de1fbf7a..39b44728 100644 --- a/src/pages/Dashboard/EventReadOnly/EventReadOnly.jsx +++ b/src/pages/Dashboard/EventReadOnly/EventReadOnly.jsx @@ -50,6 +50,7 @@ import { routinghandler } from '../../../utils/roleRoutingHandler'; import ReadOnlyPageTabLayout from '../../../layout/ReadOnlyPageTabLayout'; import { getActiveTabKey } from '../../../redux/reducer/readOnlyTabSlice'; import { isDataValid } from '../../../utils/MultiLingualFormItemSupportFunctions'; +import { doesEventExceedNextDay } from '../../../utils/doesEventExceed'; function EventReadOnly() { const { t } = useTranslation(); @@ -675,6 +676,12 @@ function EventReadOnly() { {moment .tz(eventData?.endDateTime, eventData?.scheduleTimezone ?? 'Canada/Eastern') .format(i18n?.language === 'en' ? 'h:mm a' : 'HH:mm')} + {dateType === dateTypes.SINGLE && + doesEventExceedNextDay( + eventData?.startDateTime, + eventData?.endDateTime, + eventData?.scheduleTimezone ?? 'Canada/Eastern', + ) && +1 {t('common.day')}}

)} diff --git a/src/utils/doesEventExceed.js b/src/utils/doesEventExceed.js new file mode 100644 index 00000000..ce166d4b --- /dev/null +++ b/src/utils/doesEventExceed.js @@ -0,0 +1,14 @@ +import moment from 'moment-timezone'; + +export const doesEventExceedNextDay = (startDateTime, endDateTime, timezone) => { + if (startDateTime && endDateTime) { + const start = moment.tz(startDateTime, timezone); + const end = moment.tz(endDateTime, timezone); + + const exceedsToNextDay = end.isAfter(start) && !start.isSame(end, 'day'); + + const isWithin24Hours = end.diff(start, 'hours') <= 24; + + return exceedsToNextDay && isWithin24Hours; + } +};