diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts new file mode 100644 index 000000000000..a7fbc5f3bd4e --- /dev/null +++ b/src/libs/BankAccountUtils.ts @@ -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, user: OnyxEntry): string { + return user?.isFromPublicDomain ? 'https://' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`; +} +// eslint-disable-next-line import/prefer-default-export +export {getDefaultCompanyWebsite}; diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 3d529ce54cd6..4663fbb5bcc3 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -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'; @@ -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, policyID: string) { +function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry, policyID: string, user: OnyxEntry) { if (!bankAccountID) { throw new Error('Missing bankAccountID when attempting to reset free plan bank account'); } @@ -84,7 +85,7 @@ function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry (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({ diff --git a/src/pages/workspace/WorkspaceResetBankAccountModal.js b/src/pages/workspace/WorkspaceResetBankAccountModal.js index f98077a546ca..4c4b022039ba 100644 --- a/src/pages/workspace/WorkspaceResetBankAccountModal.js +++ b/src/pages/workspace/WorkspaceResetBankAccountModal.js @@ -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') || {}; @@ -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 /> @@ -62,4 +68,7 @@ export default withOnyx({ session: { key: ONYXKEYS.SESSION, }, + user: { + key: ONYXKEYS.USER, + }, })(WorkspaceResetBankAccountModal);