Add/Remove white label logo in enterprise preferences panel

This commit is contained in:
Jean-Baptiste Bellet
2023-03-16 16:05:04 +01:00
parent bbec01a9cb
commit 6fdf9fa038
4 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
class WhiteLabelReflex < ApplicationReflex
include EnterpriseConcern
delegate :view_context, to: :controller
def remove_logo
@enterprise.update!(white_label_logo: nil)
f = ActionView::Helpers::FormBuilder.new(:enterprise, @enterprise, view_context, {})
html = with_locale {
render(partial: "admin/enterprises/form/white_label",
locals: { f: f, enterprise: @enterprise })
}
morph "#white_label_panel", html
flash[:success] = with_locale {
I18n.t("admin.enterprises.form.white_label.remove_logo_success")
}
cable_ready.dispatch_event(name: "modal:close")
morph "#flashes", render(partial: "shared/flashes", locals: { flashes: flash })
end
end

View File

@@ -1,6 +1,23 @@
- @object ||= enterprise
.row
.three.columns.alpha
= f.label :hide_ofn_navigation, t('.hide_ofn_navigation')
.three.columns
= f.check_box :hide_ofn_navigation
.row{id: "white_label_logo"}
.three.columns.alpha
= f.label :white_label_logo, t('.upload_logo')
.three.columns
= image_tag @object.white_label_logo_url if @object.white_label_logo.present?
= f.file_field :white_label_logo, accept: "image/*"
- if @object.white_label_logo.variable?
%button.button.small{ type: "button", "data-controller": "modal-link", "data-action": "click->modal-link#open", "data-modal-link-target-value": "remove_logo" }
= t('.remove_logo')
- if @object.white_label_logo.variable?
= render ConfirmModalComponent.new(id: "remove_logo", confirm_reflexes: "click->WhiteLabel#remove_logo" ) do
.margin-bottom-30
= t('.remove_logo_confirm')

View File

@@ -1161,6 +1161,10 @@ en:
white_label:
legend: "White Label"
hide_ofn_navigation: "Hide OFN navigation"
upload_logo: "Logo used in shopfront"
remove_logo: "Remove logo"
remove_logo_confirm: "Are you sure you want to remove this logo?"
remove_logo_success: "Logo removed"
actions:
edit_profile: Settings
properties: Properties

View File

@@ -10,6 +10,7 @@ describe '
include AuthenticationHelper
include ShopWorkflow
include UIComponentHelper
include FileHelper
it "viewing an enterprise" do
e = create(:enterprise)
@@ -645,6 +646,34 @@ describe '
expect(page).not_to have_link "White Label"
end
end
context "when white label is active via `hide_ofn_navigation`" do
before do
distributor1.update_attribute(:preferred_hide_ofn_navigation, true)
end
it "can updload the white label logo for the current shop" do
attach_file "enterprise_white_label_logo", white_logo_path
click_button 'Update'
expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.white_label_logo_blob.filename).to eq("logo-white.png")
end
context "when enterprise has a white label logo" do
before do
distributor1.update white_label_logo: white_logo_file
end
it "can remove the white label logo for the current shop" do
click_button "Remove"
within ".reveal-modal" do
click_button "Confirm"
end
expect(flash_message).to eq("Logo removed")
expect(distributor1.reload.white_label_logo).to be_nil
end
end
end
end
end
end