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

33 lines
860 B
TypeScript
Raw Normal View History

2025-10-17 18:14:28 +02:00
/**
* Custom hook to detect pilot program participation via URL parameter
* Checks for ?pilot=true in URL and provides pilot status and coupon code
*/
import { useMemo } from 'react';
import { useLocation } from 'react-router-dom';
interface PilotDetectionResult {
isPilot: boolean;
couponCode: string | null;
trialMonths: number;
trialDays: number;
}
export const usePilotDetection = (): PilotDetectionResult => {
const location = useLocation();
const pilotInfo = useMemo(() => {
const searchParams = new URLSearchParams(location.search);
const pilotParam = searchParams.get('pilot');
const isPilot = pilotParam === 'true';
return {
isPilot,
couponCode: isPilot ? 'PILOT2025' : null,
trialMonths: isPilot ? 3 : 0,
trialDays: isPilot ? 90 : 14,
};
}, [location.search]);
return pilotInfo;
};