feat: add assigned badge to team event types (#27036)
* feat: add assigned badge to team event types Add an 'Assigned' badge to Round Robin and Collective event types when the current user is a host/participant of the event type. This provides visibility to users without edit permissions that they are included in the rotation. Changes: - Add isCurrentUserHost flag in getEventTypesFromGroup handler - Display blue 'Assigned' badge in event types listing view - Add i18n translation for 'assigned' text Co-Authored-By: [email protected] <[email protected]> * refactor: remove redundant isTeamEvent check for assigned badge Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
This commit is contained in:
1 parent
3b8b2299af
commit
2a98693dcd
3 files changed
+168
-321
No files matched your search
@@ -2,10 +2,9 @@ import { EventTypeRepository } from "@calcom/features/eventtypes/repositories/ev
|
||||
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../types";
|
||||
import type { TGetEventTypesFromGroupSchema } from "./getByViewer.schema";
|
||||
import { mapEventType } from "./util";
|
||||
@@ -22,12 +21,13 @@ type GetByViewerOptions = {
|
||||
|
||||
type EventType = Awaited<ReturnType<EventTypeRepository["findAllByUpId"]>>[number];
|
||||
type MappedEventType = Awaited<ReturnType<typeof mapEventType>>;
|
||||
type MappedEventTypeWithHostFlag = MappedEventType & { isCurrentUserHost: boolean };
|
||||
|
||||
export const getEventTypesFromGroup = async ({
|
||||
ctx,
|
||||
input,
|
||||
}: GetByViewerOptions): Promise<{
|
||||
eventTypes: MappedEventType[];
|
||||
eventTypes: MappedEventTypeWithHostFlag[];
|
||||
nextCursor: number | null | undefined;
|
||||
}> => {
|
||||
await checkRateLimitAndThrowError({
|
||||
@@ -144,7 +144,7 @@ export const getEventTypesFromGroup = async ({
|
||||
eventTypes.push(...teamEventTypes);
|
||||
}
|
||||
|
||||
let nextCursor: number | null | undefined = undefined;
|
||||
let nextCursor: number | null | undefined;
|
||||
if (eventTypes.length > limit) {
|
||||
const nextItem = eventTypes.pop();
|
||||
nextCursor = nextItem?.id;
|
||||
@@ -152,6 +152,12 @@ export const getEventTypesFromGroup = async ({
|
||||
|
||||
const mappedEventTypes: MappedEventType[] = await Promise.all(eventTypes.map(mapEventType));
|
||||
|
||||
// Add isCurrentUserHost flag to each event type
|
||||
const eventTypesWithHostFlag = mappedEventTypes.map((eventType) => ({
|
||||
...eventType,
|
||||
isCurrentUserHost: eventType.hosts?.some((host) => host.user.id === ctx.user.id) ?? false,
|
||||
}));
|
||||
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
@@ -169,11 +175,11 @@ export const getEventTypesFromGroup = async ({
|
||||
});
|
||||
|
||||
if (membership && membership.team.isPrivate)
|
||||
mappedEventTypes.forEach((evType) => {
|
||||
eventTypesWithHostFlag.forEach((evType) => {
|
||||
evType.users = [];
|
||||
evType.hosts = [];
|
||||
evType.children = [];
|
||||
});
|
||||
|
||||
return { eventTypes: mappedEventTypes, nextCursor: nextCursor ?? undefined };
|
||||
return { eventTypes: eventTypesWithHostFlag, nextCursor: nextCursor ?? undefined };
|
||||
};
|
||||
Reference in new issue
Block a user