86 lines
4.8 KiB
JavaScript
86 lines
4.8 KiB
JavaScript
import { signedGet, isSuccess } from '@/api/client';
|
|
import { dropdownMap } from '@/api/dropdowns';
|
|
import { splitHash } from '@/helpers/metric';
|
|
|
|
const STATUS = { active: 'Active', disabled: 'Disabled' };
|
|
|
|
function asArray(value) {
|
|
if (Array.isArray(value)) return value.filter((part) => part !== null && part !== undefined && part !== '');
|
|
return splitHash(value);
|
|
}
|
|
|
|
function yesno(value, fallback = 'no') {
|
|
return value ? String(value).toLowerCase() : fallback;
|
|
}
|
|
|
|
const rcpaforms = {
|
|
service: 'rcpa',
|
|
module: 'form',
|
|
title: 'RCPA Form',
|
|
subtitle: 'RCPA',
|
|
baseUrl: '/rcpaform',
|
|
listPath: '/rcpaforms',
|
|
listFields: [
|
|
{ key: 'actions', title: 'Actions', buttons: ['edit', 'delete'] },
|
|
{ key: 'title', title: 'Title', type: 'text' },
|
|
{ key: 'workflow', title: 'Workflow', type: 'text' },
|
|
{ key: 'status', title: 'Status', type: 'select' },
|
|
],
|
|
formFields: async () => {
|
|
const [usersRes, roles, contactRes] = await Promise.all([
|
|
signedGet('ums', 'users/dropdown'),
|
|
dropdownMap('ums', 'roles', (item) => item.name),
|
|
signedGet('contact', 'contactattribute/get_all'),
|
|
]);
|
|
const approvers = { l1manager: 'L1 Manager', l2manager: 'L2 Manager' };
|
|
const userItems = isSuccess(usersRes) ? usersRes.data?.items || [] : [];
|
|
userItems.forEach((user) => {
|
|
if (!user?.id) return;
|
|
approvers[user.id] = `${user.firstname || ''} ${user.lastname || ''} (${user.employee_code || ''})`.trim();
|
|
});
|
|
const contactAttributes = {};
|
|
(isSuccess(contactRes) ? contactRes.data?.items || [] : []).forEach((attr) => {
|
|
if (attr?.code) contactAttributes[attr.code] = attr.attribute || attr.code;
|
|
});
|
|
return [
|
|
{ key: 'title', title: 'Title', type: 'text', required: true },
|
|
{ key: 'status', title: 'Status', type: 'select', required: true, values: STATUS },
|
|
{ key: 'metric_submission', title: 'Metric Submission', type: 'yesno', required: true },
|
|
{ key: 'metric_authkey', title: 'Auth Key', type: 'text', required: true },
|
|
{ key: 'manager_de_roles', title: 'Manager Data Entry Roles', type: 'multiselect', values: roles },
|
|
{ key: 'contact_attributes', title: 'Include Doctor Attributes in Export', type: 'multiselect', values: contactAttributes },
|
|
{ key: 'self_notification', title: 'Self Email Notification', type: 'yesno', required: true, fullwidth: true },
|
|
{ key: 'manager1_email_notification', title: '1st Level Manager Email Notification', type: 'yesno', required: true },
|
|
{ key: 'manager1_push_notification', title: '1st Level Manager Mobile Notification', type: 'yesno', required: true },
|
|
{ key: 'manager2_email_notification', title: '2nd Level Manager Email Notification', type: 'yesno', required: true },
|
|
{ key: 'manager2_push_notification', title: '2nd Level Manager Mobile Notification', type: 'yesno', required: true },
|
|
{ key: 'roles_email_notification', title: 'Email Notification to Roles', type: 'multiselect', values: roles },
|
|
{ key: 'roles_push_notification', title: 'Push Notification to Roles', type: 'multiselect', values: roles },
|
|
{ key: 'allow_non_hierarchy_submission', title: 'Allow Non Hierarchy Submission', type: 'yesno', required: true },
|
|
{ key: 'workflow', title: 'Enable Workflow', type: 'yesno', required: true },
|
|
{ key: 'workflow_type', title: 'Workflow type', type: 'select', required: true, values: { single: 'Single Persoon', multiple: 'Multiple person', sequencial: 'Sequencial' } },
|
|
{ key: 'approver_can_edit', title: 'Approver can edit entry', type: 'yesno', required: true },
|
|
{ key: 'is_personalized', title: 'Is Personalization Needed', type: 'yesno', required: true },
|
|
{ key: 'allow_delete_by_user', title: 'Allow Submission Delete by User', type: 'yesno', required: true },
|
|
{ key: 'export_fields', title: 'Export Fields', type: 'textarea', fullwidth: true },
|
|
{ key: 'workflow_approvers', title: 'Metric', type: 'mapping', required: true, approvers, fullwidth: true },
|
|
];
|
|
},
|
|
beforeForm: (item) => ({
|
|
...item,
|
|
self_notification: yesno(item.self_notification),
|
|
manager1_email_notification: yesno(item.manager1_email_notification),
|
|
manager1_push_notification: yesno(item.manager1_push_notification),
|
|
manager2_email_notification: yesno(item.manager2_email_notification),
|
|
manager2_push_notification: yesno(item.manager2_push_notification),
|
|
export_fields: item.export_fields || '',
|
|
manager_de_roles: asArray(item.manager_de_roles),
|
|
contact_attributes: asArray(item.contact_attributes),
|
|
roles_email_notification: asArray(item.roles_email_notification),
|
|
roles_push_notification: asArray(item.roles_push_notification),
|
|
workflow_approvers: Array.isArray(item.workflow_approvers) && item.workflow_approvers.length ? item.workflow_approvers : ['l1manager'],
|
|
}),
|
|
};
|
|
|
|
export default rcpaforms;
|