Skip to content

Commit

Permalink
V3 fix render issue in legal documents (#717)
Browse files Browse the repository at this point in the history
* controlls if richtext in legal document is missing, and add information if it does. Also made richtext required

* Update src/blog/components/legal/Legal.tsx

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

---------

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>
  • Loading branch information
anemne and mathiazom authored Sep 27, 2024
1 parent 079eb60 commit 3508727
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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

0 comments on commit 3508727

Please sign in to comment.