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

Go back to setting page after editing category/tag name #41722

Merged
merged 1 commit into from
May 13, 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
2 changes: 2 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,7 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string
pendingFields: {
name: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
previousCategoryName: policyCategory.oldName,
},
},
},
Expand Down Expand Up @@ -3673,6 +3674,7 @@ function renamePolicyTag(policyID: string, policyTag: {oldName: string; newName:
pendingFields: {
name: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
previousTagName: policyTag.oldName,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/categories/CategoryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function CategoryForm({onSubmit, policyCategories, categoryName, validateEdit}:
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
onSubmit(values);
Keyboard.dismiss();
Navigation.dismissModal();
Navigation.goBack();
},
[onSubmit],
);
Expand Down
14 changes: 11 additions & 3 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -34,14 +34,22 @@ type CategorySettingsPageOnyxProps = {

type CategorySettingsPageProps = CategorySettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_SETTINGS>;

function CategorySettingsPage({route, policyCategories}: CategorySettingsPageProps) {
function CategorySettingsPage({route, policyCategories, navigation}: CategorySettingsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {windowWidth} = useWindowDimensions();
const [deleteCategoryConfirmModalVisible, setDeleteCategoryConfirmModalVisible] = useState(false);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID}`);

const policyCategory = policyCategories?.[route.params.categoryName];
const policyCategory =
policyCategories?.[route.params.categoryName] ?? Object.values(policyCategories ?? {}).find((category) => category.previousCategoryName === route.params.categoryName);

useEffect(() => {
if (policyCategory?.name === route.params.categoryName || !policyCategory) {
return;
}
navigation.setParams({categoryName: policyCategory?.name});
}, [route.params.categoryName, navigation, policyCategory]);

if (!policyCategory) {
return <NotFoundPage />;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/EditTagPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function EditTagPage({route, policyTags}: EditTagPageProps) {
Policy.renamePolicyTag(route.params.policyID, {oldName: currentTagName, newName: values.tagName.trim()});
}
Keyboard.dismiss();
Navigation.dismissModal();
Navigation.goBack();
},
[route.params.policyID, currentTagName],
);
Expand Down
14 changes: 11 additions & 3 deletions src/pages/workspace/tags/TagSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -35,7 +35,7 @@ type TagSettingsPageOnyxProps = {

type TagSettingsPageProps = TagSettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_SETTINGS>;

function TagSettingsPage({route, policyTags}: TagSettingsPageProps) {
function TagSettingsPage({route, policyTags, navigation}: TagSettingsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyTag = useMemo(() => PolicyUtils.getTagList(policyTags, 0), [policyTags]);
Expand All @@ -45,7 +45,15 @@ function TagSettingsPage({route, policyTags}: TagSettingsPageProps) {

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

const currentPolicyTag = policyTag.tags[decodeURIComponent(route.params.tagName)];
const currentPolicyTag =
policyTag.tags[decodeURIComponent(route.params.tagName)] ?? Object.values(policyTag.tags ?? {}).find((tag) => tag.previousTagName === decodeURIComponent(route.params.tagName));

useEffect(() => {
if (currentPolicyTag?.name === route.params.tagName || !currentPolicyTag) {
return;
}
navigation.setParams({tagName: currentPolicyTag?.name});
}, [route.params.tagName, currentPolicyTag, navigation]);

if (!currentPolicyTag) {
return <NotFoundPage />;
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/PolicyCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{
/** The external accounting service that this category comes from */
origin: string;

/** The old category name of the category when we edit the category name */
previousCategoryName?: string;

/** A list of errors keyed by microtime */
errors?: OnyxCommon.Errors | null;
}>;
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type PolicyTag = OnyxCommon.OnyxValueWithOfflineFeedback<{
/** Flag that determines if a tag is active and able to be selected */
enabled: boolean;

/** The old tag name of the tag when we edit the tag name */
previousTagName?: string;

/** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */
// eslint-disable-next-line @typescript-eslint/naming-convention
'GL Code'?: string;
Expand Down
Loading