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
@@ -57,6 +57,7 @@ const _getEventType = async (id: number) => {
|
||||
seatsPerTimeSlot: true,
|
||||
bookingLimits: true,
|
||||
durationLimits: true,
|
||||
assignAllTeamMembers: true,
|
||||
timeZone: true,
|
||||
length: true,
|
||||
metadata: true,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type z from "zod";
|
||||
|
||||
import { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Team, User } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
@@ -56,6 +57,7 @@ export const createOrUpdateMemberships = async ({
|
||||
},
|
||||
});
|
||||
}
|
||||
await updateNewTeamMemberEventTypes(user.id, team.id);
|
||||
return { membership, orgMembership };
|
||||
});
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export async function joinOrganization({
|
||||
@@ -52,4 +53,6 @@ export async function joinAnyChildTeamOnOrgInvite({ userId, orgId }: { userId: n
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
await updateNewTeamMemberEventTypes(userId, orgId);
|
||||
}
|
||||
@@ -333,6 +333,7 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||
seatsShowAvailabilityCount: true,
|
||||
bookingLimits: true,
|
||||
durationLimits: true,
|
||||
assignAllTeamMembers: true,
|
||||
parentId: true,
|
||||
owner: {
|
||||
select: {
|
||||
|
||||
@@ -112,6 +112,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
},
|
||||
},
|
||||
hidden: true,
|
||||
assignAllTeamMembers: true,
|
||||
});
|
||||
|
||||
export const getPublicEvent = async (
|
||||
@@ -264,6 +265,7 @@ export const getPublicEvent = async (
|
||||
},
|
||||
isDynamic: false,
|
||||
isInstantEvent: event.isInstantEvent,
|
||||
assignAllTeamMembers: event.assignAllTeamMembers,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "assignAllTeamMembers" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -119,6 +119,7 @@ model EventType {
|
||||
/// @zod.custom(imports.intervalLimitsType)
|
||||
durationLimits Json?
|
||||
isInstantEvent Boolean @default(false)
|
||||
assignAllTeamMembers Boolean @default(false)
|
||||
|
||||
@@unique([userId, slug])
|
||||
@@unique([teamId, slug])
|
||||
|
||||
@@ -611,6 +611,7 @@ export const allManagedEventTypeProps: { [k in keyof Omit<Prisma.EventTypeSelect
|
||||
workflows: true,
|
||||
bookingFields: true,
|
||||
durationLimits: true,
|
||||
assignAllTeamMembers: true,
|
||||
};
|
||||
|
||||
// All properties that are defined as unlocked based on all managed props
|
||||
|
||||
@@ -37,6 +37,7 @@ export const EventTypeUpdateInput = _EventTypeModel
|
||||
.optional(),
|
||||
schedule: z.number().nullable().optional(),
|
||||
hashedLink: z.string(),
|
||||
assignAllTeamMembers: z.boolean().optional(),
|
||||
})
|
||||
.partial()
|
||||
.extend({
|
||||
|
||||
@@ -39,6 +39,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
recurringEvent,
|
||||
users,
|
||||
children,
|
||||
assignAllTeamMembers,
|
||||
hosts,
|
||||
id,
|
||||
hashedLink,
|
||||
@@ -65,9 +66,33 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
},
|
||||
team: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
parentId: true,
|
||||
parent: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
members: {
|
||||
select: {
|
||||
role: true,
|
||||
accepted: true,
|
||||
user: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
email: true,
|
||||
eventTypes: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -290,6 +315,8 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
}
|
||||
}
|
||||
|
||||
data.assignAllTeamMembers = assignAllTeamMembers ?? false;
|
||||
|
||||
const updatedEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
slug: true,
|
||||
schedulingType: true,
|
||||
@@ -322,6 +349,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
children,
|
||||
prisma: ctx.prisma,
|
||||
});
|
||||
|
||||
const res = ctx.res as NextApiResponse;
|
||||
if (typeof res?.revalidate !== "undefined") {
|
||||
try {
|
||||
|
||||
@@ -153,6 +153,7 @@ export async function getEventType(
|
||||
afterEventBuffer: true,
|
||||
bookingLimits: true,
|
||||
durationLimits: true,
|
||||
assignAllTeamMembers: true,
|
||||
schedulingType: true,
|
||||
periodType: true,
|
||||
periodStartDate: true,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
||||
import { closeComUpsertTeamUser } from "@calcom/lib/sync/SyncServiceManager";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
@@ -26,6 +27,8 @@ export const acceptOrLeaveHandler = async ({ ctx, input }: AcceptOrLeaveOptions)
|
||||
},
|
||||
});
|
||||
|
||||
await updateNewTeamMemberEventTypes(ctx.user.id, input.teamId);
|
||||
|
||||
closeComUpsertTeamUser(membership.team, ctx.user, membership.role);
|
||||
} else {
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { updateQuantitySubscriptionFromStripe } from "@calcom/features/ee/teams/
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
||||
import { isOrganisationOwner } from "@calcom/lib/server/queries/organisations";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
@@ -131,6 +132,12 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
|
||||
}),
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
autoJoinUsers.map(async (userToAutoJoin) => {
|
||||
await updateNewTeamMemberEventTypes(userToAutoJoin.id, team.id);
|
||||
})
|
||||
);
|
||||
|
||||
await sendTeamInviteEmails({
|
||||
currentUserName: ctx?.user?.name,
|
||||
currentUserTeamName: team?.name,
|
||||
|
||||
Reference in new issue
Block a user