Elffuss BraidHub

kikocis/continue public

0a23051cf9a6 · 5.1 KiBRawPermalink
1import { ChevronDownIcon } from "@heroicons/react/24/outline";
2import { FreeTrialStatus } from "core/control-plane/client";
3import { useContext } from "react";
4import { Button, SecondaryButton, vscButtonBackground } from "../..";
5import { IdeMessengerContext } from "../../../context/IdeMessenger";
6import { fontSize } from "../../../util";
7import { Listbox, ListboxButton, ListboxOptions, Transition } from "../../ui";
8import { useFontSize } from "../../ui/font";
9
10interface ProgressBarProps {
11 label: string;
12 current: number;
13 total: number;
14}
15
16function ProgressBar({ label, current, total }: ProgressBarProps) {
17 const percentage = Math.min((current / total) * 100, 100);
18
19 return (
20 <div className="mb-4">
21 <div className="mb-1 flex justify-between text-xs">
22 <span>{label}</span>
23 <span>
24 {current}/{total}
25 </span>
26 </div>
27 <div className="h-2 w-full rounded-full bg-gray-700">
28 <div
29 className="h-2 rounded-full transition-all duration-300"
30 style={{
31 width: `${percentage}%`,
32 backgroundColor: vscButtonBackground,
33 }}
34 />
35 </div>
36 </div>
37 );
38}
39
40interface FreeTrialProgressBarsProps {
41 freeTrialStatus: FreeTrialStatus;
42}
43
44function FreeTrialProgressBars({
45 freeTrialStatus,
46}: FreeTrialProgressBarsProps) {
47 // Use data from freeTrialStatus
48 const autocompleteUsage = {
49 current: freeTrialStatus.autocompleteCount,
50 total: freeTrialStatus.autocompleteLimit,
51 };
52 const chatUsage = {
53 current: freeTrialStatus.chatCount,
54 total: freeTrialStatus.chatLimit,
55 };
56
57 return (
58 <>
59 <ProgressBar
60 label="Autocomplete usage"
61 current={autocompleteUsage.current ?? 0}
62 total={autocompleteUsage.total}
63 />
64
65 <ProgressBar
66 label="Chat usage"
67 current={chatUsage.current ?? 0}
68 total={chatUsage.total}
69 />
70 </>
71 );
72}
73
74interface FreeTrialButtonProps {
75 freeTrialStatus?: FreeTrialStatus | null;
76}
77
78export default function FreeTrialButton({
79 freeTrialStatus,
80}: FreeTrialButtonProps) {
81 const smallFont = useFontSize(-3);
82 const tinyFont = useFontSize(-4);
83 const ideMessenger = useContext(IdeMessengerContext);
84
85 return (
86 <Listbox>
87 <div className="relative">
88 <ListboxButton
89 className="text-description border-none bg-transparent hover:brightness-125"
90 style={{ fontSize: fontSize(-3) }}
91 >
92 <div className="flex flex-row items-center gap-1.5">
93 <span className="line-clamp-1 select-none">Free trial usage</span>
94 </div>
95 <ChevronDownIcon
96 className="h-2 w-2 flex-shrink-0 select-none"
97 aria-hidden="true"
98 />
99 </ListboxButton>
100
101 <Transition>
102 <ListboxOptions className="pb-0">
103 <div className="max-w-96 px-4 pb-4">
104 <h3 className="mb-4 text-sm font-semibold">
105 Free trial of the Models Add-On
106 </h3>
107
108 <div className="mb-4">
109 <span className="text-description">
110 You are currently using a free trial the Models Add-On, which
111 allows you to use a variety of frontier models for a flat
112 monthly fee. Read more about usage limits and what models are
113 included{" "}
114 <span
115 onClick={async () => {
116 await ideMessenger.request("controlPlane/openUrl", {
117 path: "pricing",
118 orgSlug: undefined,
119 });
120 }}
121 className="cursor-pointer text-blue-400 underline hover:text-blue-300"
122 >
123 here
124 </span>
125 .
126 </span>
127 </div>
128
129 {!freeTrialStatus ? (
130 <div className="mb-4 flex items-center justify-center py-8">
131 <span className="text-description">
132 Loading trial usage...
133 </span>
134 </div>
135 ) : (
136 <FreeTrialProgressBars freeTrialStatus={freeTrialStatus} />
137 )}
138
139 <div className="mt-4 flex gap-2">
140 <SecondaryButton
141 className="flex-1"
142 onClick={async () => {
143 await ideMessenger.request("controlPlane/openUrl", {
144 path: "setup-models",
145 orgSlug: undefined,
146 });
147 }}
148 >
149 Exit trial
150 </SecondaryButton>
151 <Button
152 className="flex-1"
153 onClick={async () => {
154 await ideMessenger.request("controlPlane/openUrl", {
155 path: "settings/billing",
156 orgSlug: undefined,
157 });
158 }}
159 >
160 Upgrade
161 </Button>
162 </div>
163 </div>
164 </ListboxOptions>
165 </Transition>
166 </div>
167 </Listbox>
168 );
169}