Skip to content

Commit

Permalink
Merge pull request #51350 from cretadn22/move-state-to-parent-component
Browse files Browse the repository at this point in the history
Move visible state to parent component
  • Loading branch information
carlosmiceli authored Oct 31, 2024
2 parents 4a4b76f + a067700 commit e7532e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
26 changes: 12 additions & 14 deletions src/pages/settings/Security/AddDelegate/ConfirmDelegatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,18 @@ function ConfirmDelegatePage({route}: ConfirmDelegatePageProps) {
onPress={() => Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role))}
shouldShowRightIcon
/>

{isValidateCodeActionModalVisible && (
<DelegateMagicCodeModal
login={login}
role={role}
onClose={() => {
if (!showValidateActionModal) {
return;
}

Navigation.navigate(ROUTES.SETTINGS_SECURITY);
}}
/>
)}
<DelegateMagicCodeModal
login={login}
role={role}
onClose={() => {
if (!showValidateActionModal) {
setIsValidateCodeActionModalVisible(false);
return;
}
Navigation.navigate(ROUTES.SETTINGS_SECURITY);
}}
isValidateCodeActionModalVisible={isValidateCodeActionModalVisible}
/>
</HeaderPageLayout>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react';
import React, {useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
Expand All @@ -14,13 +14,13 @@ import ROUTES from '@src/ROUTES';
type DelegateMagicCodeModalProps = {
login: string;
role: ValueOf<typeof CONST.DELEGATE_ROLE>;
isValidateCodeActionModalVisible: boolean;
onClose?: () => void;
};

function DelegateMagicCodeModal({login, role, onClose}: DelegateMagicCodeModalProps) {
function DelegateMagicCodeModal({login, role, onClose, isValidateCodeActionModalVisible}: DelegateMagicCodeModalProps) {
const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(true);

const currentDelegate = account?.delegatedAccess?.delegates?.find((d) => d.email === login);
const validateLoginError = ErrorUtils.getLatestErrorField(currentDelegate, 'addDelegate');
Expand All @@ -36,7 +36,6 @@ function DelegateMagicCodeModal({login, role, onClose}: DelegateMagicCodeModalPr

const onBackButtonPress = () => {
onClose?.();
setIsValidateCodeActionModalVisible(false);
};

const clearError = () => {
Expand Down

0 comments on commit e7532e9

Please sign in to comment.