-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
feat: category settings page #37209
feat: category settings page #37209
Changes from all commits
581f720
8256c93
5fec6fd
eb30d4f
984a729
3b12585
4aa8daf
1698e9a
6831991
4e4c7f3
f020194
a529784
ba0c181
c77d0f4
21cbb10
e840259
e8b86d5
7db77b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,12 @@ const config: LinkingOptions<RootStackParamList>['config'] = { | |
[SCREENS.WORKSPACE.INVITE_MESSAGE]: { | ||
path: ROUTES.WORKSPACE_INVITE_MESSAGE.route, | ||
}, | ||
[SCREENS.WORKSPACE.CATEGORY_SETTINGS]: { | ||
path: ROUTES.WORKSPACE_CATEGORY_SETTINGS.route, | ||
parse: { | ||
categoryName: (categoryName: string) => decodeURI(categoryName), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding to checklist, It appears that this is a new pattern. Previously, parsing and linking were not utilized in this manner, In my opinion, it would be more effective to decode the category name before passing it to the route props. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luacmartins ☝️ any thoughts ?
|
||
}, | ||
}, | ||
[SCREENS.WORKSPACE.CATEGORIES_SETTINGS]: { | ||
path: ROUTES.WORKSPACE_CATEGORIES_SETTINGS.route, | ||
}, | ||
|
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line introduced regression #37885, because
encodeURI
won't encode/
.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI#description