Fix no error shows when saving personal bank account that exist in workspace BA draft#39398
Conversation
|
@cubuspl42 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
80fa57a to
b014e37
Compare
|
I accidentally comitted unrelated files, so I force pushed. |
|
TypeScript Checks |
| AddPersonalBankAccountPage.displayName = 'AddPersonalBankAccountPage'; | ||
|
|
||
| export default withOnyx<AddPersonalBankAccountPageWithOnyxProps, AddPersonalBankAccountPageWithOnyxProps>({ | ||
| // @ts-expect-error: ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT |
There was a problem hiding this comment.
Looks like the type is conflicting. We did this for all reimbursement account step.
App/src/pages/ReimbursementAccount/PersonalInfo/PersonalInfo.tsx
Lines 98 to 102 in bf1ec5a
There was a problem hiding this comment.
@blazejkustra Do you have any idea how we could solve this without expecting errors?
There was a problem hiding this comment.
Yes, we should not conflict onyx keys:
/** Stores information about the active personal bank account being set up */
PERSONAL_BANK_ACCOUNT: 'personalBankAccount',
FORMS: {
PERSONAL_BANK_ACCOUNT: 'personalBankAccountForm', // different than 'personalBankAccount'
PERSONAL_BANK_ACCOUNT_DRAFT: 'personalBankAccountFormDraft',
}PERSONAL_BANK_ACCOUNT and FORMS.PERSONAL_BANK_ACCOUNT should have different values. If not we have to use ts-expect-error 😒
There was a problem hiding this comment.
Yeah, but apparently, the backend expects this key to be personalBankAccount. This is the reason why we don't apply the *Form suffix to all keys.
I think we should do something systematic here. Either drop the assumption about unique keys or adjust the backend.
@blazejkustra Do you think the first one is possible/reasonable?
@Gonals How would you assess the difficulty of adjusting the backend?
I know that changing the backend because of the fronend typing might feel counterintuitive, but from my perspective, it's about designing a consistent Onyx key system, taking all practical aspects into consideration. We should decide whether key uniqueness should or shouldn't be a requirement in this system, and then adjust whatever needs to be adjusted.
There was a problem hiding this comment.
Do you think the first one is possible/reasonable?
It's possible, because we already have some keys that aren't unique. But this comes with a lot of ts-expect-errors in the code. We could overcome this by defining a common type for both personal bank account and personal bank account form, but this would require a big refactor across the codebase due to conflicts in these two types.
It's not reasonable, without unique keys we would compromise on types because a key could be either a PersonalDetailsForm type or PersonalDetails and this would create a big mess inside components (try it for yourself 😅)
I understand Expensify has other priorities at the moment, but the best approach would be to fix this on the backend side and keep keys unique.
| // @ts-expect-error: ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.PERSONAL_BANK_ACCOUNT, |
There was a problem hiding this comment.
This also conflicts because of the errors property. It expects to be FormValue | null | undefined, but the error type is OnyxCommon.Errors.
Lines 4 to 16 in bf1ec5a
If we don't pass anything to TInputs, then the value type is expected to be FormValue. If I pass any value to it, then the type error is gone.
type PersonalBankAccountForm = Form<"test">
|
Additional video showing that it still works in a normal case. Screen.Recording.2024-04-02.at.19.49.13.mov |
src/libs/actions/BankAccounts.ts
Outdated
| }, | ||
| ], | ||
| failureData: [ | ||
| // @ts-expect-error: ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT |
There was a problem hiding this comment.
I don't understand why we need both these keys; could you explain it to me? I thought that keeping both was the original human mistake here and the cause of all the trouble.
There was a problem hiding this comment.
I think it's mainly for type and convention. The FormProvider formID expects the value to be one of the keys of OnyxFormValuesMapping type,
Line 494 in a1801c8
and the type for ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT is FormTypes.PersonalBankAccountForm. I think it would be weird if I change the type to be OnyxTypes.PersonalBankAccount.
There was a problem hiding this comment.
And we can't switch to just ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT, right?
There was a problem hiding this comment.
Why can't we? By "switch" I mean start using ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT where we now use ONYXKEYS.PERSONAL_BANK_ACCOUNT. Are there also some typing constraints here?
There was a problem hiding this comment.
Oh, I thought you mean to use ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT with the old value (personalBankAccountForm).
We can but the type error still exists without ignoring it.
There was a problem hiding this comment.
Okey, so maybe I'm misunderstanding the error.
ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT
If ONYXKEYS.PERSONAL_BANK_ACCOUNT didn't exist (because we replaced all usages with the new key, ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT and deleted ONYXKEYS.PERSONAL_BANK_ACCOUNT itself ), than how would it conflict?
There was a problem hiding this comment.
I explained it briefly in the previous comment here.
Here is the type of the onyx update:

The KeyValueMapping type includes this custom type:
App/src/types/modules/react-native-onyx.d.ts
Lines 6 to 10 in 7446c1a
The OnyxValues contains the type for both ONYXKEYS.PERSONAL_BANK_ACCOUNT (PersonalBankAccount) and ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT (PersonalBankAccountForm).
Line 642 in 7446c1a
Because the key is the same (personalBankAccount, both types are used)
I have tried doing this:
type PersonalBankAccountForm = Form & PersonalBankAccount;
But still get the error.
There was a problem hiding this comment.
I've inspected the code; please disregard my previous suggestions. I underestimated how much is going on here type-wise.
Reviewer Checklist
Screenshots/VideosAndroid: NativeMacOS: Desktop |
|
@bernhardoj Would you solve the conflicts? |
|
It's conflicted with #39038, I'll check it more tomorrow. |
| function clearPersonalBankAccount() { | ||
| clearPlaid(); | ||
| Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {}); | ||
| Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, null); |
There was a problem hiding this comment.
Changed this to null to fix the type. Every usage of personalBankAccount already uses a null safety, so it's safe.
|
@cubuspl42 I have retested this PR and the test step from #39038 and everything still seems works fine. |
|
@Gonals The typing situation is far from perfect here, but it's not trivial to fix it. Please see this comment for context. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/Gonals in version: 1.4.63-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.4.63-21 🚀
|





Details
In personal bank account page, the form key doesn't match the key we use to save the error (and loading state), so the error (and loading) is never shown. This PR fixes it by using the correct key.
Fixed Issues
$ #38518
PROPOSAL: #38518 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
Prerequisite: have an ongoing bank account setup in workspace bank account
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2024-04-02.at.18.25.56.mov
Android: mWeb Chrome
Screen.Recording.2024-04-02.at.19.53.49.mov
iOS: Native
iOS: mWeb Safari
Screen.Recording.2024-04-02.at.18.30.20.mov
MacOS: Chrome / Safari
Screen.Recording.2024-04-02.at.18.21.09.mov
MacOS: Desktop
Screen.Recording.2024-04-02.at.18.23.20.mov