({
onDone
}: Props)
| 23 | }) => void; |
| 24 | }; |
| 25 | export function Passes({ |
| 26 | onDone |
| 27 | }: Props): React.ReactNode { |
| 28 | const [loading, setLoading] = useState(true); |
| 29 | const [passStatuses, setPassStatuses] = useState<PassStatus[]>([]); |
| 30 | const [isAvailable, setIsAvailable] = useState(false); |
| 31 | const [referralLink, setReferralLink] = useState<string | null>(null); |
| 32 | const [referrerReward, setReferrerReward] = useState<ReferrerRewardInfo | null | undefined>(undefined); |
| 33 | const exitState = useExitOnCtrlCDWithKeybindings(() => onDone('Guest passes dialog dismissed', { |
| 34 | display: 'system' |
| 35 | })); |
| 36 | const handleCancel = useCallback(() => { |
| 37 | onDone('Guest passes dialog dismissed', { |
| 38 | display: 'system' |
| 39 | }); |
| 40 | }, [onDone]); |
| 41 | useKeybinding('confirm:no', handleCancel, { |
| 42 | context: 'Confirmation' |
| 43 | }); |
| 44 | useInput((_input, key) => { |
| 45 | if (key.return && referralLink) { |
| 46 | void setClipboard(referralLink).then(raw => { |
| 47 | if (raw) process.stdout.write(raw); |
| 48 | logEvent('tengu_guest_passes_link_copied', {}); |
| 49 | onDone(`Referral link copied to clipboard!`); |
| 50 | }); |
| 51 | } |
| 52 | }); |
| 53 | useEffect(() => { |
| 54 | async function loadPassesData() { |
| 55 | try { |
| 56 | // Check eligibility first (uses cache if available) |
| 57 | const eligibilityData = await getCachedOrFetchPassesEligibility(); |
| 58 | if (!eligibilityData || !eligibilityData.eligible) { |
| 59 | setIsAvailable(false); |
| 60 | setLoading(false); |
| 61 | return; |
| 62 | } |
| 63 | setIsAvailable(true); |
| 64 | |
| 65 | // Store the referral link if available |
| 66 | if (eligibilityData.referral_code_details?.referral_link) { |
| 67 | setReferralLink(eligibilityData.referral_code_details.referral_link); |
| 68 | } |
| 69 | |
| 70 | // Store referrer reward info for v1 campaign messaging |
| 71 | setReferrerReward(eligibilityData.referrer_reward); |
| 72 | |
| 73 | // Use the campaign returned from eligibility for redemptions |
| 74 | const campaign = eligibilityData.referral_code_details?.campaign ?? 'claude_code_guest_pass'; |
| 75 | |
| 76 | // Fetch redemptions data |
| 77 | let redemptionsData: ReferralRedemptionsResponse; |
| 78 | try { |
| 79 | redemptionsData = await fetchReferralRedemptions(campaign); |
| 80 | } catch (err_0) { |
| 81 | logError(err_0 as Error); |
| 82 | setIsAvailable(false); |
nothing calls this directly
no test coverage detected