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'; ...@@ -7,7 +7,6 @@ import MessageBar from '../message_bar.jsx';
import Panel from '../panel.jsx'; import Panel from '../panel.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx'; import ZimbraStore from '../../stores/zimbra_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import * as Utils from '../../utils/utils.jsx'; import * as Utils from '../../utils/utils.jsx';
...@@ -48,7 +47,13 @@ export default class DomainMailboxPlans extends React.Component { ...@@ -48,7 +47,13 @@ export default class DomainMailboxPlans extends React.Component {
} }
const headerButtons = [ 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', label: 'Ver casillas',
props: { props: {
...@@ -65,18 +70,6 @@ export default class DomainMailboxPlans extends React.Component { ...@@ -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 = []; const mailboxPlans = [];
let panelBody = null; let panelBody = null;
const cos = Utils.getEnabledPlansByCosId(ZimbraStore.getAllCos()); const cos = Utils.getEnabledPlansByCosId(ZimbraStore.getAllCos());
......
...@@ -14,7 +14,6 @@ import EventStore from '../../stores/event_store.jsx'; ...@@ -14,7 +14,6 @@ import EventStore from '../../stores/event_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx'; import MailboxStore from '../../stores/mailbox_store.jsx';
import DomainStore from '../../stores/domain_store.jsx'; import DomainStore from '../../stores/domain_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx'; import ZimbraStore from '../../stores/zimbra_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import Constants from '../../utils/constants.jsx'; import Constants from '../../utils/constants.jsx';
...@@ -298,23 +297,21 @@ export default class CreateMailBox extends React.Component { ...@@ -298,23 +297,21 @@ export default class CreateMailBox extends React.Component {
}); });
} }
if (UserStore.isGlobalAdmin()) { const options = {
const options = { title: 'Comprar Casilla',
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?`,
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,
html: true, confirmButtonText: 'Si, compraré'
confirmButtonText: 'Si, compraré' };
};
return Utils.alertToBuy((isConfirmed) => { return Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) { if (isConfirmed) {
const {id} = this.cacheDomain; const {id} = this.cacheDomain;
if (id) { if (id) {
return Utils.handleLink(null, `/sales/${id}/mailboxes`); return Utils.handleLink(null, `/sales/${id}/mailboxes`);
}
} }
}, options); }
} }, options);
} }
getAllDomains() { getAllDomains() {
......
...@@ -90,122 +90,120 @@ export default class EditMailBox extends React.Component { ...@@ -90,122 +90,120 @@ export default class EditMailBox extends React.Component {
}); });
} }
if (UserStore.isGlobalAdmin()) { const options = {
const options = { title: 'Plan sin cupo',
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`,
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,
html: true, confirmButtonText: 'Obtener Precio',
confirmButtonText: 'Obtener Precio', showLoaderOnConfirm: true,
showLoaderOnConfirm: true, closeOnConfirm: false
closeOnConfirm: false };
};
const domainId = this.domainId || this.props.params.domain_id || null; const domainId = this.domainId || this.props.params.domain_id || null;
const dataJSON = { const dataJSON = {
domainId, domainId,
type: 'standar', type: 'standar',
currency: this.currency, currency: this.currency,
cosId: val, cosId: val,
anualRenovation: true, anualRenovation: true,
upgrade: true upgrade: true
}; };
const request = { const request = {
domainId: this.domainId, domainId: this.domainId,
adminEmail: UserStore.getCurrentUser().name, adminEmail: UserStore.getCurrentUser().name,
upgrade: true, upgrade: true,
currency: this.currency currency: this.currency
}; };
const account = this.state.data; const account = this.state.data;
Utils.alertToBuy((isConfirmed) => { Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) { if (isConfirmed) {
Client.getPrices(dataJSON, (success) => { Client.getPrices(dataJSON, (success) => {
const prices = success.result.prices; const prices = success.result.prices;
const price = prices[data.plan] ? currencyFormatter.format(prices[data.plan], this.currencyParams) + ' ' + this.currency : 0; const price = prices[data.plan] ? currencyFormatter.format(prices[data.plan], this.currencyParams) + ' ' + this.currency : 0;
const options = { const options = {
title: 'Cambio de Plan', 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>`, 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, html: true,
confirmButtonText: 'Si, Cambiar Plan', confirmButtonText: 'Si, Cambiar Plan',
showLoaderOnConfirm: true, showLoaderOnConfirm: true,
closeOnConfirm: false closeOnConfirm: false
}; };
Utils.alertToBuy((isConfirmed) => { Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) { if (isConfirmed) {
const item = {}; const item = {};
item.basic = { item.basic = {
type: 'Producto', type: 'Producto',
quantity: 1, quantity: 1,
price: prices[data.plan], price: prices[data.plan],
description: `Cambio de plan de la casilla: ${account.name} de ${this.currentPlan} a ${data.plan}`, description: `Cambio de plan de la casilla: ${account.name} de ${this.currentPlan} a ${data.plan}`,
id: data.cosId id: data.cosId
}; };
request.items = item; request.items = item;
const requestObject = JSON.stringify(request); const requestObject = JSON.stringify(request);
Client.makeSale(requestObject, () => { Client.makeSale(requestObject, () => {
Utils.alertToBuy((isConfirmed) => { Utils.alertToBuy((isConfirmed) => {
if (isConfirmed) { if (isConfirmed) {
const enabledAccounts = this.state.enabledAccounts; const enabledAccounts = this.state.enabledAccounts;
enabledAccounts.forEach((plan) => { enabledAccounts.forEach((plan) => {
if (plan.cosId === data.cosId) { if (plan.cosId === data.cosId) {
plan.enabled++; plan.enabled++;
plan.total++; plan.total++;
currentEvent.target.checked = true; currentEvent.target.checked = true;
} }
}); });
this.setState({ this.setState({
enabledAccounts, enabledAccounts,
zimbraCOSId: data.cosId zimbraCOSId: data.cosId
}); });
} }
}, { }, {
title: 'Cambio de Plan', title: 'Cambio de Plan',
text: 'Su compra se ha realizado con éxito.', text: 'Su compra se ha realizado con éxito.',
showCancelButton: false, showCancelButton: false,
confirmButtonColor: '#4EA5EC', confirmButtonColor: '#4EA5EC',
confirmButtonText: 'Muy bien', confirmButtonText: 'Muy bien',
type: 'success' 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
});
}); });
} }, (error) => {
}, options); Utils.alertToBuy(() => {
}, (error) => { return null;
return EventStore.emitToast({ }, {
type: 'error', title: 'Error',
title: 'Compras - Precios', text: error.message || error.error.message || 'Ha ocurrido un error desconocido.',
body: error.message || 'Ha ocurrido un error al intentar obtener los precios, vuelva a intentarlo por favor.', showCancelButton: false,
options: { confirmButtonColor: '#4EA5EC',
timeOut: 4000, confirmButtonText: 'Entiendo',
extendedTimeOut: 2000, type: 'error',
closeButton: true 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() { 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