fix(dashboard): cancel subscription before new checkout if free

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-24 18:49:17 +01:00
parent a26e64e80d
commit b77ee71445
2 changed files with 31 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
import { WidgetTable } from '@/components/widget-table';
import { useAppParams } from '@/hooks/useAppParams';
import useWS from '@/hooks/useWS';
import { showConfirm } from '@/modals';
import { api } from '@/trpc/client';
import type { IServiceOrganization } from '@openpanel/db';
import type { IPolarPrice } from '@openpanel/payments';
@@ -257,12 +258,23 @@ function CheckoutButton({
disabled={disabled !== null || (isActive && !isCanceled)}
key={price.id}
onClick={() => {
checkout.mutate({
projectId,
organizationId: organization.id,
productPriceId: price!.id,
productId: price.productId,
});
const createCheckout = () =>
checkout.mutate({
projectId,
organizationId: organization.id,
productPriceId: price!.id,
productId: price.productId,
});
if (organization.subscriptionStatus === 'active') {
showConfirm({
title: 'Are you sure?',
text: `You're about the change your subscription.`,
onConfirm: () => createCheckout(),
});
} else {
createCheckout();
}
}}
loading={checkout.isLoading}
className="w-28"