From c0d417b8af05e8f2228c2f6be82a4aa2cacf5096 Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:13:30 +0200 Subject: [PATCH 1/3] Add a language param to customer case query (#715) * add a lang param to customer case query * replace lang with english --- src/customerCases/CustomerCases.tsx | 6 +++++- studioShared/lib/queries/customerCases.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/customerCases/CustomerCases.tsx b/src/customerCases/CustomerCases.tsx index 9ab8c5615..ced342cf1 100644 --- a/src/customerCases/CustomerCases.tsx +++ b/src/customerCases/CustomerCases.tsx @@ -18,7 +18,11 @@ const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => { const { perspective } = getDraftModeInfo(); const [sharedCustomerCases] = await Promise.all([ - loadSharedQuery(CUSTOMER_CASES_QUERY, {}, { perspective }), + loadSharedQuery( + CUSTOMER_CASES_QUERY, + { language: "en" }, + { perspective }, + ), //TODO: Replace hard coded language with selected language ]); return ( diff --git a/studioShared/lib/queries/customerCases.ts b/studioShared/lib/queries/customerCases.ts index a8b2043c8..c9b243d98 100644 --- a/studioShared/lib/queries/customerCases.ts +++ b/studioShared/lib/queries/customerCases.ts @@ -1,4 +1,4 @@ import { groq } from "next-sanity"; -export const CUSTOMER_CASES_QUERY = groq`*[_type == "customerCase"] +export const CUSTOMER_CASES_QUERY = groq`*[_type == "customerCase" && language == $language] `; From 079eb6007d2b8e75ce477a1815ae0c5113b4b24c Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:13:50 +0200 Subject: [PATCH 2/3] replace legaldocumentquery with language param, to retrieve legal document to spesific lang (#714) --- src/app/(main)/layout.tsx | 6 +++--- src/app/(main)/legal/[id]/page.tsx | 7 ++++--- src/components/navigation/footer/Footer.tsx | 4 ++-- studio/lib/interfaces/legalDocuments.ts | 12 ++++++++++-- studio/lib/queries/legalDocuments.ts | 8 ++------ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/app/(main)/layout.tsx b/src/app/(main)/layout.tsx index 9a4763ff2..9efaac746 100644 --- a/src/app/(main)/layout.tsx +++ b/src/app/(main)/layout.tsx @@ -11,7 +11,7 @@ import { Navigation } from "studio/lib/interfaces/navigation"; import { SocialMediaProfiles } from "studio/lib/interfaces/socialMedia"; import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets"; import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails"; -import { LEGAL_DOCUMENTS_QUERY } from "studio/lib/queries/legalDocuments"; +import { LEGAL_DOCUMENTS_BY_LANG_QUERY } from "studio/lib/queries/legalDocuments"; import { NAV_QUERY } from "studio/lib/queries/navigation"; import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles"; import { loadStudioQuery } from "studio/lib/store"; @@ -42,8 +42,8 @@ export default async function Layout({ { perspective }, ), loadStudioQuery( - LEGAL_DOCUMENTS_QUERY, - {}, + LEGAL_DOCUMENTS_BY_LANG_QUERY, + { language: "en" }, //TODO: replace this with selected language for the page { perspective }, ), loadStudioQuery(BRAND_ASSETS_QUERY, {}, { perspective }), diff --git a/src/app/(main)/legal/[id]/page.tsx b/src/app/(main)/legal/[id]/page.tsx index 9013bad4f..efeda4d0f 100644 --- a/src/app/(main)/legal/[id]/page.tsx +++ b/src/app/(main)/legal/[id]/page.tsx @@ -2,7 +2,7 @@ import Legal from "src/blog/components/legal/Legal"; import LegalPreview from "src/blog/components/legal/LegalPreview"; import { getDraftModeInfo } from "src/utils/draftmode"; import { LegalDocument } from "studio/lib/interfaces/legalDocuments"; -import { LEGAL_DOCUMENT_SLUG_QUERY } from "studio/lib/queries/legalDocuments"; +import { LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY } from "studio/lib/queries/legalDocuments"; import { loadStudioQuery } from "studio/lib/store"; export const dynamic = "force-dynamic"; @@ -20,8 +20,8 @@ async function Page({ params }: Props) { const { perspective, isDraftMode } = getDraftModeInfo(); const initialDocument = await loadStudioQuery( - LEGAL_DOCUMENT_SLUG_QUERY, - { slug: id }, + LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY, + { slug: id, language: "en" }, //TODO: replace this with selected language for the page { perspective }, ); @@ -32,6 +32,7 @@ async function Page({ params }: Props) { if (isDraftMode) { return ; } + if (initialDocument) { return ; } diff --git a/src/components/navigation/footer/Footer.tsx b/src/components/navigation/footer/Footer.tsx index f1c9a400d..8851dd57e 100644 --- a/src/components/navigation/footer/Footer.tsx +++ b/src/components/navigation/footer/Footer.tsx @@ -54,7 +54,7 @@ const Footer = ({ {legalData?.map((legal) => { const path = `legal/${legal.slug.current}`; const link = { - _key: legal._key, + _key: legal._id, _type: legal._type, linkTitle: legal.basicTitle, linkType: LinkType.Internal, @@ -63,7 +63,7 @@ const Footer = ({ }, }; return ( -
  • +
  • ); diff --git a/studio/lib/interfaces/legalDocuments.ts b/studio/lib/interfaces/legalDocuments.ts index 929c3826e..ac02152e7 100644 --- a/studio/lib/interfaces/legalDocuments.ts +++ b/studio/lib/interfaces/legalDocuments.ts @@ -3,9 +3,17 @@ import { PortableTextBlock } from "sanity"; import { Slug } from "./global"; export interface LegalDocument { - _key: string; + _id: string; _type: string; - basicTitle: string; slug: Slug; + basicTitle: string; richText: PortableTextBlock[]; + _translations: Translations[]; +} + +interface Translations { + basicTitle: string; + language: string; + richText: PortableTextBlock[]; + slug: Slug; } diff --git a/studio/lib/queries/legalDocuments.ts b/studio/lib/queries/legalDocuments.ts index 6beeae488..a0aca6b31 100644 --- a/studio/lib/queries/legalDocuments.ts +++ b/studio/lib/queries/legalDocuments.ts @@ -1,9 +1,5 @@ import { groq } from "next-sanity"; -export const LEGAL_DOCUMENTS_QUERY = groq` - *[_type == "legalDocuments"] -`; +export const LEGAL_DOCUMENTS_BY_LANG_QUERY = groq`*[_type == "legalDocument" && language == $language]`; -export const LEGAL_DOCUMENT_SLUG_QUERY = groq` - *[_type == "legalDocuments" && slug.current == $slug][0] -`; +export const LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY = groq`*[_type == "legalDocument" && language == $language && slug.current == $slug][0]`; From 350872769592c92703281e598858fac5a003590c Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Fri, 27 Sep 2024 08:53:23 +0200 Subject: [PATCH 3/3] V3 fix render issue in legal documents (#717) * 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 <24361490+mathiazom@users.noreply.github.com> --------- Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> --- src/blog/components/legal/Legal.tsx | 27 +++++++++++++++++-- .../schemas/documents/admin/legalDocuments.ts | 13 ++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/blog/components/legal/Legal.tsx b/src/blog/components/legal/Legal.tsx index c010ffc20..162d7a864 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,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 (
    @@ -51,7 +63,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",