Handle enterprise edit response with turbo_stream

This commit is contained in:
wandji20
2024-10-13 01:18:21 +01:00
parent 636d4b64db
commit 766396b979
3 changed files with 15 additions and 10 deletions

View File

@@ -7,7 +7,6 @@ require 'open_food_network/order_cycle_permissions'
module Admin
class EnterprisesController < Admin::ResourceController
include GeocodeEnterpriseAddress
include CablecarResponses
include Pagy::Backend
# These need to run before #load_resource so that @object is initialised with sanitised values
@@ -51,8 +50,10 @@ module Admin
@enterprise.is_primary_producer = params[:is_primary_producer]
@enterprise.sells = params[:enterprise_sells]
render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu"))
.morph("#permalink", partial("admin/enterprises/form/permalink"))
respond_to do |format|
format.html { head :ok }
format.turbo_stream { render :edit }
end
end
def welcome

View File

@@ -0,0 +1,4 @@
= turbo_stream.replace 'side_menu' do
= render partial: 'admin/shared/side_menu'
= turbo_stream.replace 'permalink' do
= render partial: 'admin/enterprises/form/permalink'

View File

@@ -22,13 +22,13 @@ export default class extends Controller {
`?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}&is_primary_producer=${this.primaryProducerValue}`,
{
method: "GET",
headers: { "Content-type": "application/json; charset=UTF-8" },
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'text/vnd.turbo-stream.html'
}
}
)
.then((data) => data.json())
.then((operation) => {
CableReady.perform(operation);
this.spinnerTarget.classList.add("hidden");
});
}
.then(response => response.text())
.then(html => Turbo.renderStreamMessage(html))
.then(() => this.spinnerTarget.classList.add("hidden"))}
}