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

use PopoverMenu for account switcher modal #49051

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e46b607
use PopoverMenu for account switcher modal
nkdengineer Sep 12, 2024
7069e8c
remove unnecessary change
nkdengineer Sep 12, 2024
eb9e18b
fix ts error
nkdengineer Sep 12, 2024
e894d78
Merge branch 'main' into fix/48292
nkdengineer Sep 13, 2024
de3bf0f
fix style bug and add shouldUseScrollView prop
nkdengineer Sep 13, 2024
1a5aaa7
move iconType to above
nkdengineer Sep 13, 2024
a49cada
merge main
nkdengineer Sep 16, 2024
5be7a19
resolve conflict
nkdengineer Sep 16, 2024
95f4224
Merge branch 'main' into fix/48292
nkdengineer Sep 16, 2024
dd32f45
Merge branch 'main' into fix/48292
nkdengineer Sep 17, 2024
70aa7f3
fix header styles
nkdengineer Sep 18, 2024
43e1ff1
merge main
nkdengineer Sep 18, 2024
bed23eb
Merge branch 'main' into fix/48292
nkdengineer Sep 18, 2024
4002bc1
Update src/components/PopoverMenu.tsx
nkdengineer Sep 18, 2024
2d5c678
add headerStyles
nkdengineer Sep 18, 2024
584469a
remove unused style
nkdengineer Sep 18, 2024
a9da05f
Merge branch 'main' into fix/48292
nkdengineer Sep 19, 2024
9b9e00f
Merge branch 'main' into fix/48292
nkdengineer Sep 20, 2024
7bc72ef
Merge branch 'main' into fix/48292
nkdengineer Sep 20, 2024
3ac507c
move the padding bottom to the scroll view
nkdengineer Sep 20, 2024
5d6c9db
fix error doesn't display
nkdengineer Sep 20, 2024
366bce2
Merge branch 'main' into fix/48292
nkdengineer Sep 23, 2024
e2ee3c7
fix padding bottom style in large screen
nkdengineer Sep 23, 2024
6556abd
remove hard code
nkdengineer Sep 23, 2024
907b6e0
Merge branch 'main' into fix/48292
nkdengineer Sep 24, 2024
84291a0
add shouldUpdateFocusedIndex prop
nkdengineer Sep 24, 2024
3a09746
Merge branch 'main' into fix/48292
nkdengineer Sep 25, 2024
6820937
fix lint
nkdengineer Sep 25, 2024
a58ff31
change onItemSelected as optional
nkdengineer Sep 25, 2024
4fde281
use lodashIsEqual
nkdengineer Sep 25, 2024
8692d40
merge main
nkdengineer Sep 27, 2024
1e8b7ce
resovle conflict
nkdengineer Sep 27, 2024
b326494
fix perf-test
nkdengineer Sep 27, 2024
c3ed169
Merge branch 'main' into fix/48292
nkdengineer Sep 30, 2024
92d3081
revert change
nkdengineer Sep 30, 2024
a6770f8
revert change
nkdengineer Sep 30, 2024
36b7519
merge main
nkdengineer Oct 2, 2024
25547dc
Merge branch 'main' into fix/48292
nkdengineer Oct 3, 2024
ab098d6
Merge branch 'main' into fix/48292
nkdengineer Oct 4, 2024
69fefcd
Merge branch 'main' into fix/48292
nkdengineer Oct 7, 2024
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
15 changes: 9 additions & 6 deletions src/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,33 @@ function AccountSwitcher() {
const isActingAsDelegate = !!account?.delegatedAccess?.delegate ?? false;
const canSwitchAccounts = canUseNewDotCopilot && (delegators.length > 0 || isActingAsDelegate);

const createBaseMenuItem = (personalDetails: PersonalDetails | undefined, errors?: Errors, additionalProps: Partial<PopoverMenuItem> = {}): PopoverMenuItem => {
const createBaseMenuItem = (
personalDetails: PersonalDetails | undefined,
errors?: Errors,
additionalProps: Partial<Omit<PopoverMenuItem, 'icon' | 'iconType'>> = {},
): PopoverMenuItem => {
const error = Object.values(errors ?? {})[0] ?? '';
return {
text: personalDetails?.displayName ?? personalDetails?.login ?? '',
description: Str.removeSMSDomain(personalDetails?.login ?? ''),
avatarID: personalDetails?.accountID ?? -1,
icon: personalDetails?.avatar ?? '',
iconType: CONST.ICON_TYPE_AVATAR,
outerWrapperStyle: shouldUseNarrowLayout ? {} : styles.accountSwitcherPopover,
numberOfLinesDescription: 1,
errorText: error ?? '',
shouldShowRedDotIndicator: !!error,
errorTextStyle: styles.mt2,
...additionalProps,
iconType: CONST.ICON_TYPE_AVATAR,
};
};

const menuItems = (): PopoverMenuItem[] => {
const currentUserMenuItem = createBaseMenuItem(currentUserPersonalDetails, undefined, {
wrapperStyle: [styles.buttonDefaultBG],
focused: true,
shouldShowRightIcon: true,
iconRight: Expensicons.Checkmark,
success: true,
isSelected: true,
});

if (isActingAsDelegate) {
Expand All @@ -93,7 +96,6 @@ function AccountSwitcher() {
}
disconnect();
},
isSelected: true,
}),
currentUserMenuItem,
];
Expand Down Expand Up @@ -188,7 +190,8 @@ function AccountSwitcher() {
}
item.onSelected();
Copy link
Member

@rushatgabhane rushatgabhane Sep 20, 2024

Choose a reason for hiding this comment

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

nab: won't this suffice? and we can remove if

Suggested change
item.onSelected();
item?.onSelected();

}}
containerStyle={{maxHeight: windowHeight / 2}}
containerStyle={{maxHeight: windowHeight / 2, width: 'fit-content'}}
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
shouldUseScrollView
/>
)}
<ConfirmModal
Expand Down
11 changes: 8 additions & 3 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ type PopoverMenuProps = Partial<PopoverModalProps> & {

/** The style of content container which wraps all child views */
containerStyle?: StyleProp<ViewStyle>;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

/** Whether we should wrap the list item in a scroll view */
shouldUseScrollView?: boolean;
};

function PopoverMenu({
Expand All @@ -128,6 +131,7 @@ function PopoverMenu({
restoreFocusType,
shouldShowSelectedItemCheck = false,
containerStyle,
shouldUseScrollView = false,
}: PopoverMenuProps) {
const styles = useThemeStyles();
const theme = useTheme();
Expand All @@ -138,6 +142,7 @@ function PopoverMenu({
const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState<readonly number[]>(CONST.EMPTY_ARRAY);

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: currentMenuItemsFocusedIndex, maxIndex: currentMenuItems.length - 1, isActive: isVisible});
const WrapComponent = shouldUseScrollView ? ScrollView : View;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

const selectItem = (index: number) => {
const selectedItem = currentMenuItems[index];
Expand Down Expand Up @@ -256,7 +261,7 @@ function PopoverMenu({
<View style={[isSmallScreenWidth ? {} : styles.createMenuContainer, containerStyle]}>
{renderHeaderText()}
{enteredSubMenuIndexes.length > 0 && renderBackButtonItem()}
<ScrollView>
<WrapComponent>
{currentMenuItems.map((item, menuIndex) => {
const {text, onSelected, subMenuItems, shouldCallAfterModalHide, ...menuItemProps} = item;
return (
Expand All @@ -269,14 +274,14 @@ function PopoverMenu({
shouldShowSelectedItemCheck={shouldShowSelectedItemCheck}
shouldCheckActionAllowedOnPress={false}
onFocus={() => setFocusedIndex(menuIndex)}
style={{backgroundColor: item.isSelected ? theme.activeComponentBG : undefined}}
style={{backgroundColor: focusedIndex === menuIndex ? theme.activeComponentBG : undefined}}
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
titleStyle={StyleSheet.flatten([styles.flex1, item.titleStyle])}
// eslint-disable-next-line react/jsx-props-no-spreading
{...menuItemProps}
/>
);
})}
</ScrollView>
</WrapComponent>
</View>
</FocusTrapForModal>
</PopoverWithMeasuredContent>
Expand Down
Loading