Files
sign/apps/web/components/layout.tsx

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-03-01 14:26:03 +01:00
import { useEffect } from "react";
import Link from "next/link";
2022-12-06 20:44:21 +01:00
import { useRouter } from "next/router";
2023-01-16 14:25:55 +01:00
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
import { useSubscription } from "@documenso/lib/stripe";
2023-01-11 19:51:22 +01:00
import Navigation from "./navigation";
import { PaperAirplaneIcon } from "@heroicons/react/24/outline";
import { SubscriptionStatus } from "@prisma/client";
2023-04-04 22:02:32 +00:00
import { useSession } from "next-auth/react";
import { BillingWarning } from "./billing-warning";
2022-12-06 14:51:03 +01:00
2023-01-11 19:13:59 +01:00
function useRedirectToLoginIfUnauthenticated() {
const { data: session, status } = useSession();
const loading = status === "loading";
const router = useRouter();
useEffect(() => {
if (!loading && !session) {
router.replace({
pathname: "/login",
query: {
2023-01-16 14:25:55 +01:00
callbackUrl: `${NEXT_PUBLIC_WEBAPP_URL}/${location.pathname}${location.search}`,
2023-01-11 19:13:59 +01:00
},
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loading, session]);
return {
loading: loading && !session,
session,
};
}
2022-12-06 18:24:16 +01:00
export default function Layout({ children }: any) {
2023-01-11 19:13:59 +01:00
useRedirectToLoginIfUnauthenticated();
2023-01-11 18:31:30 +01:00
const { subscription } = useSubscription();
2022-12-06 13:45:23 +01:00
return (
<>
2022-12-06 14:51:03 +01:00
<div className="min-h-full">
<Navigation />
2022-12-06 18:49:38 +01:00
<main>
<BillingWarning />
2022-12-06 20:21:02 +01:00
<div className="mx-auto max-w-7xl sm:px-6 lg:px-8">{children}</div>
2022-12-06 18:49:38 +01:00
</main>
2022-12-06 14:51:03 +01:00
</div>
2022-12-06 13:45:23 +01:00
</>
);
}