forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from software-mansion-labs/ideal-nav/all-settings
Redesign settings Sidebar
- Loading branch information
Showing
9 changed files
with
171 additions
and
81 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import {useNavigationState} from '@react-navigation/native'; | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import _ from 'underscore'; | ||
import Breadcrumbs from '@components/Breadcrumbs'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import MenuItem from '@components/MenuItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useSingleExecution from '@hooks/useSingleExecution'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWaitForNavigation from '@hooks/useWaitForNavigation'; | ||
import getTopmostCentralPaneName from '@libs/Navigation/getTopmostCentralPanePath'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as Link from '@userActions/Link'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
function AllSettingsScreen() { | ||
const styles = useThemeStyles(); | ||
const {isExecuting, singleExecution} = useSingleExecution(); | ||
const waitForNavigate = useWaitForNavigation(); | ||
const {translate} = useLocalize(); | ||
const activeRoute = useNavigationState(getTopmostCentralPaneName); | ||
|
||
/** | ||
* Retuns a list of menu items data for "everything" settings | ||
* @returns {Object} object with translationKey, style and items | ||
*/ | ||
const menuItemsData = useMemo( | ||
() => ({ | ||
sectionStyle: styles.accountSettingsSectionContainer, | ||
sectionTranslationKey: 'initialSettingsPage.account', | ||
items: [ | ||
{ | ||
translationKey: 'common.workspaces', | ||
icon: Expensicons.Building, | ||
routeName: ROUTES.SETTINGS_WORKSPACES, | ||
}, | ||
{ | ||
translationKey: 'allSettingsScreen.subscriptions', | ||
icon: Expensicons.MoneyBag, | ||
action: () => { | ||
Link.openOldDotLink(CONST.ADMIN_POLICIES_URL); | ||
}, | ||
shouldShowRightIcon: true, | ||
iconRight: Expensicons.NewWindow, | ||
link: CONST.ADMIN_POLICIES_URL, | ||
}, | ||
{ | ||
translationKey: 'allSettingsScreen.cardsAndDomains', | ||
icon: Expensicons.CardsAndDomains, | ||
action: () => { | ||
Link.openOldDotLink(CONST.ADMIN_DOMAINS_URL); | ||
}, | ||
shouldShowRightIcon: true, | ||
iconRight: Expensicons.NewWindow, | ||
link: CONST.ADMIN_DOMAINS_URL, | ||
}, | ||
], | ||
}), | ||
[styles.accountSettingsSectionContainer], | ||
); | ||
|
||
/** | ||
* Retuns JSX.Element with menu items | ||
* @param {Object} data list with menu items data | ||
* @returns {JSX.Element} the menu items for passed data | ||
*/ | ||
const getMenuItemsSection = useCallback( | ||
(data) => ( | ||
<View style={[styles.pb4, styles.mh3]}> | ||
{_.map(data.items, (item, index) => { | ||
const keyTitle = item.translationKey ? translate(item.translationKey) : item.title; | ||
|
||
return ( | ||
<MenuItem | ||
key={`${keyTitle}_${index}`} | ||
wrapperStyle={styles.sectionMenuItem} | ||
title={keyTitle} | ||
icon={item.icon} | ||
shouldShowRightIcon={item.shouldShowRightIcon} | ||
iconRight={item.iconRight} | ||
disabled={isExecuting} | ||
onPress={singleExecution(() => { | ||
if (item.action) { | ||
item.action(); | ||
} else { | ||
waitForNavigate(() => { | ||
Navigation.navigate(item.routeName); | ||
})(); | ||
} | ||
})} | ||
shouldBlockSelection={Boolean(item.link)} | ||
focused={activeRoute && activeRoute.startsWith(item.routeName, 1)} | ||
/> | ||
); | ||
})} | ||
</View> | ||
), | ||
[activeRoute, isExecuting, singleExecution, styles.mh3, styles.pb4, styles.sectionMenuItem, translate, waitForNavigate], | ||
); | ||
|
||
const accountMenuItems = useMemo(() => getMenuItemsSection(menuItemsData), [menuItemsData, getMenuItemsSection]); | ||
|
||
return ( | ||
<View style={styles.w100}> | ||
<View style={[styles.ph5, styles.pv5, styles.justifyContentBetween]}> | ||
<Breadcrumbs | ||
breadcrumbs={[ | ||
{ | ||
type: CONST.BREADCRUMB_TYPE.ROOT, | ||
}, | ||
{ | ||
text: translate('common.settings'), | ||
}, | ||
]} | ||
/> | ||
</View> | ||
{accountMenuItems} | ||
</View> | ||
); | ||
} | ||
|
||
AllSettingsScreen.displayName = 'AllSettingsScreen'; | ||
|
||
export default AllSettingsScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters