Skip to content
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
18 changes: 7 additions & 11 deletions src/libs/WorkspaceReportFieldUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type {FormInputErrors} from '@components/Form/types';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type ONYXKEYS from '@src/ONYXKEYS';
import type {InputID} from '@src/types/form/WorkspaceReportFieldForm';
import type {PolicyReportField, PolicyReportFieldType} from '@src/types/onyx/Policy';
import {addErrorMessage} from './ErrorUtils';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from './Localize';
import {isRequiredFulfilled} from './ValidationUtils';

/**
Expand Down Expand Up @@ -45,19 +44,17 @@ function validateReportFieldListValueName(
priorValueName: string,
listValues: string[],
inputID: InputID,
translate: LocalizedTranslate,
): FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM> {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM> = {};

if (!isRequiredFulfilled(valueName)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
errors[inputID] = translateLocal('workspace.reportFields.listValueRequiredError');
errors[inputID] = translate('workspace.reportFields.listValueRequiredError');
} else if (priorValueName !== valueName && listValues.some((currentValueName) => currentValueName === valueName)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
errors[inputID] = translateLocal('workspace.reportFields.existingListValueError');
errors[inputID] = translate('workspace.reportFields.existingListValueError');
} else if ([...valueName].length > CONST.WORKSPACE_REPORT_FIELD_POLICY_MAX_LENGTH) {
// Uses the spread syntax to count the number of Unicode code points instead of the number of UTF-16 code units.
// eslint-disable-next-line @typescript-eslint/no-deprecated
addErrorMessage(errors, inputID, translateLocal('common.error.characterLimitExceedCounter', [...valueName].length, CONST.WORKSPACE_REPORT_FIELD_POLICY_MAX_LENGTH));
addErrorMessage(errors, inputID, translate('common.error.characterLimitExceedCounter', [...valueName].length, CONST.WORKSPACE_REPORT_FIELD_POLICY_MAX_LENGTH));
}

return errors;
Expand All @@ -72,7 +69,7 @@ function generateFieldID(name: string) {
/**
* Gets the initial value for a report field.
*/
function getReportFieldInitialValue(reportField: PolicyReportField | null): string {
function getReportFieldInitialValue(reportField: PolicyReportField | null, translate: LocalizedTranslate): string {
if (!reportField) {
return '';
}
Expand All @@ -82,8 +79,7 @@ function getReportFieldInitialValue(reportField: PolicyReportField | null): stri
}

if (reportField.type === CONST.REPORT_FIELD_TYPES.DATE) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('common.currentDate');
return translate('common.currentDate');
}

return reportField.value ?? reportField.defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function ReportFieldsAddListValuePage({

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM>) =>
validateReportFieldListValueName(values[INPUT_IDS.VALUE_NAME].trim(), '', listValues, INPUT_IDS.VALUE_NAME),
[listValues],
validateReportFieldListValueName(values[INPUT_IDS.VALUE_NAME].trim(), '', listValues, INPUT_IDS.VALUE_NAME, translate),
[listValues, translate],
);

const createValue = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/reports/ReportFieldsEditValuePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function ReportFieldsEditValuePage({

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM>) =>
validateReportFieldListValueName(values[INPUT_IDS.NEW_VALUE_NAME].trim(), currentValueName, formDraft?.[INPUT_IDS.LIST_VALUES] ?? [], INPUT_IDS.NEW_VALUE_NAME),
[currentValueName, formDraft],
validateReportFieldListValueName(values[INPUT_IDS.NEW_VALUE_NAME].trim(), currentValueName, formDraft?.[INPUT_IDS.LIST_VALUES] ?? [], INPUT_IDS.NEW_VALUE_NAME, translate),
[currentValueName, formDraft, translate],
);

const editValue = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ReportFieldsInitialValuePage({

const reportField = policy?.fieldList?.[getReportFieldKey(reportFieldID)] ?? null;
const availableListValuesLength = (reportField?.disabledOptions ?? []).filter((disabledListValue) => !disabledListValue).length;
const currentInitialValue = getReportFieldInitialValue(reportField);
const currentInitialValue = getReportFieldInitialValue(reportField, translate);
const [initialValue, setInitialValue] = useState(currentInitialValue);

const submitForm = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/reports/ReportFieldsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {View} from 'react-native';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 6 in src/pages/workspace/reports/ReportFieldsSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 6 in src/pages/workspace/reports/ReportFieldsSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
Expand Down Expand Up @@ -111,7 +111,7 @@
<MenuItemWithTopDescription
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
title={getReportFieldInitialValue(reportField)}
title={getReportFieldInitialValue(reportField, translate)}
description={translate('common.initialValue')}
shouldShowRightIcon={!isDateFieldType}
interactive={!isDateFieldType}
Expand Down
Loading