Skip to content

Commit 8b4d09e

Browse files
authored
Merge pull request Expensify#67546 from allgandalf/fixshouldRenderTransferOwnerButton
Remove Onyx.connect() for the key: ONYXKEYS.FUND_LIST in src/libs/shouldRenderTransferOwnerButton/index.native.ts
2 parents 5102377 + 1e99eef commit 8b4d09e

4 files changed

Lines changed: 38 additions & 19 deletions

File tree

src/libs/shouldRenderTransferOwnerButton/index.native.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
import isEmpty from 'lodash/isEmpty';
2-
import Onyx from 'react-native-onyx';
3-
import type {OnyxEntry} from 'react-native-onyx';
4-
import ONYXKEYS from '@src/ONYXKEYS';
5-
import type {FundList} from '@src/types/onyx';
62
import type ShouldRenderTransferOwnerButton from './types';
73

8-
let fundList: OnyxEntry<FundList>;
9-
Onyx.connect({
10-
key: ONYXKEYS.FUND_LIST,
11-
callback: (value) => {
12-
if (!value) {
13-
return;
14-
}
15-
16-
fundList = value;
17-
},
18-
});
19-
20-
const shouldRenderTransferOwnerButton: ShouldRenderTransferOwnerButton = () => {
4+
const shouldRenderTransferOwnerButton: ShouldRenderTransferOwnerButton = (fundList) => {
215
return !isEmpty(fundList);
226
};
237

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
type ShouldRenderTransferOwnerButton = () => boolean;
1+
import type {OnyxEntry} from 'react-native-onyx';
2+
import type {FundList} from '@src/types/onyx';
3+
4+
type ShouldRenderTransferOwnerButton = (fundList: OnyxEntry<FundList>) => boolean;
25

36
export default ShouldRenderTransferOwnerButton;

src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
8080
const [cardFeeds] = useCardFeeds(policyID);
8181
const [cardList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`, {canBeMissing: true});
8282
const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES, {canBeMissing: true});
83+
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
8384
const expensifyCardSettings = useExpensifyCardFeeds(policyID);
8485

8586
const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = useState(false);
@@ -321,7 +322,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
321322
</Text>
322323
)}
323324
{isSelectedMemberOwner && isCurrentUserAdmin && !isCurrentUserOwner ? (
324-
shouldRenderTransferOwnerButton() && (
325+
shouldRenderTransferOwnerButton(fundList) && (
325326
<ButtonDisabledWhenOffline
326327
text={translate('workspace.people.transferOwner')}
327328
onPress={startChangeOwnershipFlow}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type {OnyxEntry} from 'react-native-onyx';
2+
import shouldRenderTransferOwnerButton from '@libs/shouldRenderTransferOwnerButton';
3+
import type {FundList} from '@src/types/onyx';
4+
5+
describe('shouldRenderTransferOwnerButton', () => {
6+
it('should return true if the user has debit card funds', () => {
7+
const FUND_LIST: OnyxEntry<FundList> = {
8+
defaultCard: {
9+
isDefault: true,
10+
accountData: {
11+
cardYear: new Date().getFullYear(),
12+
cardMonth: new Date().getMonth() + 1,
13+
additionalData: {
14+
isBillingCard: true,
15+
},
16+
},
17+
},
18+
};
19+
20+
// eslint-disable-next-line testing-library/render-result-naming-convention
21+
const result = shouldRenderTransferOwnerButton(FUND_LIST);
22+
expect(result).toBe(true);
23+
});
24+
25+
it('should return false if fund list is empty', () => {
26+
const FUND_LIST: OnyxEntry<FundList> = {};
27+
// eslint-disable-next-line testing-library/render-result-naming-convention
28+
const result = shouldRenderTransferOwnerButton(FUND_LIST);
29+
expect(result).toBe(false);
30+
});
31+
});

0 commit comments

Comments
 (0)