diff --git a/src/languages/en.ts b/src/languages/en.ts index 5f0f1b0b57a8..9c5b388cfff8 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -225,6 +225,7 @@ export default { acceptTerms: 'You must accept the Terms of Service to continue', phoneNumber: `Please enter a valid phone number, with the country code (e.g. ${CONST.EXAMPLE_PHONE_NUMBER})`, fieldRequired: 'This field is required.', + requestModified: 'This request is being modified by another member.', characterLimit: ({limit}: CharacterLimitParams) => `Exceeds the maximum length of ${limit} characters`, characterLimitExceedCounter: ({length, limit}) => `Character limit exceeded (${length}/${limit})`, dateInvalid: 'Please select a valid date', diff --git a/src/languages/es.ts b/src/languages/es.ts index b95beffa0ece..9e2418d89233 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -215,6 +215,7 @@ export default { acceptTerms: 'Debes aceptar los Términos de Servicio para continuar', phoneNumber: `Introduce un teléfono válido, incluyendo el código del país (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER})`, fieldRequired: 'Este campo es obligatorio.', + requestModified: 'Esta solicitud está siendo modificada por otro miembro.', characterLimit: ({limit}: CharacterLimitParams) => `Supera el límite de ${limit} caracteres`, characterLimitExceedCounter: ({length, limit}) => `Se superó el límite de caracteres (${length}/${limit})`, dateInvalid: 'Por favor, selecciona una fecha válida', diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 0e3df33358c0..0d5c5b8a327b 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -1,5 +1,5 @@ import type {RouteProp} from '@react-navigation/native'; -import React, {useCallback} from 'react'; +import React, {useCallback, useEffect} from 'react'; import {View} from 'react-native'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; @@ -10,10 +10,14 @@ import Text from '@components/Text'; import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as ReportActionsUtils from '@libs/ReportActionsUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; +import * as FormActions from '@userActions/FormActions'; import * as IOU from '@userActions/IOU'; -import type ONYXKEYS from '@src/ONYXKEYS'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/MoneyRequestHoldReasonForm'; @@ -39,23 +43,43 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const {transactionID, reportID, backTo} = route.params; + const report = ReportUtils.getReport(reportID); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); + const navigateBack = () => { Navigation.navigate(backTo); }; const onSubmit = (values: FormOnyxValues) => { + if (!ReportUtils.canEditMoneyRequest(parentReportAction)) { + return; + } + IOU.putOnHold(transactionID, values.comment, reportID); navigateBack(); }; - const validate = useCallback((values: FormOnyxValues) => { - const errors: FormInputErrors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); + const validate = useCallback( + (values: FormOnyxValues) => { + const errors: FormInputErrors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); - if (!values.comment) { - errors.comment = 'common.error.fieldRequired'; - } + if (!values.comment) { + errors.comment = 'common.error.fieldRequired'; + } + if (!ReportUtils.canEditMoneyRequest(parentReportAction)) { + const formErrors = {}; + ErrorUtils.addErrorMessage(formErrors, 'reportModified', 'common.error.requestModified'); + FormActions.setErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM, formErrors); + } + + return errors; + }, + [parentReportAction], + ); - return errors; + useEffect(() => { + FormActions.clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); + FormActions.clearErrorFields(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); }, []); return (