Repository URL to install this package:
|
Version:
2.8.4 ▾
|
@skava/ui
/
dist
/
components
/
presets
/
Subscription
/
PaymentInformationForm
/
FormFields
/
index.js
|
|---|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const mobx_react_1 = require("xmobx/mobx-react");
const exotic_1 = require("exotic");
const forms_1 = require("../../../../../forms");
const fixture_1 = require("./fixture");
const styled_1 = require("./styled"); // @todo - radiogroup
class FormStateCard extends forms_1.FormState {
constructor() {
super(...arguments);
this.inputsList = fixture_1.inputList;
}
}
const formStateCard = new FormStateCard();
const SubmitButton = props => react_1.default.createElement(styled_1.StyledPrimaryButton, Object.assign({}, props));
let PaymentForm = class PaymentForm extends forms_1.ObserverForm {
constructor() {
super(...arguments);
this.SubmitButton = SubmitButton;
this.defaultSubmitButtonLabel = fixture_1.wording.button;
this.classList = {
form: 'subscription-add-new-payment-form',
submitButton: 'subscription-add-new-payment-submit-button'
};
this.handleSubmit = event => {
const {
onPaymentCardSave
} = this.props;
event.preventDefault(); // console.log('data:', this.state.toSerialized())
if (this.validateForm()) {
// this.props.cardState.handleToggle()
if (exotic_1.isFunction(onPaymentCardSave)) {
onPaymentCardSave(this.state);
}
}
};
}
toggleBillingAddress() {
const checkBoxState = this.state.get('defaultBillingAddress');
const isSelected = exotic_1.isSafe(checkBoxState) && checkBoxState.isSelected;
const toList = state => exotic_1.isArray(state.inputsList) && state.inputsList;
const inputStateList = toList(this.state);
inputStateList.map(inputs => {
if (inputs.name === 'billing-address') {
inputs.isHidden = isSelected;
}
});
}
setValueOnValidation(items, inputField) {
if (exotic_1.isSafe(items.expiry)) {
const expiryDate = items.expiry.split('/');
items.expirationMonth = exotic_1.isSafe(expiryDate[0]) ? expiryDate[0] : '';
items.expirationYear = exotic_1.isSafe(expiryDate[1]) ? expiryDate[1] : '';
}
if (exotic_1.isSafe(items[inputField.name]) && inputField.value !== items[inputField.name]) {
inputField.setValue(items[inputField.name]);
}
}
onPrefil(inputState) {
const {
item
} = this.props;
if (inputState.type === 'groupElements') {
inputState.elementList.map(inputs => {
exotic_1.isObj(item) && this.setValueOnValidation(item, inputs);
});
} else {
exotic_1.isObj(item) && this.setValueOnValidation(item, inputState);
}
}
componentWillMount() {
this.toggleBillingAddress();
}
componentWillUpdate() {
this.toggleBillingAddress();
}
};
PaymentForm.FormState = formStateCard;
PaymentForm.defaultProps = {
state: formStateCard
};
PaymentForm = tslib_1.__decorate([mobx_react_1.observer], PaymentForm);
class FormFields extends react_1.default.Component {
render() {
return react_1.default.createElement(styled_1.StyledPaymentForm, null, react_1.default.createElement(PaymentForm, Object.assign({}, this.props)));
}
}
exports.FormFields = FormFields;
exports.default = FormFields; //# sourceMappingURL=index.js.map