({
plan,
organizationSlug,
showActionText,
currentSubscription,
}: {
plan: Plan;
organizationSlug: string;
showActionText: boolean;
currentSubscription?: ActiveSubscription;
})
| 220 | } |
| 221 | |
| 222 | export function TierPro({ |
| 223 | plan, |
| 224 | organizationSlug, |
| 225 | showActionText, |
| 226 | currentSubscription, |
| 227 | }: { |
| 228 | plan: Plan; |
| 229 | organizationSlug: string; |
| 230 | showActionText: boolean; |
| 231 | currentSubscription?: ActiveSubscription; |
| 232 | }) { |
| 233 | const lastSubmission = useActionData(); |
| 234 | const [form] = useForm({ |
| 235 | id: "subscribe", |
| 236 | // TODO: type this |
| 237 | lastSubmission: lastSubmission as any, |
| 238 | onValidate({ formData }) { |
| 239 | return parse(formData, { schema: SetPlanBodySchema }); |
| 240 | }, |
| 241 | }); |
| 242 | |
| 243 | const navigation = useNavigation(); |
| 244 | const isLoading = |
| 245 | (navigation.state === "submitting" || navigation.state === "loading") && |
| 246 | navigation.formData?.get("planCode") === plan.code; |
| 247 | |
| 248 | const currentConcurrencyTier = currentSubscription?.plan.concurrentRuns.pricing?.code; |
| 249 | const [concurrentBracketCode, setConcurrentBracketCode] = useState( |
| 250 | currentConcurrencyTier ?? plan.concurrentRuns?.pricing?.tiers[0].code |
| 251 | ); |
| 252 | |
| 253 | const concurrencyTiers = plan.concurrentRuns?.pricing?.tiers ?? []; |
| 254 | const selectedTier = concurrencyTiers.find((c) => c.code === concurrentBracketCode); |
| 255 | |
| 256 | const freeRunCount = plan.runs?.pricing?.brackets[0].upto ?? 0; |
| 257 | const mostExpensiveRunCost = plan.runs?.pricing?.brackets[1]?.unitCost ?? 0; |
| 258 | |
| 259 | const isCurrentPlan = currentConcurrencyTier === concurrentBracketCode; |
| 260 | |
| 261 | let actionText = "Select plan"; |
| 262 | |
| 263 | if (showActionText) { |
| 264 | if (isCurrentPlan) { |
| 265 | actionText = "Current Plan"; |
| 266 | } else { |
| 267 | const currentTierIndex = concurrencyTiers.findIndex((c) => c.code === currentConcurrencyTier); |
| 268 | const selectedTierIndex = concurrencyTiers.findIndex((c) => c.code === concurrentBracketCode); |
| 269 | actionText = currentTierIndex < selectedTierIndex ? "Upgrade" : "Downgrade"; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return ( |
| 274 | <TierContainer isHighlighted> |
| 275 | <Form action={`/resources/${organizationSlug}/subscribe`} method="post" {...form.props}> |
| 276 | <Header title={plan.title} isHighlighted cost={selectedTier?.tierCost} /> |
| 277 | |
| 278 | <div className="mb-2 mt-6 font-sans text-sm font-normal text-text-bright"> |
| 279 | <DefinitionTip |
nothing calls this directly
no test coverage detected
searching dependent graphs…