Skip to content

Commit

Permalink
Merge pull request Expensify#49833 from rushatgabhane/fix-copilot-pro…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
dangrous authored Oct 1, 2024
2 parents 00cec11 + 3277a16 commit 313dedc
Showing 1 changed file with 64 additions and 50 deletions.
114 changes: 64 additions & 50 deletions src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import LottieAnimations from '@components/LottieAnimations';
import MenuItem from '@components/MenuItem';
import type {MenuItemProps} from '@components/MenuItem';
import MenuItemList from '@components/MenuItemList';
import {usePersonalDetails} from '@components/OnyxProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
Expand Down Expand Up @@ -36,6 +37,8 @@ function SecuritySettingsPage() {
const waitForNavigate = useWaitForNavigation();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {canUseNewDotCopilot} = usePermissions();
const personalDetails = usePersonalDetails();

const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const isActingAsDelegate = !!account?.delegatedAccess?.delegate ?? false;

Expand Down Expand Up @@ -70,60 +73,71 @@ function SecuritySettingsPage() {
}));
}, [translate, waitForNavigate, styles]);

const delegateMenuItems: MenuItemProps[] = delegates
.filter((d) => !d.optimisticAccountID)
.map(({email, role, pendingAction, errorFields}) => {
const personalDetail = getPersonalDetailByEmail(email);

const error = ErrorUtils.getLatestErrorField({errorFields}, 'addDelegate');
const delegateMenuItems: MenuItemProps[] = useMemo(
() =>
delegates
.filter((d) => !d.optimisticAccountID)
.map(({email, role, pendingAction, errorFields}) => {
const personalDetail = getPersonalDetailByEmail(email);
const error = ErrorUtils.getLatestErrorField({errorFields}, 'addDelegate');

const onPress = () => {
if (isEmptyObject(pendingAction)) {
return;
}
if (!role) {
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(email));
return;
}
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_MAGIC_CODE.getRoute(email, role));
};
const onPress = () => {
if (isEmptyObject(pendingAction)) {
return;
}
if (!role) {
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(email));
return;
}
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_MAGIC_CODE.getRoute(email, role));
};

const formattedEmail = formatPhoneNumber(email);
return {
title: personalDetail?.displayName ?? formattedEmail,
description: personalDetail?.displayName ? formattedEmail : '',
badgeText: translate('delegate.role', {role}),
avatarID: personalDetail?.accountID ?? -1,
icon: personalDetail?.avatar ?? FallbackAvatar,
iconType: CONST.ICON_TYPE_AVATAR,
numberOfLinesDescription: 1,
wrapperStyle: [styles.sectionMenuItemTopDescription],
iconRight: Expensicons.ThreeDots,
shouldShowRightIcon: true,
pendingAction,
shouldForceOpacity: !!pendingAction,
onPendingActionDismiss: () => clearAddDelegateErrors(email, 'addDelegate'),
error,
onPress,
};
});
const formattedEmail = formatPhoneNumber(email);
return {
title: personalDetail?.displayName ?? formattedEmail,
description: personalDetail?.displayName ? formattedEmail : '',
badgeText: translate('delegate.role', {role}),
avatarID: personalDetail?.accountID ?? -1,
icon: personalDetail?.avatar ?? FallbackAvatar,
iconType: CONST.ICON_TYPE_AVATAR,
numberOfLinesDescription: 1,
wrapperStyle: [styles.sectionMenuItemTopDescription],
iconRight: Expensicons.ThreeDots,
shouldShowRightIcon: true,
pendingAction,
shouldForceOpacity: !!pendingAction,
onPendingActionDismiss: () => clearAddDelegateErrors(email, 'addDelegate'),
error,
onPress,
};
}),
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
[delegates, translate, styles, personalDetails],
);

const delegatorMenuItems: MenuItemProps[] = delegators.map(({email, role}) => {
const personalDetail = getPersonalDetailByEmail(email);
const formattedEmail = formatPhoneNumber(email);
const delegatorMenuItems: MenuItemProps[] = useMemo(
() =>
delegators.map(({email, role}) => {
const personalDetail = getPersonalDetailByEmail(email);
const formattedEmail = formatPhoneNumber(email);

return {
title: personalDetail?.displayName ?? formattedEmail,
description: personalDetail?.displayName ? formattedEmail : '',
badgeText: translate('delegate.role', {role}),
avatarID: personalDetail?.accountID ?? -1,
icon: personalDetail?.avatar ?? FallbackAvatar,
iconType: CONST.ICON_TYPE_AVATAR,
numberOfLinesDescription: 1,
wrapperStyle: [styles.sectionMenuItemTopDescription],
interactive: false,
};
});
return {
title: personalDetail?.displayName ?? formattedEmail,
description: personalDetail?.displayName ? formattedEmail : '',
badgeText: translate('delegate.role', {role}),
avatarID: personalDetail?.accountID ?? -1,
icon: personalDetail?.avatar ?? FallbackAvatar,
iconType: CONST.ICON_TYPE_AVATAR,
numberOfLinesDescription: 1,
wrapperStyle: [styles.sectionMenuItemTopDescription],
interactive: false,
};
}),
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
[delegators, styles, translate, personalDetails],
);

return (
<ScreenWrapper
Expand Down

0 comments on commit 313dedc

Please sign in to comment.