Skip to content

Commit

Permalink
Merge pull request #1497 from culturecreates/feature/issue-1363
Browse files Browse the repository at this point in the history
Feature/issue 1363
  • Loading branch information
AbhishekPAnil authored Dec 12, 2024
2 parents a6c6730 + f68a0dd commit 72f0e7a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/locales/en/translationEn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@
"keepEditing": "Keep editing",
"copied": "Copied to clipboard",
"discard": "Discard",
"day": "day",
"validations": {
"informationRequired": "Information is required"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr/transalationFr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 29 additions & 3 deletions src/pages/Dashboard/AddEvent/AddEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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 = [] }) =>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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">
<TimePickerStyled
placeholder={t('dashboard.events.addEditEvent.dates.timeFormatPlaceholder')}
Expand All @@ -2616,6 +2634,14 @@ function AddEvent() {
endTime: value,
});
}}
suffixIcon={
dateType === dateTypes.SINGLE &&
doesEventExceedNextDay(
start_Time,
end_Time,
eventData?.scheduleTimezone ?? 'Canada/Eastern',
) && <sup> +1&nbsp;{t('common.day')}</sup>
}
data-cy="single-date-end-time"
/>
</Form.Item>
Expand Down
7 changes: 7 additions & 0 deletions src/pages/Dashboard/EventReadOnly/EventReadOnly.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
) && <sup> +1&nbsp;{t('common.day')}</sup>}
</p>
</Col>
)}
Expand Down
14 changes: 14 additions & 0 deletions src/utils/doesEventExceed.js
Original file line number Diff line number Diff line change
@@ -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;
}
};

0 comments on commit 72f0e7a

Please sign in to comment.