11import { Str } from 'expensify-common' ;
22import React , { useMemo } from 'react' ;
33import { View } from 'react-native' ;
4- import { withOnyx } from 'react-native-onyx' ;
5- import type { OnyxEntry } from 'react-native-onyx' ;
64import Button from '@components/Button' ;
75import DotIndicatorMessage from '@components/DotIndicatorMessage' ;
86import PressableWithFeedback from '@components/Pressable/PressableWithFeedback' ;
97import Text from '@components/Text' ;
108import useLocalize from '@hooks/useLocalize' ;
119import useNetwork from '@hooks/useNetwork' ;
10+ import useOnyx from '@hooks/useOnyx' ;
1211import useThemeStyles from '@hooks/useThemeStyles' ;
13- import * as ErrorUtils from '@libs/ErrorUtils' ;
14- import * as Session from '@userActions/Session' ;
12+ import { getErrorsWithTranslationData } from '@libs/ErrorUtils' ;
13+ import { requestUnlinkValidationLink } from '@userActions/Session' ;
1514import redirectToSignIn from '@userActions/SignInRedirect' ;
1615import CONST from '@src/CONST' ;
1716import ONYXKEYS from '@src/ONYXKEYS' ;
18- import type { Account , Credentials } from '@src/types/onyx' ;
1917import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2018
21- type UnlinkLoginFormOnyxProps = {
22- /** State for the account */
23- account : OnyxEntry < Account > ;
24-
25- /** The credentials of the logged in person */
26- credentials : OnyxEntry < Credentials > ;
27- } ;
28-
29- type UnlinkLoginFormProps = UnlinkLoginFormOnyxProps ;
30-
31- function UnlinkLoginForm ( { account, credentials} : UnlinkLoginFormProps ) {
19+ function UnlinkLoginForm ( ) {
3220 const styles = useThemeStyles ( ) ;
3321 const { translate} = useLocalize ( ) ;
3422 const { isOffline} = useNetwork ( ) ;
23+ const [ account ] = useOnyx ( ONYXKEYS . ACCOUNT , { canBeMissing : true } ) ;
24+ const [ credentials ] = useOnyx ( ONYXKEYS . CREDENTIALS , { canBeMissing : true } ) ;
25+
3526 const unlinkMessage =
3627 account ?. message === 'unlinkLoginForm.linkSent' || account ?. message === 'unlinkLoginForm.successfullyUnlinkedLogin' ? translate ( account ?. message ) : account ?. message ;
3728 const primaryLogin = useMemo ( ( ) => {
@@ -68,7 +59,7 @@ function UnlinkLoginForm({account, credentials}: UnlinkLoginFormProps) {
6859 < DotIndicatorMessage
6960 style = { [ styles . mb5 ] }
7061 type = "error"
71- messages = { ErrorUtils . getErrorsWithTranslationData ( account . errors ) }
62+ messages = { getErrorsWithTranslationData ( account . errors ) }
7263 />
7364 ) }
7465 < View style = { [ styles . mb4 , styles . flexRow , styles . justifyContentBetween , styles . alignItemsCenter ] } >
@@ -82,7 +73,7 @@ function UnlinkLoginForm({account, credentials}: UnlinkLoginFormProps) {
8273 success
8374 text = { translate ( 'unlinkLoginForm.unlink' ) }
8475 isLoading = { account ?. isLoading && account . loadingForm === CONST . FORMS . UNLINK_LOGIN_FORM }
85- onPress = { ( ) => Session . requestUnlinkValidationLink ( ) }
76+ onPress = { ( ) => requestUnlinkValidationLink ( ) }
8677 isDisabled = { ! ! isOffline || ! ! account ?. message }
8778 />
8879 </ View >
@@ -92,7 +83,4 @@ function UnlinkLoginForm({account, credentials}: UnlinkLoginFormProps) {
9283
9384UnlinkLoginForm . displayName = 'UnlinkLoginForm' ;
9485
95- export default withOnyx < UnlinkLoginFormProps , UnlinkLoginFormOnyxProps > ( {
96- credentials : { key : ONYXKEYS . CREDENTIALS } ,
97- account : { key : ONYXKEYS . ACCOUNT } ,
98- } ) ( UnlinkLoginForm ) ;
86+ export default UnlinkLoginForm ;
0 commit comments