Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix uppy modal after user edits photo (#12503)
Damian Kaczmarczyk4f390ace58e5
diff --git a/admin/app/javascript/spree/admin/controllers/active_storage_upload_controller.js b/admin/app/javascript/spree/admin/controllers/active_storage_upload_controller.jsindex d9da1097e7..299f0e28a2 100644--- a/admin/app/javascript/spree/admin/controllers/active_storage_upload_controller.js+++ b/admin/app/javascript/spree/admin/controllers/active_storage_upload_controller.js@@ -65,16 +65,16 @@ export default class extends Controller {source: 'local',isRemote: false})++ this.handleUI(updatedFile)++ this.uppy.getPlugin('Dashboard').closeModal()})this.uppy.on('upload-success', (file, response) => {this.handleUI(file, response)})- this.uppy.on('file-editor:complete', (updatedFile, result) => {- this.handleUI(updatedFile, result)- })-this.uppy.on('dashboard:modal-closed', () => {this.uppy.clear()})@@ -118,37 +118,39 @@ export default class extends Controller {}}- handleUI(file, response) {+ handleUI(file, response = null) {this.placeholderTarget.style = 'display: none !important'- const signedId = response.signed_id+ const signedId = response?.signed_id || file.response?.signed_id- if (this.hasThumbTarget) {- this.thumbTarget.src = URL.createObjectURL(file.data)- this.thumbTarget.style.display = null- this.thumbTarget.dataset.imageSignedId = signedId- this.thumbTarget.width = this.thumbWidthValue- this.thumbTarget.height = this.thumbHeightValue- }+ if (signedId?.length) {+ if (this.hasThumbTarget) {+ this.thumbTarget.src = URL.createObjectURL(file.data)+ this.thumbTarget.style.display = null+ this.thumbTarget.dataset.imageSignedId = signedId+ this.thumbTarget.width = this.thumbWidthValue+ this.thumbTarget.height = this.thumbHeightValue+ }- // Remove existing hidden field for this file, if any- const existingField = this.element.querySelector(`input[name="${this.fieldNameValue}"]`)- if (existingField) {- existingField.remove()- }+ // Remove existing hidden field for this file, if any+ const existingField = this.element.querySelector(`input[name="${this.fieldNameValue}"]`)+ if (existingField) {+ existingField.remove()+ }- const hiddenField = document.createElement('input')+ const hiddenField = document.createElement('input')- hiddenField.setAttribute('type', 'hidden')- hiddenField.setAttribute('value', signedId)+ hiddenField.setAttribute('type', 'hidden')+ hiddenField.setAttribute('value', signedId)- if (this.multipleValue) {- hiddenField.setAttribute('name', `${this.fieldNameValue}[]`)- } else {- hiddenField.setAttribute('name', this.fieldNameValue)- }+ if (this.multipleValue) {+ hiddenField.setAttribute('name', `${this.fieldNameValue}[]`)+ } else {+ hiddenField.setAttribute('name', this.fieldNameValue)+ }- this.element.appendChild(hiddenField)+ this.element.appendChild(hiddenField)+ }// show toolbar if attachedif (this.hasToolbarTarget) {diff --git a/admin/app/views/active_storage/_upload_form.html.erb b/admin/app/views/active_storage/_upload_form.html.erbindex ebb71f6901..e7d440b970 100644--- a/admin/app/views/active_storage/_upload_form.html.erb+++ b/admin/app/views/active_storage/_upload_form.html.erb@@ -46,7 +46,7 @@</div></div>- <div class="d-flex align-items-center" data-active-storage-upload-target="toolbar" <% unless form.object.send(field_name).attached? && form.object.send(field_name).variable? %>style="display: none !important"<% end %>>+ <div class="d-flex align-items-center pb-3" data-active-storage-upload-target="toolbar" <% unless form.object.send(field_name).attached? && form.object.send(field_name).variable? %>style="display: none !important"<% end %>><button type="button" class="btn btn-light" data-action="active-storage-upload#open"><%= icon('upload') %><%= Spree.t('actions.select_file') %>