Add EventTypes and Events collections
This commit is contained in:
99
src/collections/Events.ts
Normal file
99
src/collections/Events.ts
Normal 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;
|
||||
Reference in New Issue
Block a user