Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 fix render issue in legal documents #717

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/blog/components/legal/Legal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Link from "next/link";
import { PortableTextBlock } from "sanity";

import LinkButton from "src/components/linkButton/LinkButton";
import { RichText } from "src/components/richText/RichText";
import Text from "src/components/text/Text";
import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { ILink, LinkType } from "studio/lib/interfaces/navigation";

import styles from "./legal.module.css";

Expand All @@ -19,7 +21,17 @@ const extractHeadings = (blocks: PortableTextBlock[]) => {
};

const Legal = ({ document }: { document: LegalDocument }) => {
const headings = extractHeadings(document.richText);
const headings = extractHeadings(document.richText ?? []);

const link: ILink = {
_key: "string",
_type: "internalLink",
linkTitle: "Add legal data",
linkType: LinkType.Internal,
internalLink: {
_ref: `studio/structure/admin;legalDocuments;${document._id}`,
},
};

return (
<div>
Expand Down Expand Up @@ -51,7 +63,18 @@ const Legal = ({ document }: { document: LegalDocument }) => {
</ul>
</div>
<div className={styles.document}>
<RichText value={document.richText} />
{document.richText ? (
<RichText value={document.richText} />
) : (
<section className={styles.document}>
<Text type="body">
It appears that this legal document is missing some
information. Please visit the studio to add the necessary
details.
</Text>
<LinkButton link={link} />
</section>
)}
</div>
</div>
</div>
Expand Down
13 changes: 12 additions & 1 deletion studio/schemas/documents/admin/legalDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ const legalDocument = defineField({
name: legalDocumentID,
type: "document",
title: "Legal Document",
fields: [languageSchemaField, title, titleSlug, richText],
fields: [
languageSchemaField,
title,
titleSlug,
{
...richText,
validation: (Rule) =>
Rule.required().error(
"Content is required. Please add the necessary information to the legal document.",
),
},
],
preview: {
select: {
title: "basicTitle",
Expand Down