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

@@ -66,12 +66,11 @@ const BrandColorsForm = ({
defaultValue={brandColor || DEFAULT_LIGHT_BRAND_COLOR}
resetDefaultValue={DEFAULT_LIGHT_BRAND_COLOR}
onChange={(value) => {
try {
checkWCAGContrastColor("#ffffff", value);
if (checkWCAGContrastColor("#ffffff", value)) {
setLightModeError(false);
brandColorsFormMethods.setValue("brandColor", value, { shouldDirty: true });
} catch (err) {
setLightModeError(false);
} else {
setLightModeError(true);
}
}}
/>
@@ -95,11 +94,10 @@ const BrandColorsForm = ({
defaultValue={darkBrandColor || DEFAULT_DARK_BRAND_COLOR}
resetDefaultValue={DEFAULT_DARK_BRAND_COLOR}
onChange={(value) => {
try {
checkWCAGContrastColor("#101010", value);
if (checkWCAGContrastColor("#101010", value)) {
setDarkModeError(false);
brandColorsFormMethods.setValue("darkBrandColor", value, { shouldDirty: true });
} catch (err) {
} else {
setDarkModeError(true);
}
}}
@@ -185,6 +185,7 @@ export default async function handleChildrenEventTypes({
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: {
@@ -6,6 +6,7 @@ import type { PeriodType, SchedulingType } from "@calcom/prisma/enums";
import type { BookerLayoutSettings, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { customInputSchema } from "@calcom/prisma/zod-utils";
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
import type { eventTypeColor } from "@calcom/prisma/zod-utils";
import type { RouterOutputs } from "@calcom/trpc/react";
import type { IntervalLimit, RecurringEvent } from "@calcom/types/Calendar";
@@ -47,6 +48,7 @@ export type FormValues = {
hidden: boolean;
hideCalendarNotes: boolean;
hashedLink: string | undefined;
eventTypeColor: z.infer<typeof eventTypeColor>;
locations: {
type: EventLocationType["type"];
address?: string;
+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,
};
};
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "EventType" ADD COLUMN "eventTypeColor" JSONB;
+2
View File
@@ -137,6 +137,8 @@ model EventType {
assignAllTeamMembers Boolean @default(false)
useEventTypeDestinationCalendarEmail Boolean @default(false)
aiPhoneCallConfig AIPhoneCallConfiguration?
/// @zod.custom(imports.eventTypeColor)
eventTypeColor Json?
rescheduleWithSameRoundRobinHost Boolean @default(false)
secondaryEmailId Int?
+8
View File
@@ -187,6 +187,13 @@ export const iso8601 = z.string().transform((val, ctx) => {
return d;
});
export const eventTypeColor = z
.object({
lightEventTypeColor: z.string(),
darkEventTypeColor: z.string(),
})
.nullable();
export const intervalLimitsType = z
.object({
PER_DAY: z.number().optional(),
@@ -663,6 +670,7 @@ export const allManagedEventTypeProps: { [k in keyof Omit<Prisma.EventTypeSelect
lockTimeZoneToggleOnBookingPage: true,
requiresBookerEmailVerification: true,
assignAllTeamMembers: true,
eventTypeColor: true,
rescheduleWithSameRoundRobinHost: true,
};
@@ -1,4 +1,4 @@
import { parseRecurringEvent } from "@calcom/lib";
import { parseRecurringEvent, parseEventTypeColor } from "@calcom/lib";
import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings";
import type { PrismaClient } from "@calcom/prisma";
import { bookingMinimalSelect } from "@calcom/prisma";
@@ -179,6 +179,7 @@ export async function getBookings({
metadata: true,
seatsShowAttendees: true,
seatsShowAvailabilityCount: true,
eventTypeColor: true,
schedulingType: true,
team: {
select: {
@@ -409,6 +410,7 @@ export async function getBookings({
eventType: {
...booking.eventType,
recurringEvent: parseRecurringEvent(booking.eventType?.recurringEvent),
eventTypeColor: parseEventTypeColor(booking.eventType?.eventTypeColor),
price: booking.eventType?.price || 0,
currency: booking.eventType?.currency || "usd",
metadata: EventTypeMetaDataSchema.parse(booking.eventType?.metadata || {}),
@@ -75,6 +75,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
recurringEvent,
bookingLimits,
durationLimits,
eventTypeColor,
metadata,
workflows,
hashedLink,
@@ -112,6 +113,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
recurringEvent: recurringEvent || undefined,
bookingLimits: bookingLimits ?? undefined,
durationLimits: durationLimits ?? undefined,
eventTypeColor: eventTypeColor ?? undefined,
metadata: metadata === null ? Prisma.DbNull : metadata,
bookingFields: eventType.bookingFields === null ? Prisma.DbNull : eventType.bookingFields,
};
@@ -53,6 +53,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
destinationCalendar,
customInputs,
recurringEvent,
eventTypeColor,
users,
children,
assignAllTeamMembers,
@@ -137,6 +138,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
...rest,
bookingFields,
metadata: rest.metadata === null ? Prisma.DbNull : (rest.metadata as Prisma.InputJsonObject),
eventTypeColor: eventTypeColor === null ? Prisma.DbNull : (eventTypeColor as Prisma.InputJsonObject),
};
data.locations = locations ?? undefined;
if (periodType) {