diff --git a/app/controllers/account_logo_controller.rb b/app/controllers/account_logo_controller.rb new file mode 100644 index 00000000..c58ad971 --- /dev/null +++ b/app/controllers/account_logo_controller.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class AccountLogoController < ApplicationController + before_action :authorize_account_config + + def create + file = params[:file] + + if file.blank? + return redirect_to settings_personalization_path, alert: I18n.t('unable_to_save') + end + + current_account.logo.attach(file) + + redirect_to settings_personalization_path, notice: I18n.t('settings_have_been_saved') + end + + def destroy + current_account.logo.purge + + redirect_to settings_personalization_path, notice: I18n.t('settings_have_been_saved') + end + + private + + def authorize_account_config + authorize!(:create, AccountConfig) + end +end diff --git a/app/models/account.rb b/app/models/account.rb index d3d53d0c..6ca102ef 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -20,6 +20,8 @@ class Account < ApplicationRecord attribute :uuid, :string, default: -> { SecureRandom.uuid } + has_one_attached :logo + has_many :users, dependent: :destroy has_many :encrypted_configs, dependent: :destroy has_many :account_configs, dependent: :destroy diff --git a/app/views/personalization_settings/_logo_form.html.erb b/app/views/personalization_settings/_logo_form.html.erb index fc6f3ac7..9a84b78b 100644 --- a/app/views/personalization_settings/_logo_form.html.erb +++ b/app/views/personalization_settings/_logo_form.html.erb @@ -1 +1,34 @@ -<%= render 'logo_placeholder' %> +<% if current_account.logo.attached? %> +
+
+ + <%= button_to t('remove'), settings_account_logo_path, method: :delete, class: 'btn btn-sm btn-error btn-outline', data: { turbo_confirm: t('are_you_sure_') } %> +
+
+<% end %> +<%= form_with url: settings_account_logo_path, method: :post, html: { autocomplete: 'off', enctype: 'multipart/form-data' } do |f| %> + + + +
+ <%= f.submit button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> +
+<% end %> diff --git a/app/views/personalization_settings/_logo_placeholder.html.erb b/app/views/personalization_settings/_logo_placeholder.html.erb index 9a8358e3..e69de29b 100644 --- a/app/views/personalization_settings/_logo_placeholder.html.erb +++ b/app/views/personalization_settings/_logo_placeholder.html.erb @@ -1,15 +0,0 @@ -
- <%= svg_icon('info_circle', class: 'w-6 h-6') %> -
-

- <%= t('unlock_with_docuseal_pro') %> -

-

- <%= t('display_your_company_name_and_logo_when_signing_documents') %> -
- " data-turbo="false"> - <%= t('learn_more') %> - -

-
-
diff --git a/app/views/start_form/_docuseal_logo.html.erb b/app/views/start_form/_docuseal_logo.html.erb index 735c607c..9ca297c5 100644 --- a/app/views/start_form/_docuseal_logo.html.erb +++ b/app/views/start_form/_docuseal_logo.html.erb @@ -1,6 +1,10 @@ - - <%= render 'shared/logo', width: '50px', height: '50px' %> - -

DocuSeal

+ <% if @template&.account&.logo&.attached? %> + + <% else %> + + <%= render 'shared/logo', width: '50px', height: '50px' %> + +

DocuSeal

+ <% end %>
diff --git a/app/views/submissions/_logo.html.erb b/app/views/submissions/_logo.html.erb index f6b67f5c..d93caf19 100644 --- a/app/views/submissions/_logo.html.erb +++ b/app/views/submissions/_logo.html.erb @@ -1 +1,5 @@ -<%= render 'shared/logo', width: 40, height: 40 %> +<% if @submission&.account&.logo&.attached? %> + +<% else %> + <%= render 'shared/logo', width: 40, height: 40 %> +<% end %> diff --git a/app/views/submit_form/_docuseal_logo.html.erb b/app/views/submit_form/_docuseal_logo.html.erb index 645f7fc5..1c5e7549 100644 --- a/app/views/submit_form/_docuseal_logo.html.erb +++ b/app/views/submit_form/_docuseal_logo.html.erb @@ -1,4 +1,8 @@ - <%= render 'shared/logo', class: 'w-9 h-9 md:w-12 md:h-12' %> - <%= Docuseal.product_name %> + <% if @submitter&.account&.logo&.attached? %> + + <% else %> + <%= render 'shared/logo', class: 'w-9 h-9 md:w-12 md:h-12' %> + <%= Docuseal.product_name %> + <% end %>