diff --git a/apps/business/src/components/Sidebar.tsx b/apps/business/src/components/Sidebar.tsx index 071ba29..f166cad 100644 --- a/apps/business/src/components/Sidebar.tsx +++ b/apps/business/src/components/Sidebar.tsx @@ -170,7 +170,7 @@ export function Sidebar({ open = false }: SidebarProps) { { labelKey: 'nav.store.settings', to: '/store/settings' }, ], }, - ...(canAccessRollCall(user, getActiveBusinessId()) + ...(canAccessRollCall(user, getActiveBusinessId(), enabledModules) ? [ { type: 'group' as const, diff --git a/apps/business/src/pages/RollCallPage.tsx b/apps/business/src/pages/RollCallPage.tsx index ddcf3ed..ac1ffda 100644 --- a/apps/business/src/pages/RollCallPage.tsx +++ b/apps/business/src/pages/RollCallPage.tsx @@ -28,6 +28,7 @@ import { type RollCallSummary, type RollCallsListResponse, } from '../services/rollCallService' +import { useTenantBranding } from '../context/TenantBrandingContext' import { canAccessRollCall } from '../utils/rollCallAccess' import pageStyles from '../components/PageContent.module.css' import styles from './RollCallPage.module.css' @@ -102,8 +103,9 @@ export function RollCallPage() { const { locale } = useLocale() const { showToast } = useToast() const { user } = useAuth() + const { enabledModules } = useTenantBranding() const activeBusinessId = getActiveBusinessId() - const allowed = canAccessRollCall(user, activeBusinessId) + const allowed = canAccessRollCall(user, activeBusinessId, enabledModules) const [data, setData] = useState(null) const [loading, setLoading] = useState(false) diff --git a/apps/business/src/utils/businessModules.ts b/apps/business/src/utils/businessModules.ts index 28fda77..1102501 100644 --- a/apps/business/src/utils/businessModules.ts +++ b/apps/business/src/utils/businessModules.ts @@ -11,6 +11,7 @@ export const BUSINESS_DASHBOARD_MODULE_IDS = [ 'workshops', 'finance', 'multilanguage_data', + 'roll_call', ] as const /** Optional customer-dashboard modules. Always-on: home, profile, addresses, orders, favorites. */ @@ -57,7 +58,8 @@ export const DEFAULT_ENABLED_BUSINESS_MODULES: BusinessModuleId[] = (id) => id !== 'workshops' && id !== 'multilanguage_data' && - id !== 'store_installments', + id !== 'store_installments' && + id !== 'roll_call', ) export const DEFAULT_HOME_CHARTS: [HomeChartId, HomeChartId] = [ diff --git a/apps/business/src/utils/rollCallAccess.ts b/apps/business/src/utils/rollCallAccess.ts index 9a755dd..7829dc8 100644 --- a/apps/business/src/utils/rollCallAccess.ts +++ b/apps/business/src/utils/rollCallAccess.ts @@ -1,4 +1,8 @@ import type { AuthUser } from '../types/auth' +import { + hasBusinessModule, + type BusinessModuleId, +} from './businessModules' function membershipAllowsRollCall(membership: { isOwner: boolean @@ -12,10 +16,16 @@ function membershipAllowsRollCall(membership: { return membership.permissions.includes('roll_calls.read') } +/** + * Show Roll Call when the business module is enabled and the user is + * staff (owner / admin) for the active tenant. + */ export function canAccessRollCall( user: AuthUser | null | undefined, activeBusinessId: string | null, + enabledModules?: readonly BusinessModuleId[] | null, ): boolean { + if (!hasBusinessModule(enabledModules, 'roll_call')) return false if (!user) return false if (user.isSuperAdmin || user.roles.includes('super_admin')) { diff --git a/apps/customer/src/components/Sidebar.tsx b/apps/customer/src/components/Sidebar.tsx index fa8cb4c..fbf5646 100644 --- a/apps/customer/src/components/Sidebar.tsx +++ b/apps/customer/src/components/Sidebar.tsx @@ -32,7 +32,7 @@ export function Sidebar({ open = false }: SidebarProps) { const displayName = brandName || fallbackBusinessName const showMyProducts = hasBusinessModule(enabledModules, 'customer_products') const activeBusinessId = getActiveBusinessId() - const showRollCall = canAccessRollCall(user, activeBusinessId) + const showRollCall = canAccessRollCall(user, activeBusinessId, enabledModules) const navItems = [ { icon: Home, label: t('nav.home'), to: '/' }, diff --git a/apps/customer/src/pages/RollCallPage.tsx b/apps/customer/src/pages/RollCallPage.tsx index 28efef3..2a1bc86 100644 --- a/apps/customer/src/pages/RollCallPage.tsx +++ b/apps/customer/src/pages/RollCallPage.tsx @@ -27,6 +27,7 @@ import { type RollCallSummary, type RollCallsListResponse, } from '../services/rollCallService' +import { useTenantBranding } from '../context/TenantBrandingContext' import { canAccessRollCall } from '../utils/rollCallAccess' import pageStyles from '../components/PageContent.module.css' import styles from './RollCallPage.module.css' @@ -101,8 +102,9 @@ export function RollCallPage() { const { locale } = useLocale() const { showToast } = useToast() const { user } = useAuth() + const { enabledModules } = useTenantBranding() const activeBusinessId = getActiveBusinessId() - const allowed = canAccessRollCall(user, activeBusinessId) + const allowed = canAccessRollCall(user, activeBusinessId, enabledModules) const [data, setData] = useState(null) const [loading, setLoading] = useState(false) diff --git a/apps/customer/src/utils/businessModules.ts b/apps/customer/src/utils/businessModules.ts index 7b366e0..b09f4e4 100644 --- a/apps/customer/src/utils/businessModules.ts +++ b/apps/customer/src/utils/businessModules.ts @@ -11,6 +11,7 @@ export const BUSINESS_MODULE_IDS = [ 'blog', 'warehouse', 'videos', + 'roll_call', ...CUSTOMER_MODULE_IDS, ] as const diff --git a/apps/customer/src/utils/rollCallAccess.ts b/apps/customer/src/utils/rollCallAccess.ts index e018f41..78d086e 100644 --- a/apps/customer/src/utils/rollCallAccess.ts +++ b/apps/customer/src/utils/rollCallAccess.ts @@ -1,4 +1,8 @@ import type { AuthUser } from '../types/auth' +import { + hasBusinessModule, + type BusinessModuleId, +} from './businessModules' function membershipAllowsRollCall(membership: { isOwner: boolean @@ -19,14 +23,15 @@ function sameId(a: string | number | null | undefined, b: string | number | null } /** - * Show Roll Call in the customer dashboard when the user is staff - * (owner / admin) for the active tenant — same people who can open - * the business dashboard. No business module toggle is required. + * Show Roll Call when the business module is enabled and the user is + * staff (owner / admin) for the active tenant. */ export function canAccessRollCall( user: AuthUser | null | undefined, activeBusinessId: string | null, + enabledModules?: readonly BusinessModuleId[] | null, ): boolean { + if (!hasBusinessModule(enabledModules, 'roll_call')) return false if (!user) return false if (user.isSuperAdmin || user.roles.includes('super_admin')) { diff --git a/apps/super-admin/src/utils/businessModules.ts b/apps/super-admin/src/utils/businessModules.ts index 2d59c96..50e4153 100644 --- a/apps/super-admin/src/utils/businessModules.ts +++ b/apps/super-admin/src/utils/businessModules.ts @@ -11,6 +11,7 @@ export const BUSINESS_DASHBOARD_MODULE_IDS = [ 'workshops', 'finance', 'multilanguage_data', + 'roll_call', ] as const /** Optional customer-dashboard modules. Always-on: home, profile, addresses, orders, favorites. */ @@ -42,6 +43,7 @@ export const BUSINESS_DASHBOARD_MODULE_LABELS: Record< workshops: 'Workshops', finance: 'Finance', multilanguage_data: 'MultiLanguage Data', + roll_call: 'Roll Call', } export const CUSTOMER_MODULE_LABELS: Record = { @@ -87,7 +89,8 @@ export const DEFAULT_ENABLED_BUSINESS_MODULES: BusinessModuleId[] = (id) => id !== 'workshops' && id !== 'multilanguage_data' && - id !== 'store_installments', + id !== 'store_installments' && + id !== 'roll_call', ) export const DEFAULT_HOME_CHARTS: [HomeChartId, HomeChartId] = [