|
| 1 | +import { ArrowSquareOut, CreditCard } from "@phosphor-icons/react"; |
| 2 | +import { USAGE_BILLING_FLAG } from "@posthog/shared"; |
| 3 | +import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events"; |
| 4 | +import { Button, Dialog, Flex, Text } from "@radix-ui/themes"; |
| 5 | +import { useEffect } from "react"; |
| 6 | +import { track } from "../../shell/analytics"; |
| 7 | +import { openExternalUrl } from "../../shell/openExternal"; |
| 8 | +import { getBillingUrl } from "../../utils/urls"; |
| 9 | +import { useAuthStateValue } from "../auth/store"; |
| 10 | +import { useFeatureFlag } from "../feature-flags/useFeatureFlag"; |
| 11 | +import { useBillingAnnouncementStore } from "./billingAnnouncementStore"; |
| 12 | + |
| 13 | +/** |
| 14 | + * One-time blocking announcement of the usage-based billing cutover. The |
| 15 | + * flag is its launch switch — flip at cutover, delete once the fleet has |
| 16 | + * acknowledged. |
| 17 | + */ |
| 18 | +export function UsageBillingAnnouncementModal() { |
| 19 | + const armed = useFeatureFlag(USAGE_BILLING_FLAG); |
| 20 | + const acknowledged = useBillingAnnouncementStore((s) => s.acknowledged); |
| 21 | + const hasHydrated = useBillingAnnouncementStore((s) => s._hasHydrated); |
| 22 | + const acknowledge = useBillingAnnouncementStore((s) => s.acknowledge); |
| 23 | + const cloudRegion = useAuthStateValue((state) => state.cloudRegion); |
| 24 | + const isLoggedIn = useAuthStateValue((state) => state.currentOrgId !== null); |
| 25 | + |
| 26 | + const isOpen = armed && isLoggedIn && hasHydrated && !acknowledged; |
| 27 | + |
| 28 | + useEffect(() => { |
| 29 | + if (isOpen) { |
| 30 | + track(ANALYTICS_EVENTS.UPGRADE_PROMPT_SHOWN, { |
| 31 | + surface: "billing_announcement", |
| 32 | + }); |
| 33 | + } |
| 34 | + }, [isOpen]); |
| 35 | + |
| 36 | + const handleAcknowledge = () => { |
| 37 | + track(ANALYTICS_EVENTS.USAGE_BILLING_ANNOUNCEMENT_ACKNOWLEDGED, { |
| 38 | + $set: { |
| 39 | + code_usage_billing_acknowledged_at: new Date().toISOString(), |
| 40 | + }, |
| 41 | + }); |
| 42 | + acknowledge(); |
| 43 | + }; |
| 44 | + |
| 45 | + const handleManageBilling = () => { |
| 46 | + track(ANALYTICS_EVENTS.UPGRADE_PROMPT_CLICKED, { |
| 47 | + surface: "billing_announcement", |
| 48 | + }); |
| 49 | + const billingUrl = getBillingUrl(cloudRegion); |
| 50 | + if (billingUrl) openExternalUrl(billingUrl); |
| 51 | + }; |
| 52 | + |
| 53 | + return ( |
| 54 | + <Dialog.Root open={isOpen}> |
| 55 | + <Dialog.Content |
| 56 | + maxWidth="480px" |
| 57 | + onInteractOutside={(e) => e.preventDefault()} |
| 58 | + onEscapeKeyDown={(e) => e.preventDefault()} |
| 59 | + > |
| 60 | + <Flex direction="column" gap="3"> |
| 61 | + <Flex align="center" gap="2"> |
| 62 | + <CreditCard size={20} weight="bold" color="var(--accent-9)" /> |
| 63 | + <Dialog.Title className="mb-0"> |
| 64 | + PostHog Code billing has changed |
| 65 | + </Dialog.Title> |
| 66 | + </Flex> |
| 67 | + <Dialog.Description> |
| 68 | + <Text color="gray" className="text-sm"> |
| 69 | + Seat-based plans are gone. PostHog Code is now usage-based — your |
| 70 | + organization pays for AI usage at cost, and you only pay for what |
| 71 | + you use. |
| 72 | + </Text> |
| 73 | + </Dialog.Description> |
| 74 | + <Flex direction="column" gap="2" className="text-sm"> |
| 75 | + <Text> |
| 76 | + • Your organization's first <Text weight="medium">$20</Text> of |
| 77 | + usage each month is included. |
| 78 | + </Text> |
| 79 | + <Text> |
| 80 | + • Premium models (Claude, GPT) need a payment method on your |
| 81 | + organization; an open model stays available on the free tier. |
| 82 | + </Text> |
| 83 | + <Text> |
| 84 | + • Every organization starts with a{" "} |
| 85 | + <Text weight="medium">$50/month</Text> spend limit you can raise, |
| 86 | + lower, or remove in PostHog billing settings. |
| 87 | + </Text> |
| 88 | + </Flex> |
| 89 | + <Flex justify="end" gap="3" mt="2"> |
| 90 | + <Button |
| 91 | + type="button" |
| 92 | + variant="soft" |
| 93 | + color="gray" |
| 94 | + onClick={handleManageBilling} |
| 95 | + > |
| 96 | + Manage billing |
| 97 | + <ArrowSquareOut size={12} /> |
| 98 | + </Button> |
| 99 | + <Button type="button" onClick={handleAcknowledge}> |
| 100 | + Got it |
| 101 | + </Button> |
| 102 | + </Flex> |
| 103 | + </Flex> |
| 104 | + </Dialog.Content> |
| 105 | + </Dialog.Root> |
| 106 | + ); |
| 107 | +} |
0 commit comments