-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix: Change offline pattern for unassigning cards #52109
Changes from 3 commits
3056dc0
c1999bf
9e2771a
2e487d1
39b17d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
type UnassignCompanyCard = { | ||
authToken?: string | null; | ||
cardID: string; | ||
cardID: number; | ||
}; | ||
|
||
export default UnassignCompanyCard; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
type UpdateCompanyCard = { | ||
authToken?: string | null; | ||
cardID: string; | ||
cardID: number; | ||
}; | ||
|
||
export default UpdateCompanyCard; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import * as PolicyUtils from '@libs/PolicyUtils'; | |
import * as ReportUtils from '@libs/ReportUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Card} from '@src/types/onyx'; | ||
import type {AssignCard, AssignCardData} from '@src/types/onyx/AssignCard'; | ||
import type {AddNewCardFeedData, AddNewCardFeedStep, CompanyCardFeed} from '@src/types/onyx/CardFeeds'; | ||
import type {OnyxData} from '@src/types/onyx/Request'; | ||
|
@@ -232,8 +233,9 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial<AssignCardD | |
API.write(WRITE_COMMANDS.ASSIGN_COMPANY_CARD, parameters, onyxData); | ||
} | ||
|
||
function unassignWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, bankName: string) { | ||
function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: string, card?: Card) { | ||
const authToken = NetworkStore.getAuthToken(); | ||
const cardID = card?.cardID ?? '-1'; | ||
|
||
const onyxData: OnyxData = { | ||
optimisticData: [ | ||
|
@@ -244,12 +246,59 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, cardID: string | |
[cardID]: null, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: { | ||
[cardID]: null, | ||
}, | ||
}, | ||
], | ||
|
||
failureData: [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, | ||
value: { | ||
[cardID]: { | ||
...card, | ||
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: { | ||
[cardID]: { | ||
...card, | ||
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.CARD_LIST, | ||
value: { | ||
[cardID]: null, | ||
}, | ||
}, | ||
], | ||
|
||
successData: [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, | ||
value: { | ||
[cardID]: null, | ||
}, | ||
}, | ||
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. this is redundant, right? 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. whyyyy? 🤔 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. @koko57 We already removed the card on optimistic data |
||
], | ||
}; | ||
|
||
const parameters = { | ||
authToken, | ||
cardID, | ||
cardID: Number(cardID), | ||
}; | ||
|
||
API.write(WRITE_COMMANDS.UNASSIGN_COMPANY_CARD, parameters, onyxData); | ||
|
@@ -378,7 +427,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, | |
|
||
const parameters = { | ||
authToken, | ||
cardID, | ||
cardID: Number(cardID), | ||
}; | ||
|
||
API.write(WRITE_COMMANDS.UPDATE_COMPANY_CARD, parameters, {optimisticData, finallyData, failureData}); | ||
|
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.
this is redundant, right?
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.
ok, I see now 😅