Commit f7020c34 authored by Juorder Gonzalez's avatar Juorder Gonzalez Committed by GitHub

Merge pull request #244 from ZBoxApp/salesApp

allow all user to buy mailboxes and watch their buttons
parents a7092ea2 4e80d7f9
......@@ -7,7 +7,6 @@ import MessageBar from '../message_bar.jsx';
import Panel from '../panel.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import * as Utils from '../../utils/utils.jsx';
......@@ -48,7 +47,13 @@ export default class DomainMailboxPlans extends React.Component {
}
const headerButtons = [
{
label: 'Comprar Casillas',
props: {
className: 'btn btn-info btn-xs',
onClick: (e) => Utils.handleLink(e, `/sales/${this.props.params.id}/mailboxes`, this.props.location)
}
},
{
label: 'Ver casillas',
props: {
......@@ -65,18 +70,6 @@ export default class DomainMailboxPlans extends React.Component {
}
];
if (UserStore.isGlobalAdmin()) {
headerButtons.unshift(
{
label: 'Comprar Casillas',
props: {
className: 'btn btn-info btn-xs',
onClick: (e) => Utils.handleLink(e, `/sales/${this.props.params.id}/mailboxes`, this.props.location)
}
}
);
}
const mailboxPlans = [];
let panelBody = null;
const cos = Utils.getEnabledPlansByCosId(ZimbraStore.getAllCos());
......
......@@ -14,7 +14,6 @@ import EventStore from '../../stores/event_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx';
import DomainStore from '../../stores/domain_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import Constants from '../../utils/constants.jsx';
......@@ -298,23 +297,21 @@ export default class CreateMailBox extends React.Component {
});
}
if (UserStore.isGlobalAdmin()) {
const options = {
title: 'Comprar Casilla',
text: `Por ahora no tienes más cupo para crear una casilla tipo <strong>${Utils.titleCase(data.plan)}</strong>, ¿Deseas comprar más?`,
html: true,
confirmButtonText: 'Si, compraré'
};
const options = {
title: 'Comprar Casilla',
text: `Por ahora no tienes más cupo para crear una casilla tipo <strong>${Utils.titleCase(data.plan)}</strong>, ¿Deseas comprar más?`,
html: true,
confirmButtonText: 'Si, compraré'
};
return Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const {id} = this.cacheDomain;
if (id) {
return Utils.handleLink(null, `/sales/${id}/mailboxes`);
}
return Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const {id} = this.cacheDomain;
if (id) {
return Utils.handleLink(null, `/sales/${id}/mailboxes`);
}
}, options);
}
}
}, options);
}
getAllDomains() {
......
......@@ -90,122 +90,120 @@ export default class EditMailBox extends React.Component {
});
}
if (UserStore.isGlobalAdmin()) {
const options = {
title: 'Plan sin cupo',
text: `Actualmente el plan <strong>${Utils.titleCase(data.plan)}</strong> no tiene cupo para completar la acción solicitada, por lo cual es necesario que compre más casillas`,
html: true,
confirmButtonText: 'Obtener Precio',
showLoaderOnConfirm: true,
closeOnConfirm: false
};
const options = {
title: 'Plan sin cupo',
text: `Actualmente el plan <strong>${Utils.titleCase(data.plan)}</strong> no tiene cupo para completar la acción solicitada, por lo cual es necesario que compre más casillas`,
html: true,
confirmButtonText: 'Obtener Precio',
showLoaderOnConfirm: true,
closeOnConfirm: false
};
const domainId = this.domainId || this.props.params.domain_id || null;
const domainId = this.domainId || this.props.params.domain_id || null;
const dataJSON = {
domainId,
type: 'standar',
currency: this.currency,
cosId: val,
anualRenovation: true,
upgrade: true
};
const dataJSON = {
domainId,
type: 'standar',
currency: this.currency,
cosId: val,
anualRenovation: true,
upgrade: true
};
const request = {
domainId: this.domainId,
adminEmail: UserStore.getCurrentUser().name,
upgrade: true,
currency: this.currency
};
const request = {
domainId: this.domainId,
adminEmail: UserStore.getCurrentUser().name,
upgrade: true,
currency: this.currency
};
const account = this.state.data;
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
Client.getPrices(dataJSON, (success) => {
const prices = success.result.prices;
const price = prices[data.plan] ? currencyFormatter.format(prices[data.plan], this.currencyParams) + ' ' + this.currency : 0;
const options = {
title: 'Cambio de Plan',
text: `Al presionar <strong>Aceptar</strong>, está autorizando la emisión de una factura por un total de <strong>${price}</strong> correspondiente a : <br> <ul class="list-buy-dialog"><li>Asunto: Cambio de Plan</li><li>Casilla: <strong>${account.name}</strong></li><li>Plan Original: <strong>${Utils.titleCase(this.currentPlan)}</strong></li><li>Nuevo Plan: <strong>${Utils.titleCase(data.plan)}</strong></li></ul>`,
html: true,
confirmButtonText: 'Si, Cambiar Plan',
showLoaderOnConfirm: true,
closeOnConfirm: false
};
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const item = {};
item.basic = {
type: 'Producto',
quantity: 1,
price: prices[data.plan],
description: `Cambio de plan de la casilla: ${account.name} de ${this.currentPlan} a ${data.plan}`,
id: data.cosId
};
request.items = item;
const requestObject = JSON.stringify(request);
Client.makeSale(requestObject, () => {
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const enabledAccounts = this.state.enabledAccounts;
enabledAccounts.forEach((plan) => {
if (plan.cosId === data.cosId) {
plan.enabled++;
plan.total++;
currentEvent.target.checked = true;
}
});
this.setState({
enabledAccounts,
zimbraCOSId: data.cosId
});
}
}, {
title: 'Cambio de Plan',
text: 'Su compra se ha realizado con éxito.',
showCancelButton: false,
confirmButtonColor: '#4EA5EC',
confirmButtonText: 'Muy bien',
type: 'success'
});
}, (error) => {
Utils.alertToBuy(() => {
return null;
}, {
title: 'Error',
text: error.message || error.error.message || 'Ha ocurrido un error desconocido.',
showCancelButton: false,
confirmButtonColor: '#4EA5EC',
confirmButtonText: 'Entiendo',
type: 'error',
closeOnConfirm: true
});
const account = this.state.data;
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
Client.getPrices(dataJSON, (success) => {
const prices = success.result.prices;
const price = prices[data.plan] ? currencyFormatter.format(prices[data.plan], this.currencyParams) + ' ' + this.currency : 0;
const options = {
title: 'Cambio de Plan',
text: `Al presionar <strong>Aceptar</strong>, está autorizando la emisión de una factura por un total de <strong>${price}</strong> correspondiente a : <br> <ul class="list-buy-dialog"><li>Asunto: Cambio de Plan</li><li>Casilla: <strong>${account.name}</strong></li><li>Plan Original: <strong>${Utils.titleCase(this.currentPlan)}</strong></li><li>Nuevo Plan: <strong>${Utils.titleCase(data.plan)}</strong></li></ul>`,
html: true,
confirmButtonText: 'Si, Cambiar Plan',
showLoaderOnConfirm: true,
closeOnConfirm: false
};
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const item = {};
item.basic = {
type: 'Producto',
quantity: 1,
price: prices[data.plan],
description: `Cambio de plan de la casilla: ${account.name} de ${this.currentPlan} a ${data.plan}`,
id: data.cosId
};
request.items = item;
const requestObject = JSON.stringify(request);
Client.makeSale(requestObject, () => {
Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) {
const enabledAccounts = this.state.enabledAccounts;
enabledAccounts.forEach((plan) => {
if (plan.cosId === data.cosId) {
plan.enabled++;
plan.total++;
currentEvent.target.checked = true;
}
});
this.setState({
enabledAccounts,
zimbraCOSId: data.cosId
});
}
}, {
title: 'Cambio de Plan',
text: 'Su compra se ha realizado con éxito.',
showCancelButton: false,
confirmButtonColor: '#4EA5EC',
confirmButtonText: 'Muy bien',
type: 'success'
});
}
}, options);
}, (error) => {
return EventStore.emitToast({
type: 'error',
title: 'Compras - Precios',
body: error.message || 'Ha ocurrido un error al intentar obtener los precios, vuelva a intentarlo por favor.',
options: {
timeOut: 4000,
extendedTimeOut: 2000,
closeButton: true
}
});
}, (error) => {
Utils.alertToBuy(() => {
return null;
}, {
title: 'Error',
text: error.message || error.error.message || 'Ha ocurrido un error desconocido.',
showCancelButton: false,
confirmButtonColor: '#4EA5EC',
confirmButtonText: 'Entiendo',
type: 'error',
closeOnConfirm: true
});
});
}
}, options);
}, (error) => {
return EventStore.emitToast({
type: 'error',
title: 'Compras - Precios',
body: error.message || 'Ha ocurrido un error al intentar obtener los precios, vuelva a intentarlo por favor.',
options: {
timeOut: 4000,
extendedTimeOut: 2000,
closeButton: true
}
});
}
}, options);
}
});
}
}, options);
}
removeAccount() {
......
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