-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aac8d0f
commit 74d3252
Showing
10 changed files
with
369 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/libs/API/parameters/UpdateQuickbooksDesktopGenericTypeParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type UpdateQuickbooksDesktopGenericTypeParams = { | ||
policyID: string; | ||
settingValue: string; | ||
idempotencyKey: string; | ||
}; | ||
|
||
export default UpdateQuickbooksDesktopGenericTypeParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import type {OnyxUpdate} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import type UpdateQuickbooksDesktopGenericTypeParams from '@libs/API/parameters/UpdateQuickbooksDesktopGenericTypeParams'; | ||
import {WRITE_COMMANDS} from '@libs/API/types'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Connections} from '@src/types/onyx/Policy'; | ||
|
||
function buildOnyxDataForMultipleQuickbooksConfigurations<TConfigUpdate extends Partial<Connections['quickbooksDesktop']['config']>>( | ||
policyID: string, | ||
configUpdate: TConfigUpdate, | ||
configCurrentData: TConfigUpdate, | ||
) { | ||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
...configUpdate, | ||
pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE])), | ||
errorFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const failureData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
...configCurrentData, | ||
pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), | ||
errorFields: Object.fromEntries( | ||
Object.keys(configUpdate).map((settingName) => [settingName, ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')]), | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const successData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), | ||
errorFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
return { | ||
optimisticData, | ||
failureData, | ||
successData, | ||
}; | ||
} | ||
|
||
function buildOnyxDataForQuickbooksConfiguration<TSettingName extends keyof Connections['quickbooksDesktop']['config']>( | ||
policyID: string, | ||
settingName: TSettingName, | ||
settingValue: Partial<Connections['quickbooksDesktop']['config'][TSettingName]>, | ||
oldSettingValue?: Partial<Connections['quickbooksDesktop']['config'][TSettingName]>, | ||
) { | ||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
[settingName]: settingValue ?? null, | ||
pendingFields: { | ||
[settingName]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, | ||
}, | ||
errorFields: { | ||
[settingName]: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const failureData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
[settingName]: oldSettingValue ?? null, | ||
pendingFields: { | ||
[settingName]: null, | ||
}, | ||
errorFields: { | ||
[settingName]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const successData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
connections: { | ||
[CONST.POLICY.CONNECTIONS.NAME.QBD]: { | ||
config: { | ||
[settingName]: settingValue ?? null, | ||
pendingFields: { | ||
[settingName]: null, | ||
}, | ||
errorFields: { | ||
[settingName]: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
return { | ||
optimisticData, | ||
failureData, | ||
successData, | ||
}; | ||
} | ||
|
||
function updateQuickbooksDesktopMarkChecksToBePrinted<TSettingValue extends Connections['quickbooksDesktop']['config']['markChecksToBePrinted']>( | ||
policyID: string, | ||
settingValue: TSettingValue, | ||
) { | ||
const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICKBOOKS_DESKTOP_CONFIG.MARK_CHECKS_TO_BE_PRINTED, settingValue, !settingValue); | ||
|
||
const parameters: UpdateQuickbooksDesktopGenericTypeParams = { | ||
policyID, | ||
settingValue: JSON.stringify(settingValue), | ||
idempotencyKey: String(CONST.QUICKBOOKS_CONFIG.AUTO_SYNC), | ||
}; | ||
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_DESKTOP_MARK_CHECKS_TO_BE_PRINTED, parameters, onyxData); | ||
} | ||
|
||
function updateQuickbooksDesktopReimbursableExpensesAccount<TSettingValue extends Connections['quickbooksDesktop']['config']['reimbursableExpensesAccount']>( | ||
policyID: string, | ||
settingValue: TSettingValue, | ||
oldSettingValue: TSettingValue, | ||
) { | ||
const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, settingValue, oldSettingValue); | ||
|
||
const parameters: UpdateQuickbooksDesktopGenericTypeParams = { | ||
policyID, | ||
settingValue: JSON.stringify(settingValue), | ||
idempotencyKey: String(CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT), | ||
}; | ||
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_DESKTOP_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, onyxData); | ||
} | ||
|
||
export {updateQuickbooksDesktopMarkChecksToBePrinted, updateQuickbooksDesktopReimbursableExpensesAccount, buildOnyxDataForMultipleQuickbooksConfigurations}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.