diff --git a/internationalization/supportedLanguages.ts b/internationalization/supportedLanguages.ts index 7cb3a627b..7180bfd79 100644 --- a/internationalization/supportedLanguages.ts +++ b/internationalization/supportedLanguages.ts @@ -33,3 +33,6 @@ export const supportedLanguages: Language[] = [ ]; export const defaultLanguage = supportedLanguages.find((lang) => lang.default); +export function getLanguageById(id: string) { + return supportedLanguages.find((lang) => lang.id === id); +} diff --git a/studio/components/LanguageSelector.tsx b/studio/components/LanguageSelector.tsx index b8c597696..db1ba1a0d 100644 --- a/studio/components/LanguageSelector.tsx +++ b/studio/components/LanguageSelector.tsx @@ -1,17 +1,12 @@ import { Box, Button, Card, Checkbox, Flex, Text, useTheme } from "@sanity/ui"; import React from "react"; -import { PatchEvent, set } from "sanity"; +import { ArrayOfObjectsInputProps, PatchEvent, set } from "sanity"; import { Language, supportedLanguages, } from "internationalization/supportedLanguages"; -interface LanguageSelectorProps { - value?: Language[]; - onChange: (event: PatchEvent) => void; -} - const colorMap = { dark: { selected: "#29356a", @@ -23,7 +18,10 @@ const colorMap = { }, }; -const LanguageSelector = ({ value = [], onChange }: LanguageSelectorProps) => { +const LanguageSelector = ({ + value = [], + onChange, +}: ArrayOfObjectsInputProps) => { const theme = useTheme(); const prefersDark = theme.sanity.v2?.color._dark ?? false; @@ -34,7 +32,6 @@ const LanguageSelector = ({ value = [], onChange }: LanguageSelectorProps) => { const isSelected = value.some((item) => item.id === lang.id); // Prevent deselecting the last remaining language if (isSelected && value.length === 1) { - console.log("Cannot deselect the last remaining language."); return; // Exit early if there's only one language selected } diff --git a/studio/schemas/documents/admin/legalDocuments.ts b/studio/schemas/documents/admin/legalDocuments.ts index 4e6b3aec9..e26641dca 100644 --- a/studio/schemas/documents/admin/legalDocuments.ts +++ b/studio/schemas/documents/admin/legalDocuments.ts @@ -1,7 +1,7 @@ import { defineField } from "sanity"; import languageSchemaField from "internationalization/languageSchemaField"; -import { supportedLanguages } from "internationalization/supportedLanguages"; +import { getLanguageById } from "internationalization/supportedLanguages"; import { richText, title } from "studio/schemas/fields/text"; import { titleSlug } from "studio/schemas/schemaTypes/slug"; @@ -18,9 +18,7 @@ const legalDocument = defineField({ language: "language", }, prepare({ title, language }) { - const languageEntry = supportedLanguages.find( - (lang) => lang.id === language, - )?.title; + const languageEntry = getLanguageById(language)?.title; const languageTitle = languageEntry ? languageEntry diff --git a/studio/studioConfig.tsx b/studio/studioConfig.tsx index 06d7fbf7c..887ae44ca 100644 --- a/studio/studioConfig.tsx +++ b/studio/studioConfig.tsx @@ -3,6 +3,7 @@ import { visionTool } from "@sanity/vision"; import { WorkspaceOptions } from "sanity"; import { presentationTool } from "sanity/presentation"; import { structureTool } from "sanity/structure"; +import { internationalizedArray } from "sanity-plugin-internationalized-array"; import { media } from "sanity-plugin-media"; import { languageID } from "internationalization/languageSchemaField"; @@ -12,7 +13,6 @@ import { deskStructure } from "./deskStructure"; import { apiVersion, dataset, projectId } from "./env"; import { schema } from "./schema"; import { legalDocumentID } from "./schemas/documents/admin/legalDocuments"; -import { internationalizedArray } from "sanity-plugin-internationalized-array"; const config: WorkspaceOptions = { name: "studio",