| 1 | /** |
| 2 | * What a billing form posts back: an error for one section, a change to |
| 3 | * confirm, or a Stripe billing link to hand on. Shared by the workspace and |
| 4 | * enterprise pages. |
| 5 | */ |
| 6 | import type { BillingLink, Terms } from "@g1t/contracts"; |
| 7 | |
| 8 | export type Review = |
| 9 | | { intent: "terms"; before: Terms; after: Terms; fields: Record<string, string> } |
| 10 | | { intent: "attach"; workspace: string; targetName: string; fields: Record<string, string> } |
| 11 | | { intent: "detach"; workspace: string; from: string; fields: Record<string, string> } |
| 12 | | { intent: "billing-link"; workspace: string; fields: Record<string, string> }; |
| 13 | |
| 14 | export type ActionData = |
| 15 | | { error: string; section: string; values?: Record<string, string> } |
| 16 | | { review: Review } |
| 17 | | { link: BillingLink; workspace: string }; |
| 18 | |
| 19 | export type SectionError = { error: string; values?: Record<string, string> } | null; |
| 20 | |
| 21 | /** The flash messages a change redirects back with (`?done=`). */ |
| 22 | export const DONE: Record<string, string> = { |
| 23 | terms: "Terms saved. They apply to charges from now on.", |
| 24 | attach: "Workspace moved onto the enterprise.", |
| 25 | detach: "Workspace moved off the enterprise. It pays for itself again.", |
| 26 | credit: "Credit issued.", |
| 27 | created: "Enterprise created.", |
| 28 | }; |
| 29 | |
| 30 | export function doneMessage(url: string): string | null { |
| 31 | const done = new URL(url).searchParams.get("done"); |
| 32 | return done && DONE[done] ? DONE[done] : null; |
| 33 | } |