Skip to content

Commit

Permalink
Merge pull request #37477 from WikusKriek/37014-Hold-request-should-s…
Browse files Browse the repository at this point in the history
…how-error-when-request-has-been-paid

30714 Error and block submit when you can't hold request
  • Loading branch information
robertjchen authored Mar 11, 2024
2 parents e0c7776 + 0543404 commit d4cacf7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
40 changes: 32 additions & 8 deletions src/pages/iou/HoldReasonPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand All @@ -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<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
if (!ReportUtils.canEditMoneyRequest(parentReportAction)) {
return;
}

IOU.putOnHold(transactionID, values.comment, reportID);
navigateBack();
};

const validate = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM> = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]);
const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM> = 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 (
Expand Down

0 comments on commit d4cacf7

Please sign in to comment.