pronounsfu/frontend/pages/u/[user]/[member].tsx

33 lines
898 B
TypeScript
Raw Normal View History

2022-10-27 08:11:10 -07:00
import { GetServerSideProps } from "next";
2022-11-20 19:16:07 -08:00
import PersonPage from "../../../components/PersonPage";
import { Member } from "../../../lib/api";
import * as API from "../../../lib/api-fetch";
2022-10-27 08:11:10 -07:00
interface Props {
member: API.Member;
2022-10-27 08:11:10 -07:00
}
export default function MemberPage({ member }: Props) {
return <PersonPage person={new Member(member)} />;
2022-10-27 08:11:10 -07:00
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const userName = context.params!.user;
if (typeof userName !== "string") return { notFound: true };
const memberName = context.params!.member;
if (typeof memberName !== "string") return { notFound: true };
2022-10-27 08:11:10 -07:00
try {
return {
props: {
2022-11-24 17:27:46 -08:00
member: await API.fetchAPI<API.Member>(
`/users/${context.params!.user}/members/${context.params!.member}`
),
},
};
2022-10-27 08:11:10 -07:00
} catch (e) {
console.log(e);
return { notFound: true };
}
};