From be9cbb672e89c229af3ac95fac673aeae858f483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20Gutierrez?= Date: Mon, 23 Dec 2024 13:24:25 +0100 Subject: [PATCH] discount amount and rate validation before email dispatch (#548) --- .../promocode-specification-actions.js | 37 ++++++++++++------- src/i18n/en.json | 2 + 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/actions/promocode-specification-actions.js b/src/actions/promocode-specification-actions.js index 709ddd110..2cc4418b1 100644 --- a/src/actions/promocode-specification-actions.js +++ b/src/actions/promocode-specification-actions.js @@ -9,17 +9,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - **/ + * */ import T from "i18n-react/dist/i18n-react"; -import { - createAction, - escapeFilterValue, - fetchResponseHandler, - fetchErrorHandler -} from "openstack-uicore-foundation/lib/utils/actions"; - -import { getAccessTokenSafely } from "../utils/methods"; +import { createAction } from "openstack-uicore-foundation/lib/utils/actions"; export const UPDATE_SPECS = "UPDATE_SPECS"; export const VALIDATE_SPECS = "VALIDATE_SPECS"; @@ -35,17 +28,33 @@ export const updateSpecs = (promoCodeStrategy, entity) => (dispatch) => { export const validateSpecs = (promoCodeStrategy, entity, callback) => (dispatch) => { - let errors = {}; + const errors = {}; + + const spkPC = 1; + const spkDC = 2; + const agSpkPC = 3; + const agSpkDC = 4; - if ([1, 2].includes(promoCodeStrategy) && !entity.existingPromoCode) { - errors["existingPromoCode"] = T.translate( + if ( + [spkPC, spkDC].includes(promoCodeStrategy) && + !entity.existingPromoCode + ) { + errors.existingPromoCode = T.translate( "promo_code_specification.promo_code_mandatory" ); dispatch(createAction(VALIDATE_SPECS)({ errors })); return; } - if ([3, 4].includes(promoCodeStrategy) && !entity.type) { - errors["type"] = T.translate("promo_code_specification.type_mandatory"); + if ([agSpkPC, agSpkDC].includes(promoCodeStrategy) && !entity.type) { + errors.type = T.translate("promo_code_specification.type_mandatory"); + dispatch(createAction(VALIDATE_SPECS)({ errors })); + return; + } + if (promoCodeStrategy === agSpkDC && !entity.amount && !entity.rate) { + errors.amount = T.translate( + "promo_code_specification.amount_mandatory" + ); + errors.rate = T.translate("promo_code_specification.rate_mandatory"); dispatch(createAction(VALIDATE_SPECS)({ errors })); return; } diff --git a/src/i18n/en.json b/src/i18n/en.json index ab67e2579..1c25793a6 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -3024,6 +3024,8 @@ "select_promo_code_type": "-- SELECT PROMO CODE TYPE --", "promo_code_mandatory": "Existing promo code is mandatory", "type_mandatory": "Type is mandatory", + "amount_mandatory": "The discount amount is mandatory when the rate is not specified", + "rate_mandatory": "The discount rate is mandatory when the amount is not specified", "placeholders": { "amount": "Amount ($)", "rate": "Rate (% discount)",