From 86792289fff1535aee06ea1381efcddf3e74fc16 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 1 Jul 2022 17:45:55 -0300 Subject: [PATCH 01/11] initial development --- src/libs/actions/PaymentMethods.js | 10 ++++++++-- src/pages/settings/Payments/AddPayPalMePage.js | 13 ++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 987095e63a72..5bc380de4cd1 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -36,8 +36,14 @@ function deleteDebitCard(fundID) { } function deletePayPalMe() { - NameValuePair.set(CONST.NVP.PAYPAL_ME_ADDRESS, ''); - Onyx.set(ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, null); + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, + value: '', + }, + ]; + API.write('DeletePaypalUsername', {}, {optimisticData}); Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); } diff --git a/src/pages/settings/Payments/AddPayPalMePage.js b/src/pages/settings/Payments/AddPayPalMePage.js index 88f175152c55..037d2e0e4a86 100644 --- a/src/pages/settings/Payments/AddPayPalMePage.js +++ b/src/pages/settings/Payments/AddPayPalMePage.js @@ -52,7 +52,18 @@ class AddPayPalMePage extends React.Component { return; } this.setState({payPalMeUsernameError: false}); - NameValuePair.set(CONST.NVP.PAYPAL_ME_ADDRESS, this.state.payPalMeUsername, ONYXKEYS.NVP_PAYPAL_ME_ADDRESS); + + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, + value: this.state.payPalMeUsername, + }, + ]; + API.write('AddPaypalUsername', { + value: this.state.payPalMeUsername, + }, {optimisticData}); + Growl.show(this.props.translate('addPayPalMePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000); Navigation.navigate(ROUTES.SETTINGS_PAYMENTS); } From 50840cf4cfa6d49a47901bdfc43e19555a4c8088 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 1 Jul 2022 18:13:50 -0300 Subject: [PATCH 02/11] refactoring and fixing requests --- src/libs/actions/PaymentMethods.js | 12 ++----- src/libs/actions/User.js | 36 +++++++++++++++++++ .../settings/Payments/AddPayPalMePage.js | 16 ++------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 5bc380de4cd1..698286fdacf7 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -10,7 +10,7 @@ import * as Localize from '../Localize'; import Navigation from '../Navigation/Navigation'; import * as CardUtils from '../CardUtils'; import ROUTES from '../../ROUTES'; -import NameValuePair from './NameValuePair'; +import * as User from './User'; import * as store from './ReimbursementAccount/store'; /** @@ -36,14 +36,8 @@ function deleteDebitCard(fundID) { } function deletePayPalMe() { - const optimisticData = [ - { - onyxMethod: 'merge', - key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, - value: '', - }, - ]; - API.write('DeletePaypalUsername', {}, {optimisticData}); + + User.deletePaypalMeAddress(); Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); } diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 148d5cbfa40e..aafe41d277e4 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -266,6 +266,40 @@ function isBlockedFromConcierge(blockedFromConcierge) { return moment().isBefore(moment(blockedFromConcierge.expiresAt), 'day'); } +/** + * Adds a paypal.me address for the user + * + * @param {String} address + */ +function addPaypalMeAddress(address) { + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, + value: address, + }, + ]; + API.write('AddPaypalMeAddress', { + value: address, + }, {optimisticData}); +} + +/** + * Deletes a paypal.me address for the user + * + */ +function deletePaypalMeAddress() { + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, + value: '', + }, + ]; + API.write('DeletePaypalMeAddress', {}, {optimisticData}); + Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); +} + /** * Fetch the public domain info for the current user. * @@ -467,4 +501,6 @@ export { joinScreenShare, clearScreenShareRequest, generateStatementPDF, + deletePaypalMeAddress, + addPaypalMeAddress, }; diff --git a/src/pages/settings/Payments/AddPayPalMePage.js b/src/pages/settings/Payments/AddPayPalMePage.js index 037d2e0e4a86..fde6b501547a 100644 --- a/src/pages/settings/Payments/AddPayPalMePage.js +++ b/src/pages/settings/Payments/AddPayPalMePage.js @@ -8,7 +8,6 @@ import ROUTES from '../../../ROUTES'; import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; import Text from '../../../components/Text'; import ScreenWrapper from '../../../components/ScreenWrapper'; -import NameValuePair from '../../../libs/actions/NameValuePair'; import Navigation from '../../../libs/Navigation/Navigation'; import styles from '../../../styles/styles'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; @@ -19,6 +18,7 @@ import FixedFooter from '../../../components/FixedFooter'; import Growl from '../../../libs/Growl'; import TextInput from '../../../components/TextInput'; import * as ValidationUtils from '../../../libs/ValidationUtils'; +import * as User from '../../../libs/actions/User'; const propTypes = { /** Username for PayPal.Me */ @@ -52,18 +52,8 @@ class AddPayPalMePage extends React.Component { return; } this.setState({payPalMeUsernameError: false}); - - const optimisticData = [ - { - onyxMethod: 'merge', - key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, - value: this.state.payPalMeUsername, - }, - ]; - API.write('AddPaypalUsername', { - value: this.state.payPalMeUsername, - }, {optimisticData}); - + User.addPaypalMeAddress(this.state.payPalMeUsername); + Growl.show(this.props.translate('addPayPalMePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000); Navigation.navigate(ROUTES.SETTINGS_PAYMENTS); } From 9c5a6567358d0faad8fe0be7b6aecbe22ebdd0c2 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Mon, 4 Jul 2022 19:07:58 -0300 Subject: [PATCH 03/11] refactor methods to use named methods --- src/libs/actions/PersonalDetails.js | 4 +- src/libs/actions/User.js | 59 ++++++++++++++++++++++++++- src/libs/actions/Welcome.js | 4 +- src/pages/settings/PreferencesPage.js | 3 +- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index cc7add84320e..bb59fc2097c0 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -6,7 +6,7 @@ import Str from 'expensify-common/lib/str'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import * as DeprecatedAPI from '../deprecatedAPI'; -import NameValuePair from './NameValuePair'; +import * as User from './User'; import * as LoginUtils from '../LoginUtils'; import * as ReportUtils from '../ReportUtils'; import Growl from '../Growl'; @@ -278,7 +278,7 @@ function setPersonalDetails(details, shouldGrowl) { .then((response) => { if (response.jsonCode === 200) { if (details.timezone) { - NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone); + User.setPreferredTimezone(details.timezone); } mergeLocalPersonalDetails(details); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index aafe41d277e4..1c9fa79b20d4 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -422,7 +422,16 @@ function subscribeToExpensifyCardUpdates() { * @param {String} skinTone */ function setPreferredSkinTone(skinTone) { - NameValuePair.set(CONST.NVP.PREFERRED_EMOJI_SKIN_TONE, skinTone, ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE); + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, + value: skinTone, + }, + ]; + API.write('SetPreferredEmojiSkinTone', { + value: skinTone, + }, {optimisticData}); } /** @@ -430,7 +439,50 @@ function setPreferredSkinTone(skinTone) { * @param {Object[]} frequentlyUsedEmojis */ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { - NameValuePair.set(CONST.NVP.FREQUENTLY_USED_EMOJIS, frequentlyUsedEmojis, ONYXKEYS.FREQUENTLY_USED_EMOJIS); + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, + value: frequentlyUsedEmojis, + }, + ]; + API.write('SetFrequentlyUsedEmojis', { + value: frequentlyUsedEmojis, + }, {optimisticData}); +} + +/** + * Sync preferred timezone with Onyx and Server + * @param {String} timezone + */ + function setPreferredTimezone(timezone) { + API.write('SetTimezone', { + value: timezone, + }, {}); +} + +/** + * Sync user first time flag to false with Onyx and Server + */ + function setFirstTimeToFalse() { + NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); +} + +/** + * Sync user chat priority mode with Onyx and Server + * @param {String} mode + */ + function setChatPriorityMode(mode) { + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.NVP_PRIORITY_MODE, + value: mode, + }, + ]; + API.write('SetChatPriorityMode', { + value: mode, + }, {optimisticData}); } /** @@ -503,4 +555,7 @@ export { generateStatementPDF, deletePaypalMeAddress, addPaypalMeAddress, + setChatPriorityMode, + setFirstTimeToFalse, + setPreferredTimezone, }; diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index 41c559093941..b4a96867d45b 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -6,7 +6,7 @@ import * as ReportUtils from '../ReportUtils'; import ROUTES from '../../ROUTES'; import * as Policy from './Policy'; import ONYXKEYS from '../../ONYXKEYS'; -import NameValuePair from './NameValuePair'; +import * as User from './User'; import CONST from '../../CONST'; import SCREENS from '../../SCREENS'; @@ -112,7 +112,7 @@ function show({routes, showCreateMenu}) { } // Set the NVP back to false so we don't automatically run welcome actions again - NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); + User.setFirstTimeToFalse(); // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global // create menu right now. We should also stay on the workspace page if that is our destination. diff --git a/src/pages/settings/PreferencesPage.js b/src/pages/settings/PreferencesPage.js index 56b928553571..2da604f629bb 100755 --- a/src/pages/settings/PreferencesPage.js +++ b/src/pages/settings/PreferencesPage.js @@ -12,7 +12,6 @@ import ROUTES from '../../ROUTES'; import ONYXKEYS from '../../ONYXKEYS'; import styles from '../../styles/styles'; import Text from '../../components/Text'; -import NameValuePair from '../../libs/actions/NameValuePair'; import CONST from '../../CONST'; import * as User from '../../libs/actions/User'; import ScreenWrapper from '../../components/ScreenWrapper'; @@ -87,7 +86,7 @@ const PreferencesPage = (props) => { NameValuePair.set(CONST.NVP.PRIORITY_MODE, mode, ONYXKEYS.NVP_PRIORITY_MODE) + mode => User.setChatPriorityMode(mode) } items={_.values(priorityModes)} value={props.priorityMode} From 471a8eab619817a3592292892f089292685d85f9 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 5 Jul 2022 19:51:21 -0300 Subject: [PATCH 04/11] fixing styles and new methods --- src/libs/EmojiUtils.js | 1 - src/libs/actions/PaymentMethods.js | 1 - src/libs/actions/User.js | 10 +++++----- src/libs/actions/Welcome.js | 1 - 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libs/EmojiUtils.js b/src/libs/EmojiUtils.js index 47f6ab1a9a53..2279b0d37af4 100644 --- a/src/libs/EmojiUtils.js +++ b/src/libs/EmojiUtils.js @@ -196,7 +196,6 @@ function addToFrequentlyUsedEmojis(frequentlyUsedEmojis, newEmoji) { // Second sorting is required so that new emoji is properly placed at sort-ordered location frequentEmojiList = lodashOrderBy(frequentEmojiList, ['count', 'lastUpdatedAt'], ['desc', 'desc']); - User.setFrequentlyUsedEmojis(frequentEmojiList); } diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 698286fdacf7..28b2ef539b1c 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -36,7 +36,6 @@ function deleteDebitCard(fundID) { } function deletePayPalMe() { - User.deletePaypalMeAddress(); Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); } diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 1c9fa79b20d4..fd4aef9b87e8 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -424,7 +424,7 @@ function subscribeToExpensifyCardUpdates() { function setPreferredSkinTone(skinTone) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: 'set', key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, value: skinTone, }, @@ -447,7 +447,7 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { }, ]; API.write('SetFrequentlyUsedEmojis', { - value: frequentlyUsedEmojis, + value: JSON.stringify(frequentlyUsedEmojis), }, {optimisticData}); } @@ -455,7 +455,7 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { * Sync preferred timezone with Onyx and Server * @param {String} timezone */ - function setPreferredTimezone(timezone) { +function setPreferredTimezone(timezone) { API.write('SetTimezone', { value: timezone, }, {}); @@ -464,7 +464,7 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { /** * Sync user first time flag to false with Onyx and Server */ - function setFirstTimeToFalse() { +function setFirstTimeToFalse() { NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); } @@ -472,7 +472,7 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { * Sync user chat priority mode with Onyx and Server * @param {String} mode */ - function setChatPriorityMode(mode) { +function setChatPriorityMode(mode) { const optimisticData = [ { onyxMethod: 'merge', diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index b4a96867d45b..e5fa4bef14a9 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -7,7 +7,6 @@ import ROUTES from '../../ROUTES'; import * as Policy from './Policy'; import ONYXKEYS from '../../ONYXKEYS'; import * as User from './User'; -import CONST from '../../CONST'; import SCREENS from '../../SCREENS'; let resolveIsReadyPromise; From 6977763f44ef1711911fa70649e32954dbaa983d Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 6 Jul 2022 16:11:24 -0300 Subject: [PATCH 05/11] reverting changes for first time usage --- src/libs/actions/User.js | 8 -------- src/libs/actions/Welcome.js | 5 +++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index fd4aef9b87e8..f444043aa47a 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -461,13 +461,6 @@ function setPreferredTimezone(timezone) { }, {}); } -/** - * Sync user first time flag to false with Onyx and Server - */ -function setFirstTimeToFalse() { - NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); -} - /** * Sync user chat priority mode with Onyx and Server * @param {String} mode @@ -556,6 +549,5 @@ export { deletePaypalMeAddress, addPaypalMeAddress, setChatPriorityMode, - setFirstTimeToFalse, setPreferredTimezone, }; diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index e5fa4bef14a9..41c559093941 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -6,7 +6,8 @@ import * as ReportUtils from '../ReportUtils'; import ROUTES from '../../ROUTES'; import * as Policy from './Policy'; import ONYXKEYS from '../../ONYXKEYS'; -import * as User from './User'; +import NameValuePair from './NameValuePair'; +import CONST from '../../CONST'; import SCREENS from '../../SCREENS'; let resolveIsReadyPromise; @@ -111,7 +112,7 @@ function show({routes, showCreateMenu}) { } // Set the NVP back to false so we don't automatically run welcome actions again - User.setFirstTimeToFalse(); + NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global // create menu right now. We should also stay on the workspace page if that is our destination. From 20db056ca4c5b885ebf52fe83f2d1c37c8d532b5 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Jul 2022 17:05:18 -0300 Subject: [PATCH 06/11] fixing style and bug --- src/libs/actions/User.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index f444043aa47a..c2d0bd9b783f 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -15,7 +15,6 @@ import * as Pusher from '../Pusher/pusher'; import Log from '../Log'; import NetworkConnection from '../NetworkConnection'; import redirectToSignIn from './SignInRedirect'; -import NameValuePair from './NameValuePair'; import Growl from '../Growl'; import * as Localize from '../Localize'; import * as CloseAccountActions from './CloseAccount'; @@ -441,7 +440,7 @@ function setPreferredSkinTone(skinTone) { function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: 'set', key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, value: frequentlyUsedEmojis, }, @@ -457,7 +456,7 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { */ function setPreferredTimezone(timezone) { API.write('SetTimezone', { - value: timezone, + value: JSON.stringify(timezone), }, {}); } From 883f74c218d5f4d58e9787141936d6962ee86779 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Jul 2022 17:07:35 -0300 Subject: [PATCH 07/11] changing string to constant --- src/CONST.js | 1 + src/libs/actions/User.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 5dbb241e1a25..7d14ad1a53c8 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -733,6 +733,7 @@ const CONST = { ONYX: { METHOD: { MERGE: 'merge', + SET: 'set', }, }, }; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index c2d0bd9b783f..80f650b43cfb 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -423,7 +423,7 @@ function subscribeToExpensifyCardUpdates() { function setPreferredSkinTone(skinTone) { const optimisticData = [ { - onyxMethod: 'set', + onyxMethod: CONST.ONYX.METHOD.SET, key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, value: skinTone, }, @@ -440,7 +440,7 @@ function setPreferredSkinTone(skinTone) { function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { const optimisticData = [ { - onyxMethod: 'set', + onyxMethod: CONST.ONYX.METHOD.SET, key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, value: frequentlyUsedEmojis, }, @@ -467,7 +467,7 @@ function setPreferredTimezone(timezone) { function setChatPriorityMode(mode) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.NVP_PRIORITY_MODE, value: mode, }, From 03f22e1153b48975a66700671d9da55feea9849c Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Jul 2022 17:07:52 -0300 Subject: [PATCH 08/11] changing string to constant --- src/libs/actions/User.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 80f650b43cfb..293ff36b9f65 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -273,7 +273,7 @@ function isBlockedFromConcierge(blockedFromConcierge) { function addPaypalMeAddress(address) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, value: address, }, @@ -290,7 +290,7 @@ function addPaypalMeAddress(address) { function deletePaypalMeAddress() { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, value: '', }, From d2ad164ce01a1aaa895077ffcae26114beda00fb Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 13 Jul 2022 18:49:09 -0300 Subject: [PATCH 09/11] renaming methods to right naming convention --- .../EmojiPicker/EmojiPickerMenu/index.js | 2 +- .../EmojiPickerMenu/index.native.js | 2 +- src/libs/EmojiUtils.js | 2 +- src/libs/actions/PersonalDetails.js | 4 +-- src/libs/actions/User.js | 29 ++++++------------- src/pages/settings/PreferencesPage.js | 2 +- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.js b/src/components/EmojiPicker/EmojiPickerMenu/index.js index e271680da068..387f58bc6c6b 100755 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.js +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.js @@ -389,7 +389,7 @@ class EmojiPickerMenu extends Component { return; } - User.setPreferredSkinTone(skinTone); + User.updatePreferredSkinTone(skinTone); } /** diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.native.js b/src/components/EmojiPicker/EmojiPickerMenu/index.native.js index 84eda04fc89e..754ed20fd766 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.native.js +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.native.js @@ -88,7 +88,7 @@ class EmojiPickerMenu extends Component { return; } - User.setPreferredSkinTone(skinTone); + User.updatePreferredSkinTone(skinTone); } /** diff --git a/src/libs/EmojiUtils.js b/src/libs/EmojiUtils.js index 2279b0d37af4..133e21d1ba18 100644 --- a/src/libs/EmojiUtils.js +++ b/src/libs/EmojiUtils.js @@ -196,7 +196,7 @@ function addToFrequentlyUsedEmojis(frequentlyUsedEmojis, newEmoji) { // Second sorting is required so that new emoji is properly placed at sort-ordered location frequentEmojiList = lodashOrderBy(frequentEmojiList, ['count', 'lastUpdatedAt'], ['desc', 'desc']); - User.setFrequentlyUsedEmojis(frequentEmojiList); + User.updateFrequentlyUsedEmojis(frequentEmojiList); } export { diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index bb59fc2097c0..cc7add84320e 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -6,7 +6,7 @@ import Str from 'expensify-common/lib/str'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import * as DeprecatedAPI from '../deprecatedAPI'; -import * as User from './User'; +import NameValuePair from './NameValuePair'; import * as LoginUtils from '../LoginUtils'; import * as ReportUtils from '../ReportUtils'; import Growl from '../Growl'; @@ -278,7 +278,7 @@ function setPersonalDetails(details, shouldGrowl) { .then((response) => { if (response.jsonCode === 200) { if (details.timezone) { - User.setPreferredTimezone(details.timezone); + NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone); } mergeLocalPersonalDetails(details); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 29b00b1e84be..eb9947411efe 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -399,7 +399,7 @@ function subscribeToExpensifyCardUpdates() { * Sync preferredSkinTone with Onyx and Server * @param {String} skinTone */ -function setPreferredSkinTone(skinTone) { +function updatePreferredSkinTone(skinTone) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.SET, @@ -407,7 +407,7 @@ function setPreferredSkinTone(skinTone) { value: skinTone, }, ]; - API.write('SetPreferredEmojiSkinTone', { + API.write('UpdatePreferredEmojiSkinTone', { value: skinTone, }, {optimisticData}); } @@ -416,7 +416,7 @@ function setPreferredSkinTone(skinTone) { * Sync frequentlyUsedEmojis with Onyx and Server * @param {Object[]} frequentlyUsedEmojis */ -function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { +function updateFrequentlyUsedEmojis(frequentlyUsedEmojis) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.SET, @@ -424,26 +424,16 @@ function setFrequentlyUsedEmojis(frequentlyUsedEmojis) { value: frequentlyUsedEmojis, }, ]; - API.write('SetFrequentlyUsedEmojis', { + API.write('UpdateFrequentlyUsedEmojis', { value: JSON.stringify(frequentlyUsedEmojis), }, {optimisticData}); } -/** - * Sync preferred timezone with Onyx and Server - * @param {String} timezone - */ -function setPreferredTimezone(timezone) { - API.write('SetTimezone', { - value: JSON.stringify(timezone), - }, {}); -} - /** * Sync user chat priority mode with Onyx and Server * @param {String} mode */ -function setChatPriorityMode(mode) { +function updateChatPriorityMode(mode) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -451,7 +441,7 @@ function setChatPriorityMode(mode) { value: mode, }, ]; - API.write('SetChatPriorityMode', { + API.write('UpdateChatPriorityMode', { value: mode, }, {optimisticData}); } @@ -516,16 +506,15 @@ export { isBlockedFromConcierge, getDomainInfo, subscribeToUserEvents, - setPreferredSkinTone, + updatePreferredSkinTone, setShouldUseSecureStaging, clearUserErrorMessage, subscribeToExpensifyCardUpdates, - setFrequentlyUsedEmojis, + updateFrequentlyUsedEmojis, joinScreenShare, clearScreenShareRequest, generateStatementPDF, deletePaypalMeAddress, addPaypalMeAddress, - setChatPriorityMode, - setPreferredTimezone, + updateChatPriorityMode, }; diff --git a/src/pages/settings/PreferencesPage.js b/src/pages/settings/PreferencesPage.js index e287d6eaf2f0..ec453e027b86 100755 --- a/src/pages/settings/PreferencesPage.js +++ b/src/pages/settings/PreferencesPage.js @@ -86,7 +86,7 @@ const PreferencesPage = (props) => { User.setChatPriorityMode(mode) + mode => User.updateChatPriorityMode(mode) } items={_.values(priorityModes)} value={props.priorityMode} From 08b420de06eb122421bde47760f63c606da08f3f Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 13 Jul 2022 18:52:14 -0300 Subject: [PATCH 10/11] solving issue on merge for comment --- src/libs/actions/User.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index eb9947411efe..4108809063ad 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -301,11 +301,6 @@ function deletePaypalMeAddress() { } /** - * Fetch the public domain info for the current user. - * - * This API is a bit weird in that it sometimes depends on information being cached in bedrock. - * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. - * If that happens, this function will automatically retry itself in 10 minutes. * Fetch whether the user has the Expensify card enabled. */ function getDomainInfo() { From dcd38a4a30d834bdf48f01052f2d7b9033b19343 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Mon, 18 Jul 2022 15:13:15 -0300 Subject: [PATCH 11/11] solving merge issue --- src/libs/actions/User.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 01828a6c1fa4..9c1841f40030 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -300,16 +300,6 @@ function deletePaypalMeAddress() { Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000); } -/** - * Fetch whether the user has the Expensify card enabled. - */ -function getDomainInfo() { - DeprecatedAPI.User_IsUsingExpensifyCard() - .then(({isUsingExpensifyCard}) => { - Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); - }); -} - /** * Initialize our pusher subscription to listen for user changes */