From 3ca42c5705eee2f2138d0b340e4370a34532d4c2 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 30 Jun 2024 13:21:57 +0200 Subject: [PATCH] Added selectable field on languages --- src/collections/Languages/Languages.ts | 29 +++++++++++++++++++------- src/types/collections.ts | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/collections/Languages/Languages.ts b/src/collections/Languages/Languages.ts index 786f338..817c8ba 100644 --- a/src/collections/Languages/Languages.ts +++ b/src/collections/Languages/Languages.ts @@ -2,6 +2,7 @@ import { text } from "payload/dist/fields/validations"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; import { CollectionGroups, Collections } from "../../constants"; +import { rowField } from "../../fields/rowField/rowField"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { importFromStrapi } from "./endpoints/importFromStrapi"; @@ -9,6 +10,7 @@ import { importFromStrapi } from "./endpoints/importFromStrapi"; const fields = { id: "id", name: "name", + selectable: "selectable", } as const satisfies Record; export const Languages = buildCollectionConfig({ @@ -20,7 +22,7 @@ export const Languages = buildCollectionConfig({ defaultSort: fields.name, admin: { useAsTitle: fields.name, - defaultColumns: [fields.name, fields.id], + defaultColumns: [fields.name, fields.id, fields.selectable], disableDuplicate: true, group: CollectionGroups.Meta, pagination: { defaultLimit: 100 }, @@ -43,11 +45,24 @@ export const Languages = buildCollectionConfig({ return text(value, options); }, }, - { - name: fields.name, - type: "text", - unique: true, - required: true, - }, + rowField([ + { + name: fields.name, + type: "text", + unique: true, + required: true, + }, + { + name: fields.selectable, + type: "checkbox", + defaultValue: false, + required: true, + admin: { + description: + "Check this box to make the language available to visitors on the website.\ + Make sure wordings have been translated in that language before making it selectable.", + }, + }, + ]), ], }); diff --git a/src/types/collections.ts b/src/types/collections.ts index 034ff83..fa552dc 100644 --- a/src/types/collections.ts +++ b/src/types/collections.ts @@ -227,6 +227,7 @@ export interface Image { export interface Language { id: string; name: string; + selectable: boolean; } /** * This interface was referenced by `Config`'s JSON-Schema