-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #38335 from waterim/feat-37313-tagSettings
Create TagSettingsPage
- Loading branch information
Showing
14 changed files
with
226 additions
and
4 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
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 SetPolicyTagsEnabled = { | ||
policyID: string; | ||
/** | ||
* Stringified JSON object with type of following structure: | ||
* Array<{name: string; enabled: boolean}> | ||
*/ | ||
tags: string; | ||
}; | ||
|
||
export default SetPolicyTagsEnabled; |
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
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,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]); | ||
|
||
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 | ||
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); |
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