mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Can delete custom tab if uncheck the checkbox
This commit is contained in:
@@ -65,6 +65,8 @@ module Admin
|
||||
update_tag_rules(tag_rules_attributes) if tag_rules_attributes.present?
|
||||
update_enterprise_notifications
|
||||
|
||||
delete_custom_tab if params[:custom_tab] == 'false'
|
||||
|
||||
if @object.update(enterprise_params)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
respond_with(@object) do |format|
|
||||
@@ -137,6 +139,11 @@ module Admin
|
||||
|
||||
protected
|
||||
|
||||
def delete_custom_tab
|
||||
@object.custom_tab.destroy if @object.custom_tab.present?
|
||||
enterprise_params.delete(:custom_tab_attributes)
|
||||
end
|
||||
|
||||
def build_resource
|
||||
enterprise = super
|
||||
enterprise.address ||= Spree::Address.new
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
.three.columns.alpha
|
||||
= label_tag :custom_tab, t('.create_custom_tab')
|
||||
.three.columns
|
||||
= check_box_tag :custom_tab, true, @object.custom_tab&.title.present?, { "data-controller": "checkbox-display", "data-checkbox-display-target-id-value": "custom_tab_form" }
|
||||
= hidden_field_tag :custom_tab, "false" # submit `true` if checkbox is checked, `false` otherwise
|
||||
= check_box_tag :custom_tab, "true", @object.custom_tab&.title.present?, { "data-controller": "checkbox-display", "data-checkbox-display-target-id-value": "custom_tab_form" }
|
||||
|
||||
%div{id: "custom_tab_form"}
|
||||
= f.fields_for :custom_tab, @object.custom_tab do |custom_tab_form|
|
||||
|
||||
@@ -770,6 +770,14 @@ describe '
|
||||
expect(page).
|
||||
to have_field "enterprise_custom_tab_attributes_content", with: custom_tab.content
|
||||
end
|
||||
|
||||
it "can delete custom tab if uncheck the checkbox" do
|
||||
uncheck "Create custom tab in shopfront"
|
||||
click_button 'Update'
|
||||
expect(flash_message)
|
||||
.to eq('Enterprise "First Distributor" has been successfully updated!')
|
||||
expect(distributor1.reload.custom_tab).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user