From c8fb89d32ccfc3a522f96bdb86bc06d0122b5495 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 20 Jun 2022 15:12:54 -0600 Subject: [PATCH 01/35] Remove the old API method --- src/libs/actions/Report.js | 10 ++++++++-- src/libs/deprecatedAPI.js | 14 -------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index f529931b5c80..574ce9893840 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1314,8 +1314,14 @@ function syncChatAndIOUReports(chatReport, iouReport) { * @param {String} notificationPreference */ function updateNotificationPreference(reportID, notificationPreference) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {notificationPreference}); - DeprecatedAPI.Report_UpdateNotificationPreference({reportID, notificationPreference}); + const optimisticData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference}, + }, + ]; + API.write('UpdateReportNotificationPreference', {reportID, notificationPreference}, {optimisticData}); } /** diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 67333741f0a7..24a9c3e9c73c 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -368,19 +368,6 @@ function Report_UpdateLastRead(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {Number} parameters.reportID - * @param {String} parameters.notificationPreference - * @returns {Promise} - * - */ -function Report_UpdateNotificationPreference(parameters) { - const commandName = 'Report_UpdateNotificationPreference'; - requireParameters(['reportID', 'notificationPreference'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {String} parameters.email @@ -956,7 +943,6 @@ export { Report_TogglePinned, Report_EditComment, Report_UpdateLastRead, - Report_UpdateNotificationPreference, ResendValidateCode, ResetPassword, SetNameValuePair, From 8572e2b119649ca8d7dafc8815f05eaf270d02fc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 20 Jun 2022 15:45:56 -0600 Subject: [PATCH 02/35] Replace string with constant --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 574ce9893840..476114b023a1 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -168,7 +168,7 @@ function getSimplifiedReportObject(report) { const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); const notificationPreference = ReportUtils.isChatRoom({chatType}) - ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily') + ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY) : ''; // Used for User Created Policy Rooms, will denote how access to a chat room is given among workspace members From cec863d507052f35aabd8381b0ccfc5c756f43cf Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 21 Jun 2022 10:30:40 -0600 Subject: [PATCH 03/35] Set failure data to revert the notification preference --- src/libs/actions/Report.js | 19 ++++++++++--------- src/pages/ReportSettingsPage.js | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 476114b023a1..c200bc00d0c0 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1307,21 +1307,22 @@ function syncChatAndIOUReports(chatReport, iouReport) { Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReport); } -/** - * Updates a user's notification preferences for a chat room - * - * @param {Number} reportID - * @param {String} notificationPreference - */ -function updateNotificationPreference(reportID, notificationPreference) { +function updateNotificationPreference(reportID, previousValue, newValue) { const optimisticData = [ { onyxMethod: 'merge', key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: {notificationPreference}, + value: {notificationPreference: newValue}, + }, + ]; + const failureData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference: previousValue}, }, ]; - API.write('UpdateReportNotificationPreference', {reportID, notificationPreference}, {optimisticData}); + API.write('UpdateReportNotificationPreference', {reportID, notificationPreference: newValue}, {optimisticData, failureData}); } /** diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 7cb8e62e72f5..5d9881feb60b 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -171,6 +171,7 @@ class ReportSettingsPage extends Component { onInputChange={(notificationPreference) => { Report.updateNotificationPreference( this.props.report.reportID, + this.props.report.notificationPreference, notificationPreference, ); }} From 7cb3aad73e8a0ac061fd3a226195be5034c43c99 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 21 Jun 2022 12:58:08 -0600 Subject: [PATCH 04/35] Use a constant for onyx methods --- src/CONST.js | 6 ++++++ src/libs/actions/Report.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index e5b6657ebddd..403e62e639bc 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -711,6 +711,12 @@ const CONST = { // There's a limit of 60k characters in Auth - https://github.com/Expensify/Auth/blob/198d59547f71fdee8121325e8bc9241fc9c3236a/auth/lib/Request.h#L28 MAX_COMMENT_LENGTH: 60000, + + ONYX: { + METHOD: { + MERGE: 'merge', + }, + }, }; export default CONST; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c200bc00d0c0..fb7cb8fb71fb 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1310,14 +1310,14 @@ function syncChatAndIOUReports(chatReport, iouReport) { function updateNotificationPreference(reportID, previousValue, newValue) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: {notificationPreference: newValue}, }, ]; const failureData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: {notificationPreference: previousValue}, }, From fe6c2d450d6418c1d8131291ddbe70580bc9cf4c Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Mon, 27 Jun 2022 11:31:46 -0700 Subject: [PATCH 05/35] Add use new requestCall Onyx-optimized API command --- src/languages/en.js | 5 + src/languages/es.js | 5 + src/libs/Middleware/SaveResponseInOnyx.js | 3 + src/libs/actions/Inbox.js | 86 ++++++------ src/pages/RequestCallConfirmationScreen.js | 50 +++++++ src/pages/RequestCallPage.js | 156 +++++++++++++-------- 6 files changed, 202 insertions(+), 103 deletions(-) create mode 100644 src/pages/RequestCallConfirmationScreen.js diff --git a/src/languages/en.js b/src/languages/en.js index 0bc2f3940666..522638fea266 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -923,6 +923,11 @@ export default { phoneExtension: 'Please enter a valid phone extension number', }, }, + requestCallConfirmationScreen: { + callRequested: 'Call successfully requested!', + allSet: 'You’re all set. You will be receiving a call from us soon.', + gotIt: 'Got it', + }, emojiPicker: { skinTonePickerLabel: 'Change default skin tone', headers: { diff --git a/src/languages/es.js b/src/languages/es.js index 6e21739200c3..dcb3410fa7ab 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -925,6 +925,11 @@ export default { phoneExtension: 'Por favor, introduzca una extensión telefónica válida', }, }, + requestCallConfirmationScreen: { + callRequested: 'Call successfully requested!', + allSet: 'You’re all set. You will be receiving a call from us soon.', + gotIt: 'Got it', + }, emojiPicker: { skinTonePickerLabel: 'Elige el tono de piel por defecto', headers: { diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index cf8444c771dd..cded277f3502 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -9,6 +9,9 @@ import _ from 'underscore'; function SaveResponseInOnyx(response, request) { return response .then((responseData) => { + if (request.command === 'RequestCall') { + debugger; + } // We'll only save the onyxData, successData and failureData for the refactored commands if (_.has(responseData, 'onyxData')) { const data = []; diff --git a/src/libs/actions/Inbox.js b/src/libs/actions/Inbox.js index 4bd92abdf0bf..e14ea0fcae81 100644 --- a/src/libs/actions/Inbox.js +++ b/src/libs/actions/Inbox.js @@ -1,50 +1,54 @@ -import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; -import * as DeprecatedAPI from '../deprecatedAPI'; -import Growl from '../Growl'; -import * as Localize from '../Localize'; -import Navigation from '../Navigation/Navigation'; -import * as User from './User'; -/** - * @param {Object} params - * @param {String} taskID - * @param {String} policyID - * @param {String} firstName - * @param {String} lastName - * @param {String} phoneNumber - */ -function requestInboxCall({ +function requestCall({ taskID, policyID, firstName, lastName, phoneNumber, phoneNumberExtension, }) { - Onyx.merge(ONYXKEYS.REQUEST_CALL_FORM, {loading: true}); - DeprecatedAPI.Inbox_CallUser({ - policyID, - firstName, - lastName, - phoneNumber, - phoneNumberExtension, - taskID, - }) - .then((result) => { - if (result.jsonCode === 200) { - Growl.success(Localize.translateLocal('requestCallPage.growlMessageOnSave')); - Navigation.goBack(); - return; - } + const optimisticData = [{ + onyxMethod: 'merge', + key: ONYXKEYS.REQUEST_CALL_FORM, + value: { + loading: true, + }, + }]; - if (result.jsonCode === 666) { - // The fact that the API is returning this error means the BLOCKED_FROM_CONCIERGE nvp in the user details has changed since the last time we checked, so let's update - User.getUserDetails(); - } + const successData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: { + success: true, + }, + }, + { + onyxMethod: 'merge', + key: ONYXKEYS.REQUEST_CALL_FORM, + value: { + loading: false, + }, + }, + ]; - // Phone number validation is handled by the API - Growl.error(result.message, 3000); - }) - .finally(() => { - Onyx.merge(ONYXKEYS.REQUEST_CALL_FORM, {loading: false}); - }); + const failureData = [{ + onyxMethod: 'merge', + key: ONYXKEYS.REQUEST_CALL_FORM, + value: { + loading: false, + }, + }]; + + API.write( + 'RequestCall', + { + policyID, + firstName, + lastName, + phoneNumber, + phoneNumberExtension, + taskID, + }, + {optimisticData, successData, failureData}, + ); } function openRequestCallPage() { @@ -52,6 +56,6 @@ function openRequestCallPage() { } export { - requestInboxCall, openRequestCallPage, + requestCall, }; diff --git a/src/pages/RequestCallConfirmationScreen.js b/src/pages/RequestCallConfirmationScreen.js new file mode 100644 index 000000000000..22c1d3eeb2c6 --- /dev/null +++ b/src/pages/RequestCallConfirmationScreen.js @@ -0,0 +1,50 @@ +import React from 'react'; +import {Image, View} from 'react-native'; +import Text from '../components/Text'; +import withLocalize, {withLocalizePropTypes} from '../components/withLocalize'; +import styles from '../styles/styles'; +import confettiPop from '../../assets/images/confetti-pop.gif'; +import Button from '../components/Button'; +import FixedFooter from '../components/FixedFooter'; +import Navigation from '../libs/Navigation/Navigation'; + +const propTypes = { + ...withLocalizePropTypes, +}; + +const RequestCallConfirmationScreen = props => ( + <> + + + + {props.translate('requestCallConfirmationScreen.callRequested')} + + + {props.translate('requestCallConfirmationScreen.allSet')} + + + +