From d365d57902b2691539cefba1cccd989cbca8886a Mon Sep 17 00:00:00 2001 From: glen-aot <160973940+glen-aot@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:11:44 -0800 Subject: [PATCH] ORV2-3306 - FE: Refund by cheque requiring transaction ID (#1745) Co-authored-by: GlenAOT <160973940+GlenAOT@users.noreply.github.com> --- .../src/common/constants/validation_messages.json | 2 +- .../features/permits/pages/Refund/RefundPage.tsx | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/common/constants/validation_messages.json b/frontend/src/common/constants/validation_messages.json index 96ea80bb9..d6d6668c6 100644 --- a/frontend/src/common/constants/validation_messages.json +++ b/frontend/src/common/constants/validation_messages.json @@ -163,7 +163,7 @@ "transactionId": { "defaultMessage": "Invalid transaction ID", "length": { - "messageTemplate": "Transaction ID length must be no longer than :max characters", + "messageTemplate": "Maximum :max characters", "placeholders": [":max"] } } diff --git a/frontend/src/features/permits/pages/Refund/RefundPage.tsx b/frontend/src/features/permits/pages/Refund/RefundPage.tsx index d741d7a2c..cbb8ed83a 100644 --- a/frontend/src/features/permits/pages/Refund/RefundPage.tsx +++ b/frontend/src/features/permits/pages/Refund/RefundPage.tsx @@ -69,8 +69,15 @@ const transactionIdRules = { requiredMessage() ); }, - validateTransactionId: (value: Optional<string>) => { - return (value && value.length <= 15) || invalidTranactionIdLength(15); + validateTransactionId: ( + value: Optional<string>, + formValues: RefundFormData, + ) => { + return ( + !formValues.shouldUsePrevPaymentMethod || + (value && value.length <= 15) || + invalidTranactionIdLength(15) + ); }, }, }; @@ -210,6 +217,7 @@ export const RefundPage = ({ const usePrev = shouldUsePrev === "true"; setShouldUsePrevPaymentMethod(usePrev); setValue("refundOnlineMethod", usePrev ? getRefundOnlineMethod() : ""); + setValue("transactionId", ""); clearErrors("transactionId"); }; @@ -227,6 +235,7 @@ export const RefundPage = ({ e: React.ChangeEvent<HTMLInputElement>, ) => { const formattedValue = filterNonNumericValue(e.target.value); + handleRefundMethodChange("true"); setValue("transactionId", formattedValue, { shouldValidate: true }); };