-
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 #56548 from callstack-internal/feat/policy-custom-…
…rules feat: policy custom rules
- Loading branch information
Showing
21 changed files
with
258 additions
and
0 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
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,6 @@ | ||
type UpdateCustomRules = { | ||
policyID: string; | ||
description: string; | ||
}; | ||
|
||
export default UpdateCustomRules; |
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
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,47 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
import Section from '@components/Section'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import usePolicy from '@hooks/usePolicy'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
type CustomRulesSectionProps = { | ||
policyID: string; | ||
}; | ||
|
||
function CustomRulesSection({policyID}: CustomRulesSectionProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const policy = usePolicy(policyID); | ||
|
||
return ( | ||
<Section | ||
isCentralPane | ||
title={translate('workspace.rules.customRules.title')} | ||
subtitle={translate('workspace.rules.customRules.description')} | ||
titleStyles={styles.accountSettingsSectionTitle} | ||
subtitleMuted | ||
> | ||
<View style={[styles.mt3]}> | ||
{/* <OfflineWithFeedback | ||
pendingAction={item.pendingAction} | ||
key={translate(item.descriptionTranslationKey)} | ||
> */} | ||
<MenuItemWithTopDescription | ||
shouldShowRightIcon | ||
title={policy?.customRules ?? ''} | ||
description={translate('workspace.rules.customRules.subtitle')} | ||
onPress={() => Navigation.navigate(ROUTES.RULES_CUSTOM.getRoute(policyID))} | ||
wrapperStyle={[styles.sectionMenuItemTopDescription]} | ||
numberOfLinesTitle={2} | ||
/> | ||
{/* </OfflineWithFeedback> */} | ||
</View> | ||
</Section> | ||
); | ||
} | ||
|
||
export default CustomRulesSection; |
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 React, {useCallback, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import FormProvider from '@components/Form/FormProvider'; | ||
import InputWrapper from '@components/Form/InputWrapper'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import Text from '@components/Text'; | ||
import TextInput from '@components/TextInput'; | ||
import useAutoFocusInput from '@hooks/useAutoFocusInput'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import usePolicy from '@hooks/usePolicy'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
import Parser from '@libs/Parser'; | ||
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
import {updateCustomRules} from '@userActions/Policy/Policy'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import INPUT_IDS from '@src/types/form/RulesCustomForm'; | ||
|
||
type RulesCustomPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.RULES_CUSTOM>; | ||
|
||
function RulesCustomPage({ | ||
route: { | ||
params: {policyID}, | ||
}, | ||
}: RulesCustomPageProps) { | ||
const policy = usePolicy(policyID); | ||
|
||
const {inputCallbackRef} = useAutoFocusInput(); | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const [customRulesValue, setCustomRulesValue] = useState(() => Parser.htmlToMarkdown(policy?.customRules ?? '')); | ||
|
||
const onChangeCustomRules = useCallback((newValue: string) => { | ||
setCustomRulesValue(newValue); | ||
}, []); | ||
|
||
return ( | ||
<AccessOrNotFoundWrapper | ||
policyID={policyID} | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED} | ||
> | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom | ||
shouldEnableMaxHeight | ||
testID={RulesCustomPage.displayName} | ||
> | ||
<HeaderWithBackButton | ||
title={translate('workspace.rules.customRules.title')} | ||
onBackButtonPress={() => Navigation.goBack()} | ||
/> | ||
<FormProvider | ||
style={[styles.flexGrow1, styles.ph5]} | ||
formID={ONYXKEYS.FORMS.RULES_CUSTOM_FORM} | ||
onSubmit={({customRules}) => { | ||
updateCustomRules(policyID, customRules); | ||
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack); | ||
}} | ||
submitButtonText={translate('workspace.editor.save')} | ||
enabledWhenOffline | ||
> | ||
<View style={styles.mb4}> | ||
<InputWrapper | ||
InputComponent={TextInput} | ||
inputID={INPUT_IDS.CUSTOM_RULES} | ||
label={translate('workspace.rules.customRules.subtitle')} | ||
role={CONST.ROLE.PRESENTATION} | ||
value={customRulesValue} | ||
onChangeText={onChangeCustomRules} | ||
ref={inputCallbackRef} | ||
type="markdown" | ||
autoGrowHeight | ||
/> | ||
<Text style={[styles.mutedTextLabel, styles.mt2]}>{translate('workspace.rules.customRules.description')}</Text> | ||
</View> | ||
</FormProvider> | ||
</ScreenWrapper> | ||
</AccessOrNotFoundWrapper> | ||
); | ||
} | ||
|
||
RulesCustomPage.displayName = 'RulesCustomPage'; | ||
|
||
export default RulesCustomPage; |
Oops, something went wrong.