Skip to content

Commit

Permalink
Merge pull request #41158 from Krishna2323/krishna2323/issue/40826
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Jun 4, 2024
2 parents 2f48e21 + 6d772b5 commit 513c818
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/components/SelectionList/UserListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function UserListItem<TItem extends ListItem>({
rightHandSideComponent,
onFocus,
shouldSyncFocus,
pressableStyle,
}: UserListItemProps<TItem>) {
const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -63,6 +64,7 @@ function UserListItem<TItem extends ListItem>({
rightHandSideComponent={rightHandSideComponent}
errors={item.errors}
pendingAction={item.pendingAction}
pressableStyle={pressableStyle}
FooterComponent={
item.invitedSecondaryLogin ? (
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function WorkspacesSectionHeader() {
const {translate} = useLocalize();

return (
<View style={[styles.mh4, styles.mt6, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.mb1]}>
<View style={[styles.ph5, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.mv2]}>
<View>
<Text
style={styles.label}
Expand Down
91 changes: 55 additions & 36 deletions src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import type {ListItem, SectionListDataType} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import Text from '@components/Text';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import {sortWorkspacesBySelected} from '@libs/PolicyUtils';
Expand All @@ -32,14 +36,16 @@ type WorkspaceListItem = {
const WorkspaceCardCreateAWorkspaceInstance = <WorkspaceCardCreateAWorkspace />;

function WorkspaceSwitcherPage() {
const styles = useThemeStyles();
const theme = useTheme();
const {isOffline} = useNetwork();
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const {translate} = useLocalize();
const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace();

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY);

const brickRoadsForPolicies = useMemo(() => getWorkspacesBrickRoads(reports, policies, reportActions), [reports, policies, reportActions]);
const unreadStatusesForPolicies = useMemo(() => getWorkspacesUnreadStatuses(reports), [reports]);
Expand Down Expand Up @@ -130,54 +136,67 @@ function WorkspaceSwitcherPage() {
const sections = useMemo(() => {
const options: Array<SectionListDataType<WorkspaceListItem>> = [
{
title: translate('workspace.switcher.everythingSection'),
data: filteredAndSortedUserWorkspaces,
shouldShow: true,
indexOffset: 0,
data: [
{
text: CONST.WORKSPACE_SWITCHER.NAME,
icons: [{source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR}],
brickRoadIndicator: getIndicatorTypeForPolicy(undefined),
isSelected: activeWorkspaceID === undefined,
keyForList: CONST.WORKSPACE_SWITCHER.NAME,
},
],
indexOffset: 1,
},
];
options.push({
CustomSectionHeader: WorkspacesSectionHeader,
data: filteredAndSortedUserWorkspaces,
shouldShow: true,
indexOffset: 1,
});
return options;
}, [activeWorkspaceID, filteredAndSortedUserWorkspaces, getIndicatorTypeForPolicy, translate]);
}, [filteredAndSortedUserWorkspaces]);

const headerMessage = filteredAndSortedUserWorkspaces.length === 0 && usersWorkspaces.length ? translate('common.noResultsFound') : '';
const shouldShowCreateWorkspace = usersWorkspaces.length === 0;

const defaultPolicy = {
text: CONST.WORKSPACE_SWITCHER.NAME,
icons: [{source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR}],
brickRoadIndicator: getIndicatorTypeForPolicy(undefined),
keyForList: CONST.WORKSPACE_SWITCHER.NAME,
isSelected: activeWorkspaceID === undefined,
};

return (
<ScreenWrapper
testID={WorkspaceSwitcherPage.displayName}
includeSafeAreaPaddingBottom={false}
>
<HeaderWithBackButton
title={translate('workspace.switcher.headerTitle')}
onBackButtonPress={Navigation.goBack}
/>
<SelectionList<WorkspaceListItem>
ListItem={UserListItem}
sections={sections}
onSelectRow={selectPolicy}
shouldDebounceRowSelect
textInputLabel={usersWorkspaces.length >= CONST.WORKSPACE_SWITCHER.MINIMUM_WORKSPACES_TO_SHOW_SEARCH ? translate('common.search') : undefined}
textInputValue={searchTerm}
onChangeText={setSearchTerm}
headerMessage={headerMessage}
listFooterContent={shouldShowCreateWorkspace ? WorkspaceCardCreateAWorkspaceInstance : null}
initiallyFocusedOptionKey={activeWorkspaceID ?? CONST.WORKSPACE_SWITCHER.NAME}
showLoadingPlaceholder
/>
{({didScreenTransitionEnd}) => (
<>
<HeaderWithBackButton
title={translate('workspace.switcher.headerTitle')}