2
0
Files
cal/calcom/apps/web/app/WithAppDirSsg.tsx

25 lines
741 B
TypeScript
Raw Normal View History

2024-08-09 00:39:27 +02:00
import type { GetStaticProps, GetStaticPropsContext } from "next";
import { notFound, redirect } from "next/navigation";
export const withAppDirSsg =
<T extends Record<string, any>>(getStaticProps: GetStaticProps<T>) =>
async (context: GetStaticPropsContext) => {
const ssgResponse = await getStaticProps(context);
if ("redirect" in ssgResponse) {
redirect(ssgResponse.redirect.destination);
}
if ("notFound" in ssgResponse) {
notFound();
}
const props = await Promise.resolve(ssgResponse.props);
return {
...ssgResponse.props,
// includes dehydratedState required for future page trpcPropvider
...("trpcState" in props && { dehydratedState: props.trpcState }),
};
};