mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-23 15:33:52 +00:00
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
34 lines
1,017 B
TypeScript
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,
|
|
}
|
|
}
|