Skip to content

Commit

Permalink
discount amount and rate validation before email dispatch (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanetar authored Dec 23, 2024
1 parent 420deab commit be9cbb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/actions/promocode-specification-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down

0 comments on commit be9cbb6

Please sign in to comment.