46 lines
720 B
TypeScript
46 lines
720 B
TypeScript
import { CollectionConfig } from 'payload/types';
|
|
|
|
const EventTypes: CollectionConfig = {
|
|
slug: 'event-types',
|
|
access: {
|
|
read: () => true,
|
|
},
|
|
hooks: {
|
|
afterRead: [
|
|
({ doc }) => {
|
|
const hashCode = (str) => {
|
|
let hash = 0;
|
|
|
|
for (let i = 0; i < str.length; i++)
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
|
|
return hash;
|
|
};
|
|
|
|
const pickColour = (str) => {
|
|
return `hsl(${hashCode(str) % 360}, 100%, 65%)`;
|
|
};
|
|
|
|
doc.backgroundColour = pickColour(doc.name);
|
|
|
|
return doc;
|
|
}
|
|
]
|
|
},
|
|
admin: {
|
|
useAsTitle: 'name'
|
|
},
|
|
timestamps: false,
|
|
fields: [
|
|
{
|
|
name: 'name',
|
|
label: 'Name',
|
|
type: 'text',
|
|
required: true
|
|
}
|
|
]
|
|
};
|
|
|
|
export default EventTypes;
|