@meterbox/react 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,6 +87,31 @@ variables in CSS. `useBranding()` reads the values (e.g. the logo), and
87
87
  `theme` exports the variable references for styling your own elements to
88
88
  match.
89
89
 
90
+ ### Language: `<LocaleProvider locale messages?>`
91
+
92
+ Wrap the components in `<LocaleProvider locale="fr">` to show them in your
93
+ customer's language (the ones the customer portal uses: the pricing table,
94
+ plan change and preview, credits, invoices and billing details): English (the default), Spanish (`es`), French (`fr`) and
95
+ German (`de`) are built in, picked by the locale's language (`fr-CA` uses
96
+ French). Dates and amounts are formatted for the locale. `messages` overrides
97
+ any string by its key (`{ "cancel.button": "End my plan" }`), or translates
98
+ them all for another language; anything it leaves out stays in English. The
99
+ keys and English text are in [`src/i18n.js`](./src/i18n.js). Plan names,
100
+ features and offers are shown as you entered them. `useI18n()` gives your own
101
+ elements the same `t(key, vars)`, `date(iso)` and `money(amount, currency)`.
102
+
103
+ ### `<BillingDetailsButton baseUrl customerId customerToken returnUrl? label? onSession? onError? />`
104
+
105
+ Sends the customer to Stripe's own Billing Portal to update their payment
106
+ method and billing details (address, tax IDs, email, name, phone) and see
107
+ their invoices, so payment details never pass through your app or Meterbox.
108
+ POSTs to `/v1/customer-portal/:id/billing-details` and redirects; Stripe
109
+ sends them back to `returnUrl` (default: the current page). Cancelling and
110
+ plan changes aren't offered there: they stay in Meterbox's own flows. It
111
+ works once the customer has a Stripe account and the tenant has enabled
112
+ `checkout_via_meterbox`, which `GET /v1/customer-portal/:id/me` reports as
113
+ `billing_details_available`.
114
+
90
115
  ### `<PlanComparison from to onSwitch? />`
91
116
 
92
117
  Side-by-side comparison of two plan records with added / removed feature
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Embeddable React components for Meterbox: pricing tables, subscription preview, credit balance and usage charts. Presentational by default, with data fetched by your backend via @meterbox/node.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meterbox.ai",
@@ -0,0 +1,98 @@
1
+ /**
2
+ * <BillingDetailsButton baseUrl customerId customerToken returnUrl? label? />
3
+ *
4
+ * Sends the customer to Stripe's own Billing Portal to update their payment
5
+ * method and billing details (address, tax IDs, email, name, phone) and see
6
+ * their invoices, so payment details never pass through your app or
7
+ * Meterbox. POSTs to `/v1/customer-portal/:id/billing-details` and redirects
8
+ * to the returned URL; Stripe sends them back to `returnUrl` (default: this
9
+ * page). Cancelling and plan changes aren't offered there: they stay in
10
+ * Meterbox's own flows.
11
+ *
12
+ * Needs the customer to have a Stripe account and the tenant to have enabled
13
+ * `checkout_via_meterbox`; `GET /v1/customer-portal/:id/me` says whether it
14
+ * will work (`billing_details_available`). Otherwise `onError` receives the
15
+ * 409. Pass `onSession({ url })` to intercept the redirect.
16
+ */
17
+
18
+ const React = require("react");
19
+ const theme = require("./theme");
20
+ const { useI18n } = require("./i18n");
21
+
22
+ const styles = {
23
+ btn: {
24
+ padding: "8px 14px",
25
+ ...theme.button,
26
+ borderRadius: theme.radius(8),
27
+ fontWeight: 600,
28
+ cursor: "pointer",
29
+ fontFamily: theme.font,
30
+ },
31
+ disabled: { opacity: 0.6, cursor: "default" },
32
+ };
33
+
34
+ async function openBillingDetails({ baseUrl, customerId, customerToken, returnUrl, fetchImpl }) {
35
+ const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
36
+ customerId,
37
+ )}/billing-details`;
38
+ const res = await fetchImpl(url, {
39
+ method: "POST",
40
+ headers: { Authorization: `Bearer ${customerToken}`, "Content-Type": "application/json" },
41
+ body: JSON.stringify({ return_url: returnUrl }),
42
+ });
43
+ const body = await res.json().catch(() => ({}));
44
+ if (!res.ok) {
45
+ const err = new Error(body.error || `billing-details: ${res.status}`);
46
+ err.status = res.status;
47
+ throw err;
48
+ }
49
+ return body;
50
+ }
51
+
52
+ function BillingDetailsButton({
53
+ baseUrl,
54
+ customerId,
55
+ customerToken,
56
+ returnUrl,
57
+ label,
58
+ fetch: fetchImpl,
59
+ onSession,
60
+ onError,
61
+ }) {
62
+ const [busy, setBusy] = React.useState(false);
63
+ const { t } = useI18n();
64
+ const ready = baseUrl && customerId && customerToken;
65
+
66
+ async function onClick() {
67
+ setBusy(true);
68
+ try {
69
+ const session = await openBillingDetails({
70
+ baseUrl,
71
+ customerId,
72
+ customerToken,
73
+ returnUrl: returnUrl || globalThis.window?.location?.href,
74
+ fetchImpl: fetchImpl || globalThis.fetch,
75
+ });
76
+ if (onSession) onSession(session);
77
+ else if (session.url && globalThis.window) globalThis.window.location.href = session.url;
78
+ } catch (err) {
79
+ if (onError) onError(err);
80
+ } finally {
81
+ setBusy(false);
82
+ }
83
+ }
84
+
85
+ return React.createElement(
86
+ "button",
87
+ {
88
+ type: "button",
89
+ className: "meterbox-billing-details-button",
90
+ style: !ready || busy ? { ...styles.btn, ...styles.disabled } : styles.btn,
91
+ disabled: !ready || busy,
92
+ onClick,
93
+ },
94
+ busy ? t("billing.redirecting") : label || t("billing.update"),
95
+ );
96
+ }
97
+
98
+ module.exports = BillingDetailsButton;
@@ -21,6 +21,7 @@
21
21
 
22
22
  const React = require("react");
23
23
  const theme = require("./theme");
24
+ const { useI18n } = require("./i18n");
24
25
 
25
26
  async function fetchBalance({ baseUrl, customerId, customerToken, fetchImpl }) {
26
27
  const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
@@ -67,11 +68,6 @@ const styles = {
67
68
  },
68
69
  };
69
70
 
70
- function dollars(n) {
71
- if (n == null) return "—";
72
- return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
73
- }
74
-
75
71
  function CreditBalance({
76
72
  balance,
77
73
  threshold,
@@ -85,6 +81,7 @@ function CreditBalance({
85
81
  const [fetched, setFetched] = React.useState(null);
86
82
  const [error, setError] = React.useState(null);
87
83
  const [loading, setLoading] = React.useState(false);
84
+ const { t, money } = useI18n();
88
85
 
89
86
  React.useEffect(() => {
90
87
  if (!selfFetch) return undefined;
@@ -105,7 +102,7 @@ function CreditBalance({
105
102
  })
106
103
  .catch((err) => {
107
104
  if (!cancelled) {
108
- setError(err.message || "Could not load credit balance.");
105
+ setError(err.message || t("credits.balanceError"));
109
106
  setLoading(false);
110
107
  }
111
108
  });
@@ -118,7 +115,7 @@ function CreditBalance({
118
115
  return React.createElement(
119
116
  "div",
120
117
  { style: { opacity: 0.6, fontFamily: styles.card.fontFamily } },
121
- "Loading credit balance…",
118
+ t("credits.balanceLoading"),
122
119
  );
123
120
  }
124
121
  if (error) {
@@ -133,7 +130,7 @@ function CreditBalance({
133
130
  return React.createElement(
134
131
  "div",
135
132
  { style: { opacity: 0.6, fontFamily: styles.card.fontFamily } },
136
- "Loading credit balance…",
133
+ t("credits.balanceLoading"),
137
134
  );
138
135
  }
139
136
  const value = data.balance_usd ?? data.balance ?? null;
@@ -142,23 +139,23 @@ function CreditBalance({
142
139
  return React.createElement(
143
140
  "div",
144
141
  { className: "meterbox-credit-balance", style: styles.card },
145
- React.createElement("div", { style: styles.label }, "Credit balance"),
142
+ React.createElement("div", { style: styles.label }, t("credits.balance")),
146
143
  React.createElement(
147
144
  "div",
148
145
  { style: low ? { ...styles.amount, ...styles.low } : styles.amount },
149
- dollars(value),
146
+ money(value),
150
147
  ),
151
148
  React.createElement(
152
149
  "div",
153
150
  { style: styles.hint },
154
- `${grants.length} active grant${grants.length === 1 ? "" : "s"}`,
151
+ t("credits.activeGrants", { count: grants.length }),
155
152
  ),
156
153
  onTopUp &&
157
154
  low &&
158
155
  React.createElement(
159
156
  "button",
160
157
  { type: "button", style: styles.topUp, onClick: () => onTopUp(data) },
161
- "Top up credits",
158
+ t("credits.topUp"),
162
159
  ),
163
160
  );
164
161
  }
@@ -22,6 +22,7 @@
22
22
 
23
23
  const React = require("react");
24
24
  const theme = require("./theme");
25
+ const { useI18n } = require("./i18n");
25
26
 
26
27
  const styles = {
27
28
  card: {
@@ -52,24 +53,12 @@ const styles = {
52
53
  },
53
54
  };
54
55
 
55
- function dollars(n) {
56
- if (n == null) return "—";
57
- return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
58
- }
59
-
60
56
  function remaining(g) {
61
57
  const amt = Number(g.amount_usd || 0);
62
58
  const consumed = Number(g.consumed_usd || 0);
63
59
  return Math.max(amt - consumed, 0);
64
60
  }
65
61
 
66
- function fmtDate(iso) {
67
- if (!iso) return "—";
68
- const d = new Date(iso);
69
- if (Number.isNaN(d.getTime())) return iso;
70
- return d.toISOString().slice(0, 10);
71
- }
72
-
73
62
  async function fetchCredits({ baseUrl, customerId, customerToken, fetchImpl }) {
74
63
  const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
75
64
  customerId,
@@ -100,6 +89,7 @@ function CreditGrantsTable({
100
89
  const [fetched, setFetched] = React.useState(null);
101
90
  const [error, setError] = React.useState(null);
102
91
  const [loading, setLoading] = React.useState(false);
92
+ const { t, money, date } = useI18n();
103
93
 
104
94
  React.useEffect(() => {
105
95
  if (!selfFetch) return undefined;
@@ -120,7 +110,7 @@ function CreditGrantsTable({
120
110
  })
121
111
  .catch((err) => {
122
112
  if (!cancelled) {
123
- setError(err.message || "Could not load credits.");
113
+ setError(err.message || t("credits.grantsError"));
124
114
  setLoading(false);
125
115
  }
126
116
  });
@@ -133,7 +123,7 @@ function CreditGrantsTable({
133
123
  return React.createElement(
134
124
  "div",
135
125
  { style: { opacity: 0.6, fontFamily: styles.card.fontFamily } },
136
- "Loading credit grants…",
126
+ t("credits.grantsLoading"),
137
127
  );
138
128
  }
139
129
  if (error) {
@@ -149,7 +139,7 @@ function CreditGrantsTable({
149
139
  return React.createElement(
150
140
  "div",
151
141
  { style: { opacity: 0.6, fontFamily: styles.card.fontFamily } },
152
- "No credit grants.",
142
+ t("credits.noGrants"),
153
143
  );
154
144
  }
155
145
  const rows = typeof filter === "function" ? list.filter(filter) : list;
@@ -159,14 +149,19 @@ function CreditGrantsTable({
159
149
  React.createElement(
160
150
  "div",
161
151
  { style: styles.header },
162
- React.createElement("div", { style: styles.title }, "Credit grants"),
163
- bal != null && React.createElement("div", { style: styles.balance }, `Balance ${dollars(bal)}`),
152
+ React.createElement("div", { style: styles.title }, t("credits.grants")),
153
+ bal != null &&
154
+ React.createElement(
155
+ "div",
156
+ { style: styles.balance },
157
+ t("credits.balanceOf", { amount: money(bal) }),
158
+ ),
164
159
  ),
165
160
  rows.length === 0
166
161
  ? React.createElement(
167
162
  "div",
168
163
  { style: { opacity: 0.6, fontSize: 13 } },
169
- "No matching grants.",
164
+ t("credits.noMatching"),
170
165
  )
171
166
  : React.createElement(
172
167
  "table",
@@ -177,11 +172,11 @@ function CreditGrantsTable({
177
172
  React.createElement(
178
173
  "tr",
179
174
  null,
180
- React.createElement("th", { style: styles.th }, "Source"),
181
- React.createElement("th", { style: styles.th }, "Amount"),
182
- React.createElement("th", { style: styles.th }, "Remaining"),
183
- React.createElement("th", { style: styles.th }, "Expires"),
184
- React.createElement("th", { style: styles.th }, "Status"),
175
+ React.createElement("th", { style: styles.th }, t("credits.source")),
176
+ React.createElement("th", { style: styles.th }, t("credits.amount")),
177
+ React.createElement("th", { style: styles.th }, t("credits.remaining")),
178
+ React.createElement("th", { style: styles.th }, t("credits.expires")),
179
+ React.createElement("th", { style: styles.th }, t("credits.status")),
185
180
  ),
186
181
  ),
187
182
  React.createElement(
@@ -192,13 +187,17 @@ function CreditGrantsTable({
192
187
  "tr",
193
188
  { key: g.id },
194
189
  React.createElement("td", { style: styles.td }, g.reason || g.source || g.type || "—"),
195
- React.createElement("td", { style: styles.td }, dollars(g.amount_usd)),
196
- React.createElement("td", { style: styles.td }, dollars(remaining(g))),
197
- React.createElement("td", { style: styles.td }, fmtDate(g.expires_at)),
190
+ React.createElement("td", { style: styles.td }, money(g.amount_usd)),
191
+ React.createElement("td", { style: styles.td }, money(remaining(g))),
192
+ React.createElement("td", { style: styles.td }, date(g.expires_at)),
198
193
  React.createElement(
199
194
  "td",
200
195
  { style: styles.td },
201
- React.createElement("span", { style: styles.pill }, g.status || "active"),
196
+ React.createElement(
197
+ "span",
198
+ { style: styles.pill },
199
+ t(`grant.${g.status || "active"}`, null, g.status),
200
+ ),
202
201
  ),
203
202
  ),
204
203
  ),
@@ -19,6 +19,7 @@
19
19
 
20
20
  const React = require("react");
21
21
  const theme = require("./theme");
22
+ const { useI18n } = require("./i18n");
22
23
 
23
24
  const styles = {
24
25
  wrap: {
@@ -38,11 +39,6 @@ const styles = {
38
39
  line: { fill: "none", stroke: theme.accent, strokeWidth: 1.5 },
39
40
  };
40
41
 
41
- function dollars(n) {
42
- if (n == null) return "—";
43
- return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
44
- }
45
-
46
42
  async function fetchTimeseries({
47
43
  baseUrl,
48
44
  customerId,
@@ -88,6 +84,7 @@ function CreditUtilization({
88
84
  const [fetched, setFetched] = React.useState(null);
89
85
  const [error, setError] = React.useState(null);
90
86
  const [loading, setLoading] = React.useState(false);
87
+ const { t, money } = useI18n();
91
88
 
92
89
  React.useEffect(() => {
93
90
  if (!selfFetch) return undefined;
@@ -111,7 +108,7 @@ function CreditUtilization({
111
108
  })
112
109
  .catch((err) => {
113
110
  if (!cancelled) {
114
- setError(err.message || "Could not load utilization.");
111
+ setError(err.message || t("credits.utilError"));
115
112
  setLoading(false);
116
113
  }
117
114
  });
@@ -124,7 +121,7 @@ function CreditUtilization({
124
121
  return React.createElement(
125
122
  "div",
126
123
  { style: { opacity: 0.6, fontFamily: styles.wrap.fontFamily } },
127
- "Loading utilization…",
124
+ t("credits.utilLoading"),
128
125
  );
129
126
  }
130
127
  if (error) {
@@ -139,7 +136,7 @@ function CreditUtilization({
139
136
  return React.createElement(
140
137
  "div",
141
138
  { style: { opacity: 0.6, fontFamily: styles.wrap.fontFamily } },
142
- "No utilization in window.",
139
+ t("credits.utilEmpty"),
143
140
  );
144
141
  }
145
142
  const values = points.map((p) => Number(p.balance_usd || 0));
@@ -157,13 +154,13 @@ function CreditUtilization({
157
154
  return React.createElement(
158
155
  "div",
159
156
  { className: "meterbox-credit-utilization", style: styles.wrap },
160
- React.createElement("div", { style: styles.label }, "Credit balance"),
161
- React.createElement("div", { style: styles.current }, dollars(last)),
157
+ React.createElement("div", { style: styles.label }, t("credits.balance")),
158
+ React.createElement("div", { style: styles.current }, money(last)),
162
159
  React.createElement(
163
160
  "svg",
164
161
  {
165
162
  role: "img",
166
- "aria-label": "Credit balance over time",
163
+ "aria-label": t("credits.overTime"),
167
164
  width: "100%",
168
165
  height,
169
166
  preserveAspectRatio: "none",
@@ -15,6 +15,7 @@
15
15
 
16
16
  const React = require("react");
17
17
  const theme = require("./theme");
18
+ const { useI18n } = require("./i18n");
18
19
 
19
20
  const styles = {
20
21
  card: {
@@ -43,13 +44,11 @@ const styles = {
43
44
  muted: { opacity: 0.6 },
44
45
  };
45
46
 
46
- const STATUS = { open: "Due", paid: "Paid", void: "Void", uncollectible: "Uncollectible" };
47
-
48
47
  // Amounts arrive in the currency's minor unit (cents for USD, yen for JPY).
49
- function money(minor, currency) {
48
+ function money(minor, currency, locale) {
50
49
  const code = String(currency || "usd").toUpperCase();
51
50
  try {
52
- const format = new Intl.NumberFormat(undefined, { style: "currency", currency: code });
51
+ const format = new Intl.NumberFormat(locale, { style: "currency", currency: code });
53
52
  const digits = format.resolvedOptions().maximumFractionDigits;
54
53
  return format.format(minor / 10 ** digits);
55
54
  } catch (_) {
@@ -74,6 +73,7 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
74
73
  const selfFetch = !invoices && baseUrl && customerId && customerToken;
75
74
  const [fetched, setFetched] = React.useState(null);
76
75
  const [error, setError] = React.useState(null);
76
+ const { t, locale, date } = useI18n();
77
77
 
78
78
  React.useEffect(() => {
79
79
  if (!selfFetch) return undefined;
@@ -84,7 +84,7 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
84
84
  if (!cancelled) setFetched(list);
85
85
  })
86
86
  .catch((err) => {
87
- if (!cancelled) setError(err.message || "Could not load invoices.");
87
+ if (!cancelled) setError(err.message || t("invoices.error"));
88
88
  });
89
89
  return () => {
90
90
  cancelled = true;
@@ -96,9 +96,9 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
96
96
  if (error) {
97
97
  body = React.createElement("span", { role: "alert", style: { color: "#dc2626" } }, error);
98
98
  } else if (!list) {
99
- body = React.createElement("span", { style: styles.muted }, "Loading invoices…");
99
+ body = React.createElement("span", { style: styles.muted }, t("invoices.loading"));
100
100
  } else if (list.length === 0) {
101
- body = React.createElement("span", { style: styles.muted }, "No invoices yet.");
101
+ body = React.createElement("span", { style: styles.muted }, t("invoices.empty"));
102
102
  } else {
103
103
  body = React.createElement(
104
104
  "table",
@@ -109,8 +109,12 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
109
109
  React.createElement(
110
110
  "tr",
111
111
  null,
112
- ["Date", "Invoice", "Status", "Amount", ""].map((h) =>
113
- React.createElement("th", { key: h || "links", style: styles.th }, h),
112
+ ["date", "number", "status", "amount", ""].map((h) =>
113
+ React.createElement(
114
+ "th",
115
+ { key: h || "links", style: styles.th },
116
+ h && t(`invoices.${h}`),
117
+ ),
114
118
  ),
115
119
  ),
116
120
  ),
@@ -121,10 +125,18 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
121
125
  React.createElement(
122
126
  "tr",
123
127
  { key: inv.id },
124
- React.createElement("td", { style: styles.td }, String(inv.created_at).slice(0, 10)),
128
+ React.createElement("td", { style: styles.td }, date(inv.created_at)),
125
129
  React.createElement("td", { style: styles.td }, inv.number || inv.id),
126
- React.createElement("td", { style: styles.td }, STATUS[inv.status] || inv.status),
127
- React.createElement("td", { style: styles.td }, money(inv.amount_due, inv.currency)),
130
+ React.createElement(
131
+ "td",
132
+ { style: styles.td },
133
+ t(`invoice.${inv.status}`, null, inv.status),
134
+ ),
135
+ React.createElement(
136
+ "td",
137
+ { style: styles.td },
138
+ money(inv.amount_due, inv.currency, locale),
139
+ ),
128
140
  React.createElement(
129
141
  "td",
130
142
  { style: styles.td },
@@ -139,9 +151,9 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
139
151
  target: "_blank",
140
152
  rel: "noopener noreferrer",
141
153
  style: styles.link,
142
- "aria-label": `Download PDF of ${inv.number || inv.id}`,
154
+ "aria-label": t("invoices.downloadPdf", { number: inv.number || inv.id }),
143
155
  },
144
- "PDF",
156
+ t("invoices.pdf"),
145
157
  ),
146
158
  inv.hosted_invoice_url &&
147
159
  React.createElement(
@@ -152,7 +164,7 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
152
164
  rel: "noopener noreferrer",
153
165
  style: styles.link,
154
166
  },
155
- inv.status === "open" ? "Pay" : "View",
167
+ t(inv.status === "open" ? "invoices.pay" : "invoices.view"),
156
168
  ),
157
169
  ),
158
170
  ),
@@ -165,7 +177,7 @@ function InvoiceHistory({ invoices, baseUrl, customerId, customerToken, fetch: f
165
177
  return React.createElement(
166
178
  "div",
167
179
  { className: "meterbox-invoice-history", style: styles.card },
168
- React.createElement("div", { style: styles.title }, "Invoices"),
180
+ React.createElement("div", { style: styles.title }, t("invoices.title")),
169
181
  body,
170
182
  );
171
183
  }
@@ -39,6 +39,7 @@
39
39
  const React = require("react");
40
40
  const theme = require("./theme");
41
41
  const SubscriptionPreview = require("./SubscriptionPreview");
42
+ const { useI18n } = require("./i18n");
42
43
 
43
44
  const styles = {
44
45
  wrap: {
@@ -77,10 +78,6 @@ const styles = {
77
78
  error: { color: "#dc2626" },
78
79
  };
79
80
 
80
- function fmtDate(iso) {
81
- return iso ? String(iso).slice(0, 10) : "—";
82
- }
83
-
84
81
  function btnStyle(disabled, primary) {
85
82
  const base = primary ? { ...styles.btn, ...styles.btnPrimary } : styles.btn;
86
83
  return disabled ? { ...base, ...styles.disabled } : base;
@@ -144,6 +141,7 @@ function PlanChangeCard({
144
141
  const [err, setErr] = React.useState(null);
145
142
  const [message, setMessage] = React.useState(null);
146
143
  const [scheduled, setScheduled] = React.useState(scheduledChange || null);
144
+ const { t, date } = useI18n();
147
145
 
148
146
  React.useEffect(() => {
149
147
  setScheduled(scheduledChange || null);
@@ -162,13 +160,17 @@ function PlanChangeCard({
162
160
  : null;
163
161
  if (result?.scheduled) {
164
162
  setScheduled(result.scheduled_change);
165
- setMessage(`Scheduled: applies on ${fmtDate(result.scheduled_change.apply_at)}.`);
163
+ setMessage(t("planChange.scheduledOn", { date: date(result.scheduled_change.apply_at) }));
166
164
  } else {
167
- setMessage(`Plan changed${result?.new_plan ? ` to ${result.new_plan}` : ""}.`);
165
+ setMessage(
166
+ result?.new_plan
167
+ ? t("planChange.changedTo", { plan: result.new_plan })
168
+ : t("planChange.changed"),
169
+ );
168
170
  }
169
171
  if (typeof onChanged === "function") onChanged(result);
170
172
  } catch (e) {
171
- setErr(e.message || "Plan change failed.");
173
+ setErr(e.message || t("planChange.failed"));
172
174
  } finally {
173
175
  setBusy(false);
174
176
  }
@@ -185,10 +187,10 @@ function PlanChangeCard({
185
187
  await deleteScheduled({ baseUrl, customerId, customerToken, fetchImpl: fetcher });
186
188
  }
187
189
  setScheduled(null);
188
- setMessage("Scheduled change cancelled.");
190
+ setMessage(t("planChange.scheduledCancelled"));
189
191
  if (typeof onChanged === "function") onChanged({ cancelled: true });
190
192
  } catch (e) {
191
- setErr(e.message || "Cancel failed.");
193
+ setErr(e.message || t("planChange.cancelFailed"));
192
194
  } finally {
193
195
  setBusy(false);
194
196
  }
@@ -206,7 +208,10 @@ function PlanChangeCard({
206
208
  React.createElement(
207
209
  "span",
208
210
  null,
209
- `Scheduled change to ${scheduled.target_plan_id} on ${fmtDate(scheduled.apply_at)}.`,
211
+ t("planChange.pending", {
212
+ plan: scheduled.target_plan_id,
213
+ date: date(scheduled.apply_at),
214
+ }),
210
215
  ),
211
216
  React.createElement(
212
217
  "button",
@@ -216,7 +221,7 @@ function PlanChangeCard({
216
221
  disabled: busy,
217
222
  onClick: cancelScheduled,
218
223
  },
219
- "Cancel",
224
+ t("planChange.cancel"),
220
225
  ),
221
226
  ),
222
227
  React.createElement(SubscriptionPreview, {
@@ -239,7 +244,7 @@ function PlanChangeCard({
239
244
  disabled: !ready || busy,
240
245
  onClick: () => confirm("now"),
241
246
  },
242
- busy ? "Working…" : "Change now",
247
+ busy ? t("planChange.working") : t("planChange.now"),
243
248
  ),
244
249
  allowSchedule &&
245
250
  React.createElement(
@@ -250,7 +255,7 @@ function PlanChangeCard({
250
255
  disabled: !ready || busy,
251
256
  onClick: () => confirm("period_end"),
252
257
  },
253
- "Schedule for end of period",
258
+ t("planChange.schedule"),
254
259
  ),
255
260
  ),
256
261
  err && React.createElement("div", { style: { ...styles.message, ...styles.error } }, err),