2022-09-15 00:27:49 -07:00
|
|
|
import { NextPageWithLayout } from "../_app";
|
|
|
|
import WardrobePage from "../../src/app/WardrobePage";
|
|
|
|
import { GetServerSideProps } from "next";
|
2022-09-15 04:03:51 -07:00
|
|
|
import { gql, loadGraphqlQuery } from "../../src/server/ssr-graphql";
|
2021-11-01 23:03:19 -07:00
|
|
|
|
2022-09-15 04:03:51 -07:00
|
|
|
const WardrobePageWrapper: NextPageWithLayout = () => {
|
|
|
|
return <WardrobePage />;
|
2022-09-15 00:27:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
WardrobePageWrapper.renderWithLayout = (children) => children;
|
2021-11-01 23:03:19 -07:00
|
|
|
|
2022-09-15 00:27:49 -07:00
|
|
|
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
|
|
|
|
const outfitId = params?.outfitId;
|
|
|
|
if (typeof outfitId !== "string") {
|
|
|
|
throw new Error(`assertion failed: outfitId route param is missing`);
|
|
|
|
}
|
|
|
|
|
2022-09-15 04:03:51 -07:00
|
|
|
const { data, errors, graphqlState } = await loadGraphqlQuery({
|
|
|
|
query: gql`
|
|
|
|
query OutfitsOutfitId_GetServerSideProps($outfitId: ID!) {
|
|
|
|
outfit(id: $outfitId) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: { outfitId },
|
|
|
|
});
|
|
|
|
if (errors) {
|
|
|
|
console.warn(
|
|
|
|
`[SSR: /outfits/[outfitId]] Skipping GraphQL preloading, got errors:`
|
|
|
|
);
|
|
|
|
for (const error of errors) {
|
|
|
|
console.warn(`[SSR: /outfits/[outfitId]]`, error);
|
|
|
|
}
|
|
|
|
return { props: { outfit: null, graphqlState: {} } };
|
|
|
|
}
|
|
|
|
if (data?.outfit == null) {
|
2021-11-01 23:03:19 -07:00
|
|
|
return { notFound: true };
|
|
|
|
}
|
|
|
|
|
2022-09-15 04:03:51 -07:00
|
|
|
return { props: { graphqlState } };
|
2022-09-15 00:27:49 -07:00
|
|
|
};
|
2021-11-01 23:03:19 -07:00
|
|
|
|
2022-09-15 00:27:49 -07:00
|
|
|
export default WardrobePageWrapper;
|