From 105bf21c02ba58159dbfbf39feac606ebc4fcb5d Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 28 Mar 2024 17:27:18 +0700 Subject: [PATCH 1/6] fix company website field missing https --- .../resetFreePlanBankAccount.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 3d529ce54cd6..9f30b6a9bef6 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -1,3 +1,4 @@ +import Str from 'expensify-common/lib/str'; import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; @@ -9,6 +10,22 @@ import ONYXKEYS from '@src/ONYXKEYS'; import INPUT_IDS from '@src/types/form/ReimbursementAccountForm'; import type * as OnyxTypes from '@src/types/onyx'; +let user: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.USER, + callback: (value) => { + user = value; + }, +}); + +let session: OnyxTypes.Session = {}; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (value) => { + session = value ?? {}; + }, +}); + /** * Reset user's reimbursement account. This will delete the bank account. */ @@ -84,7 +101,7 @@ function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry Date: Thu, 28 Mar 2024 17:38:15 +0700 Subject: [PATCH 2/6] fix lint --- .../ReimbursementAccount/resetFreePlanBankAccount.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 9f30b6a9bef6..5c74f475ba2d 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -18,14 +18,6 @@ Onyx.connect({ }, }); -let session: OnyxTypes.Session = {}; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (value) => { - session = value ?? {}; - }, -}); - /** * Reset user's reimbursement account. This will delete the bank account. */ From d881ab02a6e8d70ceb109726cf948698f759b31a Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 14:19:55 +0700 Subject: [PATCH 3/6] fix create getDefaultCompanyWebsite --- src/libs/BankAccountUtils.ts | 8 ++++++++ .../resetFreePlanBankAccount.ts | 14 +++----------- .../BusinessInfo/substeps/WebsiteBusiness.tsx | 7 ++----- .../workspace/WorkspaceResetBankAccountModal.js | 13 +++++++++++-- 4 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 src/libs/BankAccountUtils.ts diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts new file mode 100644 index 000000000000..3ba73d1603ee --- /dev/null +++ b/src/libs/BankAccountUtils.ts @@ -0,0 +1,8 @@ +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 ?? '')}`; +} +export {getDefaultCompanyWebsite}; diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 5c74f475ba2d..4663fbb5bcc3 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -1,8 +1,8 @@ -import Str from 'expensify-common/lib/str'; 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'; @@ -10,18 +10,10 @@ import ONYXKEYS from '@src/ONYXKEYS'; import INPUT_IDS from '@src/types/form/ReimbursementAccountForm'; import type * as OnyxTypes from '@src/types/onyx'; -let user: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.USER, - callback: (value) => { - user = value; - }, -}); - /** * 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'); } @@ -93,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?.email, user?.isFromPublicDomain]); 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); From fa4b8d9803294e9f3c86460b939cc5e093841add Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 14:33:05 +0700 Subject: [PATCH 4/6] fix lint --- src/libs/BankAccountUtils.ts | 2 +- .../BusinessInfo/substeps/WebsiteBusiness.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts index 3ba73d1603ee..0a8af51e9dda 100644 --- a/src/libs/BankAccountUtils.ts +++ b/src/libs/BankAccountUtils.ts @@ -5,4 +5,4 @@ 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 ?? '')}`; } -export {getDefaultCompanyWebsite}; +export default getDefaultCompanyWebsite; diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx index 93e15d6be5ce..5a819ff1bd51 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx @@ -10,7 +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 getDefaultCompanyWebsite from '@libs/BankAccountUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import * as BankAccounts from '@userActions/BankAccounts'; import CONST from '@src/CONST'; @@ -48,7 +48,7 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing const {translate} = useLocalize(); const styles = useThemeStyles(); - const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session?.email, user?.isFromPublicDomain]); + const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session, user]); const defaultCompanyWebsite = reimbursementAccount?.achData?.website ?? defaultWebsiteExample; const handleSubmit = useReimbursementAccountStepFormSubmit({ From e97a964599daafc2d193523ddb5f94ff4c9d72d6 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 14:39:05 +0700 Subject: [PATCH 5/6] fix typecheck --- .../actions/ReimbursementAccount/resetFreePlanBankAccount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 4663fbb5bcc3..5a4a21df6bfb 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -2,7 +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 getDefaultCompanyWebsite from '@libs/BankAccountUtils'; import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes'; import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes'; import CONST from '@src/CONST'; From 4dc46831d89b223b54ca3371f3d0acf1c5d37392 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 15:42:05 +0700 Subject: [PATCH 6/6] fix remove export default --- src/libs/BankAccountUtils.ts | 3 ++- .../actions/ReimbursementAccount/resetFreePlanBankAccount.ts | 2 +- .../BusinessInfo/substeps/WebsiteBusiness.tsx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts index 0a8af51e9dda..a7fbc5f3bd4e 100644 --- a/src/libs/BankAccountUtils.ts +++ b/src/libs/BankAccountUtils.ts @@ -5,4 +5,5 @@ 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 ?? '')}`; } -export default getDefaultCompanyWebsite; +// 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 5a4a21df6bfb..4663fbb5bcc3 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -2,7 +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 {getDefaultCompanyWebsite} from '@libs/BankAccountUtils'; import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes'; import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes'; import CONST from '@src/CONST'; diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx index 5a819ff1bd51..e06c4d9d575e 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx @@ -10,7 +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 {getDefaultCompanyWebsite} from '@libs/BankAccountUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import * as BankAccounts from '@userActions/BankAccounts'; import CONST from '@src/CONST';