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
This commit is contained in:
Amit Sharma authored and GitHub committed 2024-11-20 17:54:42 +00:00
1 parent 73989da3b7
commit d952e77b78
8 files changed
+32 -33

No files matched your search

@@ -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 = {
@@ -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;
@@ -250,7 +250,6 @@ function AddMembersWithSwitch({
});
const onAssignAllTeamMembersInactive = () => {
setValue("hosts", [], { shouldDirty: true });
setAssignRRMembersUsingSegment(false);
};
@@ -76,7 +76,7 @@ export const PriorityDialog = (props: IDialog) => {
</div>
<DialogFooter>
<DialogClose />
<DialogClose onClick={() => setNewPriority(undefined)} />
<Button onClick={setPriority}>{t("confirm")}</Button>
</DialogFooter>
</DialogContent>
@@ -121,25 +121,26 @@ export const WeightDialog = (props: IDialog) => {
const { t } = useLocale();
const { isOpenDialog, setIsOpenDialog, option, onChange } = props;
const { getValues } = useFormContext<FormValues>();
const [newWeight, setNewWeight] = useState<number>(100);
const [newWeight, setNewWeight] = useState<number | undefined>();
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) => {
</div>
</div>
<DialogFooter>
<DialogClose />
<DialogClose onClick={() => setNewWeight(undefined)} />
<Button onClick={setWeight}>{t("confirm")}</Button>
</DialogFooter>
</DialogContent>
@@ -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,
};
+2 -1
View File
@@ -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 = {
+1 -2
View File
@@ -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: {
@@ -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),
};