fix: Use constants.ts for brand colours > db DEFAULT (#13167)

* fix: user proper default values if no brand colour is set.

* fix:default value

* fix: more ?? to defined default as color is possibly null
This commit is contained in:
sean-brydon authored and GitHub committed 2024-01-11 20:22:35 +00:00
1 parent 9901c91e9b
commit bc6267e99b
9 files changed
+50 -22

No files matched your search

+3 -2
View File
@@ -10,6 +10,7 @@ import dayjs from "@calcom/dayjs";
import { useEmbedType, useEmbedUiConfig, useIsEmbed } from "@calcom/embed-core/embed-iframe";
import { useNonEmptyScheduleDays } from "@calcom/features/schedules";
import classNames from "@calcom/lib/classNames";
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import { BookerLayouts, defaultBookerLayoutSettings } from "@calcom/prisma/zod-utils";
@@ -144,8 +145,8 @@ const BookerComponent = ({
: bookerLayouts.defaultLayout;
useBrandColors({
brandColor: event.data?.profile.brandColor,
darkBrandColor: event.data?.profile.darkBrandColor,
brandColor: event.data?.profile.brandColor ?? DEFAULT_LIGHT_BRAND_COLOR,
darkBrandColor: event.data?.profile.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR,
theme: event.data?.profile.theme,
});
@@ -26,7 +26,6 @@ const BrandColorsForm = ({
const brandColorsFormMethods = useFormContext();
const {
formState: { isSubmitting: isBrandColorsFormSubmitting, isDirty: isBrandColorsFormDirty },
handleSubmit,
} = brandColorsFormMethods;
const [isCustomBrandColorChecked, setIsCustomBrandColorChecked] = useState(
@@ -180,8 +180,8 @@ const OrgAppearanceView = ({
}}>
<BrandColorsForm
onSubmit={onBrandColorsFormSubmit}
brandColor={currentOrg?.brandColor}
darkBrandColor={currentOrg?.darkBrandColor}
brandColor={currentOrg?.brandColor ?? DEFAULT_LIGHT_BRAND_COLOR}
darkBrandColor={currentOrg?.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR}
/>
</Form>
@@ -61,7 +61,10 @@ const ProfileView = ({ team }: ProfileViewProps) => {
await utils.viewer.teams.get.invalidate();
if (res) {
resetTheme({ theme: res.theme });
resetBrandColors({ brandColor: res.brandColor, darkBrandColor: res.darkBrandColor });
resetBrandColors({
brandColor: res.brandColor ?? DEFAULT_LIGHT_BRAND_COLOR,
darkBrandColor: res.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR,
});
}
showToast(t("your_team_updated_successfully"), "success");
@@ -139,8 +142,8 @@ const ProfileView = ({ team }: ProfileViewProps) => {
}}>
<BrandColorsForm
onSubmit={onBrandColorsFormSubmit}
brandColor={team?.brandColor}
darkBrandColor={team?.darkBrandColor}
brandColor={team?.brandColor ?? DEFAULT_LIGHT_BRAND_COLOR}
darkBrandColor={team?.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR}
/>
</Form>
+4 -2
View File
@@ -1,7 +1,9 @@
import { useBrandColors } from "@calcom/embed-core/embed-iframe";
const BRAND_COLOR = "#292929";
const DARK_BRAND_COLOR = "#fafafa";
import { DEFAULT_DARK_BRAND_COLOR, DEFAULT_LIGHT_BRAND_COLOR } from "./constants";
const BRAND_COLOR = DEFAULT_LIGHT_BRAND_COLOR;
const DARK_BRAND_COLOR = DEFAULT_DARK_BRAND_COLOR;
type Rgb = {
r: number;
@@ -0,0 +1,17 @@
ALTER TABLE "Team" ALTER COLUMN "brandColor" DROP NOT NULL,
ALTER COLUMN "brandColor" DROP DEFAULT,
ALTER COLUMN "darkBrandColor" DROP NOT NULL,
ALTER COLUMN "darkBrandColor" DROP DEFAULT;
-- AlterTable
ALTER TABLE "users" ALTER COLUMN "brandColor" DROP NOT NULL,
ALTER COLUMN "brandColor" DROP DEFAULT,
ALTER COLUMN "darkBrandColor" DROP NOT NULL,
ALTER COLUMN "darkBrandColor" DROP DEFAULT;
UPDATE "Team" SET "brandColor" = NULL WHERE "brandColor" = '#292929';
UPDATE "Team" SET "darkBrandColor" = NULL WHERE "darkBrandColor" = '#fafafa';
UPDATE "users" SET "brandColor" = NULL WHERE "brandColor" = '#292929';
UPDATE "users" SET "darkBrandColor" = NULL WHERE "darkBrandColor" = '#fafafa';
+4 -4
View File
@@ -224,8 +224,8 @@ model User {
availability Availability[]
invitedTo Int?
webhooks Webhook[]
brandColor String @default("#292929")
darkBrandColor String @default("#fafafa")
brandColor String?
darkBrandColor String?
// the location where the events will end up
destinationCalendar DestinationCalendar?
away Boolean @default(false)
@@ -299,8 +299,8 @@ model Team {
/// @zod.custom(imports.teamMetadataSchema)
metadata Json?
theme String?
brandColor String @default("#292929")
darkBrandColor String @default("#fafafa")
brandColor String?
darkBrandColor String?
verifiedNumbers VerifiedNumber[]
parentId Int?
parent Team? @relation("organization", fields: [parentId], references: [id], onDelete: Cascade)