Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
56 linesCodeBlameRaw
1/**
2 * What a billing form posts back: an error for one section, a change to
3 * confirm, or a result to show once (a Stripe billing link, an invoice).
4 * Shared by the workspace and enterprise pages.
5 */
6import type { BillingLink, EnterpriseInvoice, Terms } from "@g1t/contracts";
7
8export 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 | { intent: "billing-email"; name: string; before: string | null; after: string; fields: Record<string, string> }
14 | { intent: "invoice"; name: string; email: string | null; workspaces: number; fields: Record<string, string> };
15
16export type ActionData =
17 | { error: string; section: string; values?: Record<string, string> }
18 | { review: Review }
19 | { link: BillingLink; workspace: string }
20 | { invoice: EnterpriseInvoice };
21
22export type SectionError = { error: string; values?: Record<string, string> } | null;
23
24/** The flash messages a change redirects back with (`?done=`). */
25export const DONE: Record<string, string> = {
26 terms: "Terms saved. They apply to charges from now on.",
27 allowances: "Plan, pools and caps saved. They apply from now on.",
28 attach: "Workspace moved onto the enterprise.",
29 detach: "Workspace moved off the enterprise. It pays for itself again.",
30 credit: "Credit given. It is on the balance and the statement, and the owners were emailed.",
31 revoked: "What was left of the credit was taken back. It is on the statement and in the audit log.",
32 reset: "Billing reset. The workspace starts again as a new customer, and the costs analysis ran again, so every figure is fresh.",
33 "reset-stale": "Billing reset. The workspace starts again as a new customer; the costs analysis did not finish, so press Run the analysis now on Costs & margin.",
34 "test-detach": "Detached from Stripe's test mode. What changed is in the audit log; the ledger keeps every line.",
35 "test-detach-none": "Nothing from Stripe's test mode was left on this workspace: nothing changed.",
36 created: "Enterprise created.",
37 "billing-email": "Saved where the enterprise's invoices go.",
38 "billing-address": "Billing address saved on its Stripe customer. Its invoices are taxed from it.",
39 sales: "Sales record saved.",
40 note: "Note added.",
41 payment: "Payment recorded. It is on the workspace's statement and counts toward its limit.",
42 approved: "Approved. The owner is told in the app and by email.",
43 declined: "Declined. The owner is told why, in the app and by email.",
44 goodwill: "Goodwill credit given. It is on the statement and in the audit log.",
45};
46
47/** The `?done=` key, if it is one sudo knows. */
48export function doneKey(url: string): string | null {
49 const done = new URL(url).searchParams.get("done");
50 return done && DONE[done] ? done : null;
51}
52
53export function doneMessage(url: string): string | null {
54 const done = new URL(url).searchParams.get("done");
55 return done && DONE[done] ? DONE[done] : null;
56}