From 40e1f72b09a41486b206cb6a300be9792943aab1 Mon Sep 17 00:00:00 2001 From: retrofox Date: Wed, 27 Mar 2019 17:09:35 -0300 Subject: [PATCH 1/3] simple-paymenrts-button: loading properly product it populates rightly the product properties gotten from the data/response when it comes from a shortcode transformation. --- extensions/blocks/simple-payments/edit.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/blocks/simple-payments/edit.js b/extensions/blocks/simple-payments/edit.js index dad71668aefd9..51027ade26695 100644 --- a/extensions/blocks/simple-payments/edit.js +++ b/extensions/blocks/simple-payments/edit.js @@ -7,7 +7,7 @@ import { __, _n, sprintf } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { compose, withInstanceId } from '@wordpress/compose'; import { dispatch, withSelect } from '@wordpress/data'; -import { get, isEqual, pick, trimEnd } from 'lodash'; +import { get, isEmpty, isEqual, pick, trimEnd } from 'lodash'; import { getCurrencyDefaults } from '@automattic/format-currency'; import { Disabled, @@ -89,11 +89,13 @@ class SimplePaymentsEdit extends Component { * When subsequent saves occur, we should avoid injecting attributes so that we do not * overwrite changes that the user has made with stale state from the previous save. */ - if ( ! this.shouldInjectPaymentAttributes ) { + + const { simplePayment } = this.props; + if ( ! this.shouldInjectPaymentAttributes || isEmpty( simplePayment ) ) { return; } - const { attributes, setAttributes, simplePayment } = this.props; + const { attributes, setAttributes } = this.props; const { content, currency, From 37b5d53bc47239b7c9d7ddc37ba6588064e81f13 Mon Sep 17 00:00:00 2001 From: retrofox Date: Wed, 27 Mar 2019 17:59:52 -0300 Subject: [PATCH 2/3] simple-payments-button: remove unneeded checking --- extensions/blocks/simple-payments/edit.js | 34 ++++++++--------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/extensions/blocks/simple-payments/edit.js b/extensions/blocks/simple-payments/edit.js index 51027ade26695..f9f51c9ec3c45 100644 --- a/extensions/blocks/simple-payments/edit.js +++ b/extensions/blocks/simple-payments/edit.js @@ -96,29 +96,19 @@ class SimplePaymentsEdit extends Component { } const { attributes, setAttributes } = this.props; - const { - content, - currency, - email, - featuredMediaId, - multiple, - price, - productId, - title, - } = attributes; + const { content, currency, email, featuredMediaId, multiple, price, title } = attributes; + + setAttributes( { + content: get( simplePayment, [ 'content', 'raw' ], content ), + currency: get( simplePayment, [ 'meta', 'spay_currency' ], currency ), + email: get( simplePayment, [ 'meta', 'spay_email' ], email ), + featuredMediaId: get( simplePayment, [ 'featured_media' ], featuredMediaId ), + multiple: Boolean( get( simplePayment, [ 'meta', 'spay_multiple' ], Boolean( multiple ) ) ), + price: get( simplePayment, [ 'meta', 'spay_price' ], price || undefined ), + title: get( simplePayment, [ 'title', 'raw' ], title ), + } ); - if ( productId && simplePayment ) { - setAttributes( { - content: get( simplePayment, [ 'content', 'raw' ], content ), - currency: get( simplePayment, [ 'meta', 'spay_currency' ], currency ), - email: get( simplePayment, [ 'meta', 'spay_email' ], email ), - featuredMediaId: get( simplePayment, [ 'featured_media' ], featuredMediaId ), - multiple: Boolean( get( simplePayment, [ 'meta', 'spay_multiple' ], Boolean( multiple ) ) ), - price: get( simplePayment, [ 'meta', 'spay_price' ], price || undefined ), - title: get( simplePayment, [ 'title', 'raw' ], title ), - } ); - this.shouldInjectPaymentAttributes = ! this.shouldInjectPaymentAttributes; - } + this.shouldInjectPaymentAttributes = ! this.shouldInjectPaymentAttributes; } toApi() { From 341f90c1429befec5810989df8daae1cc4da36ed Mon Sep 17 00:00:00 2001 From: retrofox Date: Wed, 27 Mar 2019 18:09:00 -0300 Subject: [PATCH 3/3] simple-payments-button: fix isDisable condition --- extensions/blocks/simple-payments/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/blocks/simple-payments/edit.js b/extensions/blocks/simple-payments/edit.js index f9f51c9ec3c45..f49ca94d383fc 100644 --- a/extensions/blocks/simple-payments/edit.js +++ b/extensions/blocks/simple-payments/edit.js @@ -412,7 +412,7 @@ class SimplePaymentsEdit extends Component { * The only disabled state that concerns us is when we expect a product but don't have it in * local state. */ - const isDisabled = productId && ! simplePayment; + const isDisabled = productId && isEmpty( simplePayment ); if ( ! isSelected && isDisabled ) { return (