-
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 no error shows when saving personal bank account that exist in workspace BA draft #39398
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 |
@@ -103,6 +103,7 @@ function AddPersonalBankAccountPage({personalBankAccount, plaidData}: AddPersona | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
export default withOnyx<PersonalInfoProps, PersonalInfoOnyxProps>({ | |
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM | |
reimbursementAccount: { | |
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, | |
}, |
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.
@blazejkustra Do you have any idea how we could solve this without expecting errors?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/libs/actions/BankAccounts.ts
Outdated
@@ -208,6 +208,7 @@ function addPersonalBankAccount(account: PlaidBankAccount) { | |||
}, | |||
], | |||
failureData: [ | |||
// @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
type BaseForm = { | |
/** Controls the loading state of the form */ | |
isLoading?: boolean; | |
/** Server side errors keyed by microtime */ | |
errors?: OnyxCommon.Errors | null; | |
/** Field-specific server side errors keyed by microtime */ | |
errorFields?: OnyxCommon.ErrorFields | null; | |
}; | |
type FormValues<TInputs extends string> = Record<TInputs, FormValue>; | |
type Form<TInputs extends string = string, TFormValues extends FormValues<TInputs> = FormValues<TInputs>> = TFormValues & BaseForm; |
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; |
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
@@ -208,6 +208,7 @@ function addPersonalBankAccount(account: PlaidBankAccount) { | |||
}, | |||
], | |||
failureData: [ | |||
// @ts-expect-error: ONYXKEYS.PERSONAL_BANK_ACCOUNT is conflicting with ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
[ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT]: FormTypes.PersonalBankAccountForm; |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we can't switch to just ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT
, 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.
Yes
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
interface CustomTypeOptions { | |
keys: OnyxValueKey | OnyxFormKey | OnyxFormDraftKey; | |
collectionKeys: OnyxCollectionKey; | |
values: OnyxValues; | |
} |
The OnyxValues
contains the type for both ONYXKEYS.PERSONAL_BANK_ACCOUNT
(PersonalBankAccount) and ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT
(PersonalBankAccountForm).
Line 642 in 7446c1a
type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -113,7 +113,7 @@ function setPersonalBankAccountContinueKYCOnSuccess(onSuccessFallbackRoute: Rout | |||
|
|||
function clearPersonalBankAccount() { | |||
clearPlaid(); | |||
Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {}); | |||
Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, null); |
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.
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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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