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

54 lines
1.3 KiB
TypeScript
Raw Normal View History

import { GetServerSidePropsContext } from "next";
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import SettingsShell from "@components/Settings";
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-06-16 12:44:25 +00:00
<div className="my-6">
<form
method="POST"
action={`${process.env.NEXT_PUBLIC_BASE_URL}/api/integrations/stripepayment/portal`}>
<Button type="submit">Manage billing</Button>
</form>
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
}