-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move visible state to parent component #51350
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -14,13 +14,14 @@ import ROUTES from '@src/ROUTES'; | |
type DelegateMagicCodeModalProps = { | ||
login: string; | ||
role: ValueOf<typeof CONST.DELEGATE_ROLE>; | ||
isValidateCodeActionModalVisible: boolean; | ||
setIsValidateCodeActionModalVisible: (isValidateCodeActionModalVisible: boolean) => void; | ||
onClose?: () => void; | ||
}; | ||
|
||
function DelegateMagicCodeModal({login, role, onClose}: DelegateMagicCodeModalProps) { | ||
function DelegateMagicCodeModal({login, role, onClose, isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible}: DelegateMagicCodeModalProps) { | ||
const {translate} = useLocalize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cretadn22 ⬆️ |
||
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'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jayeshmangwani I'm not clear on why this code is necessary. Which use case is it addressing?
cc @getusha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cretadn22 It seems this case was added to handle navigation depending on the source page. If we arrive from the
SecuritySettingsPage
and close theDelegateMagicCodeModal
, we need to navigate back to theSecuritySettingsPage
on close. However, if we come from the Add Copilot flow, we should simply hide the modal without further navigation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the
git blame
and testing the flow, I believe a bit of refactoring is needed here. For example, we can remove the entire usage ofshowValidateActionModal
and useDelegateMagicCodeModal
directly on theSecuritySettingsPage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@getusha Could you help us understand why we navigate to the
DelegateConfirmPage
from theSecuritySettingsPage
? Wouldn’t it be easier to handle if we used theDelegateMagicCodeModal
directly on theSecuritySettingsPage
instead? Or am I missing some underlying logic here?App/src/pages/settings/Security/SecuritySettingsPage.tsx
Line 157 in 6cd5c64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cretadn22, I've pinged Getabalew on Slack to see why the above was added and what it does. Let's see if they can help us understand.
cc: @carlosmiceli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we proceed by adding
setIsValidateCodeActionModalVisible
in theonClose
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I missed your commit. Have you tested all the platforms again after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question: can we add
setIsValidateCodeActionModalVisible(false);
inside theif (!showValidateActionModal) {
block? Since, ifshowValidateActionModal
is true, we’re already calling the navigation.navigate, so when we return to this page,isValidateCodeActionModalVisible
will be set to true.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jayeshmangwani I made updates and tests, it is fine