From 41a36f72b3dc71bd32fda7d61131445051d330d4 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 4 Feb 2026 00:58:22 +0100 Subject: [PATCH] Add WhatsApp feature flag and improve onboarding - Add getFeatureFlags endpoint to check if WhatsApp is enabled - Skip phone step in onboarding when WhatsApp is disabled - Hide WhatsApp notification options when disabled - Add ExpertiseSelect component with predefined ocean conservation tags - Fix onboarding layout to fill viewport on desktop Co-Authored-By: Claude Opus 4.5 --- src/app/(auth)/onboarding/page.tsx | 47 ++++++++++++++++++++---------- src/server/routers/settings.ts | 16 ++++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) 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 ( -
- +
+ {/* Progress indicator */}
@@ -112,7 +125,7 @@ export default function OnboardingPage() { ))}

- Step {currentIndex + 1} of {steps.length - 1} + Step {currentIndex + 1} of {totalVisibleSteps}

@@ -148,8 +161,8 @@ export default function OnboardingPage() { )} - {/* Step 2: Phone */} - {step === 'phone' && ( + {/* Step 2: Phone (only if WhatsApp enabled) */} + {step === 'phone' && whatsappEnabled && ( <> @@ -248,16 +261,20 @@ export default function OnboardingPage() { Email only - - WhatsApp only - - - Both Email and WhatsApp - + {whatsappEnabled && ( + <> + + WhatsApp only + + + Both Email and WhatsApp + + + )} No notifications - {!phoneNumber && ( + {whatsappEnabled && !phoneNumber && (

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 */