-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve feed removal flow offline #54425
Merged
mountiny
merged 9 commits into
Expensify:main
from
callstack-internal:VickyStash/bugfix/54379-delete-feed-offline
Dec 26, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
daf0d1b
Improve feed removal offline
VickyStash 2f4ece3
Merge branch 'refs/heads/main' into VickyStash/bugfix/54379-delete-fe…
VickyStash c3accb3
Fix lint errors
VickyStash 7d7324f
Fix tests
VickyStash 470b835
Code improvement
VickyStash b75a4cf
Fix lint
VickyStash 785eccd
Improve getCompanyFeeds function and get rid of removeExpensifyCardFr…
VickyStash 75299dc
Lint fixes
VickyStash d11c081
Buf fix
VickyStash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -124,7 +124,6 @@ function setWorkspaceCompanyCardFeedName(policyID: string, workspaceAccountID: n | |
|
||
function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, policyID: string, bankName: CompanyCardFeed, liabilityType: string) { | ||
const authToken = NetworkStore.getAuthToken(); | ||
const isCustomFeed = CardUtils.isCustomFeed(bankName); | ||
const feedUpdates = { | ||
[bankName]: {liabilityType}, | ||
}; | ||
|
@@ -135,7 +134,7 @@ function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, | |
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: isCustomFeed ? {companyCards: feedUpdates} : {oAuthAccountDetails: feedUpdates}, | ||
settings: {companyCards: feedUpdates}, | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
], | ||
|
@@ -151,41 +150,97 @@ function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, | |
API.write(WRITE_COMMANDS.SET_COMPANY_CARD_TRANSACTION_LIABILITY, parameters, onyxData); | ||
} | ||
|
||
function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: number, bankName: CompanyCardFeed, feedToOpen?: CompanyCardFeed) { | ||
function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: number, bankName: CompanyCardFeed, cardIDs: string[], feedToOpen?: CompanyCardFeed) { | ||
const authToken = NetworkStore.getAuthToken(); | ||
const isCustomFeed = CardUtils.isCustomFeed(bankName); | ||
const feedUpdates = {[bankName]: null}; | ||
const optimisticFeedUpdates = {[bankName]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}; | ||
const successFeedUpdates = {[bankName]: null}; | ||
const failureFeedUpdates = {[bankName]: {pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}}; | ||
const optimisticCardUpdates = Object.fromEntries(cardIDs.map((cardID) => [cardID, {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}])); | ||
const successAndFailureCardUpdates = Object.fromEntries(cardIDs.map((cardID) => [cardID, {pendingAction: null}])); | ||
|
||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: { | ||
...(isCustomFeed ? {companyCards: feedUpdates} : {oAuthAccountDetails: feedUpdates}), | ||
companyCards: optimisticFeedUpdates, | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, | ||
value: optimisticCardUpdates, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: optimisticCardUpdates, | ||
}, | ||
]; | ||
|
||
const successData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: { | ||
...(isCustomFeed ? {companyCards: successFeedUpdates} : {oAuthAccountDetails: successFeedUpdates, companyCards: successFeedUpdates}), | ||
companyCardNicknames: { | ||
[bankName]: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, | ||
value: successAndFailureCardUpdates, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: successAndFailureCardUpdates, | ||
}, | ||
]; | ||
|
||
if (feedToOpen) { | ||
optimisticData.push({ | ||
const failureData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, | ||
value: feedToOpen, | ||
}); | ||
} | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: { | ||
companyCards: failureFeedUpdates, | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, | ||
value: successAndFailureCardUpdates, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: successAndFailureCardUpdates, | ||
}, | ||
]; | ||
|
||
optimisticData.push({ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, | ||
value: feedToOpen ?? null, | ||
}); | ||
Comment on lines
+231
to
+235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: no need to push this right? we can just add it to the array above |
||
|
||
const parameters = { | ||
authToken, | ||
policyID, | ||
bankName, | ||
}; | ||
|
||
API.write(WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED, parameters, {optimisticData}); | ||
API.write(WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED, parameters, {optimisticData, successData, failureData}); | ||
} | ||
|
||
function assignWorkspaceCompanyCard(policyID: string, data?: Partial<AssignCardData>) { | ||
|
@@ -194,7 +249,7 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial<AssignCardD | |
} | ||
const {bankName = '', email = '', encryptedCardNumber = '', startDate = '', cardName = ''} = data; | ||
const assigneeDetails = PersonalDetailsUtils.getPersonalDetailByEmail(email); | ||
const optimisticCardAssignedReportAction = ReportUtils.buildOptimisticCardAssignedReportAction(assigneeDetails?.accountID ?? -1); | ||
const optimisticCardAssignedReportAction = ReportUtils.buildOptimisticCardAssignedReportAction(assigneeDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID); | ||
|
||
const parameters: AssignCompanyCardParams = { | ||
policyID, | ||
|
@@ -206,7 +261,7 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial<AssignCardD | |
reportActionID: optimisticCardAssignedReportAction.reportActionID, | ||
}; | ||
const policy = PolicyUtils.getPolicy(policyID); | ||
const policyExpenseChat = ReportUtils.getPolicyExpenseChat(policy?.ownerAccountID ?? -1, policyID); | ||
const policyExpenseChat = ReportUtils.getPolicyExpenseChat(policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID, policyID); | ||
|
||
const onyxData: OnyxData = { | ||
optimisticData: [ | ||
|
@@ -242,9 +297,9 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial<AssignCardD | |
API.write(WRITE_COMMANDS.ASSIGN_COMPANY_CARD, parameters, onyxData); | ||
} | ||
|
||
function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: string, card?: Card) { | ||
function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: string, card: Card) { | ||
const authToken = NetworkStore.getAuthToken(); | ||
const cardID = card?.cardID ?? '-1'; | ||
const cardID = card.cardID; | ||
|
||
const onyxData: OnyxData = { | ||
optimisticData: [ | ||
|
@@ -319,7 +374,6 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri | |
|
||
function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, bankName: CompanyCardFeed) { | ||
const authToken = NetworkStore.getAuthToken(); | ||
const isCustomFeed = CardUtils.isCustomFeed(bankName); | ||
const optimisticFeedUpdates = {[bankName]: {errors: null}}; | ||
const failureFeedUpdates = {[bankName]: {errors: {error: CONST.COMPANY_CARDS.CONNECTION_ERROR}}}; | ||
|
||
|
@@ -358,7 +412,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, | |
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: isCustomFeed ? {companyCards: optimisticFeedUpdates} : {oAuthAccountDetails: optimisticFeedUpdates}, | ||
settings: {companyCards: optimisticFeedUpdates}, | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
]; | ||
|
@@ -425,7 +479,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, | |
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||
value: { | ||
settings: isCustomFeed ? {companyCards: failureFeedUpdates} : {oAuthAccountDetails: failureFeedUpdates}, | ||
settings: {companyCards: failureFeedUpdates}, | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
]; | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VickyStash Why do we remove cardFeeds?.settings?.oAuthAccountDetails here? As I understand, direct feeds will be saved in oAuthAccountDetails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, both custom and direct feed settings are stored under the
companyCards
field.oAuthAccountDetails
stores only data for direct feed card assignment.See the data:
Please, see related discussion in slack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks