Skip to content

Commit

Permalink
Merge branch 'v3' into add-translations-to-richText
Browse files Browse the repository at this point in the history
  • Loading branch information
christinaroise committed Sep 27, 2024
2 parents 607b82b + 3508727 commit 1257a27
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,8 +42,8 @@ export default async function Layout({
{ perspective },
),
loadStudioQuery<LegalDocument[]>(
LEGAL_DOCUMENTS_QUERY,
{},
LEGAL_DOCUMENTS_BY_LANG_QUERY,
{ language: "en" }, //TODO: replace this with selected language for the page
{ perspective },
),
loadStudioQuery<BrandAssets>(BRAND_ASSETS_QUERY, {}, { perspective }),
Expand Down
7 changes: 4 additions & 3 deletions src/app/(main)/legal/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -20,8 +20,8 @@ async function Page({ params }: Props) {
const { perspective, isDraftMode } = getDraftModeInfo();

const initialDocument = await loadStudioQuery<LegalDocument>(
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 },
);

Expand All @@ -32,6 +32,7 @@ async function Page({ params }: Props) {
if (isDraftMode) {
return <LegalPreview initialDocument={initialDocument} />;
}

if (initialDocument) {
return <Legal document={initialDocument.data} />;
}
Expand Down
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
4 changes: 2 additions & 2 deletions src/components/navigation/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -63,7 +63,7 @@ const Footer = ({
},
};
return (
<li key={legal.slug.current}>
<li key={legal._id}>
<CustomLink link={link} type="footerLink" />
</li>
);
Expand Down
6 changes: 5 additions & 1 deletion src/customerCases/CustomerCases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => {
const { perspective } = getDraftModeInfo();

const [sharedCustomerCases] = await Promise.all([
loadSharedQuery<CustomerCase[]>(CUSTOMER_CASES_QUERY, {}, { perspective }),
loadSharedQuery<CustomerCase[]>(
CUSTOMER_CASES_QUERY,
{ language: "en" },
{ perspective },
), //TODO: Replace hard coded language with selected language
]);

return (
Expand Down
12 changes: 10 additions & 2 deletions studio/lib/interfaces/legalDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 2 additions & 6 deletions studio/lib/queries/legalDocuments.ts
Original file line number Diff line number Diff line change
@@ -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]`;
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
2 changes: 1 addition & 1 deletion studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
@@ -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]
`;

0 comments on commit 1257a27

Please sign in to comment.