2022-08-17 03:04:06 +02:00
|
|
|
import { GetServerSideProps } from "next";
|
2022-12-22 15:49:08 +01:00
|
|
|
|
2022-11-21 03:52:24 +01:00
|
|
|
import PersonPage from "../../../components/PersonPage";
|
2022-11-24 20:44:47 +01:00
|
|
|
import { User } from "../../../lib/api";
|
|
|
|
import * as API from "../../../lib/api-fetch";
|
2022-08-17 03:04:06 +02:00
|
|
|
|
|
|
|
interface Props {
|
2022-11-24 20:44:47 +01:00
|
|
|
user: API.User;
|
2022-08-17 03:04:06 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 03:57:30 +01:00
|
|
|
export default function Index({ user }: Props) {
|
2022-11-24 20:44:47 +01:00
|
|
|
return <PersonPage person={new User(user)} />;
|
2022-08-17 03:04:06 +02:00
|
|
|
}
|
|
|
|
|
2022-11-20 16:04:53 +01:00
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
2022-11-24 20:44:47 +01:00
|
|
|
const userName = context.params!.user;
|
|
|
|
if (typeof userName !== "string") return { notFound: true };
|
2022-11-20 16:04:53 +01:00
|
|
|
try {
|
2022-11-24 20:44:47 +01:00
|
|
|
return { props: { user: await API.fetchAPI<User>(`/users/${userName}`) } };
|
2022-11-20 16:04:53 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
return { notFound: true };
|
|
|
|
}
|
2022-11-18 14:11:52 +01:00
|
|
|
};
|