Files
sign/apps/remix/app/routes/_authenticated+/_layout.tsx

66 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-02-17 22:46:36 +11:00
import { Outlet, redirect } from 'react-router';
2025-01-02 15:33:37 +11:00
2025-02-17 22:46:36 +11:00
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
2025-01-02 15:33:37 +11:00
import { getLimits } from '@documenso/ee/server-only/limits/client';
import { LimitsProvider } from '@documenso/ee/server-only/limits/provider/client';
2025-02-17 22:46:36 +11:00
import { useSession } from '@documenso/lib/client-only/providers/session';
2025-01-02 15:33:37 +11:00
import { getSiteSettings } from '@documenso/lib/server-only/site-settings/get-site-settings';
import { SITE_SETTINGS_BANNER_ID } from '@documenso/lib/server-only/site-settings/schemas/banner';
import { AppBanner } from '~/components/general/app-banner';
import { Header } from '~/components/general/app-header';
import { VerifyEmailBanner } from '~/components/general/verify-email-banner';
import type { Route } from './+types/_layout';
2025-02-17 22:46:36 +11:00
/**
* Don't revalidate (run the loader on sequential navigations)
*
* Update values via providers.
*/
export const shouldRevalidate = () => false;
2025-01-02 15:33:37 +11:00
2025-02-26 18:39:21 +11:00
export async function loader({ request }: Route.LoaderArgs) {
2025-01-02 15:33:37 +11:00
const requestHeaders = Object.fromEntries(request.headers.entries());
2025-02-17 22:46:36 +11:00
const session = await getOptionalSession(request);
if (!session.isAuthenticated) {
2025-02-20 15:06:36 +11:00
throw redirect('/signin');
2025-02-17 22:46:36 +11:00
}
2025-01-02 15:33:37 +11:00
const [limits, banner] = await Promise.all([
2025-02-17 22:46:36 +11:00
getLimits({ headers: requestHeaders }),
2025-01-02 15:33:37 +11:00
getSiteSettings().then((settings) =>
settings.find((setting) => setting.id === SITE_SETTINGS_BANNER_ID),
),
]);
return {
banner,
limits,
};
2025-02-26 18:39:21 +11:00
}
2025-01-02 15:33:37 +11:00
export default function Layout({ loaderData }: Route.ComponentProps) {
2025-02-17 22:46:36 +11:00
const { user, teams } = useSession();
const { banner, limits } = loaderData;
2025-01-02 15:33:37 +11:00
return (
2025-02-17 22:46:36 +11:00
<LimitsProvider initialValue={limits}>
<div id="portal-header"></div>
2025-01-02 15:33:37 +11:00
2025-02-17 22:46:36 +11:00
{!user.emailVerified && <VerifyEmailBanner email={user.email} />}
2025-01-02 15:33:37 +11:00
{banner && <AppBanner banner={banner} />}
<Header user={user} teams={teams} />
<main className="mt-8 pb-8 md:mt-12 md:pb-12">
<Outlet />
</main>
</LimitsProvider>
);
}