diff --git a/src/app/(auth)/onboarding/page.tsx b/src/app/(auth)/onboarding/page.tsx index bf4c5db..f3178c9 100644 --- a/src/app/(auth)/onboarding/page.tsx +++ b/src/app/(auth)/onboarding/page.tsx @@ -1,6 +1,6 @@ 'use client' -import { useState } from 'react' +import { useState, useMemo } from 'react' import { useRouter } from 'next/navigation' import { trpc } from '@/lib/trpc/client' import { Button } from '@/components/ui/button' @@ -48,10 +48,23 @@ export default function OnboardingPage() { 'EMAIL' | 'WHATSAPP' | 'BOTH' | 'NONE' >('EMAIL') + // Fetch feature flags + const { data: featureFlags } = trpc.settings.getFeatureFlags.useQuery() + const whatsappEnabled = featureFlags?.whatsappEnabled ?? false + const completeOnboarding = trpc.user.completeOnboarding.useMutation() - const steps: Step[] = ['name', 'phone', 'tags', 'preferences', 'complete'] + // Dynamic steps based on WhatsApp availability + const steps: Step[] = useMemo(() => { + if (whatsappEnabled) { + return ['name', 'phone', 'tags', 'preferences', 'complete'] + } + // Skip phone step if WhatsApp is disabled + return ['name', 'tags', 'preferences', 'complete'] + }, [whatsappEnabled]) + const currentIndex = steps.indexOf(step) + const totalVisibleSteps = steps.length - 1 // Exclude 'complete' from count const goNext = () => { if (step === 'name' && !name.trim()) { @@ -92,8 +105,8 @@ export default function OnboardingPage() { } return ( -
- Step {currentIndex + 1} of {steps.length - 1} + Step {currentIndex + 1} of {totalVisibleSteps}
Add a phone number to enable WhatsApp notifications
@@ -270,7 +287,7 @@ export default function OnboardingPage() {Name: {name}
- {phoneNumber && ( + {whatsappEnabled && phoneNumber && (Phone:{' '} {phoneNumber} diff --git a/src/server/routers/settings.ts b/src/server/routers/settings.ts index 9a65b4f..0128b90 100644 --- a/src/server/routers/settings.ts +++ b/src/server/routers/settings.ts @@ -19,6 +19,22 @@ function categorizeModel(modelId: string): string { } export const settingsRouter = router({ + /** + * Get public feature flags (no auth required) + * These are non-sensitive settings that can be exposed to any user + */ + getFeatureFlags: protectedProcedure.query(async ({ ctx }) => { + const [whatsappEnabled] = await Promise.all([ + ctx.prisma.systemSettings.findUnique({ + where: { key: 'whatsapp_enabled' }, + }), + ]) + + return { + whatsappEnabled: whatsappEnabled?.value === 'true', + } + }), + /** * Get all settings by category */