Scheduling infrastructure for absolutely everyone.
fix: show bookings-v3 only in the settings but not in the banner (#27330)
Eunjae Leeea15474edf67
diff --git a/apps/web/modules/feature-opt-in/hooks/useFeatureOptInBanner.ts b/apps/web/modules/feature-opt-in/hooks/useFeatureOptInBanner.tsindex 484eef4853f..1e9050bed2c 100644--- a/apps/web/modules/feature-opt-in/hooks/useFeatureOptInBanner.ts+++ b/apps/web/modules/feature-opt-in/hooks/useFeatureOptInBanner.ts@@ -1,7 +1,7 @@"use client";import type { OptInFeatureConfig } from "@calcom/features/feature-opt-in/config";-import { getOptInFeatureConfig } from "@calcom/features/feature-opt-in/config";+import { getOptInFeatureConfig, shouldDisplayFeatureAt } from "@calcom/features/feature-opt-in/config";import { trpc } from "@calcom/trpc/react";import { useCallback, useMemo, useState } from "react";@@ -122,6 +122,8 @@ function useFeatureOptInBanner(featureId: string): UseFeatureOptInBannerResult {if (isDismissed) return false;if (isOptedIn) return false;if (!featureConfig) return false;+ // Only show banner if the feature is configured to be displayed as a banner+ if (!shouldDisplayFeatureAt(featureConfig, "banner")) return false;if (eligibilityQuery.isLoading) return false;if (!eligibilityQuery.data) return false;return eligibilityQuery.data.status === "can_opt_in";diff --git a/apps/web/playwright/feature-opt-in-banner.e2e.ts b/apps/web/playwright/feature-opt-in-banner.e2e.tsindex 624b405c296..ec0c27be14f 100644--- a/apps/web/playwright/feature-opt-in-banner.e2e.ts+++ b/apps/web/playwright/feature-opt-in-banner.e2e.ts@@ -1,4 +1,4 @@-import { OPT_IN_FEATURES } from "@calcom/features/feature-opt-in/config";+import { getOptInFeatureConfig, shouldDisplayFeatureAt } from "@calcom/features/feature-opt-in/config";import { expect } from "@playwright/test";import { test } from "./lib/fixtures";@@ -10,7 +10,8 @@ test.describe("Feature Opt-In Banner", () => {users,prisma,}) => {- if (!OPT_IN_FEATURES.some((item) => item.slug === "bookings-v3")) {+ const featureConfig = getOptInFeatureConfig("bookings-v3");+ if (!featureConfig || !shouldDisplayFeatureAt(featureConfig, "banner")) {return;}diff --git a/packages/features/feature-opt-in/config.ts b/packages/features/feature-opt-in/config.tsindex 170841cb1f5..73429af75fa 100644--- a/packages/features/feature-opt-in/config.ts+++ b/packages/features/feature-opt-in/config.ts@@ -1,6 +1,10 @@import type { FeatureId } from "@calcom/features/flags/config";import type { OptInFeaturePolicy, OptInFeatureScope } from "./types";+export type OptInFeatureDisplayLocation = "settings" | "banner";++const DEFAULT_DISPLAY_LOCATIONS: OptInFeatureDisplayLocation[] = ["settings"];+export interface OptInFeatureConfig {slug: FeatureId;i18n: {@@ -16,32 +20,39 @@ export interface OptInFeatureConfig {policy: OptInFeaturePolicy;/** Scopes where this feature can be configured. Defaults to all scopes if not specified. */scope?: OptInFeatureScope[];+ /**+ * Where this feature should be displayed for opt-in.+ * - 'settings': Show in the Settings page+ * - 'banner': Show as a banner notification+ *+ * Defaults to ['settings'] if omitted.+ * Use ['settings', 'banner'] for both locations.+ * Use [] if you want the feature defined but not displayed anywhere.+ */+ displayLocations?: OptInFeatureDisplayLocation[];}-/** All available scopes for feature opt-in configuration */-export const ALL_SCOPES: OptInFeatureScope[] = ["org", "team", "user"];-/*** Features that appear in opt-in settings.* Add new features here to make them available for user/team opt-in.*/export const OPT_IN_FEATURES: OptInFeatureConfig[] = [- // Example - to be populated with actual features- // {- // slug: "bookings-v3",- // i18n: {- // title: "bookings_v3_title",- // name: "bookings_v3_name",- // description: "bookings_v3_description",- // },- // bannerImage: {- // src: "/opt_in_banner_bookings_v3.png",- // width: 548,- // height: 348,- // },- // policy: "permissive",- // scope: ["org", "team", "user"], // Optional: defaults to all scopes if not specified- // },+ {+ slug: "bookings-v3",+ i18n: {+ title: "bookings_v3_title",+ name: "bookings_v3_name",+ description: "bookings_v3_description",+ },+ bannerImage: {+ src: "/opt_in_banner_bookings_v3.png",+ width: 548,+ height: 348,+ },+ policy: "permissive",+ displayLocations: ["settings"],+ scope: ["org", "team", "user"], // Optional: defaults to all scopes if not specified+ },];/**@@ -60,31 +71,51 @@ export function isOptInFeature(slug: string): slug is FeatureId {}/**- * Check if there are any opt-in features available.+ * Check if a feature should be displayed at a specific location.+ * Defaults to 'settings' if displayLocations is not specified.*/-export const HAS_OPT_IN_FEATURES: boolean = OPT_IN_FEATURES.length > 0;+export function shouldDisplayFeatureAt(+ feature: OptInFeatureConfig,+ location: OptInFeatureDisplayLocation+): boolean {+ return (feature.displayLocations ?? DEFAULT_DISPLAY_LOCATIONS).includes(location);+}-/** Whether there are opt-in features available for the user scope */-export const HAS_USER_OPT_IN_FEATURES: boolean = OPT_IN_FEATURES.some(- (f) => !f.scope || f.scope.includes("user")-);+/**+ * Whether there are opt-in features available for the user scope in settings.+ * Only counts features that should be displayed in settings (displayLocations includes 'settings' or is omitted).+ */+export const HAS_USER_OPT_IN_FEATURES: boolean = getOptInFeaturesForScope("user", "settings").length > 0;-/** Whether there are opt-in features available for the team scope */-export const HAS_TEAM_OPT_IN_FEATURES: boolean = OPT_IN_FEATURES.some(- (f) => !f.scope || f.scope.includes("team")-);+/**+ * Whether there are opt-in features available for the team scope in settings.+ * Only counts features that should be displayed in settings (displayLocations includes 'settings' or is omitted).+ */+export const HAS_TEAM_OPT_IN_FEATURES: boolean = getOptInFeaturesForScope("team", "settings").length > 0;-/** Whether there are opt-in features available for the org scope */-export const HAS_ORG_OPT_IN_FEATURES: boolean = OPT_IN_FEATURES.some(- (f) => !f.scope || f.scope.includes("org")-);+/**+ * Whether there are opt-in features available for the org scope in settings.+ * Only counts features that should be displayed in settings (displayLocations includes 'settings' or is omitted).+ */+export const HAS_ORG_OPT_IN_FEATURES: boolean = getOptInFeaturesForScope("org", "settings").length > 0;/*** Get opt-in features that are available for a specific scope.* Features without a scope field are available for all scopes.+ * Optionally filter by display location (e.g., 'settings' or 'banner').*/-export function getOptInFeaturesForScope(scope: OptInFeatureScope): OptInFeatureConfig[] {- return OPT_IN_FEATURES.filter((f) => !f.scope || f.scope.includes(scope));+export function getOptInFeaturesForScope(+ scope: OptInFeatureScope,+ displayLocation?: OptInFeatureDisplayLocation+): OptInFeatureConfig[] {+ return OPT_IN_FEATURES.filter((f) => {+ const scopeMatches = !f.scope || f.scope.includes(scope);+ if (!scopeMatches) return false;+ if (displayLocation) {+ return shouldDisplayFeatureAt(f, displayLocation);+ }+ return true;+ });}/**diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.test.ts b/packages/features/feature-opt-in/services/FeatureOptInService.test.tsindex 4ae35abfb99..cd41c7239ed 100644--- a/packages/features/feature-opt-in/services/FeatureOptInService.test.ts+++ b/packages/features/feature-opt-in/services/FeatureOptInService.test.ts@@ -15,41 +15,41 @@ const mockFindAllByUserId: Mock = vi.fn();// Mock the OPT_IN_FEATURES configvi.mock("../config", () => {- const mockFeatures = [- {- slug: "test-feature-1",- i18n: { title: "test_feature_1_title", name: "test_feature_1", description: "test_feature_1_desc" },- policy: "permissive",- },- {- slug: "test-feature-2",- i18n: { title: "test_feature_2_title", name: "test_feature_2", description: "test_feature_2_desc" },- policy: "permissive",- },- {- slug: "org-only-feature",- i18n: { title: "org_only_title", name: "org_only", description: "org_only_desc" },- policy: "permissive",- scope: ["org"],- },- {- slug: "team-only-feature",- i18n: { title: "team_only_title", name: "team_only", description: "team_only_desc" },- policy: "permissive",- scope: ["team"],- },- {- slug: "user-only-feature",- i18n: { title: "user_only_title", name: "user_only", description: "user_only_desc" },- policy: "permissive",- scope: ["user"],- },- {- slug: "strict-feature",- i18n: { title: "strict_feature_title", name: "strict_feature", description: "strict_feature_desc" },- policy: "strict",- },- ];+ const mockFeatures = [+ {+ slug: "test-feature-1",+ i18n: { title: "test_feature_1_title", name: "test_feature_1", description: "test_feature_1_desc" },+ policy: "permissive",+ },+ {+ slug: "test-feature-2",+ i18n: { title: "test_feature_2_title", name: "test_feature_2", description: "test_feature_2_desc" },+ policy: "permissive",+ },+ {+ slug: "org-only-feature",+ i18n: { title: "org_only_title", name: "org_only", description: "org_only_desc" },+ policy: "permissive",+ scope: ["org"],+ },+ {+ slug: "team-only-feature",+ i18n: { title: "team_only_title", name: "team_only", description: "team_only_desc" },+ policy: "permissive",+ scope: ["team"],+ },+ {+ slug: "user-only-feature",+ i18n: { title: "user_only_title", name: "user_only", description: "user_only_desc" },+ policy: "permissive",+ scope: ["user"],+ },+ {+ slug: "strict-feature",+ i18n: { title: "strict_feature_title", name: "strict_feature", description: "strict_feature_desc" },+ policy: "strict",+ },+ ];return {OPT_IN_FEATURES: mockFeatures,isOptInFeature: (slug: string) => mockFeatures.some((feature) => feature.slug === slug),diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.ts b/packages/features/feature-opt-in/services/FeatureOptInService.tsindex 6c91b441191..55844f09275 100644--- a/packages/features/feature-opt-in/services/FeatureOptInService.ts+++ b/packages/features/feature-opt-in/services/FeatureOptInService.ts@@ -244,11 +244,12 @@ export class FeatureOptInService implements IFeatureOptInService {/*** List all opt-in features with their states for a user across teams.- * Only returns features that are in the allowlist, globally enabled, and scoped to "user".+ * Only returns features that are in the allowlist, globally enabled, scoped to "user",+ * and configured to be displayed in settings.*/async listFeaturesForUser(input: { userId: number }): Promise<ListFeaturesForUserResult[]> {const { userId } = input;- const userScopedFeatures = getOptInFeaturesForScope("user");+ const userScopedFeatures = getOptInFeaturesForScope("user", "settings");const featureIds = userScopedFeatures.map((config) => config.slug);const resolvedStates = await this.resolveFeatureStates({@@ -262,7 +263,8 @@ export class FeatureOptInService implements IFeatureOptInService {/*** List all opt-in features with their raw states for a team or organization.* Used for team/org admin settings page to configure feature opt-in.- * Only returns features that are in the allowlist, globally enabled, and scoped to the specified scope.+ * Only returns features that are in the allowlist, globally enabled, scoped to the specified scope,+ * and configured to be displayed in settings.* If parentOrgId is provided, also returns the organization state for each feature.*/async listFeaturesForTeam(input: {@@ -272,7 +274,7 @@ export class FeatureOptInService implements IFeatureOptInService {}): Promise<ListFeaturesForTeamResult[]> {const { teamId, parentOrgId, scope = "team" } = input;const teamIdsToQuery = getTeamIdsToQuery(teamId, parentOrgId);- const scopedFeatures = getOptInFeaturesForScope(scope);+ const scopedFeatures = getOptInFeaturesForScope(scope, "settings");const [allFeatures, teamStates] = await Promise.all([this.deps.featureRepo.findAll(),