From 744cba65080fb47a051821fc324fcd4adf460b5c Mon Sep 17 00:00:00 2001 From: wikuskriek Date: Thu, 29 Feb 2024 09:51:43 +0200 Subject: [PATCH 1/5] fix: error when you can't hold request --- src/languages/en.ts | 1 + src/pages/iou/HoldReasonPage.tsx | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 4fa22d8e255d..cf845d2523b2 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.', + transactionModified: 'This transaction has been modified', 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/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 0e3df33358c0..d9eaee7f22c5 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'; @@ -13,9 +13,11 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as ValidationUtils from '@libs/ValidationUtils'; 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'; +import * as FormActions from '@userActions/FormActions'; +import * as ReportUtils from '@libs/ReportUtils'; type HoldReasonPageRouteParams = { /** ID of the transaction the page was opened for */ @@ -44,6 +46,10 @@ function HoldReasonPage({route}: HoldReasonPageProps) { }; const onSubmit = (values: FormOnyxValues) => { + if (!ReportUtils.isReportApproved(reportID) && !ReportUtils.isSettled(reportID)) { + FormActions.setErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM, {reportModified: translate('common.error.transactionModified')}); + return; + } IOU.putOnHold(transactionID, values.comment, reportID); navigateBack(); }; @@ -51,13 +57,18 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const validate = useCallback((values: FormOnyxValues) => { const errors: FormInputErrors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); - if (!values.comment) { + if (!values.comment) { errors.comment = 'common.error.fieldRequired'; } return errors; }, []); + useEffect(() => { + FormActions.clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); + FormActions.clearErrorFields(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); + } , []); + return ( Date: Thu, 29 Feb 2024 09:57:42 +0200 Subject: [PATCH 2/5] fix: format --- src/pages/iou/HoldReasonPage.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index d9eaee7f22c5..11c3378b3ec9 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -11,13 +11,13 @@ import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +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 ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/MoneyRequestHoldReasonForm'; -import * as FormActions from '@userActions/FormActions'; -import * as ReportUtils from '@libs/ReportUtils'; type HoldReasonPageRouteParams = { /** ID of the transaction the page was opened for */ @@ -57,7 +57,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const validate = useCallback((values: FormOnyxValues) => { const errors: FormInputErrors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); - if (!values.comment) { + if (!values.comment) { errors.comment = 'common.error.fieldRequired'; } @@ -67,7 +67,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { useEffect(() => { FormActions.clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); FormActions.clearErrorFields(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); - } , []); + }, []); return ( Date: Sat, 2 Mar 2024 18:10:50 +0200 Subject: [PATCH 3/5] fix: copy --- src/languages/en.ts | 2 +- src/languages/es.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index cf845d2523b2..b67423cf17b2 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -225,7 +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.', - transactionModified: 'This transaction has been modified', + 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 7bea48d71d36..5c86d5602ddc 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', From bc681c3d73fd60147c26abc26e61793379c853db Mon Sep 17 00:00:00 2001 From: wikuskriek Date: Sat, 2 Mar 2024 18:14:26 +0200 Subject: [PATCH 4/5] fix: used canEditMoneyRequest --- src/pages/iou/HoldReasonPage.tsx | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 11c3378b3ec9..3b579d583b7b 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -10,7 +10,9 @@ 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'; @@ -41,28 +43,39 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const {transactionID, reportID, backTo} = route.params; + const reportData = ReportUtils.getReport(reportID); + const parentReportAction = ReportActionsUtils.getReportAction(reportData?.parentReportID ?? '', reportData?.parentReportActionID ?? ''); + const navigateBack = () => { Navigation.navigate(backTo); }; const onSubmit = (values: FormOnyxValues) => { - if (!ReportUtils.isReportApproved(reportID) && !ReportUtils.isSettled(reportID)) { - FormActions.setErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM, {reportModified: translate('common.error.transactionModified')}); + 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; - }, []); + return errors; + }, + [parentReportAction], + ); useEffect(() => { FormActions.clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); From 05434042afcc5c2ce4adbbb6449802496a317cd8 Mon Sep 17 00:00:00 2001 From: wikuskriek Date: Sat, 2 Mar 2024 18:47:42 +0200 Subject: [PATCH 5/5] Refactor variable names --- src/pages/iou/HoldReasonPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 3b579d583b7b..0d5c5b8a327b 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -43,8 +43,8 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const {transactionID, reportID, backTo} = route.params; - const reportData = ReportUtils.getReport(reportID); - const parentReportAction = ReportActionsUtils.getReportAction(reportData?.parentReportID ?? '', reportData?.parentReportActionID ?? ''); + const report = ReportUtils.getReport(reportID); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); const navigateBack = () => { Navigation.navigate(backTo);