-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: categorize all expense switch is not disabled #39036
Changes from 8 commits
299e1e6
67322e1
547f69b
3874d9c
830640c
85cd494
7520ddf
eceebef
a19beb1
6367292
9eaf74a
6b05057
a45c9a9
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
|
@@ -9,23 +11,32 @@ import Text from '@components/Text'; | |
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import {setWorkspaceRequiresCategory} from '@libs/actions/Policy'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
import type {SettingsNavigatorParamList} from '@navigation/types'; | ||
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; | ||
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper'; | ||
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
||
type WorkspaceCategoriesSettingsPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORIES_SETTINGS>; | ||
type WorkspaceCategoriesSettingsPageOnyxProps = { | ||
/** Collection of categories attached to a policy */ | ||
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>; | ||
}; | ||
|
||
function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPageProps) { | ||
type WorkspaceCategoriesSettingsPageProps = WorkspaceCategoriesSettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORIES_SETTINGS>; | ||
|
||
function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCategoriesSettingsPageProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
||
const updateWorkspaceRequiresCategory = (value: boolean) => { | ||
setWorkspaceRequiresCategory(route.params.policyID, value); | ||
}; | ||
|
||
const policyCategoriesCount = OptionsListUtils.getEnabledCategoriesCount(policyCategories ?? {}); | ||
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. Could we use 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. I updated to use |
||
return ( | ||
<AdminPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
<PaidPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
|
@@ -53,7 +64,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag | |
isOn={policy?.requiresCategory ?? false} | ||
accessibilityLabel={translate('workspace.categories.requiresCategory')} | ||
onToggle={updateWorkspaceRequiresCategory} | ||
disabled={!policy?.areCategoriesEnabled} | ||
disabled={!policy?.areCategoriesEnabled || policyCategoriesCount === 0} | ||
/> | ||
</View> | ||
</View> | ||
|
@@ -69,4 +80,8 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag | |
|
||
WorkspaceCategoriesSettingsPage.displayName = 'WorkspaceCategoriesSettingsPage'; | ||
|
||
export default WorkspaceCategoriesSettingsPage; | ||
export default withOnyx<WorkspaceCategoriesSettingsPageProps, WorkspaceCategoriesSettingsPageOnyxProps>({ | ||
policyCategories: { | ||
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. Looks like we're back at it again 🙂 #37508 (comment) 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. Yeah. Previously, I said that:
It is because we can use |
||
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`, | ||
}, | ||
})(WorkspaceCategoriesSettingsPage); |
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.
can we do the same for
deleteWorkspaceCategories
?App/src/libs/actions/Policy.ts
Line 3439 in 5986481
Screen.Recording.2024-04-02.at.9.55.11.at.night.mov
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.
I updated to do the same when deleting category
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.
Nice catch!