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