import { API } from './formFields.config'
import { TAX_RECEIPT_PROFILE_ROUTE } from 'routes/config/routes.config'

// ------------------------------------
// Required fields and fields that are conditionally required
// ------------------------------------


export function _locationToObjectKey (location) {
  return location.replace(/-/, '_').replace(/\//, '')
}

export const FORM_ELEMENTS = {
  [_locationToObjectKey(TAX_RECEIPT_PROFILE_ROUTE)]: {
    [API.FIRST_NAME]: true,
    [API.LAST_NAME]: true,
    [API.SALUTATION_CODE]: true,
    [API.EMAIL]: true,
    [API.TAX_OPTOUT]: true,
    [API.BIRTH_DATE]: {
      [API.TAX_OPTOUT]: {
        value: false
      }
    }
  }
}




@@ -347,16 +347,17 @@
 eplace(/
+%5E
 %5C//, '')
@@ -472,215 +472,1584 @@
 E%5D: 
-true,%0A    %5BAPI.LAST_NAME%5D: true,%0A    %5BAPI.SALUTATION_CODE%5D: true,%0A    %5BAPI.EMAIL%5D: true,%0A    %5BAPI.TAX_OPTOUT%5D: true,%0A    %5BAPI.BIRTH_DATE%5D: %7B%0A      %5BAPI.TAX_OPTOUT%5D: %7B%0A        value: false%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A%0A%0A
+%7B%0A      %5BAPI.REGISTERED_COMPANY%5D: %7B%0A        value: false%0A      %7D%0A    %7D,%0A    %5BAPI.LAST_NAME%5D: %7B%0A      %5BAPI.REGISTERED_COMPANY%5D: %7B%0A        value: false%0A      %7D%0A    %7D,%0A    %5BAPI.SALUTATION_CODE%5D: %7B%0A      %5BAPI.REGISTERED_COMPANY%5D: %7B%0A        value: false%0A      %7D%0A    %7D,%0A    %5BAPI.EMAIL%5D: true,%0A    %5BAPI.TAX_OPTOUT%5D: true,%0A    %5BAPI.BIRTH_DATE%5D: %7B%0A      %5BAPI.TAX_OPTOUT%5D: %7B%0A        value: false%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A%0A/**%0A * Check if current field is required%0A * @param %7Bstring%7D fieldName - i.e. firstName%0A * @param %7Bobject%7D userData - full set of user data%0A * @param %7Bstring%7D pathname - i.e. /user-data%0A * @return %7Bboolean%7D%0A */%0Aexport function checkIfFieldIsRequired (fieldName, userData, pathname) %7B%0A  const key = _locationToObjectKey(pathname)%0A  const fieldValue = FORM_ELEMENTS%5Bkey%5D%5BfieldName%5D%0A  let isRequired = false%0A  if (typeof fieldValue !== 'undefined') %7B%0A    // If there are no dependencies%0A    if (fieldValue === true) %7B%0A      isRequired = true%0A    %7D else %7B%0A      // We check the dependencies%0A      for (let element in fieldValue) %7B%0A        if (fieldValue%5Belement%5D%5B'value'%5D === userData%5Belement%5D) %7B%0A          isRequired = true%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A  return isRequired%0A%7D%0A%0Aexport function showErrorMessage (value, minValue = false, maxValue = false) %7B%0A  let addClass = 'ok'%0A  if (minValue) %7B addClass = (Number(value) %3C= minValue) ? 'error-less' : 'ok' %7D%0A  if (maxValue) %7B addClass = (Number(value) %3E= maxValue) ? 'error-exceed' : 'ok' %7D%0A  if (typeof value === 'undefined' %7C%7C value === '' %7C%7C value === '0' %7C%7C value === '00') %7B%0A    addClass = 'error'%0A  %7D%0A  return addClass%0A%7D
 %0A

Tweak required fields settings