Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🚀 Unlock custom branding through white-label add-on (#2109)

Luke Vella0cb7e2dc78e4
diff --git a/apps/web/src/app/[locale]/control-panel/branding/page.tsx b/apps/web/src/app/[locale]/control-panel/branding/page.tsx
index 78d0e1a3a..5d2a889a9 100644
--- a/apps/web/src/app/[locale]/control-panel/branding/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/branding/page.tsx
@@ -1,4 +1,5 @@
import { Alert, AlertDescription } from "@rallly/ui/alert";
+import { Input } from "@rallly/ui/input";
import { Switch } from "@rallly/ui/switch";
import { CodeIcon, GemIcon } from "lucide-react";
import type { Metadata } from "next";
@@ -19,27 +20,26 @@ import {
} from "@/app/components/settings-layout";
import { requireAdmin } from "@/auth/data";
import { Trans } from "@/components/trans";
-import {
- getLogoIconUrl,
- getLogoUrl,
- getPrimaryColor,
- shouldHideAttribution,
-} from "@/features/branding/queries";
+import { getCustomBrandingConfig } from "@/features/branding/queries";
import { loadInstanceLicense } from "@/features/licensing/data";
import { getTranslation } from "@/i18n/server";
async function loadData() {
- const [license] = await Promise.all([loadInstanceLicense(), requireAdmin()]);
- const logoUrls = getLogoUrl();
- const primaryColors = getPrimaryColor();
+ const [license, brandingConfig] = await Promise.all([
+ loadInstanceLicense(),
+ getCustomBrandingConfig(),
+ requireAdmin(),
+ ]);
+
return {
- primaryColorLight: primaryColors.light,
- primaryColorDark: primaryColors.dark,
- logoUrlLight: logoUrls.light,
- logoUrlDark: logoUrls.dark,
- hasWhiteLabelAddon: !!license?.whiteLabelAddon,
- logoIconUrl: getLogoIconUrl(),
- hideAttribution: await shouldHideAttribution(),
+ primaryColorLight: brandingConfig.primaryColor.light,
+ primaryColorDark: brandingConfig.primaryColor.dark,
+ logoUrlLight: brandingConfig.logo.light,
+ logoUrlDark: brandingConfig.logo.dark,
+ hasWhiteLabelAddon: license?.whiteLabelAddon ?? false,
+ logoIconUrl: brandingConfig.logoIcon,
+ hideAttribution: brandingConfig.hideAttribution,
+ appName: brandingConfig.appName,
};
}
@@ -71,6 +71,7 @@ export default async function BrandingPage() {
logoIconUrl,
hasWhiteLabelAddon,
hideAttribution,
+ appName,
} = await loadData();
return (
@@ -101,6 +102,28 @@ export default async function BrandingPage() {
</Alert>
) : null}
<PageSectionGroup>
+ <PageSection variant="card">
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="general" defaults="General" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="brandingDescription"
+ defaults="View your instance branding configuration"
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <div className="space-y-2">
+ <div className="text-muted-foreground text-xs">
+ <Trans i18nKey="name" defaults="App Name" />
+ </div>
+ <Input value={appName} readOnly />
+ <SetEnvironmentVariableAlert variable="APP_NAME" />
+ </div>
+ </PageSectionContent>
+ </PageSection>
<PageSection variant="card">
<PageSectionHeader>
<PageSectionTitle>
diff --git a/apps/web/src/app/[locale]/control-panel/page.tsx b/apps/web/src/app/[locale]/control-panel/page.tsx
index a0678b620..483a9e62e 100644
--- a/apps/web/src/app/[locale]/control-panel/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/page.tsx
@@ -1,4 +1,3 @@
-import { prisma } from "@rallly/database";
import { cn } from "@rallly/ui";
import { Icon } from "@rallly/ui/icon";
import { Tile, TileGrid, TileTitle } from "@rallly/ui/tile";
@@ -20,11 +19,13 @@ import {
} from "@/app/components/settings-layout";
import { requireAdmin } from "@/auth/data";
import { Trans } from "@/components/trans";
+import { DEFAULT_SEAT_LIMIT } from "@/features/licensing/constants";
import { loadInstanceLicense } from "@/features/licensing/data";
+import { getUserCount } from "@/features/user/queries";
async function loadData() {
const [userCount, license] = await Promise.all([
- prisma.user.count(),
+ getUserCount(),
loadInstanceLicense(),
requireAdmin(),
]);
@@ -38,7 +39,7 @@ async function loadData() {
export default async function AdminPage() {
const { userCount, license } = await loadData();
- const userLimit = license?.seats ?? 1;
+ const userLimit = license?.seats ?? DEFAULT_SEAT_LIMIT;
const tier = license?.type;
return (
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsx
index f74b3b087..f855954ad 100644
--- a/apps/web/src/app/[locale]/layout.tsx
+++ b/apps/web/src/app/[locale]/layout.tsx
@@ -12,12 +12,8 @@ import type { Params } from "@/app/[locale]/types";
import { requireUser } from "@/auth/data";
import { UserProvider } from "@/components/user-provider";
import { PreferencesProvider } from "@/contexts/preferences";
-import { env } from "@/env";
import { BrandingProvider } from "@/features/branding/client";
-import {
- getBrandingCssProperties,
- shouldHideAttribution,
-} from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/queries";
import { ThemeProvider } from "@/features/theme/client";
import type { UserDTO } from "@/features/user/schema";
import { I18nProvider } from "@/i18n/client";
@@ -27,6 +23,7 @@ import { featureFlagConfig } from "@/lib/feature-flags/config";
import { LocaleSync } from "@/lib/locale/client";
import { TimezoneProvider } from "@/lib/timezone/client/context";
import { TRPCProvider } from "@/trpc/client/provider";
+import { getForegroundColor } from "@/utils/color";
import { ConnectedDayjsProvider } from "@/utils/dayjs";
import { PostHogPageView } from "../posthog-page-view";
import { PostHogIdentify } from "./posthog-identify";
@@ -43,7 +40,10 @@ export const viewport: Viewport = {
};
async function loadData() {
- const [session] = await Promise.all([getSession()]);
+ const [session, brandingConfig] = await Promise.all([
+ getSession(),
+ getInstanceBrandingConfig(),
+ ]);
const user = session?.user
? !session.user.isGuest
@@ -64,6 +64,7 @@ async function loadData() {
return {
session,
user,
+ brandingConfig,
};
}
@@ -75,12 +76,18 @@ export default async function Root({
params: Promise<Params>;
}) {
const { locale } = await params;
- const { user } = await loadData();
+ const { user, brandingConfig } = await loadData();
- const [brandingStyles, hideAttribution] = await Promise.all([
- getBrandingCssProperties(),
- shouldHideAttribution(),
- ]);
+ const brandingStyles = {
+ "--primary-light": brandingConfig.primaryColor.light,
+ "--primary-light-foreground": getForegroundColor(
+ brandingConfig.primaryColor.light,
+ ),
+ "--primary-dark": brandingConfig.primaryColor.dark,
+ "--primary-dark-foreground": getForegroundColor(
+ brandingConfig.primaryColor.dark,
+ ),
+ } as React.CSSProperties;
return (
<html
@@ -92,7 +99,7 @@ export default async function Root({
<body>
<ThemeProvider>
<FeatureFlagsProvider value={featureFlagConfig}>
- <BrandingProvider value={{ hideAttribution }}>
+ <BrandingProvider value={brandingConfig}>
<Toaster />
<I18nProvider locale={locale}>
<TRPCProvider>
@@ -134,10 +141,12 @@ export default async function Root({
}
export async function generateMetadata(): Promise<Metadata> {
+ const brandingConfig = await getInstanceBrandingConfig();
+
return {
title: {
- template: `%s | ${env.APP_NAME}`,
- default: env.APP_NAME,
+ template: `%s | ${brandingConfig.appName}`,
+ default: brandingConfig.appName,
},
};
}
diff --git a/apps/web/src/components/logo.tsx b/apps/web/src/components/logo.tsx
index 5ee613202..c45fd7e7c 100644
--- a/apps/web/src/components/logo.tsx
+++ b/apps/web/src/components/logo.tsx
@@ -1,6 +1,6 @@
import { cn } from "@rallly/ui";
import { env } from "@/env";
-import { getLogoUrl } from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/queries";
const sizes = {
sm: {
@@ -18,7 +18,7 @@ export const Logo = async ({
className?: string;
size?: keyof typeof sizes;
}) => {
- const { light, dark } = getLogoUrl();
+ const { logo } = await getInstanceBrandingConfig();
return (
<div
@@ -27,7 +27,7 @@ export const Logo = async ({
>
{/* biome-ignore lint/performance/noImgElement: we don't need Image component here */}
<img
- src={light}
+ src={logo.light}
alt={env.APP_NAME}
className="block h-full w-auto object-contain dark:hidden"
style={{
@@ -36,7 +36,7 @@ export const Logo = async ({
/>
{/* biome-ignore lint/performance/noImgElement: we don't need Image component here */}
<img
- src={dark}
+ src={logo.dark}
alt={env.APP_NAME}
className="hidden h-full w-auto object-contain dark:block"
style={{
diff --git a/apps/web/src/features/branding/client.tsx b/apps/web/src/features/branding/client.tsx
index 54ef14a6a..b5f6a2984 100644
--- a/apps/web/src/features/branding/client.tsx
+++ b/apps/web/src/features/branding/client.tsx
@@ -3,7 +3,17 @@
import React from "react";
export interface BrandingConfig {
+ primaryColor: {
+ light: string;
+ dark: string;
+ };
+ logo: {
+ light: string;
+ dark: string;
+ };
+ logoIcon: string;
hideAttribution: boolean;
+ appName: string;
}
const BrandingContext = React.createContext<BrandingConfig | undefined>(
diff --git a/apps/web/src/features/branding/queries.ts b/apps/web/src/features/branding/queries.ts
index f6ea0fd7a..1a00de27e 100644
--- a/apps/web/src/features/branding/queries.ts
+++ b/apps/web/src/features/branding/queries.ts
@@ -1,9 +1,10 @@
import "server-only";
-import type React from "react";
+import { cache } from "react";
import { env } from "@/env";
import { loadInstanceLicense } from "@/features/licensing/data";
-import { adjustColorForContrast, getForegroundColor } from "@/utils/color";
+import { adjustColorForContrast } from "@/utils/color";
+import type { BrandingConfig } from "./client";
import {
DARK_MODE_BACKGROUND,
DEFAULT_APP_NAME,
@@ -14,60 +15,57 @@ import {
LIGHT_MODE_BACKGROUND,
} from "./constants";
-export function getPrimaryColor() {
- const baseColor = env.PRIMARY_COLOR ?? DEFAULT_PRIMARY_COLOR;
+function getDefaultBrandingConfig(): BrandingConfig {
+ const baseColor = DEFAULT_PRIMARY_COLOR;
const light = adjustColorForContrast(baseColor, LIGHT_MODE_BACKGROUND);
- const dark =
- env.PRIMARY_COLOR_DARK ??
- adjustColorForContrast(baseColor, DARK_MODE_BACKGROUND);
+ const dark = adjustColorForContrast(baseColor, DARK_MODE_BACKGROUND);
return {
- light,
- dark,
+ primaryColor: {
+ light,
+ dark,
+ },
+ logo: {
+ light: DEFAULT_LOGO_URL,
+ dark: DEFAULT_LOGO_URL_DARK,
+ },
+ logoIcon: DEFAULT_LOGO_ICON_URL,
+ hideAttribution: false,
+ appName: DEFAULT_APP_NAME,
};
}
-export function getAppName() {
- return env.APP_NAME ?? DEFAULT_APP_NAME;
-}
-
-export async function getBrandingCssProperties() {
- const { light, dark } = getPrimaryColor();
-
- return {
- "--primary-light": light,
- "--primary-light-foreground": getForegroundColor(light),
- "--primary-dark": dark,
- "--primary-dark-foreground": getForegroundColor(dark),
- } as React.CSSProperties;
-}
+export async function getCustomBrandingConfig() {
+ const baseColor = env.PRIMARY_COLOR ?? DEFAULT_PRIMARY_COLOR;
+ const light = adjustColorForContrast(baseColor, LIGHT_MODE_BACKGROUND);
+ const dark =
+ env.PRIMARY_COLOR_DARK ??
+ adjustColorForContrast(baseColor, DARK_MODE_BACKGROUND);
-export function getLogoUrl() {
return {
- light: env.LOGO_URL ?? DEFAULT_LOGO_URL,
- dark: env.LOGO_URL_DARK ?? env.LOGO_URL ?? DEFAULT_LOGO_URL_DARK,
+ primaryColor: {
+ light,
+ dark,
+ },
+ logo: {
+ light: env.LOGO_URL ?? DEFAULT_LOGO_URL,
+ dark: env.LOGO_URL_DARK ?? env.LOGO_URL ?? DEFAULT_LOGO_URL_DARK,
+ },
+ logoIcon: env.LOGO_ICON_URL ?? DEFAULT_LOGO_ICON_URL,
+ hideAttribution: env.HIDE_ATTRIBUTION === "true",
+ appName: env.APP_NAME ?? DEFAULT_APP_NAME,
};
}
-export function getLogoIconUrl() {
- return env.LOGO_ICON_URL ?? DEFAULT_LOGO_ICON_URL;
-}
-
-export function getHideAttribution() {
- // This function is called synchronously in feature flag config,
- // so we need to check the license synchronously
- // The actual license check will be done at runtime when needed
- return env.HIDE_ATTRIBUTION === "true";
-}
-
-export async function shouldHideAttribution() {
+/**
+ * Returns the branding config for the current instance.
+ * Automatically checks if the white label addon is enabled and returns
+ * the appropriate config (custom or default).
+ */
+export const getInstanceBrandingConfig = cache(async () => {
const license = await loadInstanceLicense();
- const hasWhiteLabelAddon = !!license?.whiteLabelAddon;
-
- // Only hide if both the env var is set and the user has white-label add-on
- if (!hasWhiteLabelAddon) {
- return false;
- }
-
- return env.HIDE_ATTRIBUTION === "true";
-}
+ const hasWhiteLabelAddon = license?.whiteLabelAddon ?? false;
+ return hasWhiteLabelAddon
+ ? await getCustomBrandingConfig()
+ : getDefaultBrandingConfig();
+});
diff --git a/apps/web/src/features/licensing/components/license-limit-warning.tsx b/apps/web/src/features/licensing/components/license-limit-warning.tsx
index 5281c95df..9264848d7 100644
--- a/apps/web/src/features/licensing/components/license-limit-warning.tsx
+++ b/apps/web/src/features/licensing/components/license-limit-warning.tsx
@@ -1,11 +1,23 @@
import Link from "next/link";
import { Trans } from "@/components/trans";
-import { didExceedLicenseLimit } from "@/features/licensing/data";
+import { DEFAULT_SEAT_LIMIT } from "@/features/licensing/constants";
+import { loadInstanceLicense } from "@/features/licensing/data";
+import { getUserCount } from "@/features/user/queries";
+import { isSelfHosted } from "@/utils/constants";
export async function LicenseLimitWarning() {
- const exceeded = await didExceedLicenseLimit();
+ if (!isSelfHosted) {
+ return null;
+ }
+
+ const [userCount, license] = await Promise.all([
+ getUserCount(),
+ loadInstanceLicense(),
+ ]);
+
+ const userLimit = license?.seats ?? DEFAULT_SEAT_LIMIT;
- if (!exceeded) {
+ if (userCount <= userLimit) {
return null;
}
diff --git a/apps/web/src/features/licensing/constants.ts b/apps/web/src/features/licensing/constants.ts
index f8fa70cd6..19ef35cee 100644
--- a/apps/web/src/features/licensing/constants.ts
+++ b/apps/web/src/features/licensing/constants.ts
@@ -1 +1,5 @@
export const INSTANCE_LICENSE_TAG = "instance-license";
+/**
+ * Default seat limit for self-hosted instances when no license is present
+ */
+export const DEFAULT_SEAT_LIMIT = 1;
diff --git a/apps/web/src/features/licensing/data.ts b/apps/web/src/features/licensing/data.ts
index 6b9351f37..55a3fc5b4 100644
--- a/apps/web/src/features/licensing/data.ts
+++ b/apps/web/src/features/licensing/data.ts
@@ -1,8 +1,10 @@
import { prisma } from "@rallly/database";
import { unstable_cache } from "next/cache";
import { cache } from "react";
-import { INSTANCE_LICENSE_TAG } from "@/features/licensing/constants";
-import { getUserCount } from "@/features/user/queries";
+import {
+ DEFAULT_SEAT_LIMIT,
+ INSTANCE_LICENSE_TAG,
+} from "@/features/licensing/constants";
import { isSelfHosted } from "@/utils/constants";
export function getInstanceLicense() {
@@ -22,6 +24,10 @@ export const cached_getInstanceLicense = unstable_cache(
);
export const loadInstanceLicense = cache(async () => {
+ if (!isSelfHosted) {
+ return null;
+ }
+
const license = await cached_getInstanceLicense();
if (!license) {
@@ -42,17 +48,21 @@ export const loadInstanceLicense = cache(async () => {
};
});
-export const didExceedLicenseLimit = async () => {
+export const getUserLimit = async () => {
if (!isSelfHosted) {
- return false;
+ return Number.POSITIVE_INFINITY;
}
const license = await loadInstanceLicense();
- const userCount = await getUserCount();
if (!license) {
- return userCount > 1;
+ return DEFAULT_SEAT_LIMIT;
}
- return license.seats < userCount;
+ return license.seats;
+};
+
+export const getWhiteLabelAddon = async () => {
+ const license = await loadInstanceLicense();
+ return license?.whiteLabelAddon ?? false;
};
diff --git a/apps/web/src/utils/emails.ts b/apps/web/src/utils/emails.ts
index 24653665c..d37517b7c 100644
--- a/apps/web/src/utils/emails.ts
+++ b/apps/web/src/utils/emails.ts
@@ -4,14 +4,11 @@ import { absoluteUrl } from "@rallly/utils/absolute-url";
import * as Sentry from "@sentry/nextjs";
import { env } from "@/env";
-import {
- getAppName,
- getLogoIconUrl,
- getPrimaryColor,
- shouldHideAttribution,
-} from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/queries";
export const getEmailClient = async (locale?: string) => {
+ const brandingConfig = await getInstanceBrandingConfig();
+
return new EmailClient({
provider: {
name: (process.env.EMAIL_PROVIDER as SupportedEmailProviders) ?? "smtp",
@@ -23,13 +20,13 @@ export const getEmailClient = async (locale?: string) => {
},
},
config: {
- logoUrl: getLogoIconUrl(),
+ logoUrl: brandingConfig.logoIcon,
baseUrl: absoluteUrl(),
domain: absoluteUrl().replace(/(^\w+:|^)\/\//, ""),
supportEmail: env.SUPPORT_EMAIL,
- primaryColor: getPrimaryColor().light,
- appName: getAppName(),
- hideAttribution: await shouldHideAttribution(),
+ primaryColor: brandingConfig.primaryColor.light,
+ appName: brandingConfig.appName,
+ hideAttribution: brandingConfig.hideAttribution,
},
locale,
onError: (e) => {