mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Remove white_label reflex and handle remove enterprise logo wth turbo stream
This commit is contained in:
@@ -13,7 +13,7 @@ module Admin
|
||||
prepend_before_action :override_owner, only: :create
|
||||
prepend_before_action :override_sells, only: :create
|
||||
|
||||
before_action :load_countries, except: [:index, :register, :check_permalink]
|
||||
before_action :load_countries, except: [:index, :register, :check_permalink, :remove_logo]
|
||||
before_action :load_methods_and_fees, only: [:edit, :update]
|
||||
before_action :load_groups, only: [:new, :edit, :update, :create]
|
||||
before_action :load_taxons, only: [:new, :edit, :update, :create]
|
||||
@@ -142,6 +142,33 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def remove_logo
|
||||
# delete the white_label_logo_link attribute as well since it has no meaning without the logo
|
||||
@object.update!(white_label_logo: nil, white_label_logo_link: "")
|
||||
|
||||
f = ActionView::Helpers::FormBuilder.new(:enterprise, @object, view_context, {})
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
|
||||
redirect_to edit_admin_enterprise_path
|
||||
end
|
||||
format.turbo_stream do
|
||||
flash.now[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
|
||||
render turbo_stream: [
|
||||
turbo_stream.replace(
|
||||
'white_label_panel',
|
||||
partial: "admin/enterprises/form/white_label", locals: { f:, enterprise: @object }
|
||||
),
|
||||
turbo_stream.append(
|
||||
"flashes",
|
||||
partial: 'admin/shared/flashes', locals: { flashes: flash }
|
||||
)
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def delete_custom_tab
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WhiteLabelReflex < ApplicationReflex
|
||||
include EnterpriseConcern
|
||||
delegate :view_context, to: :controller
|
||||
|
||||
def remove_logo
|
||||
@enterprise.update!(white_label_logo: nil)
|
||||
# delete the white_label_logo_link attribute as well since it has no meaning without the logo
|
||||
@enterprise.update!(white_label_logo_link: "")
|
||||
|
||||
f = ActionView::Helpers::FormBuilder.new(:enterprise, @enterprise, view_context, {})
|
||||
|
||||
html = render(partial: "admin/enterprises/form/white_label",
|
||||
locals: { f:, enterprise: @enterprise })
|
||||
morph "#white_label_panel", html
|
||||
|
||||
flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
|
||||
cable_ready.dispatch_event(name: "modal:close")
|
||||
morph_admin_flashes
|
||||
end
|
||||
end
|
||||
@@ -29,9 +29,13 @@
|
||||
|
||||
|
||||
- if @object.white_label_logo.present?
|
||||
= render ConfirmModalComponent.new(id: "remove_logo", confirm_reflexes: "click->WhiteLabel#remove_logo" ) do
|
||||
.margin-bottom-30
|
||||
= render ModalComponent.new(id: "remove_logo", close_button: false, modal_class: 'tiny') do
|
||||
.content.margin-bottom-30
|
||||
= t('.remove_logo_confirm')
|
||||
%p.modal-actions.justify-space-around
|
||||
= link_to t('js.admin.modals.confirm'), remove_logo_admin_enterprise_path, class: 'button primary', data: { turbo: true, turbo_method: :patch, action: 'click->modal#close' }
|
||||
%button.button.primary{ type: "button", 'data-action': 'click->modal#close' }
|
||||
= t('js.admin.modals.cancel')
|
||||
|
||||
// Hide groups tab boolean attribute
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
member do
|
||||
get :welcome
|
||||
patch :register
|
||||
patch :remove_logo
|
||||
end
|
||||
|
||||
resources :connected_apps, only: [:create, :destroy]
|
||||
|
||||
@@ -685,7 +685,7 @@ RSpec.describe '
|
||||
expect(distributor1.white_label_logo).to be_attached
|
||||
click_button "Remove"
|
||||
within ".reveal-modal" do
|
||||
click_button "Confirm"
|
||||
click_link "Confirm"
|
||||
end
|
||||
expect(flash_message).to match(/Logo removed/)
|
||||
distributor1.reload
|
||||
|
||||
Reference in New Issue
Block a user