fix: (managed-event-booking): slug conflict handling (#16540)

* fix(managed-event-booking): slug conflict handling

* refactor logic

---------

Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
This commit is contained in:
Abhijeet Singh
2024-09-12 10:05:05 -04:00
committed by GitHub
co-authored by Amit Sharma
parent f11086e9f8
commit 8ce018995a
2 changed files with 12 additions and 2 deletions
@@ -504,7 +504,7 @@ export const EventType = (props: EventTypeSetupProps & { allActiveWorkflows?: Wo
length,
...input
} = dirtyValues;
if (!Number(length)) throw new Error(t("event_setup_length_error"));
if (length && !Number(length)) throw new Error(t("event_setup_length_error"));
if (bookingLimits) {
const isValid = validateIntervalLimitOrder(bookingLimits);
@@ -633,6 +633,11 @@ export const EventType = (props: EventTypeSetupProps & { allActiveWorkflows?: Wo
id="event-type-form"
handleSubmit={async (values) => {
const { children } = values;
const conflicts = children.filter((child) => child.owner.eventTypeSlugs.includes(values.slug));
if (conflicts.length > 0) {
setSlugExistsChildrenDialogOpen(conflicts);
return;
}
const dirtyValues = getDirtyFields(values);
const dirtyFieldExists = Object.keys(dirtyValues).length !== 0;
const {
@@ -422,7 +422,12 @@ export const EventTeamAssignmentTab = ({
.map((member) => mapUserToValue(member, t("pending")));
const childrenEventTypeOptions = teamMembers.filter(pendingMembers).map((member) => {
return mapMemberToChildrenOption(
{ ...member, eventTypes: member.eventTypes.filter((et) => et !== eventType.slug) },
{
...member,
eventTypes: member.eventTypes.filter(
(et) => et !== eventType.slug || !eventType.children.some((c) => c.owner.id === member.id)
),
},
eventType.slug,
t("pending")
);