()
| 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); |
| 83 | setLoading(false); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | // Build pass statuses array |
| 88 | const redemptions = redemptionsData.redemptions || []; |
| 89 | const maxRedemptions = redemptionsData.limit || 3; |
| 90 | const statuses: PassStatus[] = []; |
| 91 | for (let i = 0; i < maxRedemptions; i++) { |
| 92 | const redemption = redemptions[i]; |
| 93 | statuses.push({ |
| 94 | passNumber: i + 1, |
| 95 | isAvailable: !redemption |
| 96 | }); |
| 97 | } |
| 98 | setPassStatuses(statuses); |
| 99 | setLoading(false); |
| 100 | } catch (err) { |
| 101 | // For any error, just show passes as not available |
| 102 | logError(err as Error); |
| 103 | setIsAvailable(false); |
| 104 | setLoading(false); |
| 105 | } |
| 106 | } |
| 107 | void loadPassesData(); |
| 108 | }, []); |
| 109 | if (loading) { |
no test coverage detected