diff --git a/apps/dicty-frontpage/src/features/EditablePages/Edit.tsx b/apps/dicty-frontpage/src/features/EditablePages/Edit.tsx new file mode 100644 index 0000000000..fc81fa570b --- /dev/null +++ b/apps/dicty-frontpage/src/features/EditablePages/Edit.tsx @@ -0,0 +1,33 @@ +import { Navigate } from "react-router-dom" +import { useContentBySlugQuery } from "dicty-graphql-schema" +import { pipe } from "fp-ts/function" +import { match, P } from "ts-pattern" +import { GraphQLErrorPage } from "../../common/components/errors/GraphQLErrorPage" +import { EditView } from "./EditView" +import { Loader } from "../../common/components/Loader" +import { useSlug } from "../../common/utils/useSlug" +import { hasNotFoundError } from "../../common/utils/hasNotFoundError" + +const Edit = () => { + const slug = useSlug() + const { loading, error, data } = useContentBySlugQuery({ + variables: { slug }, + }) + + return match({ loading, error, data }) + .with({ loading: true }, () => ) + .with( + { data: { contentBySlug: P.select({ content: P.string }) } }, + (content) => , + ) + .when( + ({ error: error_ }) => pipe(error_, hasNotFoundError), + () => , + ) + .with({ error: P.select(P.not(undefined)) }, (error_) => ( + + )) + .otherwise(() => <> This message should not appear ) +} + +export { Edit }