feat: added ability to assign event to all members (#13219)
* feat: added ability to assign event to all members * fix: types * chore: incorporate assignment for collective and round robin event sas well * fix: update event types query * feat: round robin hosts * fix: update * fix: update * fix: assignAllTeamMembers issue * design fixes --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
21 files changed
+321
-47
No files matched your search
@@ -101,6 +101,7 @@ const commons = {
|
||||
hosts: [],
|
||||
metadata: EventTypeMetaDataSchema.parse({}),
|
||||
bookingFields: [],
|
||||
assignAllTeamMembers: false,
|
||||
};
|
||||
|
||||
const dynamicEvent = {
|
||||
|
||||
@@ -105,6 +105,7 @@ export default async function getEventTypeById({
|
||||
bookingLimits: true,
|
||||
onlyShowFirstAvailableSlot: true,
|
||||
durationLimits: true,
|
||||
assignAllTeamMembers: true,
|
||||
successRedirectUrl: true,
|
||||
currency: true,
|
||||
bookingFields: true,
|
||||
|
||||
@@ -3,7 +3,12 @@ import { Prisma } from "@prisma/client";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { _EventTypeModel } from "@calcom/prisma/zod";
|
||||
import {
|
||||
EventTypeMetaDataSchema,
|
||||
allManagedEventTypeProps,
|
||||
unlockedManagedEventTypeProps,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { WEBAPP_URL } from "../../../constants";
|
||||
import { getBookerBaseUrlSync } from "../../../getBookerUrl/client";
|
||||
@@ -247,3 +252,67 @@ export async function isTeamMember(userId: number, teamId: number) {
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
export async function updateNewTeamMemberEventTypes(userId: number, teamId: number) {
|
||||
const eventTypesToAdd = await prisma.eventType.findMany({
|
||||
where: {
|
||||
team: { id: teamId },
|
||||
assignAllTeamMembers: true,
|
||||
},
|
||||
select: {
|
||||
...allManagedEventTypeProps,
|
||||
id: true,
|
||||
schedulingType: true,
|
||||
},
|
||||
});
|
||||
|
||||
const allManagedEventTypePropsZod = _EventTypeModel.pick(allManagedEventTypeProps);
|
||||
|
||||
eventTypesToAdd.length > 0 &&
|
||||
(await prisma.$transaction(
|
||||
eventTypesToAdd.map((eventType) => {
|
||||
if (eventType.schedulingType === "MANAGED") {
|
||||
const managedEventTypeValues = allManagedEventTypePropsZod
|
||||
.omit(unlockedManagedEventTypeProps)
|
||||
.parse(eventType);
|
||||
|
||||
// Define the values for unlocked properties to use on creation, not updation
|
||||
const unlockedEventTypeValues = allManagedEventTypePropsZod
|
||||
.pick(unlockedManagedEventTypeProps)
|
||||
.parse(eventType);
|
||||
|
||||
// Calculate if there are new workflows for which assigned members will get too
|
||||
const currentWorkflowIds = eventType.workflows?.map((wf) => wf.workflowId);
|
||||
|
||||
return prisma.eventType.create({
|
||||
data: {
|
||||
...managedEventTypeValues,
|
||||
...unlockedEventTypeValues,
|
||||
bookingLimits:
|
||||
(managedEventTypeValues.bookingLimits as unknown as Prisma.InputJsonObject) ?? undefined,
|
||||
recurringEvent:
|
||||
(managedEventTypeValues.recurringEvent as unknown as Prisma.InputJsonValue) ?? undefined,
|
||||
metadata: (managedEventTypeValues.metadata as Prisma.InputJsonValue) ?? undefined,
|
||||
bookingFields: (managedEventTypeValues.bookingFields as Prisma.InputJsonValue) ?? undefined,
|
||||
durationLimits: (managedEventTypeValues.durationLimits as Prisma.InputJsonValue) ?? undefined,
|
||||
onlyShowFirstAvailableSlot: managedEventTypeValues.onlyShowFirstAvailableSlot ?? false,
|
||||
userId,
|
||||
users: {
|
||||
connect: [{ id: userId }],
|
||||
},
|
||||
parentId: eventType.parentId,
|
||||
hidden: false,
|
||||
workflows: currentWorkflowIds && {
|
||||
create: currentWorkflowIds.map((wfId) => ({ workflowId: wfId })),
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return prisma.eventType.update({
|
||||
where: { id: eventType.id },
|
||||
data: { hosts: { create: [{ userId, isFixed: eventType.schedulingType === "COLLECTIVE" }] } },
|
||||
});
|
||||
}
|
||||
})
|
||||
));
|
||||
}
|
||||
@@ -105,6 +105,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
|
||||
scheduleId: null,
|
||||
bookingLimits: null,
|
||||
durationLimits: null,
|
||||
assignAllTeamMembers: false,
|
||||
price: 0,
|
||||
currency: "usd",
|
||||
slotInterval: null,
|
||||
|
||||
Reference in new issue
Block a user