Skip to content
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

prevent editing the GL code if we connected to an accounting #49629

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading