From be8474a027e71bf4ab1aaddeb31a3eafc7394150 Mon Sep 17 00:00:00 2001 From: Ane Date: Thu, 26 Sep 2024 11:08:38 +0200 Subject: [PATCH] controlls if richtext in legal document is missing, and add information if it does. Also made richtext required --- src/blog/components/legal/Legal.tsx | 28 +++++++++++++++++-- .../schemas/documents/admin/legalDocuments.ts | 13 ++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/blog/components/legal/Legal.tsx b/src/blog/components/legal/Legal.tsx index c010ffc20..f1b6eab5b 100644 --- a/src/blog/components/legal/Legal.tsx +++ b/src/blog/components/legal/Legal.tsx @@ -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"; @@ -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 (
@@ -51,7 +64,18 @@ const Legal = ({ document }: { document: LegalDocument }) => {
- + {document.richText ? ( + + ) : ( +
+ + It appears that this legal document is missing some + information. Please visit the studio to add the necessary + details. + + +
+ )}
diff --git a/studio/schemas/documents/admin/legalDocuments.ts b/studio/schemas/documents/admin/legalDocuments.ts index e26641dca..6fafb5724 100644 --- a/studio/schemas/documents/admin/legalDocuments.ts +++ b/studio/schemas/documents/admin/legalDocuments.ts @@ -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",