2022-12-07 20:53:44 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-10-04 22:54:15 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { HelpScout, useChat } from "react-live-chat-loader";
|
|
|
|
|
2023-01-05 17:00:16 +00:00
|
|
|
import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout";
|
2022-10-04 22:54:15 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2022-10-04 22:54:15 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Button, Meta } from "@calcom/ui";
|
|
|
|
import { FiExternalLink } from "@calcom/ui/components/icon";
|
2022-10-04 22:54:15 +00:00
|
|
|
|
2022-12-07 20:53:44 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2022-10-04 22:54:15 +00:00
|
|
|
interface CtaRowProps {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
children: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CtaRow = ({ title, description, className, children }: CtaRowProps) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<section className={classNames("flex flex-col sm:flex-row", className)}>
|
|
|
|
<div>
|
|
|
|
<h2 className="font-medium">{title}</h2>
|
|
|
|
<p>{description}</p>
|
|
|
|
</div>
|
|
|
|
<div className="flex-shrink-0 pt-3 sm:ml-auto sm:pt-0 sm:pl-3">{children}</div>
|
|
|
|
</section>
|
2023-01-20 22:04:58 +00:00
|
|
|
<hr className="border-gray-200" />
|
2022-10-04 22:54:15 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const BillingView = () => {
|
|
|
|
const { t } = useLocale();
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: user } = trpc.viewer.me.useQuery();
|
2022-10-04 22:54:15 +00:00
|
|
|
const [, loadChat] = useChat();
|
|
|
|
const [showChat, setShowChat] = useState(false);
|
2022-11-10 20:23:56 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const returnTo = router.asPath;
|
|
|
|
const billingHref = `/api/integrations/stripepayment/portal?returnTo=${WEBAPP_URL}${returnTo}`;
|
2022-10-04 22:54:15 +00:00
|
|
|
|
|
|
|
const onContactSupportClick = () => {
|
|
|
|
setShowChat(true);
|
|
|
|
loadChat({ open: true });
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Meta title={t("billing")} description={t("manage_billing_description")} />
|
|
|
|
<div className="space-y-6 text-sm sm:space-y-8">
|
|
|
|
<CtaRow
|
|
|
|
title={t("billing_manage_details_title")}
|
|
|
|
description={t("billing_manage_details_description")}>
|
2023-01-23 23:08:01 +00:00
|
|
|
<Button color="primary" href={billingHref} target="_blank" EndIcon={FiExternalLink}>
|
2022-10-04 22:54:15 +00:00
|
|
|
{t("billing_portal")}
|
|
|
|
</Button>
|
|
|
|
</CtaRow>
|
|
|
|
|
|
|
|
<CtaRow title={t("billing_help_title")} description={t("billing_help_description")}>
|
|
|
|
<Button color="secondary" onClick={onContactSupportClick}>
|
2022-12-07 20:53:44 +00:00
|
|
|
{t("contact_support")}
|
2022-10-04 22:54:15 +00:00
|
|
|
</Button>
|
|
|
|
</CtaRow>
|
|
|
|
{showChat && <HelpScout color="#292929" icon="message" horizontalPosition="right" zIndex="1" />}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
BillingView.getLayout = getLayout;
|
|
|
|
|
2022-12-07 20:53:44 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
|
|
|
const ssr = await ssrInit(context);
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
trpcState: ssr.dehydrate(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-04 22:54:15 +00:00
|
|
|
export default BillingView;
|