Skip to content

Commit 33578e1

Browse files
committed
[dashboard] Show error messages in the UI when upgrading with Stripe fails
1 parent fcb426e commit 33578e1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

components/dashboard/src/components/UsageBasedBillingConfig.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { PaymentContext } from "../payment-context";
1313
import { getGitpodService } from "../service/service";
1414
import DropDown from "../components/DropDown";
1515
import Modal from "../components/Modal";
16+
import Alert from "./Alert";
1617

1718
interface Props {
1819
userOrTeamId: string;
@@ -150,6 +151,7 @@ function CreditCardInputForm(props: { id: string }) {
150151
const elements = useElements();
151152
const { currency, setCurrency } = useContext(PaymentContext);
152153
const [isLoading, setIsLoading] = useState<boolean>(false);
154+
const [billingError, setBillingError] = useState<string | undefined>();
153155

154156
const handleSubmit = async (event: React.FormEvent) => {
155157
event.preventDefault();
@@ -176,14 +178,19 @@ function CreditCardInputForm(props: { id: string }) {
176178
}
177179
} catch (error) {
178180
console.error(error);
179-
alert(error?.message || "Failed to submit form. See console for error message.");
181+
setBillingError(error?.message || "Failed to submit form. See console for error message.");
180182
} finally {
181183
setIsLoading(false);
182184
}
183185
};
184186

185187
return (
186188
<form className="mt-4 flex-grow flex flex-col" onSubmit={handleSubmit}>
189+
{billingError && (
190+
<Alert className="mb-4" closable={false} showIcon={true} type="error">
191+
{billingError}
192+
</Alert>
193+
)}
187194
<PaymentElement />
188195
<div className="mt-4 flex-grow flex justify-end items-end">
189196
<div className="flex-grow flex space-x-1">

components/dashboard/src/teams/TeamUsageBasedBilling.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
1010
import { getCurrentTeam, TeamsContext } from "./teams-context";
1111
import { getGitpodService } from "../service/service";
1212
import UsageBasedBillingConfig from "../components/UsageBasedBillingConfig";
13+
import Alert from "../components/Alert";
1314

1415
type PendingStripeSubscription = { pendingSince: number };
1516

@@ -24,6 +25,7 @@ export default function TeamUsageBasedBilling() {
2425
const [pollStripeSubscriptionTimeout, setPollStripeSubscriptionTimeout] = useState<NodeJS.Timeout | undefined>();
2526
const [stripePortalUrl, setStripePortalUrl] = useState<string | undefined>();
2627
const [usageLimit, setUsageLimit] = useState<number | undefined>();
28+
const [billingError, setBillingError] = useState<string | undefined>();
2729

2830
useEffect(() => {
2931
if (!team) {
@@ -85,6 +87,7 @@ export default function TeamUsageBasedBilling() {
8587
window.localStorage.removeItem(`pendingStripeSubscriptionForTeam${team.id}`);
8688
clearTimeout(pollStripeSubscriptionTimeout!);
8789
setPendingStripeSubscription(undefined);
90+
setBillingError(error.message || "Could not subscribe team to Stripe. See console for error messages.");
8891
}
8992
})();
9093
}, [location.search, team]);
@@ -160,6 +163,11 @@ export default function TeamUsageBasedBilling() {
160163

161164
return (
162165
<>
166+
{billingError && (
167+
<Alert className="max-w-xl mb-4" closable={false} showIcon={true} type="error">
168+
{billingError}
169+
</Alert>
170+
)}
163171
<h3>Usage-Based Billing</h3>
164172
<UsageBasedBillingConfig
165173
userOrTeamId={team?.id || ""}

0 commit comments

Comments
 (0)