Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve React code for cart
Paweł Kowalewski3e25e3026dbb
diff --git a/Gruntfile.js b/Gruntfile.jsindex 8f60cb53ab..9b3cf61905 100644--- a/Gruntfile.js+++ b/Gruntfile.js@@ -3,7 +3,7 @@ module.exports = function(grunt) {babel: {dist: {files: {- 'saleor/static/js/storefront_react.js': 'saleor/static/js_src/storefront_react.js'+ 'saleor/static/js/storefront_fromjsx.js': 'saleor/static/js_src/storefront.jsx'}}},@@ -131,8 +131,8 @@ module.exports = function(grunt) {"saleor/static/components/jquery/dist/jquery.js","saleor/static/components/react/react.js","saleor/static/components/bootstrap-sass/assets/javascripts/bootstrap.js",- "saleor/static/js_src/storefront.js",- "saleor/static/js/storefront_react.js"+ "saleor/static/js/storefront_fromjsx.js",+ "saleor/static/js_src/storefront.js"]}}@@ -149,7 +149,7 @@ module.exports = function(grunt) {tasks: ["sass", "postcss"]},uglify: {- files: ["saleor/static/js_src/**/*.js"],+ files: ["saleor/static/js_src/**/*.js", "saleor/static/js_src/**/*.jsx"],tasks: ["babel", "uglify"]}}diff --git a/saleor/cart/templates/cart/index.html b/saleor/cart/templates/cart/index.htmlindex 163e2b6469..1bea3268b5 100644--- a/saleor/cart/templates/cart/index.html+++ b/saleor/cart/templates/cart/index.html@@ -45,24 +45,26 @@</a></td><td>- <div class="input-group cart-item-quantity hidden{% if form.quantity.errors %} has-error{% endif %}">- {{ form.quantity }}- <span class="input-group-btn">- <button class="btn btn-info" type="submit">{% trans "Update" %}</button>- </span>+ <div>+ <div class="input-group cart-item-quantity hidden{% if form.quantity.errors %} has-error{% endif %}">+ {{ form.quantity }}+ <span class="input-group-btn">+ <button class="btn btn-info" type="submit">{% trans "Update" %}</button>+ </span>+ </div></div>{% if form.quantity.errors %}{% for error in form.quantity.errors %}<span class="text-danger">{{ error }}</span>{% endfor %}{% endif %}+ <button type="submit" class="btn btn-link btn-sm cart-item-remove">+ <span class="text-muted">{% trans "Remove from cart" %}</span>+ </button></td><td class="text-right">{% gross form.cart_line.get_price_per_item %}</td><td class="text-right cart-item-subtotal">{% gross form.cart_line.get_total %}- <button type="submit" class="btn btn-link btn-sm cart-item-remove">- <span class="text-muted">{% trans "Remove from cart" %}</span>- </button></td></tr>{% endfor %}diff --git a/saleor/checkout/templates/checkout/address.html b/saleor/checkout/templates/checkout/address.htmlindex cb289f6154..1c2c2306d3 100644--- a/saleor/checkout/templates/checkout/address.html+++ b/saleor/checkout/templates/checkout/address.html@@ -41,7 +41,7 @@<div class="col-sm-6">{% block additional_message %}{% endblock %}- <div class="panel panel-default{% if addresses %} collapse{% endif %}" id="address-form">+ <div class="panel panel-default{% if addresses and existing_address_selected %} collapse{% endif %}" id="address-form"><div class="panel-body"><form method="post" class="{% if not address_book or not existing_address_selected %} in{% endif %}">{% csrf_token %}diff --git a/saleor/checkout/templates/checkout/billing.html b/saleor/checkout/templates/checkout/billing.htmlindex 9ef6b15c20..c89f6cb46d 100644--- a/saleor/checkout/templates/checkout/billing.html+++ b/saleor/checkout/templates/checkout/billing.html@@ -17,19 +17,19 @@{% endblock %}{% block fields %}+ {{ step.forms.address.first_name|as_vertical_form }}+ {{ step.forms.address.last_name|as_vertical_form }}{% if not user.is_authenticated %}- {{ step.forms.address.first_name|as_vertical_form }}- {{ step.forms.address.last_name|as_vertical_form }}{{ step.forms.anonymous|as_vertical_form }}- {{ step.forms.address.company_name|as_vertical_form }}- {{ step.forms.address.street_address_1|as_vertical_form }}- {{ step.forms.address.street_address_2|as_vertical_form }}- {{ step.forms.address.city|as_vertical_form }}- {{ step.forms.address.postal_code|as_vertical_form }}- {{ step.forms.address.country|as_vertical_form }}- {{ step.forms.address.country_area|as_vertical_form }}- {{ step.forms.address.phone|as_vertical_form }}{% endif %}+ {{ step.forms.address.company_name|as_vertical_form }}+ {{ step.forms.address.street_address_1|as_vertical_form }}+ {{ step.forms.address.street_address_2|as_vertical_form }}+ {{ step.forms.address.city|as_vertical_form }}+ {{ step.forms.address.postal_code|as_vertical_form }}+ {{ step.forms.address.country|as_vertical_form }}+ {{ step.forms.address.country_area|as_vertical_form }}+ {{ step.forms.address.phone|as_vertical_form }}{% endblock fields %}{% block form_submit %}diff --git a/saleor/checkout/templates/checkout/shipping.html b/saleor/checkout/templates/checkout/shipping.htmlindex cb02495729..b8d857842a 100644--- a/saleor/checkout/templates/checkout/shipping.html+++ b/saleor/checkout/templates/checkout/shipping.html@@ -25,8 +25,9 @@{{ step.forms.address.country|as_vertical_form }}{{ step.forms.address.country_area|as_vertical_form }}{{ step.forms.address.phone|as_vertical_form }}- {{ delivery_form|as_horizontal_form }}</div>++ {{ delivery_form|as_horizontal_form }}{% endblock fields %}{% block form_submit %}diff --git a/saleor/order/templates/order/details.html b/saleor/order/templates/order/details.htmlindex b6e744e7ab..c885c6512f 100644--- a/saleor/order/templates/order/details.html+++ b/saleor/order/templates/order/details.html@@ -57,7 +57,7 @@<div class="form-group text-right">{% block form_submit %}<button type="submit" class="btn btn-primary">- {% trans "Make a payment" %}+ {% trans "Proceed to payment" %}</button>{% endblock %}</div>diff --git a/saleor/static/js_src/storefront.js b/saleor/static/js_src/storefront.jsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/static/js_src/storefront_react.js b/saleor/static/js_src/storefront.jsxsimilarity index 77%rename from saleor/static/js_src/storefront_react.jsrename to saleor/static/js_src/storefront.jsxindex da5869ca53..c852e28e61 100644--- a/saleor/static/js_src/storefront_react.js+++ b/saleor/static/js_src/storefront.jsx@@ -22,11 +22,13 @@ var CartItemAmount = React.createClass({render: function() {this.lastOptionValue = this.props.options[this.props.options.length - 1];var that = this;- return <select name={this.props.name} onChange={this.change} value={this.state.value} className="form-control cart-item-quantity-select">- {this.props.options.map(function(option) {- return <CartItemAmountOption key={option} value={option} label={option == that.lastOptionValue ? option+" +" : option} />- })}- </select>;+ return <div className={this.props.className}>+ <select name={this.props.name} onChange={this.change} value={this.state.value} className="form-control cart-item-quantity-select">+ {this.props.options.map(function(option) {+ return <CartItemAmountOption key={option} value={option} label={option == that.lastOptionValue ? option+" +" : option} />+ })}+ </select>+ </div>;}});@@ -41,6 +43,7 @@ class CartItemAmountOption extends React.Component {var textInput = [];$(".cart-item-quantity").each(function() {var $input = $(this).find("input");+ var $button = $(this).find("button");var value = $input.val();var name = $input.attr("name");var hasErrors = $(this).hasClass("has-error");@@ -52,7 +55,11 @@ $(".cart-item-quantity").each(function() {}$(this).removeClass("hidden");+ $button.addClass("invisible");textInput[name] = this;+}).on("keyup change", function() {+ $(this).find("input").addClass("input-left");+ $(this).find("button").removeClass("invisible");});var FormShippingToggler = React.createClass({diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scssindex 8040ac5b61..bc042fbe5c 100644--- a/saleor/static/scss/_app.scss+++ b/saleor/static/scss/_app.scss@@ -76,8 +76,11 @@ $icon-font-path: "../fonts/";&-quantity {input {@extend .form-control;- border-bottom-right-radius: 0;- border-top-right-radius: 0;++ &.input-left {+ border-bottom-right-radius: 0;+ border-top-right-radius: 0;+ }}&-select {@@ -96,9 +99,7 @@ $icon-font-path: "../fonts/";}&-remove {- position: absolute;- bottom: 0;- right: 0;+ padding-left: 0;}select {@@ -138,3 +139,17 @@ $icon-font-path: "../fonts/";}}}++.nav {+ > li {+ > a {+ @extend .text-info;+ }++ &.active {+ > a, a:hover {+ background-color: $brand-info;+ }+ }+ }+}