Skip to content

Commit

Permalink
fix(mespapiers): Translate country metadata only if valid
Browse files Browse the repository at this point in the history
If the data is entered via OCR and for backward compatibility,
it is important to check that the `country` metadata is filled in
with the ISO 3166-1 alpha-2 code before translating it.
  • Loading branch information
Merkur39 committed May 17, 2024
1 parent a6fc326 commit 4512b99
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import PropType from 'prop-types'
import React, { useState, useEffect, Fragment } from 'react'

import { getAllCountries } from 'cozy-client/dist/models/country/countries'
import {
getAllCountries,
checkCountryCode
} from 'cozy-client/dist/models/country/countries'
import { getLocalizer } from 'cozy-client/dist/models/country/locales'
import Divider from 'cozy-ui/transpiled/react/Divider'
import List from 'cozy-ui/transpiled/react/List'
Expand All @@ -20,7 +23,7 @@ export const CountryListAdapter = ({
idx
}) => {
const { t, lang } = useI18n()
const translatedFormDataValue = formDataValue
const translatedFormDataValue = checkCountryCode(formDataValue)
? getLocalizer(lang)(`nationalities.${formDataValue}`)
: null
const [searchValue, setSearchValue] = useState(translatedFormDataValue || '')
Expand Down

0 comments on commit 4512b99

Please sign in to comment.