From b317e2dffff2677b5d702bf0fbed0edf84d58229 Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 27 Mar 2024 08:56:24 +0100 Subject: [PATCH 01/10] switched to use of correct currency utility function --- src/libs/WorkspacesSettingsUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 00e8a96e56b4..438c36e3dede 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -12,6 +12,7 @@ import * as OptionsListUtils from './OptionsListUtils'; import {hasCustomUnitsError, hasPolicyError, hasPolicyMemberError, hasTaxRateError} from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; +import {convertToDisplayString} from "./CurrencyUtils"; type CheckingMethod = () => boolean; @@ -247,7 +248,7 @@ function getOwnershipChecksDisplayText( title = translate('workspace.changeOwner.ownerOwesAmountTitle'); text = translate('workspace.changeOwner.ownerOwesAmountText', { email: ownerOwesAmount?.ownerEmail, - amount: CurrencyUtils.convertAmountToDisplayString(ownerOwesAmount?.amount, ownerOwesAmount?.currency), + amount: CurrencyUtils.convertToDisplayString(ownerOwesAmount?.amount, ownerOwesAmount?.currency), }); buttonText = translate('workspace.changeOwner.ownerOwesAmountButtonText'); break; From cc3fb59106ef99be4cadce483db9ec9c2f7ca0f8 Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 27 Mar 2024 09:04:13 +0100 Subject: [PATCH 02/10] missing flags setting for add billing card action added --- src/libs/actions/Policy.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 45fc139b6742..9e71eb36ac38 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1131,6 +1131,8 @@ function addBillingCardAndRequestPolicyOwnerChange( value: { errorFields: null, isLoading: true, + isChangeOwnerSuccessful: false, + isChangeOwnerFailed: false, }, }, ]; @@ -1141,6 +1143,8 @@ function addBillingCardAndRequestPolicyOwnerChange( key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { isLoading: false, + isChangeOwnerSuccessful: true, + isChangeOwnerFailed: false, }, }, ]; @@ -1151,6 +1155,8 @@ function addBillingCardAndRequestPolicyOwnerChange( key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { isLoading: false, + isChangeOwnerSuccessful: false, + isChangeOwnerFailed: true, }, }, ]; From b69dee8190b965013e8145d062f637f3f408c1b7 Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 27 Mar 2024 09:09:36 +0100 Subject: [PATCH 03/10] unnecessary import removed --- src/libs/WorkspacesSettingsUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 438c36e3dede..30820fc0c48b 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -12,7 +12,6 @@ import * as OptionsListUtils from './OptionsListUtils'; import {hasCustomUnitsError, hasPolicyError, hasPolicyMemberError, hasTaxRateError} from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; -import {convertToDisplayString} from "./CurrencyUtils"; type CheckingMethod = () => boolean; From e5b480db209290b9d7d54ea4bc868c7ad08f0db7 Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 27 Mar 2024 10:57:18 +0100 Subject: [PATCH 04/10] issue with stale error messages shown for ms fixed --- .../members/WorkspaceOwnerChangeCheck.tsx | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx b/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx index fea6457824da..2b757f9c9955 100644 --- a/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx +++ b/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx @@ -1,4 +1,4 @@ -import React, {useCallback} from 'react'; +import React, {useCallback, useEffect, useMemo, useState} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; @@ -30,12 +30,39 @@ type WorkspaceOwnerChangeCheckProps = WorkspaceOwnerChangeCheckOnyxProps & { error: ValueOf; }; +const defaultDisplayTexts = { + title: '', + text: '', + buttonText: '', +}; + function WorkspaceOwnerChangeCheck({personalDetails, policy, accountID, error}: WorkspaceOwnerChangeCheckProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const [displayTexts, setDisplayTexts] = useState<{title: string; text: string; buttonText: string}>(defaultDisplayTexts); const policyID = policy?.id ?? ''; + const errorsKeys = useMemo(() => Object.keys(policy?.errorFields?.changeOwner ?? {}), [policy]); + + const updateDisplayTexts = useCallback(() => { + if (error !== errorsKeys[0]) { + return; + } + + const texts = WorkspaceSettingsUtils.getOwnershipChecksDisplayText(error, translate, policy, personalDetails?.[accountID]?.login); + setDisplayTexts(texts); + }, [accountID, error, errorsKeys, personalDetails, policy, translate]); + + useEffect(() => { + updateDisplayTexts(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + useEffect(() => { + updateDisplayTexts(); + }, [updateDisplayTexts]); + const confirm = useCallback(() => { if (error === CONST.POLICY.OWNERSHIP_ERRORS.HAS_FAILED_SETTLEMENTS || error === CONST.POLICY.OWNERSHIP_ERRORS.FAILED_TO_CLEAR_BALANCE) { // cannot transfer ownership if there are failed settlements, or we cannot clear the balance @@ -47,17 +74,15 @@ function WorkspaceOwnerChangeCheck({personalDetails, policy, accountID, error}: PolicyActions.requestWorkspaceOwnerChange(policyID); }, [accountID, error, policyID]); - const {title, text, buttonText} = WorkspaceSettingsUtils.getOwnershipChecksDisplayText(error, translate, policy, personalDetails?.[accountID]?.login); - return ( <> - {title} - {text} + {displayTexts.title} + {displayTexts.text}