From e47626cfea6763592f0902d66b34706e3c188c06 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 22 Jul 2022 03:43:49 +0100 Subject: [PATCH] Add EventTypes and Events collections --- src/collections/EventTypes.ts | 18 +++++++ src/collections/Events.ts | 99 +++++++++++++++++++++++++++++++++++ src/payload.config.ts | 6 ++- 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/collections/EventTypes.ts create mode 100644 src/collections/Events.ts diff --git a/src/collections/EventTypes.ts b/src/collections/EventTypes.ts new file mode 100644 index 0000000..27c9d3f --- /dev/null +++ b/src/collections/EventTypes.ts @@ -0,0 +1,18 @@ +import { CollectionConfig } from 'payload/types'; + +const EventTypes: CollectionConfig = { + slug: 'event-types', + admin: { + useAsTitle: 'name' + }, + fields: [ + { + name: 'name', + label: 'Name', + type: 'text', + required: true + } + ] +}; + +export default EventTypes; diff --git a/src/collections/Events.ts b/src/collections/Events.ts new file mode 100644 index 0000000..e6bd586 --- /dev/null +++ b/src/collections/Events.ts @@ -0,0 +1,99 @@ +import { CollectionConfig } from 'payload/types'; + +const Events: CollectionConfig = { + slug: 'events', + admin: { + useAsTitle: 'name' + }, + fields: [ + { + name: 'name', + label: 'Name', + type: 'text', + required: true + }, + { + name: 'type', + label: 'Type', + type: 'relationship', + relationTo: [ + 'event-types' + ], + required: true + }, + { + type: 'row', + fields: [ + { + name: 'startDate', + label: 'Start Date', + type: 'date', + required: true, + admin: { + width: '50%', + date: { + pickerAppearance: 'dayOnly' + } + } + }, + { + name: 'endDate', + label: 'End Date', + type: 'date', + validate: (val, { siblingData }) => { + const end = new Date(val).getTime(); + const start = new Date(siblingData.startDate).getTime(); + + if (end >= start) + return true; + + return 'End date must be greater than or equal to the start date'; + }, + admin: { + width: '50%', + date: { + pickerAppearance: 'dayOnly' + } + } + } + ] + }, + { + type: 'row', + fields: [ + { + name: 'startTime', + label: 'Start Time', + type: 'date', + required: true, + admin: { + width: '50%', + date: { + pickerAppearance: 'timeOnly', + timeIntervals: 15, + displayFormat: 'HH:mm', + timeFormat: 'HH:mm' + } + } + }, + { + name: 'endTime', + label: 'End Time', + type: 'date', + admin: { + width: '50%', + date: { + pickerAppearance: 'timeOnly', + timeIntervals: 15, + displayFormat: 'HH:mm', + timeFormat: 'HH:mm' + } + } + } + ] + } + + ] +}; + +export default Events; diff --git a/src/payload.config.ts b/src/payload.config.ts index 71aefdf..5887951 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -1,6 +1,8 @@ import { buildConfig } from 'payload/config'; import path from 'path'; +import EventTypes from './collections/EventTypes'; +import Events from './collections/Events'; import Users from './collections/Users'; export default buildConfig({ @@ -9,7 +11,9 @@ export default buildConfig({ user: Users.slug }, collections: [ - Users + Users, + EventTypes, + Events ], typescript: { outputFile: path.resolve(__dirname, 'payload-types.ts')