feat: Assign colors to events (#15298)

* feat: Assign colors to events

* update

* final update

* update

* fix requested changes error

* Update EventAdvancedTab.tsx

* add contrast check

* update

* fix contrsterror message visibility

* fix type error

* fix

* update test

---------

Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-08-14 15:10:40 +02:00
1 parent 95e2ad3007
commit 528a4fbb97
23 files changed
+289 -120

No files matched your search

+2 -1
View File
@@ -4,7 +4,7 @@ import { getLocationGroupedOptions } from "@calcom/app-store/server";
import { getEventTypeAppData } from "@calcom/app-store/utils";
import type { LocationObject } from "@calcom/core/location";
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
import { parseBookingLimit, parseDurationLimit, parseRecurringEvent } from "@calcom/lib";
import { parseBookingLimit, parseDurationLimit, parseRecurringEvent, parseEventTypeColor } from "@calcom/lib";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import { getTranslation } from "@calcom/lib/server/i18n";
import { EventTypeRepository } from "@calcom/lib/server/repository/eventType";
@@ -108,6 +108,7 @@ export const getEventTypeById = async ({
recurringEvent: parseRecurringEvent(restEventType.recurringEvent),
bookingLimits: parseBookingLimit(restEventType.bookingLimits),
durationLimits: parseDurationLimit(restEventType.durationLimits),
eventTypeColor: parseEventTypeColor(restEventType.eventTypeColor),
locations: locations as unknown as LocationObject[],
metadata: parsedMetaData,
customInputs: parsedCustomInputs,
+1
View File
@@ -3,6 +3,7 @@ export { default as isPrismaObj, isPrismaObjOrUndefined } from "./isPrismaObj";
export * from "./isRecurringEvent";
export * from "./isBookingLimits";
export * from "./isDurationLimits";
export * from "./isEventTypeColor";
export * from "./validateIntervalLimitOrder";
export * from "./schedules";
export * from "./event-types";
+15
View File
@@ -0,0 +1,15 @@
import type { z } from "zod";
import { eventTypeColor as eventTypeColorSchema } from "@calcom/prisma/zod-utils";
type EventTypeColor = z.infer<typeof eventTypeColorSchema>;
export function isEventTypeColor(obj: unknown): obj is EventTypeColor {
return eventTypeColorSchema.safeParse(obj).success;
}
export function parseEventTypeColor(obj: unknown): EventTypeColor {
let eventTypeColor: EventTypeColor = null;
if (isEventTypeColor(obj)) eventTypeColor = obj;
return eventTypeColor;
}
+1
View File
@@ -51,4 +51,5 @@ export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
secondaryEmailId: true,
bookingLimits: true,
durationLimits: true,
eventTypeColor: true,
});
@@ -346,6 +346,7 @@ export async function updateNewTeamMemberEventTypes(userId: number, teamId: numb
metadata: (managedEventTypeValues.metadata as Prisma.InputJsonValue) ?? undefined,
bookingFields: (managedEventTypeValues.bookingFields as Prisma.InputJsonValue) ?? undefined,
durationLimits: (managedEventTypeValues.durationLimits as Prisma.InputJsonValue) ?? undefined,
eventTypeColor: (managedEventTypeValues.eventTypeColor as Prisma.InputJsonValue) ?? undefined,
onlyShowFirstAvailableSlot: managedEventTypeValues.onlyShowFirstAvailableSlot ?? false,
userId,
users: {
@@ -452,6 +452,7 @@ export class EventTypeRepository {
afterEventBuffer: true,
slotInterval: true,
hashedLink: true,
eventTypeColor: true,
bookingLimits: true,
onlyShowFirstAvailableSlot: true,
durationLimits: true,
+1
View File
@@ -126,6 +126,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
parentId: null,
profileId: null,
secondaryEmailId: null,
eventTypeColor: null,
...eventType,
};
};