Files
bakery-ia/frontend/src/hooks/usePilotDetection.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-10-17 18:14:28 +02:00
/**
2025-10-18 16:03:23 +02:00
* 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)
2025-10-17 18:14:28 +02:00
*/
import { useMemo } from 'react';
import { useLocation } from 'react-router-dom';
2025-10-18 16:03:23 +02:00
import PILOT_CONFIG from '../config/pilot';
2025-10-17 18:14:28 +02:00
interface PilotDetectionResult {
isPilot: boolean;
couponCode: string | null;
trialMonths: number;
trialDays: number;
}
export const usePilotDetection = (): PilotDetectionResult => {
const location = useLocation();
const pilotInfo = useMemo(() => {
2025-10-18 16:03:23 +02:00
// Check URL parameter
2025-10-17 18:14:28 +02:00
const searchParams = new URLSearchParams(location.search);
2025-10-18 16:03:23 +02:00
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;
2025-10-17 18:14:28 +02:00
return {
isPilot,
2025-10-18 16:03:23 +02:00
couponCode: isPilot ? PILOT_CONFIG.couponCode : null,
trialMonths: isPilot ? PILOT_CONFIG.trialMonths : 0,
trialDays: isPilot ? PILOT_CONFIG.trialDays : 14,
2025-10-17 18:14:28 +02:00
};
}, [location.search]);
return pilotInfo;
};