11import React , { useCallback , useEffect , useState } from 'react' ;
22import { View } from 'react-native' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
4- import { withOnyx } from 'react-native-onyx' ;
54import type { ValueOf } from 'type-fest' ;
65import Button from '@components/Button' ;
6+ import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
77import Text from '@components/Text' ;
88import useLocalize from '@hooks/useLocalize' ;
99import useThemeStyles from '@hooks/useThemeStyles' ;
10- import * as WorkspaceSettingsUtils from '@libs/WorkspacesSettingsUtils' ;
10+ import { clearWorkspaceOwnerChangeFlow , requestWorkspaceOwnerChange } from '@libs/actions/Policy/Member' ;
11+ import { getOwnershipChecksDisplayText } from '@libs/WorkspacesSettingsUtils' ;
1112import Navigation from '@navigation/Navigation' ;
12- import * as MemberActions from '@userActions/Policy/Member' ;
1313import CONST from '@src/CONST' ;
14- import ONYXKEYS from '@src/ONYXKEYS' ;
1514import ROUTES from '@src/ROUTES' ;
1615import type * as OnyxTypes from '@src/types/onyx' ;
1716
18- type WorkspaceOwnerChangeCheckOnyxProps = {
19- /** Personal details of all users */
20- personalDetails : OnyxEntry < OnyxTypes . PersonalDetailsList > ;
21- } ;
22-
23- type WorkspaceOwnerChangeCheckProps = WorkspaceOwnerChangeCheckOnyxProps & {
17+ type WorkspaceOwnerChangeCheckProps = {
2418 /** The policy */
2519 policy : OnyxEntry < OnyxTypes . Policy > ;
2620
@@ -31,24 +25,25 @@ type WorkspaceOwnerChangeCheckProps = WorkspaceOwnerChangeCheckOnyxProps & {
3125 error : ValueOf < typeof CONST . POLICY . OWNERSHIP_ERRORS > ;
3226} ;
3327
34- function WorkspaceOwnerChangeCheck ( { personalDetails , policy, accountID, error} : WorkspaceOwnerChangeCheckProps ) {
28+ function WorkspaceOwnerChangeCheck ( { policy, accountID, error} : WorkspaceOwnerChangeCheckProps ) {
3529 const styles = useThemeStyles ( ) ;
3630 const { translate} = useLocalize ( ) ;
3731 const [ displayTexts , setDisplayTexts ] = useState ( {
3832 title : '' ,
3933 text : '' ,
4034 buttonText : '' ,
4135 } ) ;
36+ const personalDetails = usePersonalDetails ( ) ;
4237
43- const policyID = policy ?. id ?? '-1' ;
38+ const policyID = policy ?. id ;
4439
4540 const updateDisplayTexts = useCallback ( ( ) => {
4641 const changeOwnerErrors = Object . keys ( policy ?. errorFields ?. changeOwner ?? { } ) ;
4742 if ( error !== changeOwnerErrors . at ( 0 ) ) {
4843 return ;
4944 }
5045
51- const texts = WorkspaceSettingsUtils . getOwnershipChecksDisplayText ( error , translate , policy , personalDetails ?. [ accountID ] ?. login ) ;
46+ const texts = getOwnershipChecksDisplayText ( error , translate , policy , personalDetails ?. [ accountID ] ?. login ) ;
5247 setDisplayTexts ( texts ) ;
5348 } , [ accountID , error , personalDetails , policy , translate ] ) ;
5449
@@ -57,15 +52,18 @@ function WorkspaceOwnerChangeCheck({personalDetails, policy, accountID, error}:
5752 } , [ updateDisplayTexts ] ) ;
5853
5954 const confirm = useCallback ( ( ) => {
55+ if ( ! policyID ) {
56+ return ;
57+ }
6058 if ( error === CONST . POLICY . OWNERSHIP_ERRORS . HAS_FAILED_SETTLEMENTS || error === CONST . POLICY . OWNERSHIP_ERRORS . FAILED_TO_CLEAR_BALANCE ) {
6159 // cannot transfer ownership if there are failed settlements, or we cannot clear the balance
62- MemberActions . clearWorkspaceOwnerChangeFlow ( policyID ) ;
60+ clearWorkspaceOwnerChangeFlow ( policyID ) ;
6361 Navigation . goBack ( ) ;
6462 Navigation . navigate ( ROUTES . WORKSPACE_MEMBER_DETAILS . getRoute ( policyID , accountID ) ) ;
6563 return ;
6664 }
6765
68- MemberActions . requestWorkspaceOwnerChange ( policyID ) ;
66+ requestWorkspaceOwnerChange ( policyID ) ;
6967 } , [ accountID , error , policyID ] ) ;
7068
7169 return (
@@ -86,8 +84,4 @@ function WorkspaceOwnerChangeCheck({personalDetails, policy, accountID, error}:
8684
8785WorkspaceOwnerChangeCheck . displayName = 'WorkspaceOwnerChangeCheckPage' ;
8886
89- export default withOnyx < WorkspaceOwnerChangeCheckProps , WorkspaceOwnerChangeCheckOnyxProps > ( {
90- personalDetails : {
91- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
92- } ,
93- } ) ( WorkspaceOwnerChangeCheck ) ;
87+ export default WorkspaceOwnerChangeCheck ;
0 commit comments