Skip to content

Commit a8958ee

Browse files
authored
Merge pull request #89961 from Expensify/claude-cleanCategoryNameOnRename
[Payment due @linhvovan29546] Clean non-breaking spaces from category name on rename
2 parents 2c02bc0 + ca62cb0 commit a8958ee

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,6 +4503,7 @@ const CONST = {
45034503
TAX_ID: /^\d{9}$/,
45044504
NON_NUMERIC: /\D/g,
45054505
ANY_SPACE: /\s/g,
4506+
NON_BREAKING_SPACE: /\u00A0/g,
45064507

45074508
EMOJI_NAME: /(?<=^|[\s\S]):[\p{L}0-9_+-]+:/gu,
45084509
EMOJI_SUGGESTIONS: /(?<=^|[\s\S]):[\p{L}0-9_+-]{1,40}$/u,

src/pages/workspace/categories/EditCategoryPage.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
3030
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.DYNAMIC_SETTINGS_CATEGORY_EDIT;
3131
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.SETTINGS_CATEGORY_EDIT.path);
3232

33+
const sanitizeCategoryName = useCallback((name: string) => name.replaceAll(CONST.REGEX.NON_BREAKING_SPACE, ' ').trim(), []);
34+
3335
const validate = useCallback(
3436
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
3537
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM> = {};
36-
const newCategoryName = values.categoryName.trim();
38+
const newCategoryName = sanitizeCategoryName(values.categoryName);
3739

3840
if (!newCategoryName) {
3941
errors.categoryName = translate('workspace.categories.categoryRequiredError');
@@ -45,23 +47,23 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
4547
}
4648
return errors;
4749
},
48-
[policyCategories, currentCategoryName, translate],
50+
[policyCategories, currentCategoryName, translate, sanitizeCategoryName],
4951
);
5052

5153
const editCategory = useCallback(
5254
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
53-
const newCategoryName = values.categoryName.trim();
55+
const newCategoryName = sanitizeCategoryName(values.categoryName);
5456
// Do not call the API if the edited category name is the same as the current category name
5557
if (currentCategoryName !== newCategoryName) {
56-
renamePolicyCategory(policyData, {oldName: currentCategoryName, newName: values.categoryName});
58+
renamePolicyCategory(policyData, {oldName: currentCategoryName, newName: newCategoryName});
5759
}
5860

5961
// Ensure Onyx.update is executed before navigation to prevent UI blinking issues, affecting the category name and rate.
6062
Navigation.setNavigationActionToMicrotaskQueue(() => {
6163
Navigation.goBack(isQuickSettingsFlow ? backPath : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, currentCategoryName), {compareParams: false});
6264
});
6365
},
64-
[currentCategoryName, policyData, isQuickSettingsFlow, backPath, policyID],
66+
[currentCategoryName, policyData, isQuickSettingsFlow, backPath, policyID, sanitizeCategoryName],
6567
);
6668

6769
return (

0 commit comments

Comments
 (0)