fix: avoid crash on billing page when payment method missing (#221)
This commit is contained in:
@@ -19,7 +19,7 @@ export default function SettingsPage() {
|
||||
const { data: subscription } = api.billing.getSubscriptionDetails.useQuery();
|
||||
const [isEditingEmail, setIsEditingEmail] = useState(false);
|
||||
const [billingEmail, setBillingEmail] = useState(
|
||||
currentTeam?.billingEmail || ""
|
||||
currentTeam?.billingEmail || "",
|
||||
);
|
||||
|
||||
const apiUtils = api.useUtils();
|
||||
@@ -46,7 +46,10 @@ export default function SettingsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const paymentMethod = JSON.parse(subscription?.paymentMethod || "{}");
|
||||
const paymentMethod =
|
||||
subscription?.paymentMethod && subscription.paymentMethod !== "null"
|
||||
? JSON.parse(subscription.paymentMethod)
|
||||
: {};
|
||||
|
||||
if (!currentIsAdmin) {
|
||||
return null;
|
||||
@@ -89,14 +92,15 @@ export default function SettingsPage() {
|
||||
{subscription ? (
|
||||
<div className="mt-2">
|
||||
<div className="text-lg font-mono uppercase flex items-center gap-2">
|
||||
{subscription.paymentMethod ? (
|
||||
{subscription.paymentMethod &&
|
||||
subscription.paymentMethod !== "null" ? (
|
||||
<>
|
||||
<span>💳</span>
|
||||
<span className="capitalize">
|
||||
{paymentMethod.card?.brand || ""} ••••{" "}
|
||||
{paymentMethod.card?.last4 || ""}
|
||||
{paymentMethod?.card?.brand || ""} ••••{" "}
|
||||
{paymentMethod?.card?.last4 || ""}
|
||||
</span>
|
||||
{paymentMethod.card && (
|
||||
{paymentMethod?.card && (
|
||||
<span className="text-sm text-muted-foreground lowercase">
|
||||
(Expires: {paymentMethod.card.exp_month}/
|
||||
{paymentMethod.card.exp_year})
|
||||
@@ -112,7 +116,7 @@ export default function SettingsPage() {
|
||||
{subscription.currentPeriodEnd
|
||||
? format(
|
||||
new Date(subscription.currentPeriodEnd),
|
||||
"MMM dd, yyyy"
|
||||
"MMM dd, yyyy",
|
||||
)
|
||||
: "N/A"}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user