From ace654564ae5717871bb23a77661bbd5850116d3 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Wed, 13 Sep 2023 15:29:08 +0100 Subject: [PATCH 1/3] fix: regressions of flat translations --- src/components/StatePicker/index.js | 3 ++- src/pages/ReimbursementAccount/CompanyStep.js | 2 +- .../settings/Preferences/PriorityModePage.js | 12 +++++----- src/pages/settings/Preferences/ThemePage.js | 10 ++++----- .../Report/NotificationPreferencePage.js | 22 +++++++++++-------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 9653a207c1fb..8c9c3b1b8d65 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -2,6 +2,7 @@ import React, {useState} from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; import styles from '../../styles/styles'; +import CONST from '../../CONST'; import MenuItemWithTopDescription from '../MenuItemWithTopDescription'; import useLocalize from '../../hooks/useLocalize'; import FormHelpMessage from '../FormHelpMessage'; @@ -51,7 +52,7 @@ function StatePicker({value, errorText, onInputChange, forwardedRef, label}) { hidePickerModal(); }; - const title = value ? translate(`allStates.${value}.stateName`) : ''; + const title = value && CONST.ALL_US_ISO_STATES.includes(value) ? translate(`allStates.${value}.stateName`) : ''; const descStyle = title.length === 0 ? styles.textNormal : null; return ( diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index d76d10c9e52c..22133415cea8 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -224,7 +224,7 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul ({value, label}))} + items={_.map(_.keys(CONST.INCORPORATION_TYPES), (key) => ({value: key, label: translate(`companyStep.incorporationTypes.${key}`)}))} placeholder={{value: '', label: '-'}} defaultValue={getDefaultStateForField('incorporationType')} shouldSaveDraft diff --git a/src/pages/settings/Preferences/PriorityModePage.js b/src/pages/settings/Preferences/PriorityModePage.js index b32987e242de..0c3d28fe9d81 100644 --- a/src/pages/settings/Preferences/PriorityModePage.js +++ b/src/pages/settings/Preferences/PriorityModePage.js @@ -26,12 +26,12 @@ const defaultProps = { }; function PriorityModePage(props) { - const priorityModes = _.map(props.translate('priorityModePage.priorityModes'), (mode, key) => ({ - value: key, - text: mode.label, - alternateText: mode.description, - keyForList: key, - isSelected: props.priorityMode === key, + const priorityModes = _.map(_.values(CONST.PRIORITY_MODE), (mode) => ({ + value: mode, + text: props.translate(`priorityModePage.priorityModes.${mode}.label`), + alternateText: props.translate(`priorityModePage.priorityModes.${mode}.description`), + keyForList: mode, + isSelected: props.priorityMode === mode, })); const updateMode = useCallback( diff --git a/src/pages/settings/Preferences/ThemePage.js b/src/pages/settings/Preferences/ThemePage.js index a260caa283e3..4e41d5fc7129 100644 --- a/src/pages/settings/Preferences/ThemePage.js +++ b/src/pages/settings/Preferences/ThemePage.js @@ -27,11 +27,11 @@ const defaultProps = { }; function ThemePage(props) { - const localesToThemes = _.map(props.translate('themePage.themes'), (theme, key) => ({ - value: key, - text: theme.label, - keyForList: key, - isSelected: (props.preferredTheme || CONST.THEME.DEFAULT) === key, + const localesToThemes = _.map(_.values(_.omit(CONST.THEME, 'DEFAULT')), (theme) => ({ + value: theme, + text: props.translate(`themePage.themes.${theme}.label`), + keyForList: theme, + isSelected: (props.preferredTheme || CONST.THEME.DEFAULT) === theme, })); return ( diff --git a/src/pages/settings/Report/NotificationPreferencePage.js b/src/pages/settings/Report/NotificationPreferencePage.js index 9765cf1ae0b4..17bd77a235ce 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.js +++ b/src/pages/settings/Report/NotificationPreferencePage.js @@ -11,6 +11,7 @@ import withReportOrNotFound from '../../home/report/withReportOrNotFound'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; import reportPropTypes from '../../reportPropTypes'; import ROUTES from '../../../ROUTES'; +import CONST from '../../../CONST'; import * as Report from '../../../libs/actions/Report'; import * as ReportUtils from '../../../libs/ReportUtils'; import * as Expensicons from '../../../components/Icon/Expensicons'; @@ -26,17 +27,20 @@ const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; function NotificationPreferencePage(props) { const shouldDisableNotificationPreferences = ReportUtils.shouldDisableSettings(props.report) || ReportUtils.isArchivedRoom(props.report); - const notificationPreferenceOptions = _.map(props.translate('notificationPreferencesPage.notificationPreferences'), (preference, key) => ({ - value: key, - text: preference, - keyForList: key, + const notificationPreferenceOptions = _.map( + _.filter(_.values(CONST.REPORT.NOTIFICATION_PREFERENCE), (pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN), + (preference) => ({ + value: preference, + text: props.translate(`notificationPreferencesPage.notificationPreferences.${preference}`), + keyForList: preference, - // Include the green checkmark icon to indicate the currently selected value - customIcon: key === props.report.notificationPreference ? greenCheckmark : null, + // Include the green checkmark icon to indicate the currently selected value + customIcon: preference === props.report.notificationPreference ? greenCheckmark : null, - // This property will make the currently selected value have bold text - boldStyle: key === props.report.notificationPreference, - })); + // This property will make the currently selected value have bold text + boldStyle: preference === props.report.notificationPreference, + }), + ); return ( From 3cd2e9c9ab496f53a5083a42a6a4d4ca792e3151 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Wed, 13 Sep 2023 15:37:54 +0100 Subject: [PATCH 2/3] fix: missing translate in pronouns --- src/pages/settings/Profile/PronounsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/PronounsPage.js b/src/pages/settings/Profile/PronounsPage.js index fe92281750cb..5f8824046d69 100644 --- a/src/pages/settings/Profile/PronounsPage.js +++ b/src/pages/settings/Profile/PronounsPage.js @@ -31,7 +31,7 @@ function PronounsPage({currentUserPersonalDetails}) { .find((_value) => _value === currentPronounsKey) .value(); - return currentPronounsText || ''; + return currentPronounsText ? translate(`pronouns.${currentPronounsText}`) : ''; }); const filteredPronounsList = useMemo(() => { From 62b96d7b4e5422d652a4addcb89f053407655508 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Wed, 13 Sep 2023 17:28:09 +0100 Subject: [PATCH 3/3] fix: remove const and use from expensify-common instead --- src/CONST.ts | 55 ------------------- .../StatePicker/StateSelectorModal.js | 3 +- src/components/StatePicker/index.js | 5 +- 3 files changed, 5 insertions(+), 58 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index ced657b06e19..2abf5f297c78 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1684,61 +1684,6 @@ const CONST = { ZW: 'Zimbabwe', }, - ALL_US_ISO_STATES: [ - 'AK', - 'AL', - 'AR', - 'AZ', - 'CA', - 'CO', - 'CT', - 'DE', - 'FL', - 'GA', - 'HI', - 'IA', - 'ID', - 'IL', - 'IN', - 'KS', - 'KY', - 'LA', - 'MA', - 'MD', - 'ME', - 'MI', - 'MN', - 'MO', - 'MS', - 'MT', - 'NC', - 'ND', - 'NE', - 'NH', - 'NJ', - 'NM', - 'NV', - 'NY', - 'OH', - 'OK', - 'OR', - 'PA', - 'PR', - 'RI', - 'SC', - 'SD', - 'TN', - 'TX', - 'UT', - 'VA', - 'VT', - 'WA', - 'WI', - 'WV', - 'WY', - 'DC', - ], - // Sources: https://github.com/Expensify/App/issues/14958#issuecomment-1442138427 // https://github.com/Expensify/App/issues/14958#issuecomment-1456026810 COUNTRY_ZIP_REGEX_DATA: { diff --git a/src/components/StatePicker/StateSelectorModal.js b/src/components/StatePicker/StateSelectorModal.js index 0caa2db6849b..bea335840c53 100644 --- a/src/components/StatePicker/StateSelectorModal.js +++ b/src/components/StatePicker/StateSelectorModal.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import React, {useMemo, useEffect} from 'react'; import PropTypes from 'prop-types'; +import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; import CONST from '../../CONST'; import Modal from '../Modal'; import HeaderWithBackButton from '../HeaderWithBackButton'; @@ -53,7 +54,7 @@ function StateSelectorModal({currentState, isVisible, onClose, onStateSelected, const countryStates = useMemo( () => - _.map(CONST.ALL_US_ISO_STATES, (state) => { + _.map(_.keys(COMMON_CONST.STATES), (state) => { const stateName = translate(`allStates.${state}.stateName`); const stateISO = translate(`allStates.${state}.stateISO`); return { diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 8c9c3b1b8d65..142654b82cd1 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -1,8 +1,9 @@ import React, {useState} from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; +import _ from 'underscore'; +import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; import styles from '../../styles/styles'; -import CONST from '../../CONST'; import MenuItemWithTopDescription from '../MenuItemWithTopDescription'; import useLocalize from '../../hooks/useLocalize'; import FormHelpMessage from '../FormHelpMessage'; @@ -52,7 +53,7 @@ function StatePicker({value, errorText, onInputChange, forwardedRef, label}) { hidePickerModal(); }; - const title = value && CONST.ALL_US_ISO_STATES.includes(value) ? translate(`allStates.${value}.stateName`) : ''; + const title = value && _.keys(COMMON_CONST.STATES).includes(value) ? translate(`allStates.${value}.stateName`) : ''; const descStyle = title.length === 0 ? styles.textNormal : null; return (