All files / app/formFields mapCustomFormFieldsFromFormValues.ts

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2630x   30x     19x 19x     32x 1x 1x 1x   31x     32x           19x    
import { forIn, isDate, padStart } from 'lodash';
 
export default function mapCustomFormFieldsFromFormValues(
    customFieldsObject: { [id: string]: any }
): Array<{fieldId: string; fieldValue: string}> {
    const customFields: Array<{fieldId: string; fieldValue: string}> = [];
    forIn(customFieldsObject, (value, key) => {
        let fieldValue: string;
 
        if (isDate(value)) {
            const padMonth = padStart((value.getMonth() + 1).toString(), 2, '0');
            const padDay = padStart((value.getDate()).toString(), 2, '0');
            fieldValue = `${value.getFullYear()}-${padMonth}-${padDay}`;
        } else {
            fieldValue = value;
        }
 
        customFields.push({
            fieldId: key,
            fieldValue,
        });
    });
 
    return customFields;
}