diff --git a/aksel.nav.no/website/sanity/logo.tsx b/aksel.nav.no/website/sanity/logo.tsx new file mode 100644 index 0000000000..bac566c6e6 --- /dev/null +++ b/aksel.nav.no/website/sanity/logo.tsx @@ -0,0 +1,35 @@ +export const AkselLogo = () => ( + + + + + +); diff --git a/aksel.nav.no/website/sanity/sanity.config.tsx b/aksel.nav.no/website/sanity/sanity.config.ts similarity index 59% rename from aksel.nav.no/website/sanity/sanity.config.tsx rename to aksel.nav.no/website/sanity/sanity.config.ts index e9c4323d1c..4e43b5bf09 100644 --- a/aksel.nav.no/website/sanity/sanity.config.tsx +++ b/aksel.nav.no/website/sanity/sanity.config.ts @@ -3,60 +3,58 @@ import { colorInput } from "@sanity/color-input"; import { nbNOLocale } from "@sanity/locale-nb-no"; import { table } from "@sanity/table"; import { visionTool } from "@sanity/vision"; -import React from "react"; -import { FieldProps, defineConfig } from "sanity"; +import { AuthConfig, defineConfig } from "sanity"; import { media } from "sanity-plugin-media"; import { structureTool } from "sanity/structure"; -import { DatabaseIcon, TestFlaskIcon } from "@navikt/aksel-icons"; -import { SANITY_API_VERSION, SANITY_PROJECT_ID } from "./config"; +import { TestFlaskIcon } from "@navikt/aksel-icons"; +import { SANITY_PROJECT_ID } from "./config"; +import { AkselLogo } from "./logo"; import { defaultDocumentNode, publicationFlow, structure } from "./plugins"; import { schema } from "./schema"; -import { InputWithCounter } from "./schema/custom-components"; import { newDocumentsCreator } from "./util"; export const workspaceConfig = defineConfig([ { - ...defaultConfig(), + projectId: SANITY_PROJECT_ID, title: "Aksel", + description: "Production environment for Aksel", name: "default", dataset: "production", basePath: "/admin/prod", - icon: DatabaseIcon, - auth: authStore("production"), + icon: AkselLogo, + auth: authStore(), + scheduledPublishing: { enabled: false }, + schema, + document: { + newDocumentOptions: newDocumentsCreator, + }, + plugins: [ + structureTool({ + title: "Editor", + structure, + defaultDocumentNode, + }), + publicationFlow(), + + /* 3rd-party */ + table(), + codeInput(), + media(), + visionTool(), + colorInput(), + nbNOLocale(), + ], }, { - ...defaultConfig(), - title: "Aksel Dev-miljø", + projectId: SANITY_PROJECT_ID, + title: "Aksel Development", + description: "Development environment for Aksel", name: "dev", dataset: "development", basePath: "/admin/dev", icon: TestFlaskIcon, - auth: authStore("development"), - }, -]); - -function defaultConfig() { - return { - projectId: SANITY_PROJECT_ID, - apiVersion: SANITY_API_VERSION, + auth: authStore(), schema, - scheduledPublishing: { enabled: false }, - form: { - components: { - field: (props: FieldProps) => { - const name = props.schemaType?.name; - - if (name === "string" && props.schemaType?.options?.maxLength) { - return ; - } - - if (name === "text" && props.schemaType?.options?.maxLength) { - return ; - } - return props.renderDefault(props); - }, - }, - }, document: { newDocumentOptions: newDocumentsCreator, }, @@ -76,15 +74,13 @@ function defaultConfig() { colorInput(), nbNOLocale(), ], - }; -} + }, +]); -function authStore(dataset: string) { +function authStore(): AuthConfig { return { redirectOnSingle: false, - mode: "replace" as const, - projectId: SANITY_PROJECT_ID, - dataset, + mode: "replace", providers: [ { name: "saml", diff --git a/aksel.nav.no/website/sanity/schema/custom-components/InputWithCounter.tsx b/aksel.nav.no/website/sanity/schema/custom-components/InputWithCounter.tsx deleted file mode 100644 index c726e86ed0..0000000000 --- a/aksel.nav.no/website/sanity/schema/custom-components/InputWithCounter.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import cl from "clsx"; -import React from "react"; -import { FieldProps } from "sanity"; -import { Box, Detail, VStack } from "@navikt/ds-react"; - -export function InputWithCounter( - props: FieldProps & { - size?: "medium" | "large"; - }, -) { - const { value, schemaType } = props; - - return ( - - {props.renderDefault(props)} - - - ); -} - -function Counter({ - maxLength, - currentLength, -}: { - maxLength: number; - currentLength: number; -}) { - const difference = maxLength - currentLength; - - return ( - - - {difference < 0 - ? `${Math.abs(difference)} tegn for mye` - : `${difference} tegn igjen`} - - - ); -} diff --git a/aksel.nav.no/website/sanity/schema/custom-components/index.ts b/aksel.nav.no/website/sanity/schema/custom-components/index.ts index 7e97708510..7962585d6b 100644 --- a/aksel.nav.no/website/sanity/schema/custom-components/index.ts +++ b/aksel.nav.no/website/sanity/schema/custom-components/index.ts @@ -1,3 +1,2 @@ -export * from "./InputWithCounter"; export * from "./updateInfo"; export * from "./WriteHelp"; diff --git a/aksel.nav.no/website/sanity/schema/documents/presets/ingress.ts b/aksel.nav.no/website/sanity/schema/documents/presets/ingress.ts index a4905d4661..0081ba7244 100644 --- a/aksel.nav.no/website/sanity/schema/documents/presets/ingress.ts +++ b/aksel.nav.no/website/sanity/schema/documents/presets/ingress.ts @@ -8,12 +8,8 @@ export const ingressField = defineField({ type: "text", group: "innhold", rows: 3, - validation: (Rule) => - Rule.required() - .max(210) - .error("Side må ha en ingress og kortere enn 210 tegn."), - options: { - //@ts-expect-error - maxLength is a custom prop not officially supported - maxLength: 210, - }, + validation: (Rule) => [ + Rule.required().min(10), + Rule.max(210).warning("Ingress bør være kortere enn 210 tegn."), + ], }); diff --git a/aksel.nav.no/website/sanity/schema/documents/presets/seo.ts b/aksel.nav.no/website/sanity/schema/documents/presets/seo.ts index 70858cf976..18958ab53f 100644 --- a/aksel.nav.no/website/sanity/schema/documents/presets/seo.ts +++ b/aksel.nav.no/website/sanity/schema/documents/presets/seo.ts @@ -30,10 +30,8 @@ const BaseSEOPreset = { title: "OG-description (valgfri)", description: "Erstatter ingress som OG-description og meta-tag", rows: 3, - options: { - // @ts-expect-error - maxLength is a custom prop not officially supported - maxLength: 160, - }, + validation: (Rule) => + Rule.max(160).warning("OG-beskrivelse bør være kortere enn 160 tegn."), }), { title: "OG-image", diff --git a/aksel.nav.no/website/sanity/schema/documents/presets/title-field.ts b/aksel.nav.no/website/sanity/schema/documents/presets/title-field.ts index 5727adf580..81542b2fc2 100644 --- a/aksel.nav.no/website/sanity/schema/documents/presets/title-field.ts +++ b/aksel.nav.no/website/sanity/schema/documents/presets/title-field.ts @@ -6,13 +6,8 @@ export const titleField = defineField({ type: "string", group: "innhold", description: "Bruk en kort og konsis tittel", - validation: (Rule) => [ - Rule.required().min(3).error("Sidetittel må være på minst 3 tegn"), - Rule.max(60).error("Sidetittel kan ikke være over 60 tegn"), + Rule.required().min(3).error("Sidetittel må være på minst 3 tegn."), + Rule.max(60).warning("Sidetittel bør ikke være over 60 tegn."), ], - options: { - //@ts-expect-error - maxLength is a custom prop not officially supported - maxLength: 60, - }, });