Commit b76823b4 authored by Juorder Antonio's avatar Juorder Antonio

fire event to finish loading bar, add json stringify to data to send ajax

parent 876c7e6a
......@@ -14,6 +14,10 @@ export default class SalesForm extends React.Component {
this.buildPurchase = this.buildPurchase.bind(this);
this.confirmShipping = this.confirmShipping.bind(this);
this.resetCounter = this.resetCounter.bind(this);
this.onChangeValue = this.onChangeValue.bind(this);
this.onKeydownInput = this.onKeydownInput.bind(this);
this.isOnlyNumber = false;
const {name, attrs} = UserStore.getCurrentUser();
const {displayName, cn, sn} = attrs._attrs;
......@@ -47,12 +51,15 @@ export default class SalesForm extends React.Component {
resetCounter() {
const purchase = {};
const reset = this.mailboxes.forEach((plan) => {
purchase[plan] = 0;
this.mailboxes.forEach((plan) => {
const isValidPlan = !this.avoidPlans.includes(plan);
if (isValidPlan) {
purchase[plan] = 0;
}
});
this.setState({
purchase: reset
purchase
});
}
......@@ -60,12 +67,6 @@ export default class SalesForm extends React.Component {
GlobalActions.emitEndLoading();
}
onKeyupInput(event, label) {
const value = event.target.value;
this.checkAmount(label, value);
}
buildFullName(displayName, cn, sn) {
const fullname = displayName && displayName.trim() !== '' ? displayName : `${cn} ${sn}`;
......@@ -92,11 +93,13 @@ export default class SalesForm extends React.Component {
const allows = [8, 9, 37, 39, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
if (allows.includes(keycode)) {
return true;
this.isOnlyNumber = true;
return this.isOnlyNumber;
}
event.preventDefault();
return null;
this.isOnlyNumber = false;
return this.isOnlyNumber;
}
buildPurchase(purchase) {
......@@ -149,8 +152,8 @@ export default class SalesForm extends React.Component {
data.domain = name;
data = JSON.stringify(data);
Client.requestMailboxes(data, (response) => {
const text = this.messageCode[response.messageCode];
this.resetCounter();
const text = this.messageCode[response.messageCode];
sweetAlert('Compra éxitosa', text, 'success');
}, (error) => {
const text = this.messageCode[error.messageCode];
......@@ -161,6 +164,14 @@ export default class SalesForm extends React.Component {
}, options);
}
onChangeValue(event, input) {
const value = event.target.value;
if (this.isOnlyNumber) {
this.checkAmount(input, value);
}
}
renderInputs() {
const {purchase} = this.state;
return this.mailboxes.map((input, index) => {
......@@ -177,8 +188,8 @@ export default class SalesForm extends React.Component {
<input
type='text'
className='form-control'
defaultValue={value}
onKeyUp={(event) => this.onKeyupInput(event, input)}
value={value}
onChange={(event) => this.onChangeValue(event, input)}
onKeyDown={this.onKeydownInput}
/>
</div>
......@@ -232,3 +243,24 @@ export default class SalesForm extends React.Component {
SalesForm.propTypes = {
params: React.PropTypes.object
};
>
<button
disabled={disabled}
className='btn btn-info'
onClick={this.confirmShipping}
>Comprar</button>
</div>
</div>
</form>
</Panel>
</div>
</div>
</div>
</div>
);
}
}
SalesForm.propTypes = {
params: React.PropTypes.object
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment