Here you are:
{
name: 'Ajouter un contrat de maintenance',
type: 'single',
fields: [{
field: 'Type de contrat',
type: 'Enum',
enums: [
'Maintenance',
'Assurance'
],
isRequired: true
}, {
field: 'Catégorie de contrat',
type: 'Enum',
enums: [],
isRequired: true
}, {
field: 'Clé de répartition',
type: 'Enum',
enums: [],
isRequired: true
}, {
field: 'N° de contrat',
type: 'String',
isRequired: true
}, {
field: 'Date de début',
type: 'Dateonly',
isRequired: true
}, {
field: 'Date de fin',
type: 'Dateonly',
isRequired: true
}, {
field: 'Préavis en jours',
type: 'Number',
isRequired: true
}, {
field: 'Tacite reconduction',
type: 'Boolean',
defaultValue: false
}, {
field: 'Montant annuel TTC',
type: 'Number',
isRequired: true
}, {
field: 'Commentaire',
type: 'String'
}, {
field: 'Périodicité du contrat d\'assurance',
type: 'Enum',
enums: [
'Mensuelle',
'Trimestrielle',
'Annuelle'
]
}, {
field: 'Recherche fournisseur (3 lettres minimum)',
type: 'String'
}, {
field: 'Fournisseur',
type: 'Enum',
enums: [],
isRequired: true
}, {
field: 'PJ du contrat',
type: 'File',
isRequired: true,
description: 'PDF uniquement'
}],
hooks: {
load: ({ fields, record }) => models.repartitionKeys.findAll({
where: { place_id: record.id }
}).then(repartitionKeys => {
fields['Clé de répartition'].enums = repartitionKeys
.sort(
(a, b) => {
if (a.letter < b.letter) { return -1; }
if (a.letter > b.letter) { return 1; }
return 0;
})
.map(repartitionKey =>
`${repartitionKey.id} - ${repartitionKey.letter}` +
(repartitionKey.displayName ? ` - ${repartitionKey.displayName}` : '') +
(repartitionKey.feesTotal ? ` - ${repartitionKey.feesTotal}` : ''));
return models.maintenanceContractCategories.findAll()
.then(result => {
fields['Catégorie de contrat'].enums = result.sort(
(a, b) => {
if (a.displayName < b.displayName) { return -1; }
if (a.displayName > b.displayName) { return 1; }
return 0;
}).map(category => {
return `${category.displayName.toUpperCase()} - ${category.id}`
});
return fields;
});
}),
change: {
['Recherche fournisseur (3 lettres minimum)']: ({ fields, record }) => {
if (fields['Recherche fournisseur (3 lettres minimum)'].value.length > 2) {
return axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
place_id: '',
provider_name: fields['Recherche fournisseur (3 lettres minimum)'].value,
siret: '',
matricule: ''
}
}).then(res => {
if (res.data && res.data.length > 0) {
fields['Fournisseur'].enums = res.data.map(provider => `${provider.matricule} - ${provider.raison_sociale} - ${provider.site_ville}`)
}
return fields;
});
}
return fields;
}
}
}
}