fix issue with ssg for resources

This commit is contained in:
Brandon Egger 2023-05-18 20:59:39 -05:00
parent a174aafbf2
commit 9fb09d9585
2 changed files with 22 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import { type NextPage } from "next/types"; import { type NextPage } from "next/types";
import Image from "next/image"; import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
import { useSession } from "next-auth/react"; import { signOut, useSession } from "next-auth/react";
interface QuickLink { interface QuickLink {
label: string; label: string;
@ -97,12 +97,26 @@ const ContactInfo = ({ name, title, email, phone }: ContactInfo) => {
const AdminLogin = () => { const AdminLogin = () => {
const { data: sessionData } = useSession(); const { data: sessionData } = useSession();
if (sessionData?.user) {
return (
<button
onClick={() => {
void signOut();
}}
className="text-sm text-neutral-300 hover:underline"
type="submit"
>
Logout of Site Admin
</button>
);
}
return ( return (
<Link <Link
className="text-sm text-neutral-300 hover:underline" className="text-sm text-neutral-300 hover:underline"
href={sessionData?.user ? "/admin/logout" : "/admin/login"} href="/admin/login"
> >
{sessionData?.user ? "Logout of Site Admin" : "Site Admin Login"} Site Admin Login
</Link> </Link>
); );
}; };

View File

@ -1,6 +1,6 @@
import { type InferGetStaticPropsType, type GetStaticPropsContext } from "next"; import { type InferGetStaticPropsType, type GetStaticPropsContext } from "next";
import { GlobeAltIcon, DocumentIcon } from "@heroicons/react/24/solid"; import { GlobeAltIcon, DocumentIcon } from "@heroicons/react/24/solid";
import { createProxySSGHelpers } from "@trpc/react-query/ssg"; import { createServerSideHelpers } from "@trpc/react-query/server";
import { appRouter } from "~/server/api/root"; import { appRouter } from "~/server/api/root";
import { prisma } from "~/server/db"; import { prisma } from "~/server/db";
import { api } from "~/utils/api"; import { api } from "~/utils/api";
@ -31,20 +31,21 @@ export const getStaticPaths = async () => {
export async function getStaticProps( export async function getStaticProps(
context: GetStaticPropsContext<{ id: string }> context: GetStaticPropsContext<{ id: string }>
) { ) {
const ssg = createProxySSGHelpers({ const helpers = createServerSideHelpers({
router: appRouter, router: appRouter,
ctx: { ctx: {
prisma, prisma,
session: null, session: null,
}, },
}); });
const id = context.params?.id as string; const id = context.params?.id as string;
await ssg.auditoryResource.byId.prefetch({ id }); await helpers.auditoryResource.byId.prefetch({ id });
return { return {
props: { props: {
trpcState: ssg.dehydrate(), trpcState: helpers.dehydrate(),
id, id,
}, },
revalidate: 1, revalidate: 1,