Skip to content

Commit

Permalink
controlls if richtext in legal document is missing, and add informati…
Browse files Browse the repository at this point in the history
…on if it does. Also made richtext required
  • Loading branch information
anemne committed Sep 26, 2024
1 parent 079eb60 commit be8474a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
28 changes: 26 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,18 @@ const extractHeadings = (blocks: PortableTextBlock[]) => {
};

const Legal = ({ document }: { document: LegalDocument }) => {
const headings = extractHeadings(document.richText);
console.log(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 +64,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 be8474a

Please sign in to comment.