mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Improve enterprise removal (success case)
Make enterprise removal use turbo, which provides the following benefits: * More responsive removal since there's no full page reload. * A success flash message (previously nothing was displayed). * No double alert prompt. It also goes in the direction of removing mrujs in favor of turbo.
This commit is contained in:
@@ -162,6 +162,15 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@object.destroy
|
||||
flash.now[:success] = flash_message_for(@object, :successfully_removed)
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render :destroy, status: :ok }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def delete_custom_tab
|
||||
|
||||
@@ -63,8 +63,11 @@ module EnterprisesHelper
|
||||
url = object_url(enterprise)
|
||||
name = t(:delete)
|
||||
options = {}
|
||||
options[:class] = "delete-resource"
|
||||
options[:data] = { action: 'remove', confirm: enterprise_confirm_delete_message(enterprise) }
|
||||
options[:data] = {
|
||||
turbo: true,
|
||||
'turbo-method': 'delete',
|
||||
'turbo-confirm': enterprise_confirm_delete_message(enterprise)
|
||||
}
|
||||
link_to_with_icon 'icon-trash', name, url, options
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
%tbody
|
||||
= f.fields_for :collection do |enterprise_form|
|
||||
- enterprise = enterprise_form.object
|
||||
%tr{class: "enterprise-#{enterprise.id}"}
|
||||
%tr{class: "enterprise-#{enterprise.id}", id: "resource-#{enterprise.id}"}
|
||||
%td= link_to enterprise.name, main_app.edit_admin_enterprise_path(enterprise)
|
||||
%td
|
||||
= enterprise_form.check_box :is_primary_producer
|
||||
|
||||
4
app/views/admin/enterprises/destroy.turbo_stream.haml
Normal file
4
app/views/admin/enterprises/destroy.turbo_stream.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
- unless flash[:error]
|
||||
= turbo_stream.remove "resource-#{@object.id}"
|
||||
= turbo_stream.append "flashes" do
|
||||
= render(partial: 'admin/shared/flashes', locals: { flashes: flash })
|
||||
@@ -68,6 +68,26 @@ RSpec.describe '
|
||||
expect(page).to have_checked_field "enterprise_visible_only_through_links"
|
||||
end
|
||||
|
||||
it "deleting an existing enterprise successfully" do
|
||||
enterprise = create(:enterprise)
|
||||
|
||||
user = create(:user)
|
||||
|
||||
admin = login_as_admin
|
||||
|
||||
visit '/admin/enterprises'
|
||||
|
||||
expect do
|
||||
accept_alert do
|
||||
within "tr.enterprise-#{enterprise.id}" do
|
||||
first("a", text: 'Delete').click
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).to have_content("Successfully Removed")
|
||||
end.to change{ Enterprise.count }.by(-1)
|
||||
end
|
||||
|
||||
it "editing an existing enterprise" do
|
||||
@enterprise = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
|
||||
Reference in New Issue
Block a user