Skip to content

Commit eeaaf29

Browse files
committed
discount amount and rate validation before email dispatch
1 parent a3b887e commit eeaaf29

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/actions/promocode-specification-actions.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
* See the License for the specific language governing permissions and
1111
* limitations under the License.
12-
**/
12+
* */
1313

1414
import T from "i18n-react/dist/i18n-react";
15-
import {
16-
createAction,
17-
escapeFilterValue,
18-
fetchResponseHandler,
19-
fetchErrorHandler
20-
} from "openstack-uicore-foundation/lib/utils/actions";
21-
22-
import { getAccessTokenSafely } from "../utils/methods";
15+
import { createAction } from "openstack-uicore-foundation/lib/utils/actions";
2316

2417
export const UPDATE_SPECS = "UPDATE_SPECS";
2518
export const VALIDATE_SPECS = "VALIDATE_SPECS";
@@ -35,17 +28,33 @@ export const updateSpecs = (promoCodeStrategy, entity) => (dispatch) => {
3528

3629
export const validateSpecs =
3730
(promoCodeStrategy, entity, callback) => (dispatch) => {
38-
let errors = {};
31+
const errors = {};
32+
33+
const spkPC = 1;
34+
const spkDC = 2;
35+
const agSpkPC = 3;
36+
const agSpkDC = 4;
3937

40-
if ([1, 2].includes(promoCodeStrategy) && !entity.existingPromoCode) {
41-
errors["existingPromoCode"] = T.translate(
38+
if (
39+
[spkPC, spkDC].includes(promoCodeStrategy) &&
40+
!entity.existingPromoCode
41+
) {
42+
errors.existingPromoCode = T.translate(
4243
"promo_code_specification.promo_code_mandatory"
4344
);
4445
dispatch(createAction(VALIDATE_SPECS)({ errors }));
4546
return;
4647
}
47-
if ([3, 4].includes(promoCodeStrategy) && !entity.type) {
48-
errors["type"] = T.translate("promo_code_specification.type_mandatory");
48+
if ([agSpkPC, agSpkDC].includes(promoCodeStrategy) && !entity.type) {
49+
errors.type = T.translate("promo_code_specification.type_mandatory");
50+
dispatch(createAction(VALIDATE_SPECS)({ errors }));
51+
return;
52+
}
53+
if (promoCodeStrategy === agSpkDC && !entity.amount && !entity.rate) {
54+
errors.amount = T.translate(
55+
"promo_code_specification.amount_mandatory"
56+
);
57+
errors.rate = T.translate("promo_code_specification.rate_mandatory");
4958
dispatch(createAction(VALIDATE_SPECS)({ errors }));
5059
return;
5160
}

src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,8 @@
30243024
"select_promo_code_type": "-- SELECT PROMO CODE TYPE --",
30253025
"promo_code_mandatory": "Existing promo code is mandatory",
30263026
"type_mandatory": "Type is mandatory",
3027+
"amount_mandatory": "The discount amount is mandatory when the rate is not specified",
3028+
"rate_mandatory": "The discount rate is mandatory when the amount is not specified",
30273029
"placeholders": {
30283030
"amount": "Amount ($)",
30293031
"rate": "Rate (% discount)",

0 commit comments

Comments
 (0)