| 1 | import { ArrowPathIcon } from "@heroicons/react/24/outline"; |
| 2 | import { useContext, useEffect, useState } from "react"; |
| 3 | import { Button } from "../.."; |
| 4 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | import { getLocalStorage } from "../../../util/localStorage"; |
| 6 | import { useOnboardingCard } from "../hooks/useOnboardingCard"; |
| 7 | |
| 8 | /** |
| 9 | * Models Add-On tab component displaying pricing and tier information |
| 10 | */ |
| 11 | export function OnboardingModelsAddOnTab() { |
| 12 | const ideMessenger = useContext(IdeMessengerContext); |
| 13 | const { close } = useOnboardingCard(); |
| 14 | const [isPolling, setIsPolling] = useState(false); |
| 15 | |
| 16 | const isJetbrains = getLocalStorage("ide") === "jetbrains"; |
| 17 | |
| 18 | // Polling effect for JetBrains |
| 19 | // This is because jetbrains doesn't support deeplinking the same way as VS Code |
| 20 | useEffect(() => { |
| 21 | if (!isPolling || !isJetbrains) return; |
| 22 | |
| 23 | const interval = setInterval(() => { |
| 24 | ideMessenger.post("config/refreshProfiles", { |
| 25 | reason: "Jetbrains onboarding polling", |
| 26 | selectProfileId: "local", |
| 27 | }); |
| 28 | }, 7000); |
| 29 | |
| 30 | return () => clearInterval(interval); |
| 31 | }, [isPolling, isJetbrains, ideMessenger]); |
| 32 | |
| 33 | function openPricingPage() { |
| 34 | ideMessenger.post("controlPlane/openUrl", { |
| 35 | path: "pricing", |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | async function handleUpgrade() { |
| 40 | try { |
| 41 | const response = await ideMessenger.request( |
| 42 | "controlPlane/getModelsAddOnUpgradeUrl", |
| 43 | { |
| 44 | vsCodeUriScheme: getLocalStorage("vsCodeUriScheme"), |
| 45 | }, |
| 46 | ); |
| 47 | |
| 48 | if (response.status === "success" && response.content?.url) { |
| 49 | await ideMessenger.request("openUrl", response.content.url); |
| 50 | } else { |
| 51 | console.error("Failed to get upgrade URL"); |
| 52 | openPricingPage(); |
| 53 | } |
| 54 | } catch (error) { |
| 55 | console.error("Error during upgrade process:", error); |
| 56 | openPricingPage(); |
| 57 | } finally { |
| 58 | if (isJetbrains) { |
| 59 | setIsPolling(true); |
| 60 | } else { |
| 61 | close(); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Show polling UI for JetBrains after upgrade |
| 67 | if (isPolling && isJetbrains) { |
| 68 | return ( |
| 69 | <div className="flex h-full w-full flex-col items-center justify-center text-center"> |
| 70 | <h2 className="text-foreground mb-4 items-center text-lg font-semibold"> |
| 71 | <ArrowPathIcon className="text-foreground animate-spin-slow mr-2 h-4 w-4" /> |
| 72 | You may close this dialog after upgrading |
| 73 | </h2> |
| 74 | </div> |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | return ( |
| 79 | <div className="flex h-full w-full flex-col items-center justify-center text-center"> |
| 80 | <div className="mb-4 flex flex-col items-center text-center"> |
| 81 | <div className="mb-1"> |
| 82 | <h2 className="text-foreground mb-1 text-2xl font-semibold"> |
| 83 | Models Add-on |
| 84 | </h2> |
| 85 | </div> |
| 86 | |
| 87 | <div className="bg-badge text-badge-foreground mb-4 rounded-full px-3 py-1 text-xs font-medium"> |
| 88 | $20/month |
| 89 | </div> |
| 90 | |
| 91 | <span className="text-description text-base"> |
| 92 | Use a{" "} |
| 93 | <span |
| 94 | className="cursor-pointer underline hover:brightness-125" |
| 95 | onClick={openPricingPage} |
| 96 | > |
| 97 | variety of frontier models |
| 98 | </span>{" "} |
| 99 | for a flat monthly fee |
| 100 | </span> |
| 101 | </div> |
| 102 | |
| 103 | <div className="mb-6 mt-4 space-y-3 text-left"> |
| 104 | <p className="text-foreground text-sm"> |
| 105 | <span className="font-bold">Base Tier:</span> 500 Chat/Edit and 25,000 |
| 106 | Autocomplete requests per month |
| 107 | </p> |
| 108 | <p className="text-foreground text-sm"> |
| 109 | <span className="font-bold">Plus Tier (2.5x):</span> 1,250 Chat/Edit |
| 110 | and 62,500 Autocomplete requests per month |
| 111 | </p> |
| 112 | <p className="text-foreground text-sm"> |
| 113 | <span className="font-bold">Pro Tier (5x):</span> 2,500 Chat/Edit and |
| 114 | 125,000 Autocomplete requests per month |
| 115 | </p> |
| 116 | </div> |
| 117 | |
| 118 | <div className="w-full"> |
| 119 | <Button onClick={handleUpgrade} className="w-full max-w-xs"> |
| 120 | Upgrade |
| 121 | </Button> |
| 122 | </div> |
| 123 | <div className="w-full text-center"> |
| 124 | <span className="text-description"> |
| 125 | <span |
| 126 | className="cursor-pointer underline hover:brightness-125" |
| 127 | onClick={openPricingPage} |
| 128 | > |
| 129 | Click here |
| 130 | </span>{" "} |
| 131 | to view pricing details |
| 132 | </span> |
| 133 | </div> |
| 134 | </div> |
| 135 | ); |
| 136 | } |