2021-09-27 22:57:23 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
|
|
|
|
2021-09-03 20:51:21 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-09-22 19:52:38 +00:00
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
|
|
|
|
import SettingsShell from "@components/Settings";
|
|
|
|
import Shell from "@components/Shell";
|
2021-09-27 22:57:23 +00:00
|
|
|
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 (
|
2021-08-02 14:10:24 +00:00
|
|
|
<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">
|
2021-09-27 22:57:23 +00:00
|
|
|
<form method="POST" action="/api/integrations/stripepayment/portal">
|
|
|
|
<Button type="submit">Manage billing</Button>
|
|
|
|
</form>
|
2021-06-16 12:44:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</SettingsShell>
|
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-27 22:57:23 +00:00
|
|
|
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 {
|
2021-09-24 10:16:46 +00:00
|
|
|
props: { session, user },
|
2021-08-02 17:29:34 +00:00
|
|
|
};
|
2021-07-30 23:05:38 +00:00
|
|
|
}
|