forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Expensify#37209 from ArekChr/feat/category_setting…
…s_page feat: category settings page
- Loading branch information
Showing
15 changed files
with
249 additions
and
23 deletions.
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
src/libs/API/parameters/SetWorkspaceCategoriesEnabledParams.ts
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,10 @@ | ||
type SetWorkspaceCategoriesEnabledParams = { | ||
policyID: string; | ||
/** | ||
* Stringified JSON object with type of following structure: | ||
* Array<{name: string; enabled: boolean}> | ||
*/ | ||
categories: string; | ||
}; | ||
|
||
export default SetWorkspaceCategoriesEnabledParams; |
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
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,90 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import Switch from '@components/Switch'; | ||
import Text from '@components/Text'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import {setWorkspaceCategoryEnabled} from '@libs/actions/Policy'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import type {SettingsNavigatorParamList} from '@navigation/types'; | ||
import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; | ||
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; | ||
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper'; | ||
import * as Policy from '@userActions/Policy'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
||
type CategorySettingsPageOnyxProps = { | ||
/** Collection of categories attached to a policy */ | ||
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>; | ||
}; | ||
|
||
type CategorySettingsPageProps = CategorySettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_SETTINGS>; | ||
|
||
function CategorySettingsPage({route, policyCategories}: CategorySettingsPageProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
||
const policyCategory = policyCategories?.[route.params.categoryName]; | ||
|
||
if (!policyCategory) { | ||
return <NotFoundPage />; | ||
} | ||
|
||
const updateWorkspaceRequiresCategory = (value: boolean) => { | ||
setWorkspaceCategoryEnabled(route.params.policyID, {[policyCategory.name]: {name: policyCategory.name, enabled: value}}); | ||
}; | ||
|
||
return ( | ||
<AdminPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
<PaidPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
style={[styles.defaultModalContainer]} | ||
testID={CategorySettingsPage.displayName} | ||
> | ||
<HeaderWithBackButton title={route.params.categoryName} /> | ||
<View style={styles.flexGrow1}> | ||
<OfflineWithFeedback | ||
errors={ErrorUtils.getLatestErrorMessageField(policyCategory)} | ||
pendingAction={policyCategory?.pendingFields?.enabled} | ||
errorRowStyles={styles.mh5} | ||
onClose={() => Policy.clearCategoryErrors(route.params.policyID, route.params.categoryName)} | ||
> | ||
<View style={[styles.mt2, styles.mh5]}> | ||
<View style={[styles.flexRow, styles.mb5, styles.mr2, styles.alignItemsCenter, styles.justifyContentBetween]}> | ||
<Text>{translate('workspace.categories.enableCategory')}</Text> | ||
<Switch | ||
isOn={policyCategory.enabled} | ||
accessibilityLabel={translate('workspace.categories.enableCategory')} | ||
onToggle={updateWorkspaceRequiresCategory} | ||
/> | ||
</View> | ||
</View> | ||
</OfflineWithFeedback> | ||
<MenuItemWithTopDescription | ||
title={policyCategory.name} | ||
description={translate(`workspace.categories.categoryName`)} | ||
/> | ||
</View> | ||
</ScreenWrapper> | ||
</PaidPolicyAccessOrNotFoundWrapper> | ||
</AdminPolicyAccessOrNotFoundWrapper> | ||
); | ||
} | ||
|
||
CategorySettingsPage.displayName = 'CategorySettingsPage'; | ||
|
||
export default withOnyx<CategorySettingsPageProps, CategorySettingsPageOnyxProps>({ | ||
policyCategories: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`, | ||
}, | ||
})(CategorySettingsPage); |
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
Oops, something went wrong.