From d952e77b7815be6f2690d074908ee66c1da53877 Mon Sep 17 00:00:00 2001
From: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
Date: Wed, 20 Nov 2024 23:24:42 +0530
Subject: [PATCH] feat: Don't remove hosts when disabling 'Add all team
members' (#17747)
* feat: Don't remove hosts when disabling 'Add all team members'
* retain existing host weights and priorities
* fix: merge changes, revert onInactive removal
* lint fix
* fix: weight priority dialog value
---
.../trpc/getAttributesForTeam.handler.ts | 2 +-
.../Booker/components/hooks/useBookings.ts | 2 +-
.../components/AddMembersWithSwitch.tsx | 1 -
.../eventtypes/components/HostEditDialogs.tsx | 38 ++++++++++---------
.../assignment/EventTeamAssignmentTab.tsx | 12 +++---
packages/features/eventtypes/lib/types.ts | 3 +-
packages/lib/server/queries/teams/index.ts | 3 +-
.../viewer/eventTypes/update.handler.ts | 4 +-
8 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/packages/app-store/routing-forms/trpc/getAttributesForTeam.handler.ts b/packages/app-store/routing-forms/trpc/getAttributesForTeam.handler.ts
index 9ebbcaeedf..f6b8e51bd3 100644
--- a/packages/app-store/routing-forms/trpc/getAttributesForTeam.handler.ts
+++ b/packages/app-store/routing-forms/trpc/getAttributesForTeam.handler.ts
@@ -1,9 +1,9 @@
+import { getAttributesForTeam } from "@calcom/lib/raqb/getAttributes";
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
-import { getAttributesForTeam } from "@calcom/lib/raqb/getAttributes";
import type { TGetAttributesForTeamInputSchema } from "./getAttributesForTeam.schema";
type GetAttributesForTeamHandlerOptions = {
diff --git a/packages/features/bookings/Booker/components/hooks/useBookings.ts b/packages/features/bookings/Booker/components/hooks/useBookings.ts
index 208ab06b85..875475a743 100644
--- a/packages/features/bookings/Booker/components/hooks/useBookings.ts
+++ b/packages/features/bookings/Booker/components/hooks/useBookings.ts
@@ -309,7 +309,7 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata, teamMemb
mutationFn: createRecurringBooking,
onSuccess: async (bookings) => {
const booking = bookings[0] || {};
-
+
if (booking.isDryRun) {
showToast(t("booking_dry_run_successful"), "success");
return;
diff --git a/packages/features/eventtypes/components/AddMembersWithSwitch.tsx b/packages/features/eventtypes/components/AddMembersWithSwitch.tsx
index 0272263726..8e68d0c3de 100644
--- a/packages/features/eventtypes/components/AddMembersWithSwitch.tsx
+++ b/packages/features/eventtypes/components/AddMembersWithSwitch.tsx
@@ -250,7 +250,6 @@ function AddMembersWithSwitch({
});
const onAssignAllTeamMembersInactive = () => {
- setValue("hosts", [], { shouldDirty: true });
setAssignRRMembersUsingSegment(false);
};
diff --git a/packages/features/eventtypes/components/HostEditDialogs.tsx b/packages/features/eventtypes/components/HostEditDialogs.tsx
index ebd2729d73..ca2b89b86d 100644
--- a/packages/features/eventtypes/components/HostEditDialogs.tsx
+++ b/packages/features/eventtypes/components/HostEditDialogs.tsx
@@ -76,7 +76,7 @@ export const PriorityDialog = (props: IDialog) => {
-
+ setNewPriority(undefined)} />
@@ -121,25 +121,26 @@ export const WeightDialog = (props: IDialog) => {
const { t } = useLocale();
const { isOpenDialog, setIsOpenDialog, option, onChange } = props;
const { getValues } = useFormContext();
- const [newWeight, setNewWeight] = useState(100);
+ const [newWeight, setNewWeight] = useState();
const setWeight = () => {
- const hosts: Host[] = getValues("hosts");
- const updatedHosts = hosts
- .filter((host) => !host.isFixed)
- .map((host) => {
- return {
- ...option,
- value: host.userId.toString(),
- priority: host.priority,
- weight: host.userId === parseInt(option.value, 10) ? newWeight : host.weight,
- isFixed: false,
- };
- });
+ if (!!newWeight) {
+ const hosts: Host[] = getValues("hosts");
+ const updatedHosts = hosts
+ .filter((host) => !host.isFixed)
+ .map((host) => {
+ return {
+ ...option,
+ value: host.userId.toString(),
+ priority: host.priority,
+ weight: host.userId === parseInt(option.value, 10) ? newWeight : host.weight,
+ isFixed: false,
+ };
+ });
- const sortedHosts = updatedHosts.sort((a, b) => sortHosts(a, b, true));
-
- onChange(sortedHosts);
+ const sortedHosts = updatedHosts.sort((a, b) => sortHosts(a, b, true));
+ onChange(sortedHosts);
+ }
setIsOpenDialog(false);
};
@@ -154,6 +155,7 @@ export const WeightDialog = (props: IDialog) => {
min={0}
label={t("Weight")}
value={newWeight}
+ defaultValue={option.weight ?? 100}
type="number"
onChange={(e) => setNewWeight(parseInt(e.target.value))}
addOnSuffix={<>%>}
@@ -161,7 +163,7 @@ export const WeightDialog = (props: IDialog) => {
-
+ setNewWeight(undefined)} />
diff --git a/packages/features/eventtypes/components/tabs/assignment/EventTeamAssignmentTab.tsx b/packages/features/eventtypes/components/tabs/assignment/EventTeamAssignmentTab.tsx
index c7046d46ba..f0c7c2770a 100644
--- a/packages/features/eventtypes/components/tabs/assignment/EventTeamAssignmentTab.tsx
+++ b/packages/features/eventtypes/components/tabs/assignment/EventTeamAssignmentTab.tsx
@@ -151,8 +151,8 @@ const FixedHosts = ({
return {
isFixed: true,
userId: parseInt(teamMember.value, 10),
- priority: 2,
- weight: 100,
+ priority: host?.priority ?? 2,
+ weight: host?.weight ?? 100,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
@@ -202,8 +202,8 @@ const FixedHosts = ({
return {
isFixed: true,
userId: parseInt(teamMember.value, 10),
- priority: 2,
- weight: 100,
+ priority: host?.priority ?? 2,
+ weight: host?.weight ?? 100,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
@@ -292,8 +292,8 @@ const RoundRobinHosts = ({
return {
isFixed: false,
userId: parseInt(teamMember.value, 10),
- priority: 2,
- weight: 100,
+ priority: host?.priority ?? 2,
+ weight: host?.weight ?? 100,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
diff --git a/packages/features/eventtypes/lib/types.ts b/packages/features/eventtypes/lib/types.ts
index 604796ae9e..3d0390b5b5 100644
--- a/packages/features/eventtypes/lib/types.ts
+++ b/packages/features/eventtypes/lib/types.ts
@@ -2,6 +2,7 @@ import type { z } from "zod";
import type { EventLocationType } from "@calcom/core/location";
import type { ChildrenEventType } from "@calcom/features/eventtypes/components/ChildrenEventTypeSelect";
+import type { AttributesQueryValue } from "@calcom/lib/raqb/types";
import type { EventTypeTranslation } from "@calcom/prisma/client";
import type { PeriodType, SchedulingType } from "@calcom/prisma/enums";
import type { BookerLayoutSettings, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
@@ -10,7 +11,7 @@ import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
import type { eventTypeColor } from "@calcom/prisma/zod-utils";
import type { RouterOutputs, RouterInputs } from "@calcom/trpc/react";
import type { IntervalLimit, RecurringEvent } from "@calcom/types/Calendar";
-import type { AttributesQueryValue } from "@calcom/lib/raqb/types";
+
export type CustomInputParsed = typeof customInputSchema._output;
export type AvailabilityOption = {
diff --git a/packages/lib/server/queries/teams/index.ts b/packages/lib/server/queries/teams/index.ts
index 3246d17224..a615eb6656 100644
--- a/packages/lib/server/queries/teams/index.ts
+++ b/packages/lib/server/queries/teams/index.ts
@@ -452,8 +452,7 @@ export async function updateNewTeamMemberEventTypes(userId: number, teamId: numb
durationLimits: (managedEventTypeValues.durationLimits as Prisma.InputJsonValue) ?? undefined,
eventTypeColor: (managedEventTypeValues.eventTypeColor as Prisma.InputJsonValue) ?? undefined,
rrSegmentQueryValue:
- (managedEventTypeValues.rrSegmentQueryValue as Prisma.InputJsonValue) ??
- undefined,
+ (managedEventTypeValues.rrSegmentQueryValue as Prisma.InputJsonValue) ?? undefined,
onlyShowFirstAvailableSlot: managedEventTypeValues.onlyShowFirstAvailableSlot ?? false,
userId,
users: {
diff --git a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
index 954be95e80..819ac79b75 100644
--- a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
+++ b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
@@ -160,9 +160,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
bookingFields,
isRRWeightsEnabled,
rrSegmentQueryValue:
- rest.rrSegmentQueryValue === null
- ? Prisma.DbNull
- : (rest.rrSegmentQueryValue as Prisma.InputJsonValue),
+ rest.rrSegmentQueryValue === null ? Prisma.DbNull : (rest.rrSegmentQueryValue as Prisma.InputJsonValue),
metadata: rest.metadata === null ? Prisma.DbNull : (rest.metadata as Prisma.InputJsonObject),
eventTypeColor: eventTypeColor === null ? Prisma.DbNull : (eventTypeColor as Prisma.InputJsonObject),
};