@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
91 lines (90 loc) • 3.02 kB
JavaScript
import { deepMerge, withCollectionHook } from '@websolutespa/payload-utils';
import { options } from '../../options';
import { roles } from '../../types';
import { isRole } from '../access';
import { afterChangeActionHook, beforeChangeActionHook, beforeValidateActionHook } from '../api/action.service';
import { afterCollectionReadHook, collectionIndexGet } from '../api/collection.service';
import { encryptData } from '../encryption';
import { translateCollection } from '../translations';
import { mergeFields } from '../utils';
export const ActionDefault = {
admin: {
group: options.group.actions,
defaultColumns: [
'createdAt',
'_status'
]
},
access: {
create: isRole(roles.Guest, roles.User),
read: isRole(roles.Admin, roles.Contributor),
update: ()=>false,
delete: ()=>false
}
};
/**
* @param {CollectionConfig} config
* @returns {CollectionConfig} Return a `CollectionConfig`.
*/ export const withAction = (config)=>{
const actionConfig = deepMerge(ActionDefault, config);
const defaultFields = [
{
type: 'email',
name: 'email'
},
{
name: 'endUser',
type: 'relationship',
relationTo: options.slug.endUsers
},
{
type: 'collapsible',
label: 'consentPreferences',
fields: [
{
name: 'consentPreferences',
type: 'relationship',
relationTo: options.slug.consentPreference,
hasMany: true
},
{
type: 'checkbox',
name: 'consentsRevoked'
},
{
type: 'date',
name: 'consentsRevokedDate',
admin: {
date: {
pickerAppearance: 'dayAndTime'
}
}
}
]
},
{
name: 'utmz',
type: 'text'
}
];
actionConfig.fields = mergeFields(defaultFields, actionConfig.fields);
// !!! todo check if
if (!actionConfig.endpoints) {
actionConfig.endpoints = [
collectionIndexGet(config.slug)
];
}
withCollectionHook(actionConfig, 'beforeValidate', beforeValidateActionHook(actionConfig));
withCollectionHook(actionConfig, 'beforeChange', beforeChangeActionHook(actionConfig));
withCollectionHook(actionConfig, 'afterChange', afterChangeActionHook(actionConfig));
withCollectionHook(actionConfig, 'afterRead', afterCollectionReadHook(actionConfig));
/*
!!! removed on v3
actionConfig.admin.hooks = {
beforeDuplicate: beforeDuplicateCollectionHook,
};
*/ translateCollection(actionConfig);
encryptData(actionConfig);
return actionConfig;
};
//# sourceMappingURL=withAction.js.map