Elffuss BraidHub

kikocis/continue public

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