Skip to content

Commit f7eac51

Browse files
committed
refactor rulesCustomNameForm to align with the current implementation
1 parent 670c7ea commit f7eac51

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/ONYXKEYS.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,8 @@ const ONYXKEYS = {
823823
SEARCH_SAVED_SEARCH_RENAME_FORM_DRAFT: 'searchSavedSearchRenameFormDraft',
824824
TEXT_PICKER_MODAL_FORM: 'textPickerModalForm',
825825
TEXT_PICKER_MODAL_FORM_DRAFT: 'textPickerModalFormDraft',
826-
RULES_CUSTOM_NAME_MODAL_FORM: 'rulesCustomNameModalForm',
827-
RULES_CUSTOM_NAME_MODAL_FORM_DRAFT: 'rulesCustomNameModalFormDraft',
826+
REPORTS_DEFAULT_TITLE_MODAL_FORM: 'ReportsDefaultTitleModalForm',
827+
REPORTS_DEFAULT_TITLE_MODAL_FORM_DRAFT: 'ReportsDefaultTitleModalFormDraft',
828828
RULES_AUTO_APPROVE_REPORTS_UNDER_MODAL_FORM: 'rulesAutoApproveReportsUnderModalForm',
829829
RULES_AUTO_APPROVE_REPORTS_UNDER_MODAL_FORM_DRAFT: 'rulesAutoApproveReportsUnderModalFormDraft',
830830
RULES_RANDOM_REPORT_AUDIT_MODAL_FORM: 'rulesRandomReportAuditModalForm',
@@ -942,7 +942,7 @@ type OnyxFormValuesMapping = {
942942
[ONYXKEYS.FORMS.SAGE_INTACCT_DIMENSION_TYPE_FORM]: FormTypes.SageIntacctDimensionForm;
943943
[ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM]: FormTypes.SearchAdvancedFiltersForm;
944944
[ONYXKEYS.FORMS.TEXT_PICKER_MODAL_FORM]: FormTypes.TextPickerModalForm;
945-
[ONYXKEYS.FORMS.RULES_CUSTOM_NAME_MODAL_FORM]: FormTypes.RulesCustomNameModalForm;
945+
[ONYXKEYS.FORMS.REPORTS_DEFAULT_TITLE_MODAL_FORM]: FormTypes.ReportsDefaultTitleModalForm;
946946
[ONYXKEYS.FORMS.RULES_AUTO_APPROVE_REPORTS_UNDER_MODAL_FORM]: FormTypes.RulesAutoApproveReportsUnderModalForm;
947947
[ONYXKEYS.FORMS.RULES_RANDOM_REPORT_AUDIT_MODAL_FORM]: FormTypes.RulesRandomReportAuditModalForm;
948948
[ONYXKEYS.FORMS.RULES_AUTO_PAY_REPORTS_UNDER_MODAL_FORM]: FormTypes.RulesAutoPayReportsUnderModalForm;

src/pages/workspace/reports/ReportsDefaultTitle.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import {clearPolicyTitleFieldError, setPolicyDefaultReportTitle} from '@userActi
2525
import CONST from '@src/CONST';
2626
import ONYXKEYS from '@src/ONYXKEYS';
2727
import type SCREENS from '@src/SCREENS';
28-
import INPUT_IDS from '@src/types/form/RulesCustomNameModalForm';
28+
import INPUT_IDS from '@src/types/form/ReportsDefaultTitleModalForm';
2929

3030
type RulesCustomNamePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.REPORTS_DEFAULT_TITLE>;
3131

32-
function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
32+
function ReportsDefaultTitlePage({route}: RulesCustomNamePageProps) {
3333
const policyID = route.params.policyID;
3434
const policy = usePolicy(policyID);
3535

@@ -48,13 +48,13 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
4848
const customNameDefaultValue = Str.htmlDecode(fieldListItem?.defaultValue ?? '');
4949

5050
const validateCustomName = useCallback(
51-
({customName}: FormOnyxValues<typeof ONYXKEYS.FORMS.RULES_CUSTOM_NAME_MODAL_FORM>) => {
52-
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.RULES_CUSTOM_NAME_MODAL_FORM> = {};
53-
if (!customName) {
54-
errors[INPUT_IDS.CUSTOM_NAME] = translate('common.error.fieldRequired');
55-
} else if (customName.length > CONST.WORKSPACE_NAME_CHARACTER_LIMIT) {
56-
errors[INPUT_IDS.CUSTOM_NAME] = translate('common.error.characterLimitExceedCounter', {
57-
length: customName.length,
51+
({defaultTitle}: FormOnyxValues<typeof ONYXKEYS.FORMS.REPORTS_DEFAULT_TITLE_MODAL_FORM>) => {
52+
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.REPORTS_DEFAULT_TITLE_MODAL_FORM> = {};
53+
if (!defaultTitle) {
54+
errors[INPUT_IDS.DEFAULT_TITLE] = translate('common.error.fieldRequired');
55+
} else if (defaultTitle.length > CONST.WORKSPACE_NAME_CHARACTER_LIMIT) {
56+
errors[INPUT_IDS.DEFAULT_TITLE] = translate('common.error.characterLimitExceedCounter', {
57+
length: defaultTitle.length,
5858
limit: CONST.WORKSPACE_NAME_CHARACTER_LIMIT,
5959
});
6060
}
@@ -75,8 +75,8 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
7575
clearTitleFieldError();
7676
});
7777

78-
const submitForm = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.RULES_CUSTOM_NAME_MODAL_FORM>) => {
79-
setPolicyDefaultReportTitle(policyID, values.customName);
78+
const submitForm = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.REPORTS_DEFAULT_TITLE_MODAL_FORM>) => {
79+
setPolicyDefaultReportTitle(policyID, values.defaultTitle);
8080
Navigation.goBack();
8181
};
8282

@@ -91,7 +91,7 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
9191
<ScreenWrapper
9292
enableEdgeToEdgeBottomSafeAreaPadding
9393
shouldEnableMaxHeight
94-
testID={RulesCustomNamePage.displayName}
94+
testID={ReportsDefaultTitlePage.displayName}
9595
>
9696
<HeaderWithBackButton
9797
title={translate('workspace.rules.expenseReportRules.customNameTitle')}
@@ -111,7 +111,7 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
111111
</View>
112112
<FormProvider
113113
style={[styles.flexGrow1, styles.mh5]}
114-
formID={ONYXKEYS.FORMS.RULES_CUSTOM_NAME_MODAL_FORM}
114+
formID={ONYXKEYS.FORMS.REPORTS_DEFAULT_TITLE_MODAL_FORM}
115115
validate={validateCustomName}
116116
onSubmit={submitForm}
117117
submitButtonText={translate('common.save')}
@@ -128,7 +128,7 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
128128
>
129129
<InputWrapper
130130
InputComponent={TextInput}
131-
inputID={INPUT_IDS.CUSTOM_NAME}
131+
inputID={INPUT_IDS.DEFAULT_TITLE}
132132
defaultValue={customNameDefaultValue}
133133
label={translate('workspace.rules.expenseReportRules.customNameInputLabel')}
134134
aria-label={translate('workspace.rules.expenseReportRules.customNameInputLabel')}
@@ -145,6 +145,6 @@ function RulesCustomNamePage({route}: RulesCustomNamePageProps) {
145145
);
146146
}
147147

148-
RulesCustomNamePage.displayName = 'RulesCustomNamePage';
148+
ReportsDefaultTitlePage.displayName = 'ReportsDefaultTitlePage';
149149

150-
export default RulesCustomNamePage;
150+
export default ReportsDefaultTitlePage;

src/types/form/ReportsDefaultTitleModalForm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import type {ValueOf} from 'type-fest';
22
import type Form from './Form';
33

44
const INPUT_IDS = {
5-
CUSTOM_NAME: 'customName',
5+
DEFAULT_TITLE: 'defaultTitle',
66
} as const;
77

88
type InputID = ValueOf<typeof INPUT_IDS>;
99

10-
type RulesCustomNameModalForm = Form<
10+
type ReportsDefaultTitleModalForm = Form<
1111
InputID,
1212
{
13-
[INPUT_IDS.CUSTOM_NAME]: string;
13+
[INPUT_IDS.DEFAULT_TITLE]: string;
1414
}
1515
>;
1616

17-
export type {RulesCustomNameModalForm};
17+
export type {ReportsDefaultTitleModalForm};
1818
export default INPUT_IDS;

src/types/form/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export type {SearchAdvancedFiltersForm} from './SearchAdvancedFiltersForm';
7474
export type {EditExpensifyCardLimitForm} from './EditExpensifyCardLimitForm';
7575
export type {default as TextPickerModalForm} from './TextPickerModalForm';
7676
export type {default as Form} from './Form';
77-
export type {RulesCustomNameModalForm} from './RulesCustomNameModalForm';
77+
export type {ReportsDefaultTitleModalForm} from './ReportsDefaultTitleModalForm';
7878
export type {RulesAutoApproveReportsUnderModalForm} from './RulesAutoApproveReportsUnderModalForm';
7979
export type {RulesRandomReportAuditModalForm} from './RulesRandomReportAuditModalForm';
8080
export type {RulesAutoPayReportsUnderModalForm} from './RulesAutoPayReportsUnderModalForm';

0 commit comments

Comments
 (0)