-
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
Create TagSettingsPage #38335
Create TagSettingsPage #38335
Changes from all commits
88a193d
b71b348
f1122da
2038d55
e72a1e1
8654a07
397e102
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 SetPolicyTagsEnabled = { | ||
policyID: string; | ||
/** | ||
* Stringified JSON object with type of following structure: | ||
* Array<{name: string; enabled: boolean}> | ||
*/ | ||
tags: string; | ||
}; | ||
|
||
export default SetPolicyTagsEnabled; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useMemo} 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 {setWorkspaceTagEnabled} from '@libs/actions/Policy'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
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 {PolicyTagList} from '@src/types/onyx'; | ||
|
||
type TagSettingsPageOnyxProps = { | ||
/** All policy tags */ | ||
policyTags: OnyxEntry<PolicyTagList>; | ||
}; | ||
|
||
type TagSettingsPageProps = TagSettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_SETTINGS>; | ||
|
||
function TagSettingsPage({route, policyTags}: TagSettingsPageProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const policyTag = useMemo(() => PolicyUtils.getTagList(policyTags, 0), [policyTags]); | ||
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. Crash App from this line Screen.Recording.2024-03-18.at.23.49.51.movThere 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. Do you mean not found page appears? |
||
|
||
const currentPolicyTag = policyTag.tags[decodeURIComponent(route.params.tagName)]; | ||
|
||
if (!currentPolicyTag) { | ||
return <NotFoundPage />; | ||
} | ||
|
||
const updateWorkspaceTagEnabled = (value: boolean) => { | ||
setWorkspaceTagEnabled(route.params.policyID, {[currentPolicyTag.name]: {name: currentPolicyTag.name, enabled: value}}); | ||
}; | ||
|
||
return ( | ||
<AdminPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
<PaidPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}> | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
style={[styles.defaultModalContainer]} | ||
testID={TagSettingsPage.displayName} | ||
> | ||
<HeaderWithBackButton title={route.params.tagName} /> | ||
<View style={styles.flexGrow1}> | ||
<OfflineWithFeedback | ||
errors={ErrorUtils.getLatestErrorMessageField(currentPolicyTag)} | ||
pendingAction={currentPolicyTag.pendingFields?.enabled} | ||
errorRowStyles={styles.mh5} | ||
onClose={() => Policy.clearPolicyTagErrors(route.params.policyID, route.params.tagName)} | ||
> | ||
<View style={[styles.mt2, styles.mh5]}> | ||
<View style={[styles.flexRow, styles.mb5, styles.mr2, styles.alignItemsCenter, styles.justifyContentBetween]}> | ||
<Text>{translate('workspace.tags.enableTag')}</Text> | ||
<Switch | ||
isOn={currentPolicyTag.enabled} | ||
accessibilityLabel={translate('workspace.tags.enableTag')} | ||
onToggle={updateWorkspaceTagEnabled} | ||
/> | ||
</View> | ||
</View> | ||
</OfflineWithFeedback> | ||
<MenuItemWithTopDescription | ||
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. Coming from #39169. |
||
title={currentPolicyTag.name} | ||
description={translate(`workspace.tags.tagName`)} | ||
/> | ||
</View> | ||
</ScreenWrapper> | ||
</PaidPolicyAccessOrNotFoundWrapper> | ||
</AdminPolicyAccessOrNotFoundWrapper> | ||
); | ||
} | ||
|
||
TagSettingsPage.displayName = 'TagSettingsPage'; | ||
|
||
export default withOnyx<TagSettingsPageProps, TagSettingsPageOnyxProps>({ | ||
policyTags: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route.params.policyID}`, | ||
}, | ||
})(TagSettingsPage); |
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.
@waterim NAB we don't need a spread operator here.