Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1359

Merged
merged 30 commits into from
Sep 24, 2024
Merged

Develop #1359

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e0d5bec
feat: added function logic for event series sub event configuration
AbhishekPAnil Jun 26, 2024
c09ae81
refactor: simplified code
AbhishekPAnil Jun 27, 2024
ee6f247
feat: added functionality to check for changes in sub evnet and delin…
AbhishekPAnil Jun 27, 2024
cc6975f
chore: closes #1154
AbhishekPAnil Jun 27, 2024
63cff97
chore: closes #1021
AbhishekPAnil Jun 27, 2024
eb9679e
chore: closes #culturecreates/footlight-calendar-api/issues/1021
AbhishekPAnil Jun 27, 2024
f5048d5
feat: only published event sameAs is removed
AbhishekPAnil Jun 27, 2024
e39c597
fix: checked the length of subEventConfiguraion
AbhishekPAnil Jun 28, 2024
aa3122b
fix: checked the length of subEventConfiguraion while creating payloa
AbhishekPAnil Jun 28, 2024
6899be1
AbhishekPAnil Jun 28, 2024
5c212cc
AbhishekPAnil Jun 28, 2024
e4375a0
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Jul 18, 2024
0af995a
Merge branch 'feature/issue-1021' of github.com:culturecreates/footli…
AbhishekPAnil Jul 18, 2024
1ce62a3
feat: added process times function
AbhishekPAnil Jul 22, 2024
7a58f91
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Jul 24, 2024
dbaedac
fix: added a condition check for subEventConfiguration
AbhishekPAnil Jul 24, 2024
e2be859
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Jul 31, 2024
f42d183
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Jul 31, 2024
398ee2e
fix: added extra check for subEventconfiguration date change
AbhishekPAnil Jul 31, 2024
6c8bcca
chore: updated server url to test server
AbhishekPAnil Aug 1, 2024
a11ec0a
chore: changed the http to https for test server
AbhishekPAnil Aug 1, 2024
9f1f5d1
fix: added function to check array equality
AbhishekPAnil Aug 26, 2024
95b42c2
fix: added case statements for different scenarios
AbhishekPAnil Aug 26, 2024
57ec78b
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Aug 28, 2024
dc88918
Merge branch 'develop' of github.com:culturecreates/footlight-app int…
AbhishekPAnil Sep 13, 2024
ece7315
Merge pull request #1243 from culturecreates/feature/issue-1154
AbhishekPAnil Sep 24, 2024
3f4714b
chore: changed url
AbhishekPAnil Sep 24, 2024
07692de
Merge pull request #1357 from culturecreates/feature/issue-1154
AbhishekPAnil Sep 24, 2024
e4d8c37
fix: sub event config length checked
AbhishekPAnil Sep 24, 2024
eae7a87
Merge pull request #1358 from culturecreates/feature/issue-1154
AbhishekPAnil Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/RecurringEvents/RecurringEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ const RecurringEvents = function ({

useEffect(() => {
if (eventDetails) {
if (formFields?.frequency === 'CUSTOM' || eventDetails.recurringEvent?.frequency === 'CUSTOM') {
if (
formFields?.frequency === 'CUSTOM' ||
eventDetails.recurringEvent?.frequency === 'CUSTOM' ||
eventDetails.subEventConfiguration
) {
setDateModified(true);
setIsCustom(true);
} else setIsCustom(false);
Expand Down
12 changes: 9 additions & 3 deletions src/constants/dateTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ export const dateTypeOptions = [
},
];

export const dateFrequencyTypes = {
DAILY: 'DAILY',
WEEKLY: 'WEEKLY',
CUSTOM: 'CUSTOM',
};

export const dateFrequencyOptions = [
{
value: 'DAILY',
value: dateFrequencyTypes.DAILY,
label: <Translation>{(t) => t('dashboard.events.addEditEvent.dates.daily')}</Translation>,
},
{
value: 'WEEKLY',
value: dateFrequencyTypes.WEEKLY,
label: <Translation>{(t) => t('dashboard.events.addEditEvent.dates.weekly')}</Translation>,
},
{
value: 'CUSTOM',
value: dateFrequencyTypes.CUSTOM,
label: <Translation>{(t) => t('dashboard.events.addEditEvent.dates.custom')}</Translation>,
},
];
Expand Down
210 changes: 188 additions & 22 deletions src/pages/Dashboard/AddEvent/AddEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Select from '../../../components/Select';
import { eventStatus, eventStatusOptions } from '../../../constants/eventStatus';
import TimePickerStyled from '../../../components/TimePicker/TimePicker';
import DateRangePicker from '../../../components/DateRangePicker';
import { dateTypeOptions, dateTypes } from '../../../constants/dateTypes';
import { dateFrequencyTypes, dateTypeOptions, dateTypes } from '../../../constants/dateTypes';
import ChangeType from '../../../components/ChangeType';
import CardEvent from '../../../components/Card/Common/Event';
import Tags from '../../../components/Tags/Common/Tags';
Expand Down Expand Up @@ -103,6 +103,7 @@ import MultipleImageUpload from '../../../components/MultipleImageUpload';
import { adminCheckHandler } from '../../../utils/adminCheckHandler';
import { getCurrentCalendarDetailsFromUserDetails } from '../../../utils/getCurrentCalendarDetailsFromUserDetails';
import { getWeekDayDates } from '../../../utils/getWeekDayDates';
import { arraysAreEqual } from '../../../utils/arraysAreEqual';
import CreateMultiLingualFormItems from '../../../layout/CreateMultiLingualFormItems';
import { isDataValid, placeHolderCollectionCreator } from '../../../utils/MultiLingualFormItemSupportFunctions';
import MultiLingualTextEditor from '../../../components/MultilingualTextEditor/MultiLingualTextEditor';
Expand Down Expand Up @@ -279,6 +280,41 @@ function AddEvent() {
},
{ label: t('dashboard.events.addEditEvent.otherInformation.contact.email'), value: 'email' },
];
const hasSubEventConfigChanges = (customDates = [], subEventConfig = []) => {
// Convert both arrays to a simpler format for easier comparison
const formatCustomDates = customDates.flatMap(({ startDate, customTimes = [] }) =>
customTimes.length === 0 ? [{ startDate }] : customTimes.map((time) => ({ startDate, ...time })),
);

const formatSubEventConfig = subEventConfig.map(({ startDate, startTime, endTime }) => ({
startDate,
startTime,
endTime,
// sameAs,
}));

// Check if the length of both arrays are different
if (formatCustomDates.length !== formatSubEventConfig.length) {
return true;
}

// Function to compare two objects for equality
const isEqual = (obj1, obj2) =>
obj1 &&
obj2 &&
Object.keys(obj1).length === Object.keys(obj2).length &&
Object.keys(obj1).every((key) => obj1[key] === obj2[key]);

// Check each item in both arrays for differences
for (let i = 0; i < formatCustomDates.length; i++) {
if (!isEqual(formatCustomDates[i], formatSubEventConfig[i])) {
return true;
}
}

// If no differences found, return false
return false;
};

const validateVideoLink = (rule, value) => {
if (!value) {
Expand All @@ -292,7 +328,60 @@ function AddEvent() {
return Promise.resolve();
};

const addUpdateEventApiHandler = (eventObj, toggle) => {
const detectDateChange = ({
initialDateType,
currentDateType,
initialStartDate,
currentStartDate,
initialEndDate,
currentEndDate,
initialFrequency,
currentFrequency,
initialRecurringEvent,
currentRecurringEvent,
customDates,
}) => {
if (initialDateType !== currentDateType) return true;
else
switch (currentDateType) {
case dateTypes.RANGE:
if (initialStartDate != currentStartDate || initialEndDate != currentEndDate) return true;
else return false;
case dateTypes.MULTIPLE:
if (initialFrequency != currentFrequency) return true;
else
switch (currentFrequency) {
case dateFrequencyTypes.DAILY:
if (
initialRecurringEvent?.startDate != currentRecurringEvent?.startDate ||
initialRecurringEvent?.endDate != currentRecurringEvent?.endDate ||
initialRecurringEvent?.startTime != currentRecurringEvent?.startTime ||
initialRecurringEvent?.endTime != currentRecurringEvent?.endTime
)
return true;
else return false;

case dateFrequencyTypes.WEEKLY:
if (
initialRecurringEvent?.startDate != currentRecurringEvent?.startDate ||
initialRecurringEvent?.endDate != currentRecurringEvent?.endDate ||
initialRecurringEvent?.startTime != currentRecurringEvent?.startTime ||
initialRecurringEvent?.endTime != currentRecurringEvent?.endTime ||
!arraysAreEqual(initialRecurringEvent?.weekDays, currentRecurringEvent?.weekDays)
)
return true;
else return false;

case dateFrequencyTypes.CUSTOM:
return hasSubEventConfigChanges(customDates, eventData?.subEventConfiguration);
}
break;
default:
break;
}
};

const addUpdateEventApiHandler = (eventObj, toggle, sameAs) => {
var promise = new Promise(function (resolve, reject) {
if ((!eventId || eventId === '') && newEventId === null) {
addEvent({
Expand Down Expand Up @@ -322,7 +411,7 @@ function AddEvent() {
} else {
eventObj = {
...eventObj,
sameAs: eventData?.sameAs,
sameAs,
};
updateEvent({
data: eventObj,
Expand Down Expand Up @@ -399,7 +488,9 @@ function AddEvent() {
recurringEvent,
description = {},
name = {},
subEventConfiguration = undefined,
inLanguage = [],
sameAs = eventId ? (eventData?.sameAs ? eventData?.sameAs : []) : [],
eventDiscipline = [];

let eventObj;
Expand Down Expand Up @@ -459,10 +550,10 @@ function AddEvent() {
let multipleDatesFlag = false;
let multipleStartTimeFlag = false;
let multipleEndTimeFlag = false;

let recurEvent = {};
if (dateTypeValue === dateTypes.MULTIPLE) {
const recurEvent = {
frequency: values.frequency,
recurEvent = {
frequency: form.getFieldsValue().frequency !== 'CUSTOM' && values.frequency,
startDate:
form.getFieldsValue().frequency !== 'CUSTOM'
? moment(values.startDateRecur[0]).format('YYYY-MM-DD')
Expand All @@ -482,8 +573,8 @@ function AddEvent() {
? moment(values.endTimeRecur).format('HH:mm')
: undefined,
weekDays: values.frequency === 'WEEKLY' ? values.daysOfWeek : undefined,
customDates:
form.getFieldsValue().frequency === 'CUSTOM' ? form.getFieldsValue().customDates : undefined,
// customDates:
// form.getFieldsValue().frequency === 'CUSTOM' ? form.getFieldsValue().customDates : undefined,
};

customDatesFlag = !!recurEvent?.customDates;
Expand Down Expand Up @@ -530,6 +621,55 @@ function AddEvent() {
recurringEvent = recurEvent;
}
}
const { customDates, frequency } = form.getFieldsValue() || {};
if (customDates && frequency === 'CUSTOM') {
recurringEvent = undefined;
subEventConfiguration = [];
const subEventConfig = eventData?.subEventConfiguration || [];

const processCustomTimes = (startDate, customTimes) => {
if (customTimes.length === 0) {
subEventConfiguration.push({ startDate });
} else {
customTimes.forEach(({ startTime, endTime }) => {
const sameAs = subEventConfig.find(
({ startDate: subStartDate, startTime: subStartTime, endTime: subEndTime }) => {
return (
subStartDate === startDate &&
((!subStartTime && !subEndTime) ||
(subStartTime === startTime && !subEndTime) ||
(!subStartTime && subEndTime === endTime) ||
(subStartTime === startTime && subEndTime === endTime))
);
},
);
subEventConfiguration.push({
startDate,
startTime,
endTime,
sameAs: sameAs?.sameAs,
});
});
}
};

if (eventId) {
if (hasSubEventConfigChanges(customDates, subEventConfig)) {
// Changes detected

customDates.forEach(({ startDate, customTimes = [] }) => {
processCustomTimes(startDate, customTimes);
});
} else {
// No changes detected
subEventConfiguration = subEventConfig;
}
} else {
customDates.forEach(({ startDate, customTimes = [] }) => {
processCustomTimes(startDate, customTimes);
});
}
}

if (dateTypeValue === dateTypes.SINGLE) {
if (startTimeValue) startDateTime = dateTimeConverter(datePickerValue, startTimeValue, customTimeFlag);
Expand All @@ -553,6 +693,30 @@ function AddEvent() {
.format('YYYY-MM-DD');
}

if (eventId && values?.initialDateType !== dateTypes.SINGLE) {
if (
detectDateChange({
initialDateType: values.initialDateType,
currentDateType: dateType,
initialStartDate: eventData?.startDate ?? eventData?.startDateTime,
currentStartDate: startDateTime,
initialEndDate: eventData?.endDate ?? eventData?.endDateTime,
currentEndDate: endDateTime,
initialFrequency: eventData?.subEventConfiguration
? dateFrequencyTypes.CUSTOM
: eventData?.recurringEvent?.frequency,
currentFrequency: values.frequency,
initialRecurringEvent: eventData?.recurringEvent,
currentRecurringEvent: recurEvent,
customDates,
})
) {
if (eventData?.publishState === eventPublishState.PUBLISHED) {
sameAs = eventData?.sameAs?.filter((item) => item?.type !== sameAsTypes.ARTSDATA_IDENTIFIER);
}
}
}

if (values?.eventType) {
additionalType = values?.eventType?.map((eventTypeId) => ({
entityId: eventTypeId,
Expand Down Expand Up @@ -766,7 +930,7 @@ function AddEvent() {
...(dateTypes.MULTIPLE && { recurringEvent }),
inLanguage,
isFeatured: values?.isFeatured,
subEventConfiguration: eventData?.subEventConfiguration,
subEventConfiguration,
};

let imageCrop = form.getFieldValue('imageCrop') ? [form.getFieldValue('imageCrop')] : [];
Expand Down Expand Up @@ -881,7 +1045,7 @@ function AddEvent() {

if (values.multipleImagesCrop?.length > 0) await uploadImageList();
eventObj['image'] = imageCrop;
addUpdateEventApiHandler(eventObj, toggle)
addUpdateEventApiHandler(eventObj, toggle, sameAs)
.then((id) => resolve(id))
.catch((error) => {
reject(error);
Expand All @@ -906,7 +1070,7 @@ function AddEvent() {
eventObj['image'] = [];
} else eventObj['image'] = imageCrop;

addUpdateEventApiHandler(eventObj, toggle)
addUpdateEventApiHandler(eventObj, toggle, sameAs)
.then((id) => resolve(id))
.catch((error) => {
reject(error);
Expand Down Expand Up @@ -1556,18 +1720,20 @@ function AddEvent() {
if (routinghandler(user, calendarId, eventData?.creator?.userId, eventData?.publishState, false) || duplicateId) {
if (
(eventData?.recurringEvent && Object.keys(eventData?.recurringEvent)?.length > 0) ||
eventData?.subEventConfiguration
eventData?.subEventConfiguration?.length > 0
)
isRecurring = true;
setDateType(
dateTimeTypeHandler(
eventData?.startDate,
eventData?.startDateTime,
eventData?.endDate,
eventData?.endDateTime,
isRecurring,
),
let initialDateType = dateTimeTypeHandler(
eventData?.startDate,
eventData?.startDateTime,
eventData?.endDate,
eventData?.endDateTime,
isRecurring,
);
setDateType(initialDateType);
form.setFieldsValue({
initialDateType,
});
setTicketType(eventData?.offerConfiguration?.category);
if (initialPlace && initialPlace?.length > 0) {
initialPlace[0] = {
Expand Down Expand Up @@ -1731,7 +1897,7 @@ function AddEvent() {
if (eventData?.inLanguage?.length > 0)
initialAddedFields = initialAddedFields?.concat(otherInformationFieldNames?.inLanguage);
setAddedFields(initialAddedFields);
if (eventData?.recurringEvent) {
if (eventData?.recurringEvent && eventData?.recurringEvent?.frequency != 'CUSTOM') {
form.setFieldsValue({
frequency: eventData?.recurringEvent?.frequency,
startDateRecur: [
Expand Down Expand Up @@ -1792,7 +1958,7 @@ function AddEvent() {
};
setFormValue(obj);
}
if (eventData?.subEventConfiguration) {
if (eventData?.subEventConfiguration && eventData?.subEventConfiguration?.length > 0) {
form.setFieldsValue({
frequency: 'CUSTOM',
startDateRecur: [
Expand Down
20 changes: 20 additions & 0 deletions src/utils/arraysAreEqual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const arraysAreEqual = (arr1, arr2) => {
// Check if both arrays are the same length
if (arr1.length !== arr2.length) {
return false;
}

// Sort both arrays
const sortedArr1 = [...arr1].sort();
const sortedArr2 = [...arr2].sort();

// Compare each element in the sorted arrays
for (let i = 0; i < sortedArr1.length; i++) {
if (sortedArr1[i] !== sortedArr2[i]) {
return false;
}
}

// If no mismatches were found, the arrays are equal
return true;
};
Loading
Loading