feat: upgrade to pro via auth client
This commit is contained in:
@@ -1,37 +1,42 @@
|
|||||||
import { t } from "@lingui/core/macro";
|
import { t } from "@lingui/core/macro";
|
||||||
|
|
||||||
|
import { authClient } from "@kan/auth/client";
|
||||||
|
|
||||||
import Button from "~/components/Button";
|
import Button from "~/components/Button";
|
||||||
import { useModal } from "~/providers/modal";
|
import { useModal } from "~/providers/modal";
|
||||||
|
import { usePopup } from "~/providers/popup";
|
||||||
|
|
||||||
export function CustomURLConfirmation({
|
export function CustomURLConfirmation({
|
||||||
|
userId,
|
||||||
workspacePublicId,
|
workspacePublicId,
|
||||||
}: {
|
}: {
|
||||||
|
userId: string;
|
||||||
workspacePublicId: string;
|
workspacePublicId: string;
|
||||||
}) {
|
}) {
|
||||||
const { closeModal, entityId } = useModal();
|
const { closeModal, entityId } = useModal();
|
||||||
|
const { showPopup } = usePopup();
|
||||||
|
|
||||||
const handleUpgrade = async () => {
|
const handleUpgrade = async () => {
|
||||||
try {
|
const { data, error } = await authClient.subscription.upgrade({
|
||||||
const response = await fetch("/api/stripe/create_checkout_session", {
|
plan: "pro",
|
||||||
method: "POST",
|
referenceId: workspacePublicId,
|
||||||
headers: {
|
metadata: { userId, workspacePublicId, workspaceSlug: entityId },
|
||||||
"Content-Type": "application/json",
|
successUrl: "/settings",
|
||||||
},
|
cancelUrl: "/settings",
|
||||||
body: JSON.stringify({
|
returnUrl: "/settings",
|
||||||
slug: entityId,
|
disableRedirect: true,
|
||||||
workspacePublicId: workspacePublicId,
|
});
|
||||||
cancelUrl: "/settings",
|
|
||||||
successUrl: "/settings",
|
if (data?.url) {
|
||||||
}),
|
window.location.href = data.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
showPopup({
|
||||||
|
header: t`Error upgrading subscription`,
|
||||||
|
message: t`Please try again later, or contact customer support.`,
|
||||||
|
icon: "error",
|
||||||
});
|
});
|
||||||
|
|
||||||
const { url } = (await response.json()) as { url: string };
|
|
||||||
|
|
||||||
if (url) {
|
|
||||||
window.location.href = url;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating checkout session:", error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user