Skip to content
Snippets Groups Projects
withCountries.js 727 B
Newer Older
import { withProps } from 'recompose'
import countrylist from 'country-list'

const countryMapper = (c = 'RO') => {
Sebastian Mihalache's avatar
Sebastian Mihalache committed
  switch (c) {
    case 'GB':
      return 'UK'
    case 'RS':
      return 'SRB'
    case 'ME':
      return 'MNT'
    default:
      return c
  }
}

const codeMapper = (c = 'RO') => {
Sebastian Mihalache's avatar
Sebastian Mihalache committed
  switch (c) {
    case 'UK':
      return 'GB'
    case 'SRB':
      return 'RS'
    case 'MNT':
      return 'ME'
    default:
      return c
  }
}

const countries = countrylist()
const countryList = countries
  .getNames()
Sebastian Mihalache's avatar
Sebastian Mihalache committed
  .map(c => ({ value: countryMapper(countries.getCode(c)), label: c }))

export default withProps(() => ({
  countries: countryList,
Sebastian Mihalache's avatar
Sebastian Mihalache committed
  countryLabel: code => countries.getName(codeMapper(code)),