Skip to content

Commit

Permalink
Merge pull request #39162 from tienifr/fix/38585
Browse files Browse the repository at this point in the history
fix company website field missing https
  • Loading branch information
cristipaval authored Mar 29, 2024
2 parents 5a8cb7f + 4dc4683 commit fdc6836
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/libs/BankAccountUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Str from 'expensify-common/lib/str';
import type {OnyxEntry} from 'react-native-onyx';
import type * as OnyxTypes from '@src/types/onyx';

function getDefaultCompanyWebsite(session: OnyxEntry<OnyxTypes.Session>, user: OnyxEntry<OnyxTypes.User>): string {
return user?.isFromPublicDomain ? 'https://' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`;
}
// eslint-disable-next-line import/prefer-default-export
export {getDefaultCompanyWebsite};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes';
import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes';
import CONST from '@src/CONST';
Expand All @@ -12,7 +13,7 @@ import type * as OnyxTypes from '@src/types/onyx';
/**
* Reset user's reimbursement account. This will delete the bank account.
*/
function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<OnyxTypes.Session>, policyID: string) {
function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<OnyxTypes.Session>, policyID: string, user: OnyxEntry<OnyxTypes.User>) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand Down Expand Up @@ -84,7 +85,7 @@ function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<Onyx
[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]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: getDefaultCompanyWebsite(session, user),
[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,3 @@
import Str from 'expensify-common/lib/str';
import React, {useEffect, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -11,6 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import useReimbursementAccountStepFormSubmit from '@hooks/useReimbursementAccountStepFormSubmit';
import type {SubStepProps} from '@hooks/useSubStep/types';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -48,10 +48,7 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing
const {translate} = useLocalize();
const styles = useThemeStyles();

const defaultWebsiteExample = useMemo(
() => (user?.isFromPublicDomain ? 'https://' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`),
[session?.email, user?.isFromPublicDomain],
);
const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session, user]);
const defaultCompanyWebsite = reimbursementAccount?.achData?.website ?? defaultWebsiteExample;

const handleSubmit = useReimbursementAccountStepFormSubmit({
Expand Down
13 changes: 11 additions & 2 deletions src/pages/workspace/WorkspaceResetBankAccountModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ const propTypes = {
/** Currently logged in user email */
email: PropTypes.string,
}).isRequired,

/** Information about the logged in user's account */
user: PropTypes.shape({
/** Whether or not the user is on a public domain email account or not */
isFromPublicDomain: PropTypes.bool,
}).isRequired,
};

function WorkspaceResetBankAccountModal({reimbursementAccount, session}) {
function WorkspaceResetBankAccountModal({reimbursementAccount, session, user}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const achData = lodashGet(reimbursementAccount, 'achData') || {};
Expand All @@ -48,7 +54,7 @@ function WorkspaceResetBankAccountModal({reimbursementAccount, session}) {
}
danger
onCancel={BankAccounts.cancelResetFreePlanBankAccount}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session, achData.policyID)}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session, achData.policyID, user)}
shouldShowCancelButton
isVisible
/>
Expand All @@ -62,4 +68,7 @@ export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
user: {
key: ONYXKEYS.USER,
},
})(WorkspaceResetBankAccountModal);

0 comments on commit fdc6836

Please sign in to comment.