Skip to content

Commit 89557c3

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Change prop type from AttributionId to string
1 parent 31c18ec commit 89557c3

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

components/dashboard/src/components/UsageBasedBillingConfig.tsx

+13-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type PendingStripeSubscription = { pendingSince: number };
2525

2626
interface Props {
2727
subject?: hasId;
28-
attributionId: AttributionId;
28+
attributionId: string;
2929
}
3030

3131
export default function UsageBasedBillingConfig({ subject, attributionId }: Props) {
@@ -50,9 +50,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
5050
setStripeSubscriptionId(undefined);
5151
setIsLoading(true);
5252
try {
53-
const subscriptionId = await getGitpodService().server.findStripeSubscriptionId(
54-
AttributionId.render(attributionId),
55-
);
53+
const subscriptionId = await getGitpodService().server.findStripeSubscriptionId(attributionId);
5654
setStripeSubscriptionId(subscriptionId);
5755
} catch (error) {
5856
console.error(error);
@@ -68,8 +66,8 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
6866
}
6967
(async () => {
7068
const [portalUrl, spendingLimit] = await Promise.all([
71-
getGitpodService().server.getStripePortalUrl(AttributionId.render(attributionId)),
72-
getGitpodService().server.getUsageLimit(AttributionId.render(attributionId)),
69+
getGitpodService().server.getStripePortalUrl(attributionId),
70+
getGitpodService().server.getUsageLimit(attributionId),
7371
]);
7472
setStripePortalUrl(portalUrl);
7573
setUsageLimit(spendingLimit);
@@ -91,7 +89,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
9189
setPendingStripeSubscription(pendingSubscription);
9290
window.localStorage.setItem(localStorageKey, JSON.stringify(pendingSubscription));
9391
try {
94-
await getGitpodService().server.subscribeToStripe(AttributionId.render(attributionId), setupIntentId);
92+
await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId);
9593
} catch (error) {
9694
console.error("Could not subscribe subject to Stripe", error);
9795
window.localStorage.removeItem(localStorageKey);
@@ -140,9 +138,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
140138
if (!pollStripeSubscriptionTimeout) {
141139
// Refresh Stripe subscription in 5 seconds in order to poll for upgrade confirmation
142140
const timeout = setTimeout(async () => {
143-
const subscriptionId = await getGitpodService().server.findStripeSubscriptionId(
144-
AttributionId.render(attributionId),
145-
);
141+
const subscriptionId = await getGitpodService().server.findStripeSubscriptionId(attributionId);
146142
setStripeSubscriptionId(subscriptionId);
147143
setPollStripeSubscriptionTimeout(undefined);
148144
}, 5000);
@@ -161,7 +157,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
161157
const oldLimit = usageLimit;
162158
setUsageLimit(newLimit);
163159
try {
164-
await getGitpodService().server.setUsageLimit(AttributionId.render(attributionId), newLimit);
160+
await getGitpodService().server.setUsageLimit(attributionId, newLimit);
165161
} catch (error) {
166162
setUsageLimit(oldLimit);
167163
console.error(error);
@@ -239,7 +235,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
239235
);
240236
}
241237

242-
function BillingSetupModal(props: { attributionId: AttributionId; onClose: () => void }) {
238+
function BillingSetupModal(props: { attributionId: string; onClose: () => void }) {
243239
const { isDark } = useContext(ThemeContext);
244240
const [stripePromise, setStripePromise] = useState<Promise<Stripe | null> | undefined>();
245241
const [stripeSetupIntentClientSecret, setStripeSetupIntentClientSecret] = useState<string | undefined>();
@@ -283,7 +279,7 @@ function getStripeAppearance(isDark?: boolean): Appearance {
283279
};
284280
}
285281

286-
function CreditCardInputForm(props: { attributionId: AttributionId }) {
282+
function CreditCardInputForm(props: { attributionId: string }) {
287283
const stripe = useStripe();
288284
const elements = useElements();
289285
const { currency, setCurrency } = useContext(PaymentContext);
@@ -292,18 +288,16 @@ function CreditCardInputForm(props: { attributionId: AttributionId }) {
292288

293289
const handleSubmit = async (event: React.FormEvent) => {
294290
event.preventDefault();
295-
if (!stripe || !elements) {
291+
const attrId = AttributionId.parse(props.attributionId);
292+
if (!stripe || !elements || !attrId) {
296293
return;
297294
}
298295
setBillingError(undefined);
299296
setIsLoading(true);
300297
try {
301-
if (props.attributionId.kind === "team") {
298+
if (attrId.kind === "team") {
302299
// Create Stripe customer for team & currency (or update currency)
303-
await getGitpodService().server.createOrUpdateStripeCustomerForTeam(
304-
props.attributionId.teamId,
305-
currency,
306-
);
300+
await getGitpodService().server.createOrUpdateStripeCustomerForTeam(attrId.teamId, currency);
307301
} else {
308302
// Create Stripe customer for user & currency (or update currency)
309303
await getGitpodService().server.createOrUpdateStripeCustomerForUser(currency);

components/dashboard/src/settings/Billing.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function Billing() {
2121
<h3>Billing Account</h3>
2222
<BillingAccountSelector />
2323
<h3 className="mt-12">Usage-Based Billing</h3>
24-
<UsageBasedBillingConfig subject={user} attributionId={attributionId} />
24+
<UsageBasedBillingConfig subject={user} attributionId={AttributionId.render(attributionId)} />
2525
</div>
2626
</PageWithSettingsSubMenu>
2727
);

components/dashboard/src/teams/TeamUsageBasedBilling.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function TeamUsageBasedBilling() {
3535
return (
3636
<>
3737
<h3>Usage-Based Billing</h3>
38-
<UsageBasedBillingConfig subject={team} attributionId={attributionId} />
38+
<UsageBasedBillingConfig subject={team} attributionId={AttributionId.render(attributionId)} />
3939
</>
4040
);
4141
}

0 commit comments

Comments
 (0)