add profileMenu events
This commit is contained in:
parent
2c0a063975
commit
51eaa538f1
1 changed files with 15 additions and 9 deletions
|
|
@ -3,12 +3,26 @@ import { Fragment } from "react";
|
||||||
import { signOut, useSession } from "next-auth/react";
|
import { signOut, useSession } from "next-auth/react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
|
import { usePostHog } from "posthog-js/react";
|
||||||
|
|
||||||
export default function ProfileMenu() {
|
export default function ProfileMenu() {
|
||||||
const { mutateAsync: createBillingPortalSession } =
|
const { mutateAsync: createBillingPortalSession } =
|
||||||
api.stripe.createBillingPortalSession.useMutation();
|
api.stripe.createBillingPortalSession.useMutation();
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
const posthog = usePostHog();
|
||||||
|
|
||||||
|
const openBillingSettings = () => {
|
||||||
|
void createBillingPortalSession().then(({ billingPortalUrl }) => {
|
||||||
|
if (billingPortalUrl) {
|
||||||
|
void push(billingPortalUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
posthog?.capture("billing settings opened", {
|
||||||
|
stripeSubscriptionStatus: session?.user.stripeSubscriptionStatus,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu as="div" className="relative inline-block text-left">
|
<Menu as="div" className="relative inline-block text-left">
|
||||||
|
|
@ -34,15 +48,7 @@ export default function ProfileMenu() {
|
||||||
<Menu.Item>
|
<Menu.Item>
|
||||||
{({ active }) => (
|
{({ active }) => (
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={openBillingSettings}
|
||||||
void createBillingPortalSession().then(
|
|
||||||
({ billingPortalUrl }) => {
|
|
||||||
if (billingPortalUrl) {
|
|
||||||
void push(billingPortalUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
className={`mx-2 flex h-8 w-40 cursor-pointer flex-row content-center rounded-md p-2 ${
|
className={`mx-2 flex h-8 w-40 cursor-pointer flex-row content-center rounded-md p-2 ${
|
||||||
active ? "bg-gray-100" : ""
|
active ? "bg-gray-100" : ""
|
||||||
}`}
|
}`}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue