diff --git a/apps/sanity/schema/ui/cta.ts b/apps/sanity/schema/ui/cta.ts deleted file mode 100644 index 212e499..0000000 --- a/apps/sanity/schema/ui/cta.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { defineField, defineType } from "sanity" - -export default defineType({ - name: 'cta', - type: 'object', - title: 'Wezwanie do działania', - icon: () => '🗣️', - fields: [ - defineField({ - name: 'text', - type: 'string', - title: 'Tekst', - validation: Rule => Rule.required(), - }), - defineField({ - name: 'href', - type: 'string', - title: 'Link', - description: 'Link relatywny lub absolutny (wymagany protokół https://)', - validation: Rule => - Rule.custom(value => { - if (value && !value.startsWith('#') && !value.startsWith('/') && !value.startsWith('https://')) { - return 'Nieprawidłowy adres URL.'; - } - return true; - }).required(), - }), - ], - preview: { - select: { - title: 'text', - subtitle: 'href', - }, - }, -}); diff --git a/apps/sanity/structure/create-collection.tsx b/apps/sanity/structure/create-collection.tsx new file mode 100644 index 0000000..39b4c0b --- /dev/null +++ b/apps/sanity/structure/create-collection.tsx @@ -0,0 +1,29 @@ +import type { StructureBuilder } from "sanity/structure"; +import { schemaTypes } from "./schema-types"; +import { TYPES_TO_EXCLUDE_PREVIEWS } from "."; +import { Preview } from "./preview"; + +export const createCollection = (S: StructureBuilder, name: string) => { + const { title, icon } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode }; + return S.listItem() + .title(title) + .icon(icon) + .child( + S.documentTypeList(name) + .title(title) + .child(documentId => + S.document() + .documentId(documentId) + .schemaType(name) + .views([ + S.view.form().title('Editor').icon(() => '🖋️'), + ...(!TYPES_TO_EXCLUDE_PREVIEWS.includes(name) ? [ + S.view + .component(Preview) + .title('Preview') + .icon(() => '👀') + ] : []), + ]) + ) + ); +}; diff --git a/apps/sanity/structure/create-singleton.tsx b/apps/sanity/structure/create-singleton.tsx index 6dc063c..adc6590 100644 --- a/apps/sanity/structure/create-singleton.tsx +++ b/apps/sanity/structure/create-singleton.tsx @@ -1,20 +1,7 @@ import type { StructureBuilder } from 'sanity/structure' -import { Iframe, type IframeProps } from 'sanity-plugin-iframe-pane' import { schemaTypes } from "./schema-types"; -import { PREVIEW_DEPLOYMENT_DOMAIN } from '../constants'; - -const Preview = ({ document }: { document: IframeProps['document'] }) => { - const slug = (document.displayed.slug as { current?: string })?.current; - if (!slug) return