@meterbox/react 0.1.6 → 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 +13 -0
- package/package.json +1 -1
- package/src/BillingDetailsButton.js +4 -2
- package/src/CreditBalance.js +9 -12
- package/src/CreditGrantsTable.js +26 -27
- package/src/CreditUtilization.js +8 -11
- package/src/InvoiceHistory.js +28 -16
- package/src/PlanChangeCard.js +18 -13
- package/src/PricingTable.js +53 -52
- package/src/SubscriptionPreview.js +17 -24
- package/src/i18n.js +662 -0
- package/src/index.js +7 -0
package/README.md
CHANGED
|
@@ -87,6 +87,19 @@ 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
|
+
|
|
90
103
|
### `<BillingDetailsButton baseUrl customerId customerToken returnUrl? label? onSession? onError? />`
|
|
91
104
|
|
|
92
105
|
Sends the customer to Stripe's own Billing Portal to update their payment
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
const React = require("react");
|
|
19
19
|
const theme = require("./theme");
|
|
20
|
+
const { useI18n } = require("./i18n");
|
|
20
21
|
|
|
21
22
|
const styles = {
|
|
22
23
|
btn: {
|
|
@@ -53,12 +54,13 @@ function BillingDetailsButton({
|
|
|
53
54
|
customerId,
|
|
54
55
|
customerToken,
|
|
55
56
|
returnUrl,
|
|
56
|
-
label
|
|
57
|
+
label,
|
|
57
58
|
fetch: fetchImpl,
|
|
58
59
|
onSession,
|
|
59
60
|
onError,
|
|
60
61
|
}) {
|
|
61
62
|
const [busy, setBusy] = React.useState(false);
|
|
63
|
+
const { t } = useI18n();
|
|
62
64
|
const ready = baseUrl && customerId && customerToken;
|
|
63
65
|
|
|
64
66
|
async function onClick() {
|
|
@@ -89,7 +91,7 @@ function BillingDetailsButton({
|
|
|
89
91
|
disabled: !ready || busy,
|
|
90
92
|
onClick,
|
|
91
93
|
},
|
|
92
|
-
busy ? "
|
|
94
|
+
busy ? t("billing.redirecting") : label || t("billing.update"),
|
|
93
95
|
);
|
|
94
96
|
}
|
|
95
97
|
|
package/src/CreditBalance.js
CHANGED
|
@@ -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 || "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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 }, "
|
|
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
|
-
|
|
146
|
+
money(value),
|
|
150
147
|
),
|
|
151
148
|
React.createElement(
|
|
152
149
|
"div",
|
|
153
150
|
{ style: styles.hint },
|
|
154
|
-
|
|
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
|
-
"
|
|
158
|
+
t("credits.topUp"),
|
|
162
159
|
),
|
|
163
160
|
);
|
|
164
161
|
}
|
package/src/CreditGrantsTable.js
CHANGED
|
@@ -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 || "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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 }, "
|
|
163
|
-
bal != null &&
|
|
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
|
-
"
|
|
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 }, "
|
|
181
|
-
React.createElement("th", { style: styles.th }, "
|
|
182
|
-
React.createElement("th", { style: styles.th }, "
|
|
183
|
-
React.createElement("th", { style: styles.th }, "
|
|
184
|
-
React.createElement("th", { style: styles.th }, "
|
|
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 },
|
|
196
|
-
React.createElement("td", { style: styles.td },
|
|
197
|
-
React.createElement("td", { style: styles.td },
|
|
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(
|
|
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
|
),
|
package/src/CreditUtilization.js
CHANGED
|
@@ -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 || "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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 }, "
|
|
161
|
-
React.createElement("div", { style: styles.current },
|
|
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": "
|
|
163
|
+
"aria-label": t("credits.overTime"),
|
|
167
164
|
width: "100%",
|
|
168
165
|
height,
|
|
169
166
|
preserveAspectRatio: "none",
|
package/src/InvoiceHistory.js
CHANGED
|
@@ -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(
|
|
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 || "
|
|
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 }, "
|
|
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 }, "
|
|
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
|
-
["
|
|
113
|
-
React.createElement(
|
|
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 },
|
|
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(
|
|
127
|
-
|
|
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":
|
|
154
|
+
"aria-label": t("invoices.downloadPdf", { number: inv.number || inv.id }),
|
|
143
155
|
},
|
|
144
|
-
"
|
|
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" ? "
|
|
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 }, "
|
|
180
|
+
React.createElement("div", { style: styles.title }, t("invoices.title")),
|
|
169
181
|
body,
|
|
170
182
|
);
|
|
171
183
|
}
|
package/src/PlanChangeCard.js
CHANGED
|
@@ -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(
|
|
163
|
+
setMessage(t("planChange.scheduledOn", { date: date(result.scheduled_change.apply_at) }));
|
|
166
164
|
} else {
|
|
167
|
-
setMessage(
|
|
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 || "
|
|
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("
|
|
190
|
+
setMessage(t("planChange.scheduledCancelled"));
|
|
189
191
|
if (typeof onChanged === "function") onChanged({ cancelled: true });
|
|
190
192
|
} catch (e) {
|
|
191
|
-
setErr(e.message || "
|
|
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
|
-
|
|
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
|
-
"
|
|
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 ? "
|
|
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
|
-
"
|
|
258
|
+
t("planChange.schedule"),
|
|
254
259
|
),
|
|
255
260
|
),
|
|
256
261
|
err && React.createElement("div", { style: { ...styles.message, ...styles.error } }, err),
|