Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat(billing-page): added cancel subscription option in billing page (#11118)

SagarRajput-7be9dd7de0ea0
diff --git a/frontend/src/AppRoutes/__tests__/Private.test.tsx b/frontend/src/AppRoutes/__tests__/Private.test.tsx
index 7bbff0cf9d..9e31871be5 100644
--- a/frontend/src/AppRoutes/__tests__/Private.test.tsx
+++ b/frontend/src/AppRoutes/__tests__/Private.test.tsx
@@ -105,7 +105,7 @@ function createMockLicense(
status: '',
updated_at: '0',
},
- state: LicenseState.ACTIVE,
+ state: LicenseState.ACTIVATED,
status: LicenseStatus.VALID,
platform: LicensePlatform.CLOUD,
created_at: '0',
@@ -931,7 +931,7 @@ describe('PrivateRoute', () => {
isFetchingActiveLicense: false,
activeLicense: createMockLicense({
platform: LicensePlatform.CLOUD,
- state: LicenseState.ACTIVE,
+ state: LicenseState.ACTIVATED,
}),
},
isCloudUser: true,
@@ -1522,7 +1522,7 @@ describe('PrivateRoute', () => {
isFetchingActiveLicense: false,
activeLicense: createMockLicense({
platform: LicensePlatform.CLOUD,
- state: LicenseState.ACTIVE,
+ state: LicenseState.ACTIVATED,
}),
trialInfo: createMockTrialInfo({ workSpaceBlock: false }),
user: createMockUser({ role: USER_ROLES.ADMIN as ROLES }),
diff --git a/frontend/src/container/BillingContainer/BillingContainer.test.tsx b/frontend/src/container/BillingContainer/BillingContainer.test.tsx
index 0ebbd49398..d36a13123f 100644
--- a/frontend/src/container/BillingContainer/BillingContainer.test.tsx
+++ b/frontend/src/container/BillingContainer/BillingContainer.test.tsx
@@ -4,7 +4,13 @@ import {
notOfTrailResponse,
trialConvertedToSubscriptionResponse,
} from 'mocks-server/__mockdata__/licenses';
-import { act, render, screen } from 'tests/test-utils';
+import { act, render, screen, getAppContextMock } from 'tests/test-utils';
+import APIError from 'types/api/error';
+import {
+ LicensePlatform,
+ LicenseResModel,
+ LicenseState,
+} from 'types/api/licensesV3/getActive';
import { getFormattedDate } from 'utils/timeUtils';
import BillingContainer from './BillingContainer';
@@ -99,6 +105,10 @@ describe('BillingContainer', () => {
await expect(
screen.findByRole('link', { name: /here/i }),
).resolves.toBeInTheDocument();
+
+ await expect(
+ screen.findByText('Cancel Subscription', { selector: 'span' }),
+ ).resolves.toBeInTheDocument();
});
it('OnTrail but trialConvertedToSubscription', async () => {
@@ -138,6 +148,85 @@ describe('BillingContainer', () => {
const dayRemainingInBillingPeriod =
await screen.findByText(/1 days_remaining/i);
expect(dayRemainingInBillingPeriod).toBeInTheDocument();
+
+ await expect(
+ screen.findByText('Cancel Subscription', { selector: 'span' }),
+ ).resolves.toBeInTheDocument();
+ });
+ });
+
+ describe('CancelSubscriptionBanner visibility', () => {
+ const baseActiveLicense = getAppContextMock('ADMIN')
+ .activeLicense as LicenseResModel;
+
+ it('should render when license is ACTIVATED and platform is CLOUD', async () => {
+ render(<BillingContainer />);
+ await expect(
+ screen.findByText('Cancel Subscription', { selector: 'span' }),
+ ).resolves.toBeInTheDocument();
+ });
+
+ it.each([
+ ['EXPIRED', LicenseState.EXPIRED],
+ ['TERMINATED', LicenseState.TERMINATED],
+ ['CANCELLED', LicenseState.CANCELLED],
+ ['EVALUATION_EXPIRED', LicenseState.EVALUATION_EXPIRED],
+ ['DEFAULTED', LicenseState.DEFAULTED],
+ ['ISSUED', LicenseState.ISSUED],
+ ['EVALUATING', LicenseState.EVALUATING],
+ ])('should not render when license state is %s', async (_, state) => {
+ render(
+ <BillingContainer />,
+ {},
+ {
+ appContextOverrides: {
+ activeLicense: { ...baseActiveLicense, state },
+ },
+ },
+ );
+ await screen.findByText('billing');
+ expect(
+ screen.queryByText('Cancel Subscription', { selector: 'span' }),
+ ).not.toBeInTheDocument();
+ });
+
+ const makeAPIError = (statusCode: number): APIError =>
+ new APIError({
+ httpStatusCode: statusCode as any,
+ error: { code: 'error', message: 'error', url: '', errors: [] },
+ });
+
+ it.each([
+ [
+ 'Self-Hosted platform',
+ {
+ activeLicense: {
+ ...baseActiveLicense,
+ platform: LicensePlatform.SELF_HOSTED,
+ },
+ activeLicenseFetchError: null,
+ },
+ ],
+ [
+ 'Community Enterprise user (license API 404)',
+ {
+ activeLicense: null,
+ activeLicenseFetchError: makeAPIError(404),
+ },
+ ],
+ [
+ 'Community user (license API 501)',
+ {
+ activeLicense: null,
+ activeLicenseFetchError: makeAPIError(501),
+ },
+ ],
+ ])('should not render for %s', async (_, overrides) => {
+ render(<BillingContainer />, {}, { appContextOverrides: overrides });
+ await screen.findByText('billing');
+ expect(
+ screen.queryByText('Cancel Subscription', { selector: 'span' }),
+ ).not.toBeInTheDocument();
});
});
diff --git a/frontend/src/container/BillingContainer/BillingContainer.tsx b/frontend/src/container/BillingContainer/BillingContainer.tsx
index 1490edbcc3..598655027a 100644
--- a/frontend/src/container/BillingContainer/BillingContainer.tsx
+++ b/frontend/src/container/BillingContainer/BillingContainer.tsx
@@ -34,10 +34,12 @@ import { CheckoutSuccessPayloadProps } from 'types/api/billing/checkout';
import { getBaseUrl } from 'utils/basePath';
import { getFormattedDate, getRemainingDays } from 'utils/timeUtils';
+import CancelSubscriptionBanner from './CancelSubscriptionBanner';
import { BillingUsageGraph } from './BillingUsageGraph/BillingUsageGraph';
import { prepareCsvData } from './BillingUsageGraph/utils';
import './BillingContainer.styles.scss';
+import { LicenseState } from 'types/api/licensesV3/getActive';
interface DataType {
key: string;
@@ -317,7 +319,7 @@ export default function BillingContainer(): JSX.Element {
const handleBilling = useCallback(async () => {
if (!trialInfo?.trialConvertedToSubscription) {
- logEvent('Billing : Upgrade Plan', {
+ void logEvent('Billing : Upgrade Plan', {
user: pick(user, ['email', 'userId', 'name']),
org,
});
@@ -326,7 +328,7 @@ export default function BillingContainer(): JSX.Element {
url: getBaseUrl(),
});
} else {
- logEvent('Billing : Manage Billing', {
+ void logEvent('Billing : Manage Billing', {
user: pick(user, ['email', 'userId', 'name']),
org,
});
@@ -535,6 +537,10 @@ export default function BillingContainer(): JSX.Element {
{(isLoading || isFetchingBillingData) && renderTableSkeleton()}
</div>
+ {isCloudUserVal && activeLicense?.state === LicenseState.ACTIVATED && (
+ <CancelSubscriptionBanner />
+ )}
+
{!trialInfo?.trialConvertedToSubscription && (
<div className="upgrade-plan-benefits">
<Row
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss
new file mode 100644
index 0000000000..6fa299d0bf
--- /dev/null
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss
@@ -0,0 +1,35 @@
+.banner {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: var(--padding-4);
+ border-radius: 4px;
+ border: 1px solid var(--callout-error-border);
+ background-color: var(--callout-error-background);
+ margin: var(--spacing-4) 0 var(--spacing-12);
+}
+
+.info {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-2);
+}
+
+.title {
+ font-size: var(--font-size-sm);
+ font-weight: var(--font-weight-medium);
+ color: var(--callout-error-title);
+}
+
+.subtitle {
+ font-size: var(--paragraph-base-400-font-size);
+ font-weight: var(--paragraph-base-400-font-weight);
+ line-height: var(--paragraph-base-400-line-height);
+ color: var(--callout-error-icon);
+}
+
+.dialogBody {
+ font-size: var(--font-size-sm);
+ line-height: var(--line-height-relaxed);
+ color: var(--l2-foreground);
+}
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx
new file mode 100644
index 0000000000..6aa61a9810
--- /dev/null
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx
@@ -0,0 +1,68 @@
+import { render, screen, userEvent } from 'tests/test-utils';
+
+import CancelSubscriptionBanner from './CancelSubscriptionBanner';
+
+jest.mock('utils/basePath', () => ({
+ getBasePath: (): string => '/',
+ withBasePath: (path: string): string => path,
+ getAbsoluteUrl: (path: string): string => `https://test.signoz.io${path}`,
+ getBaseUrl: (): string => 'https://test.signoz.io',
+}));
+
+describe('CancelSubscriptionBanner', () => {
+ it('renders banner with title and subtitle', () => {
+ render(<CancelSubscriptionBanner />);
+ expect(
+ screen.getByText('Cancel Subscription', { selector: 'span' }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText('Cancel your SigNoz subscription.'),
+ ).toBeInTheDocument();
+ });
+
+ it('opens dialog with correct content when Cancel Subscription is clicked', async () => {
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<CancelSubscriptionBanner />);
+
+ await user.click(
+ screen.getByRole('button', { name: /cancel subscription/i }),
+ );
+
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
+ expect(
+ screen.getByText(/reach out to our support team/i),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('button', { name: /keep subscription/i }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('button', { name: /contact support/i }),
+ ).toBeInTheDocument();
+ });
+
+ it('sends mailto to cloud-support with correct subject on Contact Support', async () => {
+ const realCreateElement = document.createElement.bind(document);
+ const mockClick = jest.fn();
+ const mockAnchor = { href: '', click: mockClick };
+ jest.spyOn(document, 'createElement').mockImplementation((tag: string) => {
+ if (tag === 'a') {
+ return mockAnchor as unknown as HTMLAnchorElement;
+ }
+ return realCreateElement(tag);
+ });
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<CancelSubscriptionBanner />);
+
+ await user.click(
+ screen.getByRole('button', { name: /cancel subscription/i }),
+ );
+ await user.click(screen.getByRole('button', { name: /contact support/i }));
+
+ expect(mockAnchor.href).toContain('mailto:[email protected]');
+ expect(mockAnchor.href).toContain('Cancel%20My%20SigNoz%20Subscription');
+ expect(mockClick).toHaveBeenCalledTimes(1);
+
+ jest.restoreAllMocks();
+ });
+});
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx
new file mode 100644
index 0000000000..771094d964
--- /dev/null
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx
@@ -0,0 +1,106 @@
+import { useState } from 'react';
+import { X } from '@signozhq/icons';
+import { Button, DialogWrapper } from '@signozhq/ui';
+import logEvent from 'api/common/logEvent';
+import { pick } from 'lodash-es';
+import { useAppContext } from 'providers/App/App';
+import { getBaseUrl } from 'utils/basePath';
+
+import styles from './CancelSubscriptionBanner.module.scss';
+
+function CancelSubscriptionBanner(): JSX.Element {
+ const [open, setOpen] = useState(false);
+ const { user, org } = useAppContext();
+
+ const handleOpenCancelDialog = (): void => {
+ void logEvent('Billing : Cancel Subscription Clicked', {
+ user: pick(user, ['email', 'displayName', 'role', 'organization']),
+ role: user?.role,
+ });
+ setOpen(true);
+ };
+
+ const handleContactSupport = (): void => {
+ void logEvent('Billing : Cancel Subscription Confirmed', {
+ user: pick(user, ['email', 'displayName', 'role', 'organization']),
+ role: user?.role,
+ });
+ const subject = encodeURIComponent('Cancel My SigNoz Subscription');
+ const orgName = org?.[0]?.displayName ?? '';
+ const body = encodeURIComponent(
+ [
+ 'Hi SigNoz Team,',
+ '',
+ 'I would like to cancel my SigNoz Cloud subscription.',
+ 'Please find my account details below.',
+ '',
+ 'Account Details:',
+ ` • SigNoz URL: ${getBaseUrl()}`,
+ ...(orgName ? [` • Organization: ${orgName}`] : []),
+ ` • Account Email: ${user?.email ?? ''}`,
+ '',
+ 'Reason for Cancellation:',
+ '[Please share the reason for cancellation]',
+ '',
+ 'Additional feedback (optional):',
+ '[Any other feedback]',
+ '',
+ 'Regards,',
+ '[user name or team name]',
+ ].join('\n'),
+ );
+ const link = document.createElement('a');
+ link.href = `mailto:[email protected]?subject=${subject}&body=${body}`;
+ link.click();
+ setOpen(false);
+ };
+
+ const footer = (
+ <>
+ <Button
+ variant="solid"
+ color="secondary"
+ onClick={(): void => setOpen(false)}
+ >
+ Keep Subscription
+ </Button>
+ <Button variant="solid" color="destructive" onClick={handleContactSupport}>
+ Contact Support
+ </Button>
+ </>
+ );
+
+ return (
+ <>
+ <div className={styles.banner}>
+ <div className={styles.info}>
+ <span className={styles.title}>Cancel Subscription</span>
+ <span className={styles.subtitle}>Cancel your SigNoz subscription.</span>
+ </div>
+ <Button
+ variant="solid"
+ color="destructive"
+ prefix={<X size={12} />}
+ onClick={handleOpenCancelDialog}
+ >
+ Cancel Subscription
+ </Button>
+ </div>
+ <DialogWrapper
+ open={open}
+ onOpenChange={setOpen}
+ title="Cancel your subscription"
+ width="narrow"
+ showCloseButton={false}
+ footer={footer}
+ >
+ <p className={styles.dialogBody}>
+ To cancel your SigNoz subscription, please reach out to our support team.
+ We&apos;ll be happy to assist you.
+ </p>
+ </DialogWrapper>
+ </>
+ );
+}
+
+export default CancelSubscriptionBanner;
diff --git a/frontend/src/tests/test-utils.tsx b/frontend/src/tests/test-utils.tsx
index b030b18e2a..e26096a2a9 100644
--- a/frontend/src/tests/test-utils.tsx
+++ b/frontend/src/tests/test-utils.tsx
@@ -119,7 +119,7 @@ export function getAppContextMock(
status: '',
updated_at: '0',
},
- state: LicenseState.ACTIVE,
+ state: LicenseState.ACTIVATED,
status: LicenseStatus.VALID,
platform: LicensePlatform.CLOUD,
created_at: '0',
diff --git a/frontend/src/types/api/licensesV3/getActive.ts b/frontend/src/types/api/licensesV3/getActive.ts
index 654a70a857..cc12feb15b 100644
--- a/frontend/src/types/api/licensesV3/getActive.ts
+++ b/frontend/src/types/api/licensesV3/getActive.ts
@@ -11,7 +11,7 @@ export enum LicenseStatus {
export enum LicenseState {
DEFAULTED = 'DEFAULTED',
- ACTIVE = 'ACTIVE',
+ ACTIVATED = 'ACTIVATED',
EXPIRED = 'EXPIRED',
ISSUED = 'ISSUED',
EVALUATING = 'EVALUATING',