Skip to content
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

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST';
import type Beta from '@src/types/onyx/Beta';

function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.ALL);
return true || !!betas?.includes(CONST.BETAS.ALL);
cretadn22 marked this conversation as resolved.
Show resolved Hide resolved
}

function canUseDefaultRooms(betas: OnyxEntry<Beta[]>): boolean {
Expand Down
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) {
return;
}
Navigation.navigate(ROUTES.SETTINGS_SECURITY);
Copy link
Contributor Author

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

Copy link
Contributor

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 the DelegateMagicCodeModal, we need to navigate back to the SecuritySettingsPage on close. However, if we come from the Add Copilot flow, we should simply hide the modal without further navigation.

Copy link
Contributor

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 of showValidateActionModal and use DelegateMagicCodeModal directly on the SecuritySettingsPage

Copy link
Contributor

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 the SecuritySettingsPage? Wouldn’t it be easier to handle if we used the DelegateMagicCodeModal directly on the SecuritySettingsPage instead? Or am I missing some underlying logic here?

Navigation.navigate(ROUTES.SETTINGS_DELEGATE_CONFIRM.getRoute(email, role, true));

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, I believe the current code is both safer and simpler.

Can we proceed by adding setIsValidateCodeActionModalVisible in the onClose function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that

Copy link
Contributor

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?

Copy link
Contributor

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 the if (!showValidateActionModal) { block? Since, if showValidateActionModal is true, we’re already calling the navigation.navigate, so when we return to this page, isValidateCodeActionModalVisible will be set to true.

Copy link
Contributor Author

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

}}
isValidateCodeActionModalVisible={isValidateCodeActionModalVisible}
setIsValidateCodeActionModalVisible={setIsValidateCodeActionModalVisible}
/>
</HeaderPageLayout>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react';

Check failure on line 1 in src/pages/settings/Security/AddDelegate/DelegateMagicCodeModal.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'useState' is defined but never used
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
Expand All @@ -14,13 +14,14 @@
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a single onClose prop here, and not pass the setIsValidateCodeActionModalVisible ? By pressing onClose, we can handle the setIsValidateCodeActionModalVisible on the ConfirmDelegatePage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cretadn22 ⬆️

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 Down
Loading