supermemory/apps/web/hooks/use-trial-status.ts
MaheshtheDev 0695ca421b feat(web): take a card before the Company Brain trial starts (#1459)
Onboarding now opens a trial step that collects a card through Stripe checkout before the brain is enabled, with a timeline showing today's $0, the day-12 reminder, and the day-14 charge.

- Only leaves the card step once the API confirms the trial is live
- Brain home shows a setup banner and dims what the trial unlocks
- Recovers orgs that abandoned checkout instead of stranding them
- Adds the organization ID to account settings, copyable from the label
2026-08-13 06:58:47 +00:00

34 lines
1,017 B
TypeScript

import { useQuery } from "@tanstack/react-query"
import { useHasCompanyBrain } from "@/hooks/use-company-brain"
const BACKEND =
process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"
export type TrialStatus = {
active: boolean
reason: string | null
}
/** Distinguishes a named Company Brain org from one whose trial is actually live. */
export function useTrialStatus() {
const isCompanyBrain = useHasCompanyBrain()
const query = useQuery({
queryKey: ["brain", "trial-status"],
queryFn: async (): Promise<TrialStatus> => {
const res = await fetch(`${BACKEND}/brain/trial/status`, {
credentials: "include",
})
if (!res.ok) throw new Error("Failed to load trial status")
const data = (await res.json()) as { active?: boolean; reason?: string }
return { active: Boolean(data.active), reason: data.reason ?? null }
},
enabled: isCompanyBrain,
staleTime: 30 * 1000,
})
return {
...query,
needsSetup: isCompanyBrain && query.data ? !query.data.active : false,
}
}