cal.pub0.org/pages/settings/billing.tsx

80 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-09-28 10:27:46 +00:00
import { ExternalLinkIcon } from "@heroicons/react/solid";
import { GetServerSidePropsContext } from "next";
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import SettingsShell from "@components/SettingsShell";
import Shell from "@components/Shell";
import Button from "@components/ui/Button";
2021-06-16 12:44:25 +00:00
2021-08-02 17:29:34 +00:00
export default function Billing() {
2021-06-16 12:44:25 +00:00
return (
<Shell heading="Billing" subtitle="Manage your billing information and cancel your subscription.">
2021-06-16 12:44:25 +00:00
<SettingsShell>
2021-07-30 23:05:38 +00:00
<div className="py-6 lg:pb-8 lg:col-span-9">
2021-09-28 14:07:33 +00:00
<div className="bg-white border sm:rounded-sm">
2021-09-28 10:27:46 +00:00
<div className="px-4 py-5 sm:p-6">
<h3 className="text-lg leading-6 font-medium text-gray-900">
View and manage your billing details
</h3>
<div className="mt-2 max-w-xl text-sm text-gray-500">
<p>View and edit your billing details, as well as cancel your subscription.</p>
</div>
<div className="mt-5">
<form
method="POST"
action={`${process.env.NEXT_PUBLIC_BASE_URL}/api/integrations/stripepayment/portal`}>
<Button type="submit">
Go to the billing portal <ExternalLinkIcon className="ml-1 w-4 h-4" />
</Button>
</form>
</div>
</div>
</div>
<div className="mt-4 bg-gray-50 sm:rounded-sm border">
<div className="px-4 py-5 sm:p-6">
<h3 className="text-lg leading-6 font-medium text-gray-900">Need anything else?</h3>
<div className="mt-2 max-w-xl text-sm text-gray-500">
<p>If you need any further help with billing, our support team are here to help.</p>
</div>
<div className="mt-5">
2021-09-28 14:07:33 +00:00
<Button href="mailto:help@cal.com" color="secondary" type="submit">
2021-09-28 10:27:46 +00:00
Contact our support team
2021-09-28 14:07:33 +00:00
</Button>
2021-09-28 10:27:46 +00:00
</div>
</div>
2021-06-16 12:44:25 +00:00
</div>
</div>
</SettingsShell>
</Shell>
);
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
2021-08-02 17:29:34 +00:00
const session = await getSession(context);
if (!session) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
2021-06-16 12:44:25 +00:00
2021-08-02 17:29:34 +00:00
const user = await prisma.user.findFirst({
where: {
email: session.user.email,
},
select: {
id: true,
username: true,
name: true,
email: true,
bio: true,
avatar: true,
timeZone: true,
weekStart: true,
},
});
2021-06-16 12:44:25 +00:00
2021-08-02 17:29:34 +00:00
return {
props: { session, user },
2021-08-02 17:29:34 +00:00
};
2021-07-30 23:05:38 +00:00
}