From 607e5c5c2771cbc5a2959ebece4c616dad6210e4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 25 Aug 2022 14:05:05 +0800 Subject: [PATCH 01/32] add copy --- src/languages/en.js | 1 + src/languages/es.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.js b/src/languages/en.js index df85199e1c15..8ff452062147 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -830,6 +830,7 @@ export default { captureNoVBACopyAfterEmail: ' and download the Expensify App to track cash expenses on the go.', unlockNoVBACopy: 'Connect a bank account to reimburse your workspace members online.', fastReimbursementsVBACopy: 'You\'re all set to reimburse receipts from your bank account!', + updateCustomUnitError: "Your changes couldn't be saved. The workspace was modified while you were offline, please try again.", }, bills: { manageYourBills: 'Manage your bills', diff --git a/src/languages/es.js b/src/languages/es.js index 9bd3a33f6b58..2e202a3ef66c 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -832,6 +832,7 @@ export default { captureNoVBACopyAfterEmail: ' y descarga la App de Expensify para controlar tus gastos en efectivo sobre la marcha.', unlockNoVBACopy: 'Conecta una cuenta bancaria para reembolsar online a los miembros de tu espacio de trabajo.', fastReimbursementsVBACopy: '¡Todo listo para reembolsar recibos desde tu cuenta bancaria!', + updateCustomUnitError: 'Los cambios no han podido ser guardados. El espacio de trabajo ha sido modificado mientras estabas desconectado, por favor inténtalo de nuevo.', }, bills: { manageYourBills: 'Gestiona tus facturas', From 55af930f942802fb1ac59e8a9ce109875b4e51cf Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 25 Aug 2022 14:05:35 +0800 Subject: [PATCH 02/32] update setCustomUnitRate --- src/libs/actions/Policy.js | 82 +++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 1d0c5c596a4c..16e188ce0ad4 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -13,6 +13,8 @@ import ROUTES from '../../ROUTES'; import * as OptionsListUtils from '../OptionsListUtils'; import * as Report from './Report'; import * as Pusher from '../Pusher/pusher'; +import DateUtils from '../DateUtils'; +import * as API from '../API'; const allPolicies = {}; Onyx.connect({ @@ -467,34 +469,68 @@ function setCustomUnit(policyID, values) { /** * @param {String} policyID + * @param {Object} currentCustomUnitRate * @param {String} customUnitID * @param {Object} values */ -function setCustomUnitRate(policyID, customUnitID, values) { - DeprecatedAPI.Policy_CustomUnitRate_Update({ - policyID: policyID.toString(), - customUnitID: customUnitID.toString(), - customUnitRate: JSON.stringify(values), - lastModified: null, - }) - .then((response) => { - if (response.jsonCode !== 200) { - throw new Error(); - } - - updateLocalPolicyValues(policyID, { - customUnit: { - rate: { - id: values.customUnitRateID, - name: values.name, - value: Number(values.rate), +function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { + const optimisticData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + customUnits: { + rates: { + [values.customUnitRateID]: { + ...values, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, }, }, - }); - }).catch(() => { - // Show the user feedback - Growl.error(Localize.translateLocal('workspace.editor.genericFailureMessage'), 5000); - }); + }, + }, + ]; + + const successData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + customUnits: { + rates: { + [values.customUnitRateID]: { + pendingAction: null, + }, + }, + }, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + customUnits: { + rates: { + [currentCustomUnitRate.customUnitRateID]: { + ...currentCustomUnitRate, + error: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), + }, + }, + }, + }, + }, + }, + ]; + + // Note remember to not pass lastModified as null as per convo + API.write('UpdateWorkspaceCustomUnit', { + policyID: policyID, + customUnit: JSON.stringify(values), + }, {optimisticData, successData, failureData}); } /** From 4cbb5d4979f6c93d01761795d22894f9a98df834 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 25 Aug 2022 14:13:08 +0800 Subject: [PATCH 03/32] update setCustomUnitRate --- src/libs/actions/Policy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 16e188ce0ad4..72fde2134552 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -526,10 +526,10 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values }, ]; - // Note remember to not pass lastModified as null as per convo - API.write('UpdateWorkspaceCustomUnit', { - policyID: policyID, - customUnit: JSON.stringify(values), + API.write('SetWorkspaceCustomUnitRate', { + policyID, + customUnitID, + customUnitRate: JSON.stringify(values), }, {optimisticData, successData, failureData}); } From 065909a5b92c0e8bf86117fd58816a506c6a8204 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 29 Aug 2022 21:34:23 +0800 Subject: [PATCH 04/32] WIP, online updates work, but need to figure out issue with data shape before continuing with errors --- src/CONST.js | 1 + src/components/OfflineWithFeedback.js | 1 + src/libs/actions/Policy.js | 38 ++++++++++++------- .../reimburse/WorkspaceReimburseView.js | 26 +++++++------ 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index a6b7586c217b..0456d3fc745f 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -663,6 +663,7 @@ const CONST = { ADMIN: 'admin', }, ROOM_PREFIX: '#', + CUSTOM_UNIT_RATE_BASE_OFFSET: 100, }, TERMS: { diff --git a/src/components/OfflineWithFeedback.js b/src/components/OfflineWithFeedback.js index 27dcefd9a15e..57566f0a1e40 100644 --- a/src/components/OfflineWithFeedback.js +++ b/src/components/OfflineWithFeedback.js @@ -86,6 +86,7 @@ const OfflineWithFeedback = (props) => { .keys() .sortBy() .map(key => props.errors[key]) + .uniq() .value(); // Apply strikethrough to children if needed, but skip it if we are not going to render them diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 4132186a0ceb..aca54479494d 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -491,12 +491,16 @@ function setWorkspaceErrors(policyID, errors) { * @param {String} policyID * @param {Number} customUnitID */ -function removeUnitError(policyID, customUnitID) { +function clearCustomUnitErrors(policyID, customUnitID) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { customUnits: { [customUnitID]: { errors: null, pendingAction: null, + rates: [{ + errors: null, + pendingAction: null, + }], }, }, }); @@ -587,17 +591,21 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {Object} values */ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { + console.log(">>>>", policyID, customUnitID, values.customUnitRateID); const optimisticData = [ { onyxMethod: 'merge', key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { customUnits: { - rates: { - [values.customUnitRateID]: { - ...values, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, + [customUnitID]: { + rates: [ + { + ...values, + errors: null, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + ], }, }, }, @@ -610,10 +618,12 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { customUnits: { - rates: { - [values.customUnitRateID]: { + [customUnitID]: { + rates: [{ + ...values, pendingAction: null, - }, + errors: null, + }], }, }, }, @@ -626,13 +636,13 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { customUnits: { - rates: { - [currentCustomUnitRate.customUnitRateID]: { + [customUnitID]: { + rates: [{ ...currentCustomUnitRate, - error: { + errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), }, - }, + }], }, }, }, @@ -734,7 +744,7 @@ export { uploadAvatar, update, setWorkspaceErrors, - removeUnitError, + clearCustomUnitErrors, hasCustomUnitsError, hideWorkspaceAlertMessage, deletePolicy, diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 8307fe49dbed..3a9f2b3cdc24 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -64,9 +64,7 @@ class WorkspaceReimburseView extends React.Component { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - rateID: lodashGet(distanceCustomUnit, 'rates[0].customUnitRateID', ''), - rateName: lodashGet(distanceCustomUnit, 'rates[0].name', ''), - rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates[0].rate', 0) / 100), + rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates[0].rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), outputCurrency: lodashGet(props, 'policy.outputCurrency', ''), }; @@ -151,11 +149,12 @@ class WorkspaceReimburseView extends React.Component { rateValue: numValue.toFixed(3), }); - Policy.setCustomUnitRate(this.props.policyID, this.state.unitID, { - customUnitRateID: this.state.rateID, - name: this.state.rateName, - rate: numValue.toFixed(3) * 100, - }, null); + const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); + const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates[0]', {}); + Policy.setCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { + ..._.omit(currentCustomUnitRate, 'rate'), + rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, + }); } render() { @@ -194,9 +193,14 @@ class WorkspaceReimburseView extends React.Component { {this.props.translate('workspace.reimburse.trackDistanceCopy')} Policy.removeUnitError(this.props.policyID, this.state.unitID)} + errors={{ + ...lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'errors']), + ...lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates[0]', 'errors']), + }} + pendingAction={lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'pendingAction']) + || lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates[0]', 'pendingAction'])} + onClose={() => Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID)} + errorRowStyles={[styles.flex1]} > From 131144fd4a6b5a00b917b65b7a770d0f97a54590 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:21:14 +0800 Subject: [PATCH 05/32] merge main --- src/libs/actions/Policy.js | 106 +++++++++++------- .../reimburse/WorkspaceReimburseView.js | 12 +- 2 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 4aaebf3532e2..66c912fc88df 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -50,6 +50,21 @@ function getSimplifiedEmployeeList(employeeList) { .value(); } +/** + * For whatever reason, we store customUnit rates in an array, even though there's only ever a single rate per custom unit. + * This flattens the array of rates so that we store the single rate directly. + * + * @param {Object} fullPolicyOrPolicySummary + * @param {Object} [fullPolicyOrPolicySummary.value.customUnits] + */ +function getSimplifiedCustomUnits(fullPolicyOrPolicySummary) { + const customUnits = lodashGet(fullPolicyOrPolicySummary, 'value.customUnits', {}); + _.forEach(customUnits, (customUnit, customUnitID) => { + customUnits[customUnitID].rates = lodashGet(customUnit, 'rates[0]', {}); + }); + return customUnits; +} + /** * Takes a full policy that is returned from the policyList and simplifies it so we are only storing * the pieces of data that we need to in Onyx @@ -60,6 +75,8 @@ function getSimplifiedEmployeeList(employeeList) { * @param {String} fullPolicyOrPolicySummary.role * @param {String} fullPolicyOrPolicySummary.type * @param {String} fullPolicyOrPolicySummary.outputCurrency + * @param {String} [fullPolicyOrPolicySummary.avatar] + * @param {String} [fullPolicyOrPolicySummary.value.avatar] * @param {String} [fullPolicyOrPolicySummary.avatarURL] * @param {String} [fullPolicyOrPolicySummary.value.avatarURL] * @param {Object} [fullPolicyOrPolicySummary.value.employeeList] @@ -78,9 +95,12 @@ function getSimplifiedPolicyObject(fullPolicyOrPolicySummary, isFromFullPolicy) outputCurrency: fullPolicyOrPolicySummary.outputCurrency, // "GetFullPolicy" and "GetPolicySummaryList" returns different policy objects. If policy is retrieved by "GetFullPolicy", - // avatarUrl will be nested within the key "value" - avatarURL: fullPolicyOrPolicySummary.avatarURL || lodashGet(fullPolicyOrPolicySummary, 'value.avatarURL', ''), - customUnits: lodashGet(fullPolicyOrPolicySummary, 'value.customUnits', {}), + // avatar will be nested within the key "value" + avatar: fullPolicyOrPolicySummary.avatar + || lodashGet(fullPolicyOrPolicySummary, 'value.avatar', '') + || fullPolicyOrPolicySummary.avatarURL + || lodashGet(fullPolicyOrPolicySummary, 'value.avatarURL', ''), + customUnits: getSimplifiedCustomUnits(fullPolicyOrPolicySummary), }; } @@ -112,9 +132,11 @@ function updateAllPolicies(policyCollection) { * @returns {Promise} */ function create(name = '') { + Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, true); let res = null; return DeprecatedAPI.Policy_Create({type: CONST.POLICY.TYPE.FREE, policyName: name}) .then((response) => { + Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, false); if (response.jsonCode !== 200) { // Show the user feedback const errorMessage = Localize.translateLocal('workspace.new.genericFailureMessage'); @@ -357,6 +379,40 @@ function updateLocalPolicyValues(policyID, values) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, values); } +/** + * Updates a workspace avatar image + * + * @param {String} policyID + * @param {File|Object} file + */ +function updateWorkspaceAvatar(policyID, file) { + const optimisticData = [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + avatar: file.uri, + errorFields: { + avatar: null, + }, + pendingFields: { + avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }]; + const failureData = [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + avatar: allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`].avatar, + pendingFields: { + avatar: null, + }, + }, + }]; + + API.write('UpdateWorkspaceAvatar', {policyID, file}, {optimisticData, failureData}); +} + /** * Deletes the avatar image for the workspace * @param {String} policyID @@ -368,12 +424,12 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - avatarURL: null, + avatar: null, }, - avatarURL: '', + avatar: '', }, }, ]; @@ -383,10 +439,7 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatarURL: null, - }, - errorFields: { - avatarURL: null, + avatar: null, }, }, }, @@ -397,10 +450,10 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatarURL: null, + avatar: null, }, errorFields: { - avatarURL: { + avatar: { [DateUtils.getMicroseconds()]: Localize.translateLocal('avatarWithImagePicker.deleteWorkspaceError'), }, }, @@ -417,10 +470,10 @@ function deleteWorkspaceAvatar(policyID) { function clearAvatarErrors(policyID) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { errorFields: { - avatarURL: null, + avatar: null, }, pendingFields: { - avatarURL: null, + avatar: null, }, }); } @@ -522,29 +575,6 @@ function clearWorkspaceGeneralSettingsErrors(policyID) { }); } -/** - * Uploads the avatar image to S3 bucket and updates the policy with new avatarURL - * - * @param {String} policyID - * @param {Object} file - */ -function uploadAvatar(policyID, file) { - updateLocalPolicyValues(policyID, {isAvatarUploading: true}); - DeprecatedAPI.User_UploadAvatar({file}) - .then((response) => { - if (response.jsonCode === 200) { - // Update the policy with the new avatarURL as soon as we get it - Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {avatarURL: response.s3url, isAvatarUploading: false}); - update(policyID, {avatarURL: response.s3url}, true); - return; - } - - Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {isAvatarUploading: false}); - const errorMessage = Localize.translateLocal('workspace.editor.avatarUploadFailureMessage'); - Growl.error(errorMessage, 5000); - }); -} - /** * @param {String} policyID * @param {Object} errors @@ -798,7 +828,6 @@ export { invite, isAdminOfFreePolicy, create, - uploadAvatar, update, setWorkspaceErrors, clearCustomUnitErrors, @@ -816,6 +845,7 @@ export { updateGeneralSettings, clearWorkspaceGeneralSettingsErrors, deleteWorkspaceAvatar, + updateWorkspaceAvatar, clearAvatarErrors, generatePolicyID, }; diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 3a9f2b3cdc24..735da9140984 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -40,13 +40,11 @@ const propTypes = { attributes: PropTypes.shape({ unit: PropTypes.string, }), - rates: PropTypes.arrayOf( - PropTypes.shape({ - customUnitRateID: PropTypes.string, - name: PropTypes.string, - rate: PropTypes.number, - }), - ), + rates: PropTypes.shape({ + customUnitRateID: PropTypes.string, + name: PropTypes.string, + rate: PropTypes.number, + }), }), ), outputCurrency: PropTypes.string, From 5cff69a1f1f56b86e2ba6d18ccf412a7d5d74730 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:24:38 +0800 Subject: [PATCH 06/32] remove unused --- src/libs/actions/Policy.js | 66 ++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 66c912fc88df..01a03c3b8e67 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -95,11 +95,8 @@ function getSimplifiedPolicyObject(fullPolicyOrPolicySummary, isFromFullPolicy) outputCurrency: fullPolicyOrPolicySummary.outputCurrency, // "GetFullPolicy" and "GetPolicySummaryList" returns different policy objects. If policy is retrieved by "GetFullPolicy", - // avatar will be nested within the key "value" - avatar: fullPolicyOrPolicySummary.avatar - || lodashGet(fullPolicyOrPolicySummary, 'value.avatar', '') - || fullPolicyOrPolicySummary.avatarURL - || lodashGet(fullPolicyOrPolicySummary, 'value.avatarURL', ''), + // avatarUrl will be nested within the key "value" + avatarURL: fullPolicyOrPolicySummary.avatarURL || lodashGet(fullPolicyOrPolicySummary, 'value.avatarURL', ''), customUnits: getSimplifiedCustomUnits(fullPolicyOrPolicySummary), }; } @@ -390,12 +387,12 @@ function updateWorkspaceAvatar(policyID, file) { onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - avatar: file.uri, + avatarURL: file.uri, errorFields: { - avatar: null, + avatarURL: null, }, pendingFields: { - avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, }, }]; @@ -424,12 +421,12 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - avatar: null, + avatarURL: null, }, - avatar: '', + avatarURL: '', }, }, ]; @@ -439,7 +436,10 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatar: null, + avatarURL: null, + }, + errorFields: { + avatarURL: null, }, }, }, @@ -450,10 +450,10 @@ function deleteWorkspaceAvatar(policyID) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - avatar: null, + avatarURL: null, }, errorFields: { - avatar: { + avatarURL: { [DateUtils.getMicroseconds()]: Localize.translateLocal('avatarWithImagePicker.deleteWorkspaceError'), }, }, @@ -470,10 +470,10 @@ function deleteWorkspaceAvatar(policyID) { function clearAvatarErrors(policyID) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { errorFields: { - avatar: null, + avatarURL: null, }, pendingFields: { - avatar: null, + avatarURL: null, }, }); } @@ -575,6 +575,29 @@ function clearWorkspaceGeneralSettingsErrors(policyID) { }); } +/** + * Uploads the avatar image to S3 bucket and updates the policy with new avatarURL + * + * @param {String} policyID + * @param {Object} file + */ +function uploadAvatar(policyID, file) { + updateLocalPolicyValues(policyID, {isAvatarUploading: true}); + DeprecatedAPI.User_UploadAvatar({file}) + .then((response) => { + if (response.jsonCode === 200) { + // Update the policy with the new avatarURL as soon as we get it + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {avatarURL: response.s3url, isAvatarUploading: false}); + update(policyID, {avatarURL: response.s3url}, true); + return; + } + + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {isAvatarUploading: false}); + const errorMessage = Localize.translateLocal('workspace.editor.avatarUploadFailureMessage'); + Growl.error(errorMessage, 5000); + }); +} + /** * @param {String} policyID * @param {Object} errors @@ -603,16 +626,6 @@ function clearCustomUnitErrors(policyID, customUnitID) { }); } -/** - * Checks if we have any errors stored within the policy custom units. - * @param {Object} policy - * @returns {Boolean} - */ -function hasCustomUnitsError(policy) { - const unitsWithErrors = _.filter(lodashGet(policy, 'customUnits', {}), customUnit => (lodashGet(customUnit, 'errors', null))); - return !_.isEmpty(unitsWithErrors); -} - /** * @param {String} policyID */ @@ -831,7 +844,6 @@ export { update, setWorkspaceErrors, clearCustomUnitErrors, - hasCustomUnitsError, hideWorkspaceAlertMessage, deletePolicy, createAndNavigate, From d0b13930484d1c4859e001bd564bbcbf95b581e4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:25:16 +0800 Subject: [PATCH 07/32] remove unused --- src/libs/actions/Policy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 01a03c3b8e67..f37853b2073b 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -129,11 +129,9 @@ function updateAllPolicies(policyCollection) { * @returns {Promise} */ function create(name = '') { - Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, true); let res = null; return DeprecatedAPI.Policy_Create({type: CONST.POLICY.TYPE.FREE, policyName: name}) .then((response) => { - Onyx.set(ONYXKEYS.IS_CREATING_WORKSPACE, false); if (response.jsonCode !== 200) { // Show the user feedback const errorMessage = Localize.translateLocal('workspace.new.genericFailureMessage'); From ef7611179a408b9c844db338e335bfba05b89e9f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:25:39 +0800 Subject: [PATCH 08/32] remove unused --- src/libs/actions/Policy.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index f37853b2073b..921a273cd12a 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -374,40 +374,6 @@ function updateLocalPolicyValues(policyID, values) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, values); } -/** - * Updates a workspace avatar image - * - * @param {String} policyID - * @param {File|Object} file - */ -function updateWorkspaceAvatar(policyID, file) { - const optimisticData = [{ - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - avatarURL: file.uri, - errorFields: { - avatarURL: null, - }, - pendingFields: { - avatarURL: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - }, - }]; - const failureData = [{ - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - avatar: allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`].avatar, - pendingFields: { - avatar: null, - }, - }, - }]; - - API.write('UpdateWorkspaceAvatar', {policyID, file}, {optimisticData, failureData}); -} - /** * Deletes the avatar image for the workspace * @param {String} policyID @@ -855,7 +821,6 @@ export { updateGeneralSettings, clearWorkspaceGeneralSettingsErrors, deleteWorkspaceAvatar, - updateWorkspaceAvatar, clearAvatarErrors, generatePolicyID, }; From d2a0ea329008dff2930f698f2fd0fb2108965760 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:28:43 +0800 Subject: [PATCH 09/32] flatten customUnit rate array --- src/libs/actions/Policy.js | 21 ++++++++----------- .../reimburse/WorkspaceReimburseView.js | 8 +++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 921a273cd12a..559706a67908 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -665,7 +665,6 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {Object} values */ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { - console.log(">>>>", policyID, customUnitID, values.customUnitRateID); const optimisticData = [ { onyxMethod: 'merge', @@ -673,13 +672,11 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values value: { customUnits: { [customUnitID]: { - rates: [ - { - ...values, - errors: null, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - ], + rates: { + ...values, + errors: null, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, }, }, }, @@ -693,11 +690,11 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values value: { customUnits: { [customUnitID]: { - rates: [{ + rates: { ...values, pendingAction: null, errors: null, - }], + }, }, }, }, @@ -711,12 +708,12 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values value: { customUnits: { [customUnitID]: { - rates: [{ + rates: { ...currentCustomUnitRate, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), }, - }], + }, }, }, }, diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 735da9140984..1ad2eacbdda4 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -62,7 +62,7 @@ class WorkspaceReimburseView extends React.Component { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates[0].rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), + rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates.rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), outputCurrency: lodashGet(props, 'policy.outputCurrency', ''), }; @@ -148,7 +148,7 @@ class WorkspaceReimburseView extends React.Component { }); const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates[0]', {}); + const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates', {}); Policy.setCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ..._.omit(currentCustomUnitRate, 'rate'), rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, @@ -193,10 +193,10 @@ class WorkspaceReimburseView extends React.Component { Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID)} errorRowStyles={[styles.flex1]} > From 942416fbf987717f2d16b7560a30c3d857baacbe Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:37:47 +0800 Subject: [PATCH 10/32] flatten customUnit rate array --- src/libs/actions/Policy.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 559706a67908..1e72f0a644e4 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -581,10 +581,10 @@ function clearCustomUnitErrors(policyID, customUnitID) { [customUnitID]: { errors: null, pendingAction: null, - rates: [{ + rates: { errors: null, pendingAction: null, - }], + }, }, }, }); @@ -693,7 +693,6 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values rates: { ...values, pendingAction: null, - errors: null, }, }, }, From 46eb7b5edcd93f4b1a4086bb53a61bc3c98c1dc0 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 11:46:55 +0800 Subject: [PATCH 11/32] fix linter error --- src/libs/actions/Policy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 1e72f0a644e4..74868d04351b 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -56,6 +56,7 @@ function getSimplifiedEmployeeList(employeeList) { * * @param {Object} fullPolicyOrPolicySummary * @param {Object} [fullPolicyOrPolicySummary.value.customUnits] + * @returns {Object} */ function getSimplifiedCustomUnits(fullPolicyOrPolicySummary) { const customUnits = lodashGet(fullPolicyOrPolicySummary, 'value.customUnits', {}); @@ -801,6 +802,7 @@ export { invite, isAdminOfFreePolicy, create, + uploadAvatar, update, setWorkspaceErrors, clearCustomUnitErrors, From f2dbc3219828ff94dad29e86529e256348ee5687 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 12:05:21 +0800 Subject: [PATCH 12/32] update comment --- src/libs/actions/Policy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 74868d04351b..55a77c61cef8 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -51,7 +51,7 @@ function getSimplifiedEmployeeList(employeeList) { } /** - * For whatever reason, we store customUnit rates in an array, even though there's only ever a single rate per custom unit. + * We pass customUnit rates from PHP as an array, even though there's only ever a single rate per custom unit. * This flattens the array of rates so that we store the single rate directly. * * @param {Object} fullPolicyOrPolicySummary From 230cf4267ced8a1c5c0665757bf199ee559999e3 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:00:07 +0800 Subject: [PATCH 13/32] revert unused --- src/libs/actions/Policy.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 55a77c61cef8..8ca92267e5a3 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -50,22 +50,6 @@ function getSimplifiedEmployeeList(employeeList) { .value(); } -/** - * We pass customUnit rates from PHP as an array, even though there's only ever a single rate per custom unit. - * This flattens the array of rates so that we store the single rate directly. - * - * @param {Object} fullPolicyOrPolicySummary - * @param {Object} [fullPolicyOrPolicySummary.value.customUnits] - * @returns {Object} - */ -function getSimplifiedCustomUnits(fullPolicyOrPolicySummary) { - const customUnits = lodashGet(fullPolicyOrPolicySummary, 'value.customUnits', {}); - _.forEach(customUnits, (customUnit, customUnitID) => { - customUnits[customUnitID].rates = lodashGet(customUnit, 'rates[0]', {}); - }); - return customUnits; -} - /** * Takes a full policy that is returned from the policyList and simplifies it so we are only storing * the pieces of data that we need to in Onyx @@ -98,7 +82,7 @@ function getSimplifiedPolicyObject(fullPolicyOrPolicySummary, isFromFullPolicy) // "GetFullPolicy" and "GetPolicySummaryList" returns different policy objects. If policy is retrieved by "GetFullPolicy", // avatarUrl will be nested within the key "value" avatarURL: fullPolicyOrPolicySummary.avatarURL || lodashGet(fullPolicyOrPolicySummary, 'value.avatarURL', ''), - customUnits: getSimplifiedCustomUnits(fullPolicyOrPolicySummary), + customUnits: lodashGet(fullPolicyOrPolicySummary, 'value.customUnits', {}), }; } From 7f7cadd7c58a59106b3c9f535a29138bb33e619e Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:11:16 +0800 Subject: [PATCH 14/32] key by ID to get rates --- src/libs/actions/Policy.js | 22 ++++++++++++------- .../reimburse/WorkspaceReimburseView.js | 10 +++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 8ca92267e5a3..4f0d46a2afbd 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -650,6 +650,7 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {Object} values */ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { + const customUnitRateID = lodashGet(values, 'customUnitRateID', ''); const optimisticData = [ { onyxMethod: 'merge', @@ -658,9 +659,11 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - ...values, - errors: null, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [customUnitRateID]: { + ...values, + errors: null, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, }, }, }, @@ -676,8 +679,9 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - ...values, - pendingAction: null, + [customUnitRateID]: { + pendingAction: null, + }, }, }, }, @@ -693,9 +697,11 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - ...currentCustomUnitRate, - errors: { - [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), + [customUnitRateID]: { + ...currentCustomUnitRate, + errors: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), + }, }, }, }, diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 1ad2eacbdda4..8c5766056d93 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -57,12 +57,14 @@ class WorkspaceReimburseView extends React.Component { constructor(props) { super(props); const distanceCustomUnit = _.find(lodashGet(props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); + const customUnitRates = lodashGet(distanceCustomUnit, 'rates', {}); this.state = { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), + unitRateID: _.first(_.keys(customUnitRates)), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates.rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), + rateValue: this.getRateDisplayValue(lodashGet(customUnitRates, this.state.unitRateID, 'rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), outputCurrency: lodashGet(props, 'policy.outputCurrency', ''), }; @@ -148,7 +150,7 @@ class WorkspaceReimburseView extends React.Component { }); const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates', {}); + const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates', this.state.unitRateID, {}); Policy.setCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ..._.omit(currentCustomUnitRate, 'rate'), rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, @@ -193,10 +195,10 @@ class WorkspaceReimburseView extends React.Component { Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID)} errorRowStyles={[styles.flex1]} > From 0ced3e574663e8d7dc3a9fde45e8ab0288d18dda Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:13:16 +0800 Subject: [PATCH 15/32] access directly --- src/libs/actions/Policy.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 4f0d46a2afbd..3ac63f0acc49 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -650,7 +650,6 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {Object} values */ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { - const customUnitRateID = lodashGet(values, 'customUnitRateID', ''); const optimisticData = [ { onyxMethod: 'merge', @@ -659,7 +658,7 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - [customUnitRateID]: { + [values.customUnitRateID]: { ...values, errors: null, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, @@ -679,7 +678,7 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - [customUnitRateID]: { + [values.customUnitRateID]: { pendingAction: null, }, }, From 651ab0a14f99d745d06f8dec21f53c7b82bef68c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:14:35 +0800 Subject: [PATCH 16/32] cleanup --- src/libs/actions/Policy.js | 11 +++++++---- .../workspace/reimburse/WorkspaceReimburseView.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 3ac63f0acc49..34b25b4f58a8 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -558,17 +558,20 @@ function setWorkspaceErrors(policyID, errors) { /** * @param {String} policyID - * @param {Number} customUnitID + * @param {String} customUnitID + * @param {String} customUnitRateID */ -function clearCustomUnitErrors(policyID, customUnitID) { +function clearCustomUnitErrors(policyID, customUnitID, customUnitRateID) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { customUnits: { [customUnitID]: { errors: null, pendingAction: null, rates: { - errors: null, - pendingAction: null, + [customUnitRateID]: { + errors: null, + pendingAction: null, + }, }, }, }, diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 8c5766056d93..fb71c14a42b4 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -199,7 +199,7 @@ class WorkspaceReimburseView extends React.Component { }} pendingAction={lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'pendingAction']) || lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates', this.state.unitRateID, 'pendingAction'])} - onClose={() => Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID)} + onClose={() => Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID, this.state.unitRateID)} errorRowStyles={[styles.flex1]} > From 1e93077ad908c9b575735980e704f7f9cacc8bc8 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:15:30 +0800 Subject: [PATCH 17/32] cleanup --- src/libs/actions/Policy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 34b25b4f58a8..8d8b44648f8e 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -699,7 +699,7 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values customUnits: { [customUnitID]: { rates: { - [customUnitRateID]: { + [currentCustomUnitRate.customUnitRateID]: { ...currentCustomUnitRate, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('workspace.reimburse.updateCustomUnitError'), From c6a23044da1bfda8ee659df4563f9c293765618c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:16:03 +0800 Subject: [PATCH 18/32] fix propTypes --- .../workspace/reimburse/WorkspaceReimburseView.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index fb71c14a42b4..064b6b156adb 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -40,11 +40,13 @@ const propTypes = { attributes: PropTypes.shape({ unit: PropTypes.string, }), - rates: PropTypes.shape({ - customUnitRateID: PropTypes.string, - name: PropTypes.string, - rate: PropTypes.number, - }), + rates: PropTypes.objectOf( + PropTypes.shape({ + customUnitRateID: PropTypes.string, + name: PropTypes.string, + rate: PropTypes.number, + }), + ), }), ), outputCurrency: PropTypes.string, From 71447ecaeac3b3f68a23601ec152f32e5d7f1c7a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:28:18 +0800 Subject: [PATCH 19/32] update customUnitRate accessing --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 064b6b156adb..64eb75825347 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -59,14 +59,14 @@ class WorkspaceReimburseView extends React.Component { constructor(props) { super(props); const distanceCustomUnit = _.find(lodashGet(props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const customUnitRates = lodashGet(distanceCustomUnit, 'rates', {}); + const customUnitRate = _.find(lodashGet(distanceCustomUnit, 'rates', {}), rate => rate.name === 'Default Rate'); this.state = { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), - unitRateID: _.first(_.keys(customUnitRates)), + unitRateID: lodashGet(customUnitRate, 'customUnitRateID', ''), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - rateValue: this.getRateDisplayValue(lodashGet(customUnitRates, this.state.unitRateID, 'rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), + rateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), outputCurrency: lodashGet(props, 'policy.outputCurrency', ''), }; From 1da0a2a2a9f40892f1d5794bcb4ae8b7f748e5ec Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:28:52 +0800 Subject: [PATCH 20/32] remove unused --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 64eb75825347..2e1723c927a8 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -202,7 +202,6 @@ class WorkspaceReimburseView extends React.Component { pendingAction={lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'pendingAction']) || lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates', this.state.unitRateID, 'pendingAction'])} onClose={() => Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID, this.state.unitRateID)} - errorRowStyles={[styles.flex1]} > From 55252de2c80d011c56749fc72dd5636dee0b2437 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Tue, 30 Aug 2022 16:30:26 +0800 Subject: [PATCH 21/32] cleanup --- .../workspace/reimburse/WorkspaceReimburseView.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 2e1723c927a8..ddb79e01866a 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -152,7 +152,7 @@ class WorkspaceReimburseView extends React.Component { }); const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const currentCustomUnitRate = lodashGet(distanceCustomUnit, 'rates', this.state.unitRateID, {}); + const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['rates', this.state.unitRateID], {}); Policy.setCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ..._.omit(currentCustomUnitRate, 'rate'), rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, @@ -196,11 +196,11 @@ class WorkspaceReimburseView extends React.Component { Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID, this.state.unitRateID)} > From 4591cef217d923e838dd1f570ae367482c1891f7 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 21:50:14 +0800 Subject: [PATCH 22/32] add comment --- src/components/OfflineWithFeedback.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/OfflineWithFeedback.js b/src/components/OfflineWithFeedback.js index 18aaac61e0d1..9d3aea05e2da 100644 --- a/src/components/OfflineWithFeedback.js +++ b/src/components/OfflineWithFeedback.js @@ -87,6 +87,9 @@ const OfflineWithFeedback = (props) => { .keys() .sortBy() .map(key => props.errors[key]) + + // Using uniq here since some fields are wrapped by the same OfflineWithFeedback component (e.g. WorkspaceReimburseView) + // and can potentially pass the same error. .uniq() .value(); From f862e26dde00a89c59c642e11bd0931b19ab4b73 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 21:51:54 +0800 Subject: [PATCH 23/32] use update instead of set --- src/libs/actions/Policy.js | 6 +++--- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 13a1a28f8075..bfeacdf67590 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -673,7 +673,7 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {String} customUnitID * @param {Object} values */ -function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { +function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { const optimisticData = [ { onyxMethod: 'merge', @@ -733,7 +733,7 @@ function setCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values }, ]; - API.write('SetWorkspaceCustomUnitRate', { + API.write('UpdateWorkspaceCustomUnitRate', { policyID, customUnitID, customUnitRate: JSON.stringify(values), @@ -872,7 +872,7 @@ export { createAndNavigate, createAndGetPolicyList, updateWorkspaceCustomUnit, - setCustomUnitRate, + updateCustomUnitRate, updateLastAccessedWorkspace, subscribeToPolicyEvents, clearDeleteMemberError, diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 451d3053749c..502cfed04d38 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -152,7 +152,7 @@ class WorkspaceReimburseView extends React.Component { const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['rates', this.state.unitRateID], {}); - Policy.setCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { + Policy.updateCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ..._.omit(currentCustomUnitRate, 'rate'), rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, }); From 7aa9ab619ac7cf565a1924fcd908915fb91ba51c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 22:14:53 +0800 Subject: [PATCH 24/32] remove _.omit --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 502cfed04d38..8fc712e3b63f 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -153,7 +153,7 @@ class WorkspaceReimburseView extends React.Component { const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['rates', this.state.unitRateID], {}); Policy.updateCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { - ..._.omit(currentCustomUnitRate, 'rate'), + ...currentCustomUnitRate, rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, }); } From 74ff01e295a1bdbc1418d106358a569c16c42642 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 22:17:41 +0800 Subject: [PATCH 25/32] round to 3 decimal places before multiplying and passing to Policy action --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 8fc712e3b63f..f958ee7c33ea 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -154,7 +154,7 @@ class WorkspaceReimburseView extends React.Component { const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['rates', this.state.unitRateID], {}); Policy.updateCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ...currentCustomUnitRate, - rate: numValue * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, + rate: numValue.toFixed(3) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, }); } From 49f7118076d206a5c6b8d9471cf9e33794d49f55 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 22:18:14 +0800 Subject: [PATCH 26/32] remove defaults --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index f958ee7c33ea..10c5e3073ae5 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -198,8 +198,8 @@ class WorkspaceReimburseView extends React.Component { ...lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'errors'], {}), ...lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates', this.state.unitRateID, 'errors'], {}), }} - pendingAction={lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'pendingAction'], '') - || lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates', this.state.unitRateID, 'pendingAction'], '')} + pendingAction={lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'pendingAction']) + || lodashGet(this.props, ['policy', 'customUnits', this.state.unitID, 'rates', this.state.unitRateID, 'pendingAction'])} onClose={() => Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID, this.state.unitRateID)} > From be512f51495ee2f02dc02b3e591ea48a02aa9a25 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 31 Aug 2022 22:20:02 +0800 Subject: [PATCH 27/32] use onyxRates instead of rates --- .../workspace/reimburse/WorkspaceReimburseView.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 10c5e3073ae5..09c7c71dfba3 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -39,7 +39,7 @@ const propTypes = { attributes: PropTypes.shape({ unit: PropTypes.string, }), - rates: PropTypes.objectOf( + onyxRates: PropTypes.objectOf( PropTypes.shape({ customUnitRateID: PropTypes.string, name: PropTypes.string, @@ -58,7 +58,7 @@ class WorkspaceReimburseView extends React.Component { constructor(props) { super(props); const distanceCustomUnit = _.find(lodashGet(props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const customUnitRate = _.find(lodashGet(distanceCustomUnit, 'rates', {}), rate => rate.name === 'Default Rate'); + const customUnitRate = _.find(lodashGet(distanceCustomUnit, 'onyxRates', {}), rate => rate.name === 'Default Rate'); this.state = { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), @@ -151,7 +151,7 @@ class WorkspaceReimburseView extends React.Component { }); const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); - const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['rates', this.state.unitRateID], {}); + const currentCustomUnitRate = lodashGet(distanceCustomUnit, ['onyxRates', this.state.unitRateID], {}); Policy.updateCustomUnitRate(this.props.policyID, currentCustomUnitRate, this.state.unitID, { ...currentCustomUnitRate, rate: numValue.toFixed(3) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, @@ -196,10 +196,10 @@ class WorkspaceReimburseView extends React.Component { Policy.clearCustomUnitErrors(this.props.policyID, this.state.unitID, this.state.unitRateID)} > From 0c591d1a95b7f7b6f7835df032fc91f504cf600f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 1 Sep 2022 11:54:30 +0800 Subject: [PATCH 28/32] use onyxRates instead of rates --- src/libs/actions/Policy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index bfeacdf67590..9f42a4d08856 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -588,7 +588,7 @@ function clearCustomUnitErrors(policyID, customUnitID, customUnitRateID) { [customUnitID]: { errors: null, pendingAction: null, - rates: { + onyxRates: { [customUnitRateID]: { errors: null, pendingAction: null, @@ -681,7 +681,7 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val value: { customUnits: { [customUnitID]: { - rates: { + onyxRates: { [values.customUnitRateID]: { ...values, errors: null, @@ -701,7 +701,7 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val value: { customUnits: { [customUnitID]: { - rates: { + onyxRates: { [values.customUnitRateID]: { pendingAction: null, }, @@ -719,7 +719,7 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val value: { customUnits: { [customUnitID]: { - rates: { + onyxRates: { [currentCustomUnitRate.customUnitRateID]: { ...currentCustomUnitRate, errors: { From 39c5042941e50c8aaebcfb448c95d18938caccd6 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 5 Sep 2022 10:00:08 +0100 Subject: [PATCH 29/32] fix stuff messed up in merge --- src/pages/workspace/reimburse/WorkspaceReimburseView.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 7a327dce43b7..3c92334818e0 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -98,13 +98,13 @@ class WorkspaceReimburseView extends React.Component { .values() .findWhere({name: CONST.CUSTOM_UNITS.NAME_DISTANCE}) .value(); - + const customUnitRate = _.find(lodashGet(distanceCustomUnit, 'onyxRates', {}), rate => rate.name === 'Default Rate'); this.setState({ unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - unitRateID: lodashGet(distanceCustomUnit, 'rates[0].customUnitRateID', ''), - rateValue: this.getRateDisplayValue(lodashGet(distanceCustomUnit, 'rates[0].rate', 0) / 100), + unitRateID: lodashGet(customUnitRate, 'customUnitRateID'), + rateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / 100), }); } From dbaaa36a01ed2e97814097534ffe78ae0c9742d7 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 5 Sep 2022 10:25:30 +0100 Subject: [PATCH 30/32] rename rateValue => unitRateValue --- .../reimburse/WorkspaceReimburseView.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.js b/src/pages/workspace/reimburse/WorkspaceReimburseView.js index 3c92334818e0..29c04b7b8921 100644 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.js +++ b/src/pages/workspace/reimburse/WorkspaceReimburseView.js @@ -66,10 +66,10 @@ class WorkspaceReimburseView extends React.Component { this.state = { unitID: lodashGet(distanceCustomUnit, 'customUnitID', ''), - unitRateID: lodashGet(customUnitRate, 'customUnitRateID', ''), unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), - rateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), + unitRateID: lodashGet(customUnitRate, 'customUnitRateID', ''), + unitRateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET), outputCurrency: lodashGet(props, 'policy.outputCurrency', ''), }; @@ -104,7 +104,7 @@ class WorkspaceReimburseView extends React.Component { unitName: lodashGet(distanceCustomUnit, 'name', ''), unitValue: lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'), unitRateID: lodashGet(customUnitRate, 'customUnitRateID'), - rateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / 100), + unitRateValue: this.getRateDisplayValue(lodashGet(customUnitRate, 'rate', 0) / 100), }); } @@ -129,10 +129,10 @@ class WorkspaceReimburseView extends React.Component { const isInvalidRateValue = value !== '' && !CONST.REGEX.RATE_VALUE.test(value); this.setState(prevState => ({ - rateValue: !isInvalidRateValue ? value : prevState.rateValue, + unitRateValue: !isInvalidRateValue ? value : prevState.unitRateValue, }), () => { // Set the corrected value with a delay and sync to the server - this.updateRateValueDebounced(this.state.rateValue); + this.updateRateValueDebounced(this.state.unitRateValue); }); } @@ -155,7 +155,7 @@ class WorkspaceReimburseView extends React.Component { return; } - this.updateRateValueDebounced(this.state.rateValue); + this.updateRateValueDebounced(this.state.unitRateValue); } updateRateValue(value) { @@ -166,7 +166,7 @@ class WorkspaceReimburseView extends React.Component { } this.setState({ - rateValue: numValue.toFixed(3), + unitRateValue: numValue.toFixed(3), }); const distanceCustomUnit = _.find(lodashGet(this.props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); @@ -228,7 +228,7 @@ class WorkspaceReimburseView extends React.Component { label={this.props.translate('workspace.reimburse.trackDistanceRate')} placeholder={this.state.outputCurrency} onChangeText={value => this.setRate(value)} - value={this.state.rateValue} + value={this.state.unitRateValue} autoCompleteType="off" autoCorrect={false} keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD} From c55d97b27817d5a0859847064a984e7a52891ef8 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 5 Sep 2022 10:42:23 +0100 Subject: [PATCH 31/32] fix stuff messed up in merge --- src/components/DotIndicatorMessage.js | 4 ++++ src/components/OfflineWithFeedback.js | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/DotIndicatorMessage.js b/src/components/DotIndicatorMessage.js index 2b073627ef51..53a2ec337809 100644 --- a/src/components/DotIndicatorMessage.js +++ b/src/components/DotIndicatorMessage.js @@ -45,6 +45,10 @@ const DotIndicatorMessage = (props) => { .keys() .sortBy() .map(key => props.messages[key]) + + // Using uniq here since some fields are wrapped by the same OfflineWithFeedback component (e.g. WorkspaceReimburseView) + // and can potentially pass the same error. + .uniq() .value(); return ( diff --git a/src/components/OfflineWithFeedback.js b/src/components/OfflineWithFeedback.js index 754161ce71c4..54d6bc0ab9be 100644 --- a/src/components/OfflineWithFeedback.js +++ b/src/components/OfflineWithFeedback.js @@ -81,15 +81,6 @@ const OfflineWithFeedback = (props) => { const needsStrikeThrough = props.network.isOffline && props.pendingAction === 'delete'; const hideChildren = !props.network.isOffline && props.pendingAction === 'delete' && !hasErrors; let children = props.children; - const sortedErrors = _.chain(props.errors) - .keys() - .sortBy() - .map(key => props.errors[key]) - - // Using uniq here since some fields are wrapped by the same OfflineWithFeedback component (e.g. WorkspaceReimburseView) - // and can potentially pass the same error. - .uniq() - .value(); // Apply strikethrough to children if needed, but skip it if we are not going to render them if (needsStrikeThrough && !hideChildren) { From 555a48978f9e3bf5bb2b34507589a9496981651f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 5 Sep 2022 11:30:07 +0100 Subject: [PATCH 32/32] rename variables --- src/libs/actions/Policy.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 85c72767f1b4..d921fd41fae3 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -610,17 +610,17 @@ function hideWorkspaceAlertMessage(policyID) { /** * @param {String} policyID * @param {Object} currentCustomUnit - * @param {Object} values The new custom unit values + * @param {Object} newCustomUnit */ -function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { +function updateWorkspaceCustomUnit(policyID, currentCustomUnit, newCustomUnit) { const optimisticData = [ { onyxMethod: 'merge', key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { customUnits: { - [values.customUnitID]: { - ...values, + [newCustomUnit.customUnitID]: { + ...newCustomUnit, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, }, @@ -634,7 +634,7 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { customUnits: { - [values.customUnitID]: { + [newCustomUnit.customUnitID]: { pendingAction: null, errors: null, }, @@ -664,7 +664,7 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { API.write('UpdateWorkspaceCustomUnit', { policyID, - customUnit: JSON.stringify(values), + customUnit: JSON.stringify(newCustomUnit), }, {optimisticData, successData, failureData}); } @@ -672,9 +672,9 @@ function updateWorkspaceCustomUnit(policyID, currentCustomUnit, values) { * @param {String} policyID * @param {Object} currentCustomUnitRate * @param {String} customUnitID - * @param {Object} values + * @param {Object} newCustomUnitRate */ -function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, values) { +function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, newCustomUnitRate) { const optimisticData = [ { onyxMethod: 'merge', @@ -683,8 +683,8 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val customUnits: { [customUnitID]: { onyxRates: { - [values.customUnitRateID]: { - ...values, + [newCustomUnitRate.customUnitRateID]: { + ...newCustomUnitRate, errors: null, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, @@ -703,7 +703,7 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val customUnits: { [customUnitID]: { onyxRates: { - [values.customUnitRateID]: { + [newCustomUnitRate.customUnitRateID]: { pendingAction: null, }, }, @@ -737,7 +737,7 @@ function updateCustomUnitRate(policyID, currentCustomUnitRate, customUnitID, val API.write('UpdateWorkspaceCustomUnitRate', { policyID, customUnitID, - customUnitRate: JSON.stringify(values), + customUnitRate: JSON.stringify(newCustomUnitRate), }, {optimisticData, successData, failureData}); }