Files
bakery-ia/frontend/src/hooks/usePilotDetection.ts
2025-10-18 16:03:23 +02:00

41 lines
1.2 KiB
TypeScript

/**
* Custom hook to detect pilot program participation
*
* Checks both environment variable (VITE_PILOT_MODE_ENABLED) and URL parameter (?pilot=true)
* to determine if pilot mode is active.
*
* Priority: Environment variable OR URL parameter (either can enable pilot mode)
*/
import { useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import PILOT_CONFIG from '../config/pilot';
interface PilotDetectionResult {
isPilot: boolean;
couponCode: string | null;
trialMonths: number;
trialDays: number;
}
export const usePilotDetection = (): PilotDetectionResult => {
const location = useLocation();
const pilotInfo = useMemo(() => {
// Check URL parameter
const searchParams = new URLSearchParams(location.search);
const urlPilotParam = searchParams.get('pilot') === 'true';
// Pilot mode is active if EITHER env var is true OR URL param is true
const isPilot = PILOT_CONFIG.enabled || urlPilotParam;
return {
isPilot,
couponCode: isPilot ? PILOT_CONFIG.couponCode : null,
trialMonths: isPilot ? PILOT_CONFIG.trialMonths : 0,
trialDays: isPilot ? PILOT_CONFIG.trialDays : 14,
};
}, [location.search]);
return pilotInfo;
};