Skip to content

Commit

Permalink
V3-translation in customer case page in /studio (#778)
Browse files Browse the repository at this point in the history
* add field translation in customerCasesPage

* add tranlation for title and slug in customerPage

* add SEO response for customerCase

* translation for customer case page

* add translation for seo (#779)
  • Loading branch information
anemne authored Oct 15, 2024
1 parent 4e8cf68 commit ca46b0a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/app/(main)/[lang]/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function seoDataFromPageData(
// TODO
return null;
case "customerCasesPage":
// TODO
return null;
return data.queryResponse.data.seo;
case "pageBuilder":
// TODO
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/components/customerCases/CustomerCases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => {
const [sharedCustomerCases] = await Promise.all([
loadSharedQuery<CustomerCase[]>(
CUSTOMER_CASES_QUERY,
{ language: "en" },
{ language: customerCasesPage.language },
{ perspective },
), //TODO: Replace hard coded language with selected language
),
]);

return (
Expand Down
1 change: 1 addition & 0 deletions src/utils/pageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ async function fetchCustomerCase({
}
const customerCasesPageParams = {
slug: path[0],
language,
};
const customerCasesPageResult =
await loadStudioQuery<CustomerCasePage | null>(
Expand Down
4 changes: 4 additions & 0 deletions studio/lib/interfaces/specialPages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SeoData } from "src/utils/seo";

import { Slug } from "./global";

export interface CustomerCasePage {
Expand All @@ -9,4 +11,6 @@ export interface CustomerCasePage {
basicTitle: string;
page: string;
slug: Slug;
language: string;
seo: SeoData;
}
13 changes: 12 additions & 1 deletion studio/lib/queries/specialPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ export const COMPENSATIONS_PAGE_SITEMAP_QUERY = groq`

//Customer Cases
export const CUSTOMER_CASES_PAGE_QUERY = groq`
*[_type == "customerCasesPage" && slug.current == $slug][0]`;
*[_type == "customerCasesPage" && ${translatedFieldFragment("slug")} == $slug][0]{
...,
"language": $language,
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"seo": ${translatedFieldFragment("seo")} {
"title": seoTitle,
"description": seoDescription,
"imageUrl": seoImage.asset->url,
"keywords": seoKeywords
},
}`;

export const CUSTOMER_CASES_PAGE_SITEMAP_QUERY = groq`
*[_type == "customerCasesPage"][0] {
Expand Down
30 changes: 24 additions & 6 deletions studio/schemas/documents/specialPages/customerCasesPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineType } from "sanity";

import { title } from "studio/schemas/fields/text";
import seo from "studio/schemas/objects/seo";
import { isInternationalizedString } from "studio/lib/interfaces/global";
import { titleID } from "studio/schemas/fields/text";
import { titleSlug } from "studio/schemas/schemaTypes/slug";
import { firstTranslation } from "studio/utils/i18n";

export const customerCasesPageID = "customerCasesPage";

Expand All @@ -12,17 +13,34 @@ const customerCasesPage = defineType({
title: "Customer Cases",
fields: [
{
...title,
name: titleID.basic,
type: "internationalizedArrayString",
title: "Customer Case Page Title",
description:
"Enter the primary title that will be displayed at the top of the customer cases page. This is what users will see when they visit the page.",
},
titleSlug,
seo,
{
...titleSlug,
type: "internationalizedArrayString",
},
{
name: "seo",
type: "internationalizedArraySeo",
},
],
preview: {
select: {
title: "basicTitle",
title: titleID.basic,
},
prepare({ title }) {
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title: firstTranslation(title) ?? undefined,
};
},
},
});
Expand Down

0 comments on commit ca46b0a

Please sign in to comment.