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.

fix(billing): fix cancel subscription flow failing silently for users without a default mail client (#11622)

SagarRajput-7927951b67aa3
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss
index 6860a6dfe8..eae868c6c0 100644
--- a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.module.scss
@@ -67,3 +67,40 @@
background: var(--secondary-background);
border: 1px solid var(--l1-border);
}
+
+.fallbackBody {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-4);
+}
+
+.fallbackHint {
+ 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(--l2-foreground);
+ margin: 0;
+}
+
+.fallbackEmail {
+ font-size: var(--paragraph-base-500-font-size);
+ font-weight: var(--paragraph-base-500-font-weight);
+ color: var(--l1-foreground);
+ word-break: break-all;
+}
+
+.fallbackActions {
+ display: flex;
+ gap: var(--spacing-3);
+ flex-wrap: wrap;
+ padding-top: var(--padding-4);
+}
+
+.retryLink {
+ box-sizing: border-box;
+ text-decoration: none;
+
+ &:hover {
+ text-decoration: none;
+ }
+}
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx
index cb3d482b3e..d9d074c45c 100644
--- a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.test.tsx
@@ -9,7 +9,37 @@ jest.mock('utils/basePath', () => ({
getBaseUrl: (): string => 'https://test.signoz.io',
}));
+function mockMailto(): {
+ mockClick: jest.Mock;
+ appendSpy: jest.SpyInstance;
+ removeSpy: jest.SpyInstance;
+} {
+ const mockClick = jest.fn();
+ const realCreateElement = document.createElement.bind(document);
+
+ // Create a real anchor so JSDOM's appendChild/removeChild accept it.
+ // Override its click() so no navigation occurs.
+ jest
+ .spyOn(document, 'createElement')
+ .mockImplementation((tag: string, options?: ElementCreationOptions) => {
+ if (tag === 'a') {
+ const anchor = realCreateElement('a') as HTMLAnchorElement;
+ anchor.click = mockClick;
+ return anchor;
+ }
+ return realCreateElement(tag, options);
+ });
+
+ const appendSpy = jest.spyOn(document.body, 'appendChild');
+ const removeSpy = jest.spyOn(document.body, 'removeChild');
+ return { mockClick, appendSpy, removeSpy };
+}
+
describe('CancelSubscriptionBanner', () => {
+ afterEach(() => {
+ jest.restoreAllMocks();
+ });
+
it('renders banner with title and subtitle', () => {
render(<CancelSubscriptionBanner />);
expect(
@@ -35,12 +65,10 @@ describe('CancelSubscriptionBanner', () => {
screen.getByText(/Cancelling your subscription would stop your data/i),
).toBeInTheDocument();
expect(screen.getByText(/Type/i)).toBeInTheDocument();
- expect(
- screen.getByPlaceholderText(/Enter the word cancel/i),
- ).toBeInTheDocument();
+ expect(screen.getByTestId('cancel-confirm-input')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /go back/i })).toBeInTheDocument();
expect(
- screen.getByRole('button', { name: /cancel subscription/i }),
+ screen.getByTestId('cancel-subscription-confirm-btn'),
).toBeInTheDocument();
});
@@ -52,12 +80,10 @@ describe('CancelSubscriptionBanner', () => {
screen.getByRole('button', { name: /cancel subscription/i }),
);
- const confirmButton = screen.getByRole('button', {
- name: /cancel subscription/i,
- });
+ const confirmButton = screen.getByTestId('cancel-subscription-confirm-btn');
expect(confirmButton).toBeDisabled();
- const input = screen.getByPlaceholderText(/Enter the word cancel/i);
+ const input = screen.getByTestId('cancel-confirm-input');
await user.type(input, 'canc');
expect(confirmButton).toBeDisabled();
@@ -73,7 +99,7 @@ describe('CancelSubscriptionBanner', () => {
screen.getByRole('button', { name: /cancel subscription/i }),
);
- const input = screen.getByPlaceholderText(/Enter the word cancel/i);
+ const input = screen.getByTestId('cancel-confirm-input');
await user.type(input, 'cancel');
await user.click(screen.getByRole('button', { name: /go back/i }));
@@ -84,19 +110,11 @@ describe('CancelSubscriptionBanner', () => {
await user.click(
screen.getByRole('button', { name: /cancel subscription/i }),
);
- expect(screen.getByPlaceholderText(/Enter the word cancel/i)).toHaveValue('');
+ expect(screen.getByTestId('cancel-confirm-input')).toHaveValue('');
});
- it('sends mailto to cloud-support with correct subject after typing "cancel"', 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);
- });
+ it('fires mailto via DOM-attached anchor and shows fallback view after confirming', async () => {
+ const { mockClick, appendSpy, removeSpy } = mockMailto();
const user = userEvent.setup({ pointerEventsCheck: 0 });
render(<CancelSubscriptionBanner />);
@@ -104,18 +122,85 @@ describe('CancelSubscriptionBanner', () => {
await user.click(
screen.getByRole('button', { name: /cancel subscription/i }),
);
+ await user.type(screen.getByTestId('cancel-confirm-input'), 'cancel');
+ await user.click(screen.getByTestId('cancel-subscription-confirm-btn'));
+
+ const appendedAnchor = appendSpy.mock.calls
+ .map(([node]) => node)
+ .find(
+ (node): node is HTMLAnchorElement =>
+ node instanceof HTMLAnchorElement && node.href.startsWith('mailto:'),
+ );
+ expect(appendedAnchor).toBeDefined();
+ expect(mockClick).toHaveBeenCalledTimes(1);
+ expect(removeSpy.mock.calls.some(([node]) => node === appendedAnchor)).toBe(
+ true,
+ );
- const input = screen.getByPlaceholderText(/Enter the word cancel/i);
- await user.type(input, 'cancel');
+ expect(
+ screen.getByText(/An email draft has been opened/i),
+ ).toBeInTheDocument();
+ expect(screen.getByText('[email protected]')).toBeInTheDocument();
+ expect(screen.getByTestId('copy-email-template-btn')).toBeInTheDocument();
+ expect(screen.getByTestId('retry-mailto-btn')).toBeInTheDocument();
+ });
+
+ it('copies email template to clipboard when Copy button is clicked', async () => {
+ mockMailto();
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<CancelSubscriptionBanner />);
await user.click(
screen.getByRole('button', { name: /cancel subscription/i }),
);
+ await user.type(screen.getByTestId('cancel-confirm-input'), 'cancel');
+ await user.click(screen.getByTestId('cancel-subscription-confirm-btn'));
- expect(mockAnchor.href).toContain('mailto:[email protected]');
- expect(mockAnchor.href).toContain('Cancel%20My%20SigNoz%20Subscription');
- expect(mockClick).toHaveBeenCalledTimes(1);
+ await user.click(screen.getByTestId('copy-email-template-btn'));
- jest.restoreAllMocks();
+ await waitFor(() =>
+ expect(screen.getByTestId('copy-email-template-btn')).toHaveTextContent(
+ 'Copied!',
+ ),
+ );
+ });
+
+ it('retry link is a native anchor with correct mailto href in fallback view', async () => {
+ mockMailto();
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<CancelSubscriptionBanner />);
+
+ await user.click(
+ screen.getByRole('button', { name: /cancel subscription/i }),
+ );
+ await user.type(screen.getByTestId('cancel-confirm-input'), 'cancel');
+ await user.click(screen.getByTestId('cancel-subscription-confirm-btn'));
+
+ const retryLink = screen.getByTestId('retry-mailto-btn');
+ expect(retryLink.tagName).toBe('A');
+ expect(retryLink).toHaveAttribute(
+ 'href',
+ expect.stringContaining('mailto:[email protected]'),
+ );
+ });
+
+ it('closes fallback view when Close is clicked and resets state', async () => {
+ mockMailto();
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<CancelSubscriptionBanner />);
+
+ await user.click(
+ screen.getByRole('button', { name: /cancel subscription/i }),
+ );
+ await user.type(screen.getByTestId('cancel-confirm-input'), 'cancel');
+ await user.click(screen.getByTestId('cancel-subscription-confirm-btn'));
+
+ await user.click(screen.getByRole('button', { name: /close/i }));
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
});
});
diff --git a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx
index 86b247f853..06e7cfd661 100644
--- a/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx
+++ b/frontend/src/container/BillingContainer/CancelSubscriptionBanner.tsx
@@ -1,27 +1,100 @@
-import { useState } from 'react';
-import { SolidInfoCircle, Undo2, X } from '@signozhq/icons';
+import { useEffect, useRef, useState } from 'react';
+import {
+ CircleCheck,
+ Copy,
+ MailOpen,
+ SolidInfoCircle,
+ Undo2,
+ X,
+} from '@signozhq/icons';
import { Button } from '@signozhq/ui/button';
import { DialogWrapper } from '@signozhq/ui/dialog';
import { Input } from '@signozhq/ui/input';
import logEvent from 'api/common/logEvent';
import { pick } from 'lodash-es';
import { useAppContext } from 'providers/App/App';
+import { useCopyToClipboard } from 'react-use';
import { getBaseUrl } from 'utils/basePath';
+import { Color } from '@signozhq/design-tokens';
import styles from './CancelSubscriptionBanner.module.scss';
-import { Color } from '@signozhq/design-tokens';
+
+const SUPPORT_EMAIL = '[email protected]';
+const MAX_MAILTO_URI_LENGTH = 1800;
+
+type DialogView = 'confirm' | 'fallback';
+
+function buildEmailBody(orgName: string, userEmail: string): string {
+ return [
+ '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: ${userEmail}`,
+ '',
+ 'Reason for Cancellation:',
+ '[Please share the reason for cancellation]',
+ '',
+ 'Additional feedback (optional):',
+ '[Any other feedback]',
+ '',
+ 'Regards,',
+ '[user name or team name]',
+ ].join('\n');
+}
+
+function buildMailtoUri(orgName: string, userEmail: string): string {
+ const subject = encodeURIComponent('Cancel My SigNoz Subscription');
+ const body = encodeURIComponent(buildEmailBody(orgName, userEmail));
+ const full = `mailto:${SUPPORT_EMAIL}?subject=${subject}&body=${body}`;
+ if (full.length <= MAX_MAILTO_URI_LENGTH) {
+ return full;
+ }
+ const shortBody = encodeURIComponent(
+ 'Hi SigNoz Team,\n\nI would like to cancel my SigNoz Cloud subscription.\nPlease find my account details and reason for cancellation below.\n\n[Your details here]\n\nRegards,',
+ );
+ return `mailto:${SUPPORT_EMAIL}?subject=${subject}&body=${shortBody}`;
+}
+
+function openMailto(uri: string): void {
+ const link = document.createElement('a');
+ link.href = uri;
+ link.style.display = 'none';
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+}
function CancelSubscriptionBanner(): JSX.Element {
- const [open, setOpen] = useState(false);
+ const [dialogView, setDialogView] = useState<DialogView | null>(null);
const [confirmText, setConfirmText] = useState('');
+ const [copied, setCopied] = useState(false);
+ const [, copyToClipboard] = useCopyToClipboard();
+ const copyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const { user, org } = useAppContext();
+ useEffect(
+ () => (): void => {
+ if (copyTimerRef.current) {
+ clearTimeout(copyTimerRef.current);
+ }
+ },
+ [],
+ );
+
+ const orgName = org?.[0]?.displayName ?? '';
+ const userEmail = user?.email ?? '';
+
const handleOpenCancelDialog = (): void => {
void logEvent('Billing : Cancel Subscription Clicked', {
user: pick(user, ['email', 'displayName', 'role', 'organization']),
role: user?.role,
});
- setOpen(true);
+ setDialogView('confirm');
};
const handleContactSupport = (): void => {
@@ -29,43 +102,41 @@ function CancelSubscriptionBanner(): JSX.Element {
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);
+ openMailto(buildMailtoUri(orgName, userEmail));
setConfirmText('');
+ setDialogView('fallback');
+ };
+
+ const handleCopyTemplate = (): void => {
+ void logEvent('Billing : Cancel Subscription Email Template Copied', {
+ user: pick(user, ['email', 'displayName', 'role', 'organization']),
+ role: user?.role,
+ });
+ copyToClipboard(buildEmailBody(orgName, userEmail));
+ setCopied(true);
+ if (copyTimerRef.current) {
+ clearTimeout(copyTimerRef.current);
+ }
+ copyTimerRef.current = setTimeout(() => setCopied(false), 2000);
+ };
+
+ const handleRetryMailto = (): void => {
+ void logEvent('Billing : Cancel Subscription Email Client Reopened', {
+ user: pick(user, ['email', 'displayName', 'role', 'organization']),
+ role: user?.role,
+ });
};
const handleClose = (): void => {
- setOpen(false);
+ if (copyTimerRef.current) {
+ clearTimeout(copyTimerRef.current);
+ }
+ setDialogView(null);
setConfirmText('');
+ setCopied(false);
};
- const footer = (
+ const confirmFooter = (
<>
<Button
variant="solid"
@@ -81,12 +152,19 @@ function CancelSubscriptionBanner(): JSX.Element {
prefix={<X size={14} />}
disabled={confirmText !== 'cancel'}
onClick={handleContactSupport}
+ data-testid="cancel-subscription-confirm-btn"
>
Cancel subscription
</Button>
</>
);
+ const fallbackFooter = (
+ <Button variant="solid" color="secondary" onClick={handleClose}>
+ Close
+ </Button>
+ );
+
return (
<>
<div className={styles.banner}>
@@ -111,27 +189,67 @@ function CancelSubscriptionBanner(): JSX.Element {
</Button>
</div>
<DialogWrapper
- open={open}
+ open={dialogView !== null}
onOpenChange={handleClose}
title="Cancel your subscription?"
width="narrow"
showCloseButton={false}
- footer={footer}
+ footer={dialogView === 'confirm' ? confirmFooter : fallbackFooter}
>
- <div className={styles.dialogBody}>
- <p className={styles.dialogDescription}>
- Cancelling your subscription would stop your data from being ingested to
- SigNoz. All the data that has been already sent will also be deleted.
- </p>
- <p className={styles.dialogConfirmLabel}>
- Type <code>cancel</code> to confirm the cancellation.
- </p>
- <Input
- placeholder="Enter the word cancel..."
- value={confirmText}
- onChange={(e): void => setConfirmText(e.target.value)}
- />
- </div>
+ {dialogView === 'confirm' && (
+ <div className={styles.dialogBody}>
+ <p className={styles.dialogDescription}>
+ Cancelling your subscription would stop your data from being ingested to
+ SigNoz. All the data that has been already sent will also be deleted.
+ </p>
+ <p className={styles.dialogConfirmLabel}>
+ Type <code>cancel</code> to confirm the cancellation.
+ </p>
+ <Input
+ placeholder="Enter the word cancel..."
+ value={confirmText}
+ onChange={(e): void => setConfirmText(e.target.value)}
+ data-testid="cancel-confirm-input"
+ />
+ </div>
+ )}
+ {dialogView === 'fallback' && (
+ <div className={styles.fallbackBody}>
+ <p className={styles.fallbackHint}>
+ An email draft has been opened. If it did not open, send your
+ cancellation request directly to:
+ </p>
+ <span className={styles.fallbackEmail}>{SUPPORT_EMAIL}</span>
+ <div className={styles.fallbackActions}>
+ <Button
+ variant="outlined"
+ color="secondary"
+ prefix={copied ? <CircleCheck size={14} /> : <Copy size={14} />}
+ onClick={handleCopyTemplate}
+ data-testid="copy-email-template-btn"
+ >
+ {copied ? 'Copied!' : 'Copy email template'}
+ </Button>
+ <Button
+ asChild
+ variant="outlined"
+ color="secondary"
+ data-testid="retry-mailto-btn"
+ >
+ <a
+ href={buildMailtoUri(orgName, userEmail)}
+ onClick={handleRetryMailto}
+ className={styles.retryLink}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <MailOpen size={14} />
+ Reopen email client
+ </a>
+ </Button>
+ </div>
+ </div>
+ )}
</DialogWrapper>
</>
);