Skip to content

Commit c92b555

Browse files
jankeromnesroboquat
authored andcommitted
[dashboard] Show error messages in the UI when upgrading with Stripe fails
1 parent b634fb3 commit c92b555

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

components/dashboard/src/components/UsageBasedBillingConfig.tsx

Lines changed: 9 additions & 1 deletion
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,12 +151,14 @@ 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();
156158
if (!stripe || !elements) {
157159
return;
158160
}
161+
setBillingError(undefined);
159162
setIsLoading(true);
160163
try {
161164
// Create Stripe customer for team & currency (or update currency)
@@ -176,14 +179,19 @@ function CreditCardInputForm(props: { id: string }) {
176179
}
177180
} catch (error) {
178181
console.error(error);
179-
alert(error?.message || "Failed to submit form. See console for error message.");
182+
setBillingError(`Failed to submit form. ${error?.message || String(error)}`);
180183
} finally {
181184
setIsLoading(false);
182185
}
183186
};
184187

185188
return (
186189
<form className="mt-4 flex-grow flex flex-col" onSubmit={handleSubmit}>
190+
{billingError && (
191+
<Alert className="mb-4" closable={false} showIcon={true} type="error">
192+
{billingError}
193+
</Alert>
194+
)}
187195
<PaymentElement />
188196
<div className="mt-4 flex-grow flex justify-end items-end">
189197
<div className="flex-grow flex space-x-1">

components/dashboard/src/teams/TeamUsageBasedBilling.tsx

Lines changed: 8 additions & 0 deletions
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(`Could not subscribe team to Stripe. ${error?.message || String(error)}`);
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)