Add EventTypes and Events collections

This commit is contained in:
2022-07-22 03:43:49 +01:00
parent 42cc681805
commit e47626cfea
3 changed files with 122 additions and 1 deletions

View File

@@ -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;

99
src/collections/Events.ts Normal file
View File

@@ -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;

View File

@@ -1,6 +1,8 @@
import { buildConfig } from 'payload/config'; import { buildConfig } from 'payload/config';
import path from 'path'; import path from 'path';
import EventTypes from './collections/EventTypes';
import Events from './collections/Events';
import Users from './collections/Users'; import Users from './collections/Users';
export default buildConfig({ export default buildConfig({
@@ -9,7 +11,9 @@ export default buildConfig({
user: Users.slug user: Users.slug
}, },
collections: [ collections: [
Users Users,
EventTypes,
Events
], ],
typescript: { typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts') outputFile: path.resolve(__dirname, 'payload-types.ts')