From a663d64d38c22a2071ded62c92469953b1bb9d91 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 6 Dec 2023 15:54:55 +0000 Subject: [PATCH 01/11] refactor(typescript): partial migration of countryselector --- ...CountrySelector.js => CountrySelector.tsx} | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) rename src/components/{CountrySelector.js => CountrySelector.tsx} (62%) diff --git a/src/components/CountrySelector.js b/src/components/CountrySelector.tsx similarity index 62% rename from src/components/CountrySelector.js rename to src/components/CountrySelector.tsx index 13fc215f1d8c..696c47f28a00 100644 --- a/src/components/CountrySelector.js +++ b/src/components/CountrySelector.tsx @@ -1,38 +1,29 @@ -import PropTypes from 'prop-types'; -import React, {useEffect} from 'react'; +import React, {ForwardedRef, forwardRef, useEffect} from 'react'; import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; import useThemeStyles from '@styles/useThemeStyles'; +import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import FormHelpMessage from './FormHelpMessage'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; -const propTypes = { +type CountrySelectorProps = { /** Form error text. e.g when no country is selected */ - errorText: PropTypes.string, + errorText?: string; /** Callback called when the country changes. */ - onInputChange: PropTypes.func.isRequired, + onInputChange: (value?: string) => void; /** Current selected country */ - value: PropTypes.string, + value?: keyof typeof CONST.ALL_COUNTRIES; /** inputID used by the Form component */ // eslint-disable-next-line react/no-unused-prop-types - inputID: PropTypes.string.isRequired, - - /** React ref being forwarded to the MenuItemWithTopDescription */ - forwardedRef: PropTypes.func, -}; - -const defaultProps = { - errorText: '', - value: undefined, - forwardedRef: () => {}, + inputID: string; }; -function CountrySelector({errorText, value: countryCode, onInputChange, forwardedRef}) { +function CountrySelector({errorText = '', value: countryCode, onInputChange}: CountrySelectorProps, ref: ForwardedRef) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -50,12 +41,12 @@ function CountrySelector({errorText, value: countryCode, onInputChange, forwarde { const activeRoute = Navigation.getActiveRouteWithoutParams(); - Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY.getRoute(countryCode, activeRoute)); + Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY.getRoute(countryCode ?? '', activeRoute)); }} /> @@ -65,18 +56,6 @@ function CountrySelector({errorText, value: countryCode, onInputChange, forwarde ); } -CountrySelector.propTypes = propTypes; -CountrySelector.defaultProps = defaultProps; CountrySelector.displayName = 'CountrySelector'; -const CountrySelectorWithRef = React.forwardRef((props, ref) => ( - -)); - -CountrySelectorWithRef.displayName = 'CountrySelectorWithRef'; - -export default CountrySelectorWithRef; +export default forwardRef(CountrySelector); From 9a2d896b06c6dbccb345156de27bddd0e3bf3997 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 21 Dec 2023 17:38:18 +0000 Subject: [PATCH 02/11] refactor: remove unused import and apply right ref type --- src/components/CountrySelector.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/CountrySelector.tsx b/src/components/CountrySelector.tsx index 479d33c1faa2..0b3f17ca1c5f 100644 --- a/src/components/CountrySelector.tsx +++ b/src/components/CountrySelector.tsx @@ -7,7 +7,6 @@ import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import FormHelpMessage from './FormHelpMessage'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; -import refPropTypes from './refPropTypes'; type CountrySelectorProps = { /** Form error text. e.g when no country is selected */ @@ -24,7 +23,7 @@ type CountrySelectorProps = { inputID: string; }; -function CountrySelector({errorText = '', value: countryCode, onInputChange}: CountrySelectorProps, ref: ForwardedRef) { +function CountrySelector({errorText = '', value: countryCode, onInputChange}: CountrySelectorProps, ref: ForwardedRef) { const styles = useThemeStyles(); const {translate} = useLocalize(); From ddb7820c21a5bcc5bf6c6dfec794efa95f0773b4 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 5 Jan 2024 22:09:54 -0500 Subject: [PATCH 03/11] add new updateMoneyRequestCategory function --- src/libs/actions/IOU.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index fb4e9f02f1b6..5685f8196425 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1124,6 +1124,21 @@ function updateMoneyRequestTag(transactionID, transactionThreadReportID, tag) { API.write('UpdateMoneyRequestTag', params, onyxData); } +/** + * Updates the category of a money request + * + * @param {String} transactionID + * @param {Number} transactionThreadReportID + * @param {String} category + */ +function updateMoneyRequestCategory(transactionID, transactionThreadReportID, category) { + const transactionChanges = { + category, + }; + const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true); + API.write('UpdateMoneyRequestCategory', params, onyxData); +} + /** * Edits an existing distance request * @@ -3588,6 +3603,7 @@ export { navigateToNextPage, updateMoneyRequestDate, updateMoneyRequestTag, + updateMoneyRequestCategory, updateMoneyRequestAmountAndCurrency, replaceReceipt, detachReceipt, From bd3759bc4bbf7901bf352826a0b4454e6104061d Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 5 Jan 2024 22:10:09 -0500 Subject: [PATCH 04/11] update category logic to use saveCategory --- src/pages/EditRequestPage.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index bc05c110ab2f..dcf27fa4719f 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -158,6 +158,15 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep [transactionTag, transaction.transactionID, report.reportID], ); + const saveCategory = useCallback( + ({category: newCategory}) => { + let updatedCategory = newCategory === transactionCategory ? '' : newCategory; + IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory); + Navigation.dismissModal(); + }, + [transactionCategory, transaction.transactionID, report.reportID], + ); + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( { - let updatedCategory = transactionChanges.category; - // In case the same category has been selected, do reset of the category. - if (transactionCategory === updatedCategory) { - updatedCategory = ''; - } - editMoneyRequest({category: updatedCategory}); - }} + onSubmit={saveCategory} /> ); } From f8138f648e0ed2414fc521cefa52c4fecd0e0c00 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 8 Jan 2024 18:03:41 +0300 Subject: [PATCH 05/11] add recently used tags and categories for startSplitBill --- src/libs/actions/IOU.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index fb4e9f02f1b6..225fea5593ea 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1883,6 +1883,32 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co }); }); + _.each(participants, (participant) => { + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(participant); + if (!isPolicyExpenseChat) { + return; + } + + const optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(participant.policyID, category); + const optimisticPolicyRecentlyUsedTags = Policy.buildOptimisticPolicyRecentlyUsedTags(participant.policyID, tag); + + if (!_.isEmpty(optimisticPolicyRecentlyUsedCategories)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${participant.policyID}`, + value: optimisticPolicyRecentlyUsedCategories, + }); + } + + if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${participant.policyID}`, + value: optimisticPolicyRecentlyUsedTags, + }); + } + }); + // Save the new splits array into the transaction's comment in case the user calls CompleteSplitBill while offline optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From cecdfc3fb809e23993cb5abe8044baa0cf4a69ca Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Wed, 10 Jan 2024 14:39:34 -0500 Subject: [PATCH 06/11] const instead of let --- src/pages/EditRequestPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index dcf27fa4719f..778bbf71a91d 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -160,7 +160,7 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep const saveCategory = useCallback( ({category: newCategory}) => { - let updatedCategory = newCategory === transactionCategory ? '' : newCategory; + const updatedCategory = newCategory === transactionCategory ? '' : newCategory; IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory); Navigation.dismissModal(); }, From 4611ebba233fe2bc7f168f8074d50b798fff1888 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Mon, 15 Jan 2024 11:24:35 -0800 Subject: [PATCH 07/11] remove unused editMoneyRequest function --- src/pages/EditRequestPage.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index d18ca2db8a27..db43154f5a12 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -110,12 +110,6 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep }); }, [parentReportAction, fieldToEdit]); - // Update the transaction object and close the modal - function editMoneyRequest(transactionChanges) { - IOU.editMoneyRequest(transaction, report.reportID, transactionChanges); - Navigation.dismissModal(report.reportID); - } - const saveAmountAndCurrency = useCallback( ({amount, currency: newCurrency}) => { const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); From 6c2492654a44245445b78de566b6ed1baad82a74 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 16 Jan 2024 17:30:21 +0000 Subject: [PATCH 08/11] refactor(typescript): add country type --- src/CONST.ts | 4 ++++ src/components/CountrySelector.tsx | 4 ++-- src/languages/en.ts | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index d6f3d3cdcef6..468a803bff43 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3123,4 +3123,8 @@ const CONST = { }, } as const; +type Country = keyof typeof CONST.ALL_COUNTRIES; + +export type {Country}; + export default CONST; diff --git a/src/components/CountrySelector.tsx b/src/components/CountrySelector.tsx index 2d352cb16e04..5be7f9f630a4 100644 --- a/src/components/CountrySelector.tsx +++ b/src/components/CountrySelector.tsx @@ -3,7 +3,7 @@ import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; -import type CONST from '@src/CONST'; +import type {Country} from '@src/CONST'; import ROUTES from '@src/ROUTES'; import FormHelpMessage from './FormHelpMessage'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; @@ -16,7 +16,7 @@ type CountrySelectorProps = { onInputChange: (value?: string) => void; /** Current selected country */ - value?: keyof typeof CONST.ALL_COUNTRIES; + value?: Country; /** inputID used by the Form component */ // eslint-disable-next-line react/no-unused-prop-types diff --git a/src/languages/en.ts b/src/languages/en.ts index b6fa37560536..7c338e4b9897 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1,6 +1,7 @@ import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; import Str from 'expensify-common/lib/str'; import CONST from '@src/CONST'; +import type {Country} from '@src/CONST'; import type { AddressLineParams, AdminCanceledRequestParams, @@ -107,7 +108,7 @@ type StateValue = { type States = Record; -type AllCountries = Record; +type AllCountries = Record; /* eslint-disable max-len */ export default { From 7b15836e88b605cf8e9e2e4a3d4ac77f9ff354c6 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 16 Jan 2024 17:33:07 +0000 Subject: [PATCH 09/11] refactor(typescript): apply pull request feedback --- src/components/CountrySelector.tsx | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/components/CountrySelector.tsx b/src/components/CountrySelector.tsx index 5be7f9f630a4..589530cd7879 100644 --- a/src/components/CountrySelector.tsx +++ b/src/components/CountrySelector.tsx @@ -1,4 +1,5 @@ -import React, {type ForwardedRef, useEffect} from 'react'; +import React, {forwardRef, useEffect} from 'react'; +import type {ForwardedRef} from 'react'; import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -23,11 +24,7 @@ type CountrySelectorProps = { inputID: string; }; -type CountrySelectorPropsWithForwardedRef = CountrySelectorProps & { - forwardedRef: ForwardedRef; -}; - -function CountrySelector({errorText = '', value: countryCode, onInputChange, forwardedRef = () => {}}: CountrySelectorPropsWithForwardedRef) { +function CountrySelector({errorText = '', value: countryCode, onInputChange}: CountrySelectorProps, ref: ForwardedRef) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -45,7 +42,7 @@ function CountrySelector({errorText = '', value: countryCode, onInputChange, for { @@ -62,12 +59,4 @@ function CountrySelector({errorText = '', value: countryCode, onInputChange, for CountrySelector.displayName = 'CountrySelector'; -const CountrySelectorWithRef = React.forwardRef((props: CountrySelectorProps, ref: ForwardedRef) => ( - -)); - -export default CountrySelectorWithRef; +export default forwardRef(CountrySelector); From db1bbe77372b5f9027788eabd0a7d0d5a96c5e14 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Mon, 22 Jan 2024 11:18:56 -0800 Subject: [PATCH 10/11] add clarifying comment --- src/pages/EditRequestPage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index db43154f5a12..3eb9d88f1120 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -172,6 +172,7 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep const saveCategory = useCallback( ({category: newCategory}) => { + // In case the same category has been selected, reset the category. const updatedCategory = newCategory === transactionCategory ? '' : newCategory; IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory); Navigation.dismissModal(); From 8390cbf610ab83ec280753061c6ec4b6c812acf6 Mon Sep 17 00:00:00 2001 From: OSBotify Date: Tue, 23 Jan 2024 04:17:01 +0000 Subject: [PATCH 11/11] Update version to 1.4.30-0 --- android/app/build.gradle | 4 ++-- ios/NewExpensify/Info.plist | 4 ++-- ios/NewExpensifyTests/Info.plist | 4 ++-- ios/NotificationServiceExtension/Info.plist | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index f367beb199ba..25acb6f86df5 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -98,8 +98,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1001042901 - versionName "1.4.29-1" + versionCode 1001043000 + versionName "1.4.30-0" } flavorDimensions "default" diff --git a/ios/NewExpensify/Info.plist b/ios/NewExpensify/Info.plist index d4078ea25068..124077702be2 100644 --- a/ios/NewExpensify/Info.plist +++ b/ios/NewExpensify/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.4.29 + 1.4.30 CFBundleSignature ???? CFBundleURLTypes @@ -40,7 +40,7 @@ CFBundleVersion - 1.4.29.1 + 1.4.30.0 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/ios/NewExpensifyTests/Info.plist b/ios/NewExpensifyTests/Info.plist index 2d52c398bbf5..2554f5dce3f2 100644 --- a/ios/NewExpensifyTests/Info.plist +++ b/ios/NewExpensifyTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.29 + 1.4.30 CFBundleSignature ???? CFBundleVersion - 1.4.29.1 + 1.4.30.0 diff --git a/ios/NotificationServiceExtension/Info.plist b/ios/NotificationServiceExtension/Info.plist index f1b09af842f4..1069a5847a02 100644 --- a/ios/NotificationServiceExtension/Info.plist +++ b/ios/NotificationServiceExtension/Info.plist @@ -3,9 +3,9 @@ CFBundleShortVersionString - 1.4.29 + 1.4.30 CFBundleVersion - 1.4.29.1 + 1.4.30.0 NSExtension NSExtensionPointIdentifier diff --git a/package-lock.json b/package-lock.json index 9979a58f53fa..3e5ae6e8d58c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "new.expensify", - "version": "1.4.29-1", + "version": "1.4.30-0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "new.expensify", - "version": "1.4.29-1", + "version": "1.4.30-0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index bd01bd26a106..f1c077102930 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new.expensify", - "version": "1.4.29-1", + "version": "1.4.30-0", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "New Expensify is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.",