Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

dashboard: billing action feedback, non-admin sidebar crash, chat report save

Carl-Gerhard Lindesvärd2e34b963f42d
diff --git a/apps/start/src/components/chat/tool-results/chat-report-result.tsx b/apps/start/src/components/chat/tool-results/chat-report-result.tsx
index a1fada105..131fa92b1 100644
--- a/apps/start/src/components/chat/tool-results/chat-report-result.tsx
+++ b/apps/start/src/components/chat/tool-results/chat-report-result.tsx
@@ -86,22 +86,27 @@ function ChatReportInner({
report={report as unknown as IReportInput}
/>
</div>
- {value.dashboard_url && (
+ {(value.dashboard_url || !report.id) && (
<div className="flex items-center justify-between gap-2 border-t px-3 py-1.5">
- <a
- className="text-muted-foreground text-sm hover:underline"
- href={value.dashboard_url}
- rel="noopener noreferrer"
- target="_blank"
- >
- Open in dashboard →
- </a>
+ {value.dashboard_url && (
+ <a
+ className="text-muted-foreground text-sm hover:underline"
+ href={value.dashboard_url}
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ Open in dashboard →
+ </a>
+ )}
{!report.id && (
<Button
- className="h-6 text-sm"
+ className="ml-auto h-6 text-sm"
onClick={() =>
pushModal('SaveReport', {
- report: report as unknown as IReport,
+ report: {
+ ...report,
+ name: value.name ?? report.name,
+ } as unknown as IReport,
disableRedirect: true,
})
}
diff --git a/apps/start/src/components/organization/billing-plan-picker.tsx b/apps/start/src/components/organization/billing-plan-picker.tsx
index 14a3dd36b..b4905ec18 100644
--- a/apps/start/src/components/organization/billing-plan-picker.tsx
+++ b/apps/start/src/components/organization/billing-plan-picker.tsx
@@ -31,6 +31,31 @@ const getPrice = (product: IPolarProduct) => {
: 0;
};
+const PolarLogo = ({ className }: { className?: string }) => (
+ <svg
+ className={className}
+ fill="none"
+ height="300"
+ viewBox="0 0 300 300"
+ width="300"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <g clip-path="url(#clip0_1_4)">
+ <path
+ clip-rule="evenodd"
+ d="M66.4284 274.26C134.876 320.593 227.925 302.666 274.258 234.219C320.593 165.771 302.666 72.7222 234.218 26.3885C165.77 -19.9451 72.721 -2.0181 26.3873 66.4297C-19.9465 134.877 -2.01938 227.927 66.4284 274.26ZM47.9555 116.67C30.8375 169.263 36.5445 221.893 59.2454 256.373C18.0412 217.361 7.27564 150.307 36.9437 92.318C55.9152 55.2362 87.5665 29.3937 122.5 18.3483C90.5911 36.7105 62.5549 71.8144 47.9555 116.67ZM175.347 283.137C211.377 272.606 244.211 246.385 263.685 208.322C293.101 150.825 282.768 84.4172 242.427 45.2673C264.22 79.7626 269.473 131.542 252.631 183.287C237.615 229.421 208.385 265.239 175.347 283.137ZM183.627 266.229C207.945 245.418 228.016 210.604 236.936 168.79C251.033 102.693 232.551 41.1978 195.112 20.6768C214.97 47.3945 225.022 99.2902 218.824 157.333C214.085 201.724 200.814 240.593 183.627 266.229ZM63.7178 131.844C49.5155 198.43 68.377 260.345 106.374 280.405C85.9962 254.009 75.5969 201.514 81.8758 142.711C86.5375 99.0536 99.4504 60.737 116.225 35.0969C92.2678 55.983 72.5384 90.4892 63.7178 131.844ZM199.834 149.561C200.908 217.473 179.59 272.878 152.222 273.309C124.853 273.742 101.797 219.039 100.724 151.127C99.6511 83.2138 120.968 27.8094 148.337 27.377C175.705 26.9446 198.762 81.648 199.834 149.561Z"
+ fill="currentColor"
+ fill-rule="evenodd"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_1_4">
+ <rect fill="white" height="300" width="300" />
+ </clipPath>
+ </defs>
+ </svg>
+);
+
export default function BillingPlanPicker({
organization,
currentProduct,
@@ -78,6 +103,7 @@ export default function BillingPlanPicker({
if (data?.url) {
window.location.href = data.url;
} else {
+ setPendingProductId(null);
queryClient.invalidateQueries(
trpc.organization.get.queryOptions({
organizationId: organization.id,
@@ -117,7 +143,7 @@ export default function BillingPlanPicker({
};
const handleCheckout = () => {
- if (!selectedProduct) {
+ if (!selectedProduct || checkoutMutation.isPending) {
return;
}
startCheckout(selectedProduct);
@@ -189,9 +215,18 @@ export default function BillingPlanPicker({
return 'Pay with Polar';
})();
+ // A checkout click charges the card via Polar, so the button must lock
+ // while the request is in flight — otherwise each extra click is another
+ // charge attempt.
+ const isCheckingOut = checkoutMutation.isPending;
+
return (
<button
- className="group mt-4 w-full overflow-hidden rounded-lg transition-all hover:translate-y-[-1px]"
+ className={cn(
+ 'group mt-4 w-full overflow-hidden rounded-lg transition-all',
+ isCheckingOut ? 'cursor-wait opacity-70' : 'hover:translate-y-[-1px]'
+ )}
+ disabled={isCheckingOut}
onClick={handleCheckout}
type="button"
>
@@ -211,28 +246,11 @@ export default function BillingPlanPicker({
<span>{number.currency(getPrice(selectedProduct))}</span>
</div>
<div className="center-center row gap-4 bg-primary p-4 text-primary-foreground transition-colors group-hover:bg-primary/90">
- <svg
- className="size-6"
- fill="none"
- height="300"
- viewBox="0 0 300 300"
- width="300"
- xmlns="http://www.w3.org/2000/svg"
- >
- <g clip-path="url(#clip0_1_4)">
- <path
- clip-rule="evenodd"
- d="M66.4284 274.26C134.876 320.593 227.925 302.666 274.258 234.219C320.593 165.771 302.666 72.7222 234.218 26.3885C165.77 -19.9451 72.721 -2.0181 26.3873 66.4297C-19.9465 134.877 -2.01938 227.927 66.4284 274.26ZM47.9555 116.67C30.8375 169.263 36.5445 221.893 59.2454 256.373C18.0412 217.361 7.27564 150.307 36.9437 92.318C55.9152 55.2362 87.5665 29.3937 122.5 18.3483C90.5911 36.7105 62.5549 71.8144 47.9555 116.67ZM175.347 283.137C211.377 272.606 244.211 246.385 263.685 208.322C293.101 150.825 282.768 84.4172 242.427 45.2673C264.22 79.7626 269.473 131.542 252.631 183.287C237.615 229.421 208.385 265.239 175.347 283.137ZM183.627 266.229C207.945 245.418 228.016 210.604 236.936 168.79C251.033 102.693 232.551 41.1978 195.112 20.6768C214.97 47.3945 225.022 99.2902 218.824 157.333C214.085 201.724 200.814 240.593 183.627 266.229ZM63.7178 131.844C49.5155 198.43 68.377 260.345 106.374 280.405C85.9962 254.009 75.5969 201.514 81.8758 142.711C86.5375 99.0536 99.4504 60.737 116.225 35.0969C92.2678 55.983 72.5384 90.4892 63.7178 131.844ZM199.834 149.561C200.908 217.473 179.59 272.878 152.222 273.309C124.853 273.742 101.797 219.039 100.724 151.127C99.6511 83.2138 120.968 27.8094 148.337 27.377C175.705 26.9446 198.762 81.648 199.834 149.561Z"
- fill="currentColor"
- fill-rule="evenodd"
- />
- </g>
- <defs>
- <clipPath id="clip0_1_4">
- <rect fill="white" height="300" width="300" />
- </clipPath>
- </defs>
- </svg>
+ {isCheckingOut ? (
+ <Loader2Icon className="size-6 animate-spin" />
+ ) : (
+ <PolarLogo className="size-6" />
+ )}
<span className="font-semibold">{payLabel}</span>
</div>
</button>
@@ -316,10 +334,7 @@ export default function BillingPlanPicker({
'text-muted-foreground line-through',
isProductDisabled && '!cursor-not-allowed opacity-50'
)}
- disabled={
- isProductDisabled ||
- (directCheckout && checkoutMutation.isPending)
- }
+ disabled={isProductDisabled || checkoutMutation.isPending}
key={product.id}
onClick={() =>
directCheckout
diff --git a/apps/start/src/components/organization/billing-prompt.tsx b/apps/start/src/components/organization/billing-prompt.tsx
index c1055eafd..c4e7f5e08 100644
--- a/apps/start/src/components/organization/billing-prompt.tsx
+++ b/apps/start/src/components/organization/billing-prompt.tsx
@@ -116,6 +116,9 @@ export default function BillingPrompt({
});
}
},
+ onError(error) {
+ toast.error(error.message);
+ },
})
);
const portal = useMutation(
@@ -241,8 +244,7 @@ export default function BillingPrompt({
op.track('billing_prompt_upgrade_clicked', {
type,
cta: 'checkout',
- price:
- 'priceAmount' in bestPrice ? bestPrice.priceAmount / 100 : 0,
+ price: 'priceAmount' in bestPrice ? bestPrice.priceAmount / 100 : 0,
});
checkout.mutate({
organizationId: organization.id,
@@ -261,7 +263,7 @@ export default function BillingPrompt({
<div className="mx-auto w-full max-w-xl px-4 py-12 md:py-20">
<div className="relative overflow-hidden rounded-lg border bg-card">
<div
- className="pointer-events-none absolute -top-16 -right-16 h-64 w-64 rounded-full opacity-20 blur-3xl"
+ className="-top-16 -right-16 pointer-events-none absolute h-64 w-64 rounded-full opacity-20 blur-3xl"
style={{
background: `radial-gradient(circle, ${copy.gradient} 0%, transparent 70%)`,
}}
diff --git a/apps/start/src/components/organization/billing.tsx b/apps/start/src/components/organization/billing.tsx
index 933cab89c..1eed08932 100644
--- a/apps/start/src/components/organization/billing.tsx
+++ b/apps/start/src/components/organization/billing.tsx
@@ -228,6 +228,7 @@ export default function Billing({ organization }: Props) {
/>
<div className="row mt-4 justify-between">
<Button
+ loading={portalMutation.isPending}
onClick={() =>
portalMutation.mutate({ organizationId: organization.id })
}
diff --git a/apps/start/src/components/organization/cancel-subscription-flow.tsx b/apps/start/src/components/organization/cancel-subscription-flow.tsx
index b675ca384..38a1a5b9f 100644
--- a/apps/start/src/components/organization/cancel-subscription-flow.tsx
+++ b/apps/start/src/components/organization/cancel-subscription-flow.tsx
@@ -259,6 +259,7 @@ export default function CancelSubscriptionFlow({
<ButtonContainer className="shrink-0 gap-2 [&>*]:flex-1">
<Button
disabled={isPending}
+ loading={cancelMutation.isPending}
onClick={() => {
op.track('cancel_pause_declined', {
organizationId: organization.id,
@@ -275,6 +276,7 @@ export default function CancelSubscriptionFlow({
{discountAvailable ? 'No thanks' : 'No thanks, cancel'}
</Button>
<Button
+ disabled={isPending}
loading={pauseMutation.isPending}
onClick={() => {
op.track('cancel_pause_accepted', {
@@ -325,6 +327,7 @@ export default function CancelSubscriptionFlow({
Cancel subscription
</Button>
<Button
+ disabled={isPending}
loading={discountMutation.isPending}
onClick={() => {
op.track('cancel_discount_accepted', {
diff --git a/apps/start/src/components/sidebar-organization-menu.tsx b/apps/start/src/components/sidebar-organization-menu.tsx
index b4551fe2f..b71295e82 100644
--- a/apps/start/src/components/sidebar-organization-menu.tsx
+++ b/apps/start/src/components/sidebar-organization-menu.tsx
@@ -1,4 +1,5 @@
-import { Link } from '@tanstack/react-router';
+import { getSubscriptionStateMeta } from '@openpanel/payments/subscription-state-meta';
+import { Link, useParams } from '@tanstack/react-router';
import { AnimatePresence, motion } from 'framer-motion';
import {
ChevronDownIcon,
@@ -17,12 +18,10 @@ import {
DropdownMenuTrigger,
} from './ui/dropdown-menu';
import { useAppContext } from '@/hooks/use-app-context';
-import { getSubscriptionStateMeta } from '@openpanel/payments/subscription-state-meta';
import { useOrganizationAccess } from '@/hooks/use-organization-access';
import { pushModal } from '@/modals';
import type { RouterOutputs } from '@/trpc/client';
import { cn } from '@/utils/cn';
-import { useParams } from '@tanstack/react-router';
export default function SidebarOrganizationMenu({
organization,
@@ -123,27 +122,38 @@ export function ActionCTAButton() {
];
const [currentActionIndex, setCurrentActionIndex] = useState(0);
+ const actionCount = ACTIONS.length;
useEffect(() => {
+ if (actionCount === 0) {
+ return;
+ }
const interval = setInterval(() => {
- setCurrentActionIndex((prevIndex) => (prevIndex + 1) % ACTIONS.length);
+ setCurrentActionIndex((prevIndex) => (prevIndex + 1) % actionCount);
}, 2000);
return () => clearInterval(interval);
- }, []);
+ }, [actionCount]);
+
+ // Members (non-admins) have no org-level actions; render nothing instead of
+ // indexing into an empty list.
+ const currentAction = ACTIONS[currentActionIndex];
+ if (!currentAction) {
+ return null;
+ }
return (
<div className="mb-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
- type="button"
className={cn(
'group flex w-full items-center gap-2 rounded-md border border-border bg-def-200 px-3 py-2 text-left',
- 'text-[13px] font-medium text-foreground',
+ 'font-medium text-[13px] text-foreground',
'transition-colors hover:bg-def-300',
- 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'
)}
+ type="button"
>
<PlusIcon className="size-5 shrink-0" />
<div className="relative flex h-5 flex-1 items-center overflow-hidden">
@@ -161,7 +171,7 @@ export function ActionCTAButton() {
duration: 0.3,
}}
>
- {ACTIONS[currentActionIndex].label}
+ {currentAction.label}
</motion.span>
</AnimatePresence>
</div>
diff --git a/packages/core/src/modules/assistant/src/report-runner.ts b/packages/core/src/modules/assistant/src/report-runner.ts
index 43c69f49f..07aef2b88 100644
--- a/packages/core/src/modules/assistant/src/report-runner.ts
+++ b/packages/core/src/modules/assistant/src/report-runner.ts
@@ -17,7 +17,10 @@ import type { ServiceDeps } from '../../../services';
import { executeAggregateChart, executeChart } from '../../chart/chart.service';
import { getFunnel } from '../../chart/funnel.service';
import { getSettingsForProject } from '../../organization/organization.service';
-import { getReportById } from '../../report/report.service';
+import {
+ getReportById,
+ type IServiceReport,
+} from '../../report/report.service';
import { getChartStartEndDate } from '../../report/src/chart-dates';
const DEFAULT_DASHBOARD_URL = 'https://dashboard.openpanel.dev';
@@ -63,6 +66,12 @@ export async function runReport(
startDate: string;
endDate: string;
dashboard_url: string;
+ /**
+ * The saved config in the same `zReportInput` shape `runReportFromConfig`
+ * returns, so the chat renderer can draw the chart instead of only
+ * reading the numbers off `data`.
+ */
+ report: Omit<NonNullable<IServiceReport>, 'layout'>;
data: unknown;
}
> {
@@ -83,6 +92,12 @@ export async function runReport(
const { startDate, endDate } = getChartStartEndDate(report, timezone);
const chartInput = { ...report, startDate, endDate, timezone };
+ // `layout` is the dashboard grid position, not part of the chart config —
+ // everything else `transformReport` returns already matches `zReportInput`
+ // (the DB `events` column arrives here as `series`). `id` stays on, so the
+ // renderer can tell an already-saved report from an ad-hoc one.
+ const { layout: _layout, ...config } = report;
+
const meta = {
id: report.id,
name: report.name,
@@ -97,6 +112,7 @@ export async function runReport(
input.projectId,
input.reportId
),
+ report: config,
};
if (report.chartType === 'funnel') {