/** * Product sub-component * * @type {*|Function} * * @author Rai Icasiano */ window.Product = React.createClass({ getInitialState: function() { return { itemTotal: this.props.itemTotal, quantity: this.props.quantity, isbn: this.props.isbn, displayAction: false } }, /** * Render the quantity select element option list * * @param key * @returns {Array} */ quantityOptionValues: function (key) { let options = []; for (let i = 1; i <= 10; ++i) { options.push(); } return options; }, /** * Trigger API call to delete the product */ deleteProduct: function () { this.props.setConfirmModal(false); this.props.setLoading(true); let successCallback = function (componentReference) { componentReference.props.removeItemFromCart(componentReference.props.index); componentReference.props.setLoading(false); }; let failCallback = function (componentReference) { componentReference.props.setAPIError(true); componentReference.props.setLoading(false); }; //API Call deleteProduct(this, successCallback, failCallback, this.state.isbn); }, /** * Updates product quantity and computes the total per product * * @param event */ updateProduct: function (event) { let quantity = event.target.value; let successCallback = function (componentReference) { componentReference.setState({itemTotal: quantity * componentReference.props.price}); componentReference.setState({quantity: quantity}); componentReference.props.updateGrandTotal(componentReference.props.index, quantity); componentReference.props.setLoading(false); }; let failCallback = function (componentReference) { componentReference.props.setAPIError(true); componentReference.props.setLoading(false); }; //API Call putProduct(this, successCallback, failCallback, this.state.isbn, quantity); }, deleteProductConfirmation: function() { this.props.setConfirmModal(true); this.props.setConfirmModalAction(this.deleteProduct); this.props.setConfirmModalErrorMessage('Are you sure you want to delete ' + this.props.title + '(' + this.props.isbn + ')?'); }, render: function () { return (
{this.props.title}
{this.props.author}
{this.props.format} (ISBN-13: {this.props.isbn})
{this.props.currency}{this.props.price}
{this.props.currency}{this.props.itemTotal.toLocaleString('en-US', {minimumFractionDigits: 2})}
); } });