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
1414import 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
2417export const UPDATE_SPECS = "UPDATE_SPECS" ;
2518export const VALIDATE_SPECS = "VALIDATE_SPECS" ;
@@ -35,17 +28,33 @@ export const updateSpecs = (promoCodeStrategy, entity) => (dispatch) => {
3528
3629export 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 }
0 commit comments