Skip to content
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 company's website step is skipped #46940

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Form/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type {RegisterInput} from './FormContext';
import FormContext from './FormContext';
import FormWrapper from './FormWrapper';
import type {FormInputErrors, FormOnyxValues, FormProps, FormRef, InputComponentBaseProps, InputRefs, ValueTypeKey} from './types';
import type {FormInputErrors, FormOnyxValues, FormProps, FormRef, FormValue, InputComponentBaseProps, InputRefs, ValueTypeKey} from './types';

// In order to prevent Checkbox focus loss when the user are focusing a TextInput and proceeds to toggle a CheckBox in web and mobile web.
// 200ms delay was chosen as a result of empirical testing.
Expand All @@ -40,6 +40,10 @@
}
}

function isEmptyValue(value: FormValue) {
return value === undefined || value === '';
};

Check failure on line 45 in src/components/Form/FormProvider.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Delete `;`

type FormProviderOnyxProps = {
/** Contains the form state that must be accessed outside the component */
formState: OnyxEntry<Form>;
Expand Down Expand Up @@ -249,7 +253,7 @@
} else if (inputProps.shouldUseDefaultValue && inputProps.defaultValue !== undefined && inputValues[inputID] === undefined) {
// We force the form to set the input value from the defaultValue props if there is a saved valid value
inputValues[inputID] = inputProps.defaultValue;
} else if (inputValues[inputID] === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did some testing to see if this change affects other forms in the app and I found an issue in the money request merchant page.

e.mp4

From the video above, you can see that when I try to clear the merchant, the value always reverted back to the saved merchant, so, I believe we can't change this to check for an empty string.

I have reverted this change and instead reset the website to undefined instead of an empty string.

} else if (isEmptyValue(inputValues[inputID])) {
// We want to initialize the input value if it's undefined
inputValues[inputID] = inputProps.defaultValue ?? getInitialValueByType(inputProps.valueType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';

Check failure on line 5 in src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'getDefaultCompanyWebsite' is defined but never used
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
Expand All @@ -18,7 +18,7 @@
/**
* Reset user's reimbursement account. This will delete the bank account.
*/
function resetFreePlanBankAccount(bankAccountID: number | undefined, session: OnyxEntry<OnyxTypes.Session>, policyID: string, user: OnyxEntry<OnyxTypes.User>) {

Check failure on line 21 in src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'user' is defined but never used
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand Down Expand Up @@ -98,7 +98,7 @@
[INPUT_IDS.BUSINESS_INFO_STEP.STATE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.ZIP_CODE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_PHONE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: getDefaultCompanyWebsite(session, user),
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_TAX_ID]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_TYPE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_DATE]: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect, useMemo} from 'react';

Check failure on line 1 in src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'useEffect' is defined but never used
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
Expand All @@ -12,7 +12,7 @@
import useThemeStyles from '@hooks/useThemeStyles';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as BankAccounts from '@userActions/BankAccounts';

Check failure on line 15 in src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'BankAccounts' is defined but never used
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
Expand All @@ -39,7 +39,7 @@
const styles = useThemeStyles();

const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session, user]);
const defaultCompanyWebsite = reimbursementAccount?.achData?.website ?? defaultWebsiteExample;
const defaultCompanyWebsite = reimbursementAccount?.achData?.website || defaultWebsiteExample;

Check failure on line 42 in src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM> => {
Expand All @@ -59,10 +59,6 @@
shouldSaveDraft: isEditing,
});

useEffect(() => {
BankAccounts.addBusinessWebsiteForDraft(defaultCompanyWebsite);
}, [defaultCompanyWebsite]);

return (
<FormProvider
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as ValidationUtils from '@libs/ValidationUtils';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';
import type {CompanyStepProps} from '@src/types/form/ReimbursementAccountForm';

Expand All @@ -15,7 +16,7 @@ function getInitialSubstepForBusinessInfo(data: CompanyStepProps): number {
return 1;
}

if (data[businessInfoStepKeys.COMPANY_WEBSITE] === '') {
if (data[businessInfoStepKeys.COMPANY_WEBSITE] === '' || !ValidationUtils.isValidWebsite(data[businessInfoStepKeys.COMPANY_WEBSITE])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (data[businessInfoStepKeys.COMPANY_WEBSITE] === '' || !ValidationUtils.isValidWebsite(data[businessInfoStepKeys.COMPANY_WEBSITE])) {
if (!ValidationUtils.isValidWebsite(data[businessInfoStepKeys.COMPANY_WEBSITE])) {

Function isValidWebsite also cover an empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, updated!

return 2;
}

Expand Down
Loading