const { collection } =require('forest-express-mongoose');const { customFieldsStyles } =require('../style/fields-style.js');// This file allows you to add to your Forest UI:// - Smart actions: <https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions>
// - Smart fields: <https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields>// - Smart relationships: <https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship>
// - Smart segments: <https://docs.forestadmin.com/documentation/reference-guide/segments/smart-segments>collection('user', { actions: [], fields: [ { field:'status', type:'String',get: (user) => {// check if the user has a subdocument to returnif (user.onboarding_progress) {// list all your fields from the subdocument you want to displayconstfieldsNameList= ['registered','payment_complete','data_uploaded','location_data_added','data_processed','complete', ]; // create empty string which will be filled with a div per field listed above - this string will be the value returned
let fieldValueList ='';//// iterate over the list of fields and add style that will be used to display the subdocument fieldsfor (index =0; index <fieldsNameList.length; index++) {constfieldName= fieldsNameList[index];let fieldValueStyle =customFieldsStyles.fieldValueStyleRed;if (user.onboarding_progress[fieldName] ===true) { fieldValueStyle =customFieldsStyles.fieldValueStyleGreen; }// insert the div with the field info to the string that will be returned fieldValueList +=`<div style="${customFieldsStyles.fieldDivStyle}"> <span style="${customFieldsStyles.fieldNameStyle}">${fieldName}</span> <span style="${fieldValueStyle}">${user.onboarding_progress[fieldName]}</span> </div>`; }return fieldValueList; } }, }, { field:'visualizations', type: ['String'], reference:'visualization._id', }, ], segments: [],});