diff --git a/src/components/customerCases/CustomerCases.tsx b/src/components/customerCases/CustomerCases.tsx index 1ca7f3e36..442b5d75e 100644 --- a/src/components/customerCases/CustomerCases.tsx +++ b/src/components/customerCases/CustomerCases.tsx @@ -1,3 +1,4 @@ +import { headers } from "next/headers"; import Link from "next/link"; import { SanitySharedImage } from "src/components/image/SanityImage"; @@ -5,6 +6,7 @@ import LinkButton from "src/components/linkButton/LinkButton"; import Text from "src/components/text/Text"; import { sharedCustomerCasesLink } from "src/components/utils/linkTypes"; import { getDraftModeInfo } from "src/utils/draftmode"; +import { domainFromHostname } from "src/utils/url"; import { CustomerCasePage } from "studio/lib/interfaces/specialPages"; import { CustomerCaseBase } from "studioShared/lib/interfaces/customerCases"; import { CUSTOMER_CASES_QUERY } from "studioShared/lib/queries/customerCases"; @@ -19,14 +21,18 @@ interface CustomerCasesProps { const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => { const { perspective } = getDraftModeInfo(); + const domain = domainFromHostname(headers().get("host")); + const [sharedCustomerCases] = await Promise.all([ loadSharedQuery( CUSTOMER_CASES_QUERY, - { language: customerCasesPage.language }, + { language: customerCasesPage.language, domain }, { perspective }, ), ]); + console.log(sharedCustomerCases); + return (
diff --git a/src/utils/pageData.ts b/src/utils/pageData.ts index a161b2c42..e24e8d8eb 100644 --- a/src/utils/pageData.ts +++ b/src/utils/pageData.ts @@ -37,6 +37,7 @@ import { customerCaseID } from "studioShared/schemas/documents/customerCase"; import { emailFromAliasAndHostname, fetchChewbaccaEmployee } from "./employees"; import { isNonNullQueryResponse } from "./queryResponse"; +import { domainFromHostname } from "./url"; type PageFromParams = { queryResponse: D; @@ -150,6 +151,7 @@ async function fetchCompensationsPage({ async function fetchCustomerCase({ language, + hostname, path, perspective, }: PageDataParams): Promise< @@ -166,6 +168,9 @@ async function fetchCustomerCase({ if (path.length === 0) { return null; } + + const domain = hostname === null ? null : domainFromHostname(hostname); + const customerCasesPageResult = await loadStudioQuery( CUSTOMER_CASES_PAGE_QUERY, @@ -197,6 +202,7 @@ async function fetchCustomerCase({ const customerCaseResult = await loadSharedQuery( CUSTOMER_CASE_QUERY, { + domain, slug: path[1], language, }, diff --git a/studioShared/lib/interfaces/customerCases.ts b/studioShared/lib/interfaces/customerCases.ts index c7f4ed9ab..c3b46808c 100644 --- a/studioShared/lib/interfaces/customerCases.ts +++ b/studioShared/lib/interfaces/customerCases.ts @@ -46,6 +46,7 @@ export interface CustomerCaseBase { _id: string; language: string; slug: string; + domains: string[]; basicTitle: string; description: string; image: IImage; diff --git a/studioShared/lib/queries/customerCases.ts b/studioShared/lib/queries/customerCases.ts index 8477776e2..3ea5efa0e 100644 --- a/studioShared/lib/queries/customerCases.ts +++ b/studioShared/lib/queries/customerCases.ts @@ -13,6 +13,7 @@ const INTERNATIONALIZED_IMAGE_FRAGMENT = groq` const CUSTOMER_CASE_BASE_FRAGMENT = groq` _id, + domains, ${LANGUAGE_FIELD_FRAGMENT}, "slug": ${translatedFieldFragment("slug")}, "basicTitle": ${translatedFieldFragment("basicTitle")}, @@ -23,7 +24,7 @@ const CUSTOMER_CASE_BASE_FRAGMENT = groq` `; export const CUSTOMER_CASES_QUERY = groq` - *[_type == "customerCase"]{ + *[_type == "customerCase" && ($domain == null || $domain in domains)]{ ${CUSTOMER_CASE_BASE_FRAGMENT} } `; @@ -34,7 +35,7 @@ export const SPLIT_SECTIONS_FRAGMENT = groq` "sectionTitle": ${translatedFieldFragment("sectionTitle")}, "text": ${translatedFieldFragment("text")}, url, - textBlockType, + textBlockType, }, _type == "imageBlock" => { "image": image {${INTERNATIONALIZED_IMAGE_FRAGMENT}}, @@ -43,14 +44,14 @@ export const SPLIT_SECTIONS_FRAGMENT = groq` `; export const CUSTOMER_CASE_QUERY = groq` - *[_type == "customerCase" && ${translatedFieldFragment("slug")} == $slug][0] { + *[_type == "customerCase" && ${translatedFieldFragment("slug")} == $slug && ($domain == null || $domain in domains)][0] { ${CUSTOMER_CASE_BASE_FRAGMENT}, "projectInfo": projectInfo { - customer, + customer, "customerSectors": customerSectors[] { "customerSector": ${translatedFieldFragment("customerSectorItem")} }, - url, + url, "deliveries": { "design": deliveries.design[] { "designDelivery": ${translatedFieldFragment("designDelivery")} @@ -62,7 +63,7 @@ export const CUSTOMER_CASE_QUERY = groq` "projectManagementDelivery": ${translatedFieldFragment("projectManagementDelivery")} } }, - collaborators, + collaborators, consultants }, "sections": sections[] { @@ -72,7 +73,7 @@ export const CUSTOMER_CASE_QUERY = groq` "sections": sections[] { _key, _type, - + ${SPLIT_SECTIONS_FRAGMENT} } }, @@ -95,7 +96,7 @@ export const CUSTOMER_CASE_QUERY = groq` _key, "text": ${translatedFieldFragment("text")}, }, - }, + }, _type == "imageBlock" => { "image": image {${INTERNATIONALIZED_IMAGE_FRAGMENT}}, fullWidth diff --git a/studioShared/schemas/documents/customerCase.ts b/studioShared/schemas/documents/customerCase.ts index 987a891d9..2b37f1df4 100644 --- a/studioShared/schemas/documents/customerCase.ts +++ b/studioShared/schemas/documents/customerCase.ts @@ -9,6 +9,7 @@ import { titleSlug } from "studio/schemas/schemaTypes/slug"; import { buildDraftId, buildPublishedId } from "studio/utils/documentUtils"; import { firstTranslation } from "studio/utils/i18n"; import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo"; +import { domainsField } from "studioShared/schemas/fields/domains"; import imageBlock from "studioShared/schemas/objects/imageBlock"; import listBlock from "studioShared/schemas/objects/listBlock"; import resultsBlock from "studioShared/schemas/objects/resultsBlock"; @@ -38,6 +39,7 @@ const customerCase = defineType({ type: "internationalizedArrayString", title: "Title", }), + defineField({ ...domainsField, validation: (rule) => rule.required() }), defineField({ name: "description", type: "internationalizedArrayText", diff --git a/studioShared/schemas/fields/domains.ts b/studioShared/schemas/fields/domains.ts new file mode 100644 index 000000000..c93ec4219 --- /dev/null +++ b/studioShared/schemas/fields/domains.ts @@ -0,0 +1,18 @@ +import { defineField } from "sanity"; + +export const domains = ["variant.no", "variant.se"] as const; + +export const domainsField = defineField({ + name: "domains", + type: "array", + title: "Domains", + description: + "The customer case will only be shown on the domains checked here. IMPORTANT: Remember to have translations in the language for the domains you add here!", + of: [{ type: "string" }], + options: { + list: domains.map((domain) => { + return { title: domain, value: domain }; + }), + }, + initialValue: domains.map((domain) => domain), +});