<commit_before>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
      }
    }
  }
}


<commit_msg>Tweak required fields settings<commit_after>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]: {
      [API.REGISTERED_COMPANY]: {
        value: false
      }
    },
    [API.LAST_NAME]: {
      [API.REGISTERED_COMPANY]: {
        value: false
      }
    },
    [API.SALUTATION_CODE]: {
      [API.REGISTERED_COMPANY]: {
        value: false
      }
    },
    [API.EMAIL]: true,
    [API.TAX_OPTOUT]: true,
    [API.BIRTH_DATE]: {
      [API.TAX_OPTOUT]: {
        value: false
      }
    }
  }
}

/**
 * Check if current field is required
 * @param {string} fieldName - i.e. firstName
 * @param {object} userData - full set of user data
 * @param {string} pathname - i.e. /user-data
 * @return {boolean}
 */
export function checkIfFieldIsRequired (fieldName, userData, pathname) {
  const key = _locationToObjectKey(pathname)
  const fieldValue = FORM_ELEMENTS[key][fieldName]
  let isRequired = false
  if (typeof fieldValue !== 'undefined') {
    // If there are no dependencies
    if (fieldValue === true) {
      isRequired = true
    } else {
      // We check the dependencies
      for (let element in fieldValue) {
        if (fieldValue[element]['value'] === userData[element]) {
          isRequired = true
        }
      }
    }
  }
  return isRequired
}

export function showErrorMessage (value, minValue = false, maxValue = false) {
  let addClass = 'ok'
  if (minValue) { addClass = (Number(value) <= minValue) ? 'error-less' : 'ok' }
  if (maxValue) { addClass = (Number(value) >= maxValue) ? 'error-exceed' : 'ok' }
  if (typeof value === 'undefined' || value === '' || value === '0' || value === '00') {
    addClass = 'error'
  }
  return addClass
}
{'fraction_non_alphanumeric': 0.18832324670701317, 'fraction_numerical': 0.001067995728017088, 'mean_word_length': 2.3978234582829505, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5993348', 'n_tokens_mistral': 917, 'n_tokens_neox': 904, 'n_words': 201}