Skip to content

Commit

Permalink
Merge pull request #49629 from mkzie2/fix/49179
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl committed Sep 24, 2024
2 parents ea12dd2 + ce39083 commit a175c8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/pages/workspace/tags/TagGLCodePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormOnyxValues} from '@components/Form/types';
Expand All @@ -10,6 +9,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
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 * as PolicyUtils from '@libs/PolicyUtils';
Expand All @@ -21,19 +21,15 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/WorkspaceTagForm';
import type {PolicyTagLists} from '@src/types/onyx';

type WorkspaceEditTagGLCodePageOnyxProps = {
/** Collection of categories attached to a policy */
policyTags: OnyxEntry<PolicyTagLists>;
};
type EditTagGLCodePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_GL_CODE>;

type EditTagGLCodePageProps = WorkspaceEditTagGLCodePageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_GL_CODE>;

function TagGLCodePage({route, policyTags}: EditTagGLCodePageProps) {
function TagGLCodePage({route}: EditTagGLCodePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const policy = usePolicy(route.params.policyID);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`);

const tagName = route.params.tagName;
const orderWeight = route.params.orderWeight;
Expand All @@ -60,6 +56,7 @@ function TagGLCodePage({route, policyTags}: EditTagGLCodePageProps) {
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.CONTROL]}
policyID={route.params.policyID}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED}
shouldBeBlocked={PolicyUtils.hasAccountingConnections(policy)}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down Expand Up @@ -96,8 +93,4 @@ function TagGLCodePage({route, policyTags}: EditTagGLCodePageProps) {

TagGLCodePage.displayName = 'TagGLCodePage';

export default withOnyx<EditTagGLCodePageProps, WorkspaceEditTagGLCodePageOnyxProps>({
policyTags: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`,
},
})(TagGLCodePage);
export default TagGLCodePage;
3 changes: 3 additions & 0 deletions src/pages/workspace/tags/TagSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) {
const {translate} = useLocalize();
const policyTag = useMemo(() => PolicyUtils.getTagList(policyTags, orderWeight), [policyTags, orderWeight]);
const policy = usePolicy(policyID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false);

Expand Down Expand Up @@ -146,6 +147,8 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) {
title={currentPolicyTag['GL Code']}
description={translate(`workspace.tags.glCode`)}
onPress={navigateToEditGlCode}
iconRight={hasAccountingConnections ? Expensicons.Lock : undefined}
interactive={!hasAccountingConnections}
shouldShowRightIcon
/>
</OfflineWithFeedback>
Expand Down

0 comments on commit a175c8e

Please sign in to comment.