chore: mark preferred domain to new domain when closing notice
This commit is contained in:
parent
a16f88f8af
commit
2f4444bd5e
9 changed files with 41 additions and 5 deletions
|
@ -2,11 +2,18 @@
|
|||
class Dsfr::NoticeComponent < ApplicationComponent
|
||||
renders_one :title
|
||||
|
||||
def initialize(closable: false)
|
||||
attr_reader :data_attributes
|
||||
|
||||
def initialize(closable: false, data_attributes: {})
|
||||
@closable = closable
|
||||
@data_attributes = data_attributes
|
||||
end
|
||||
|
||||
def closable?
|
||||
!!@closable
|
||||
end
|
||||
|
||||
def notice_data_attributes
|
||||
{ "data-dsfr-header-target": "notice" }.merge(data_attributes)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.fr-notice.fr-notice--info{ "data-dsfr-header-target": "notice" }
|
||||
.fr-notice.fr-notice--info{ **notice_data_attributes }
|
||||
.fr-container
|
||||
.fr-notice__body
|
||||
%p.fr-notice__title
|
||||
|
|
|
@ -9,8 +9,7 @@ class SwitchDomainBannerComponent < ApplicationComponent
|
|||
|
||||
def render?
|
||||
return false unless helpers.switch_domain_enabled?(request)
|
||||
|
||||
# TODO if preferred hosts
|
||||
return false if user&.preferred_domain_demarches_gouv_fr? && requested_from_new_domain?
|
||||
|
||||
true
|
||||
end
|
||||
|
@ -27,6 +26,8 @@ class SwitchDomainBannerComponent < ApplicationComponent
|
|||
helpers.url_for(url_options)
|
||||
end
|
||||
|
||||
def requested_from_new_domain?
|
||||
Current.host == ApplicationHelper::APP_HOST
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
// TODO: notify us in order to monitor connectivity issues volume
|
||||
})
|
||||
|
||||
= render Dsfr::NoticeComponent.new(closable: true) do |c|
|
||||
|
||||
= render Dsfr::NoticeComponent.new(closable: true, data_attributes: { "data-switch-domain-notice" => true }) do |c|
|
||||
- c.with_title do
|
||||
= t(".message_new_domain")
|
||||
= "#{helpers.link_to APPLICATION_NAME, new_host_url}."
|
||||
|
@ -17,3 +18,10 @@
|
|||
= t(".follow_link")
|
||||
- elsif auto_switch? || true
|
||||
= t(".detected_error")
|
||||
|
||||
- if user && !user.preferred_domain_demarches_gouv_fr? && requested_from_new_domain?
|
||||
= form_tag(helpers.preferred_domain_path, method: :patch, remote: true, name: "update-preferred-domain")
|
||||
:javascript
|
||||
document.addEventListener('noticeClosed', function(e) {
|
||||
document.forms['update-preferred-domain'].submit();
|
||||
});
|
||||
|
|
|
@ -63,6 +63,12 @@ module Users
|
|||
redirect_to profil_path
|
||||
end
|
||||
|
||||
def preferred_domain
|
||||
current_user.update_preferred_domain(request.host_with_port)
|
||||
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_transfers
|
||||
|
|
|
@ -9,5 +9,8 @@ export class DSFRHeaderController extends ApplicationController {
|
|||
this.noticeTarget.parentNode?.removeChild(this.noticeTarget);
|
||||
|
||||
this.element.classList.remove('fr-header__with-notice-info');
|
||||
|
||||
const event = new CustomEvent('noticeClosed', { bubbles: true });
|
||||
this.element.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,5 +5,14 @@ module DomainMigratableConcern
|
|||
enum preferred_domain: { demarches_gouv_fr: 0, demarches_simplifiees_fr: 1 }, _prefix: true
|
||||
|
||||
validates :preferred_domain, inclusion: { in: User.preferred_domains.keys, allow_nil: true }
|
||||
|
||||
def update_preferred_domain(host)
|
||||
case host
|
||||
when ApplicationHelper::APP_HOST
|
||||
preferred_domain_demarches_gouv_fr!
|
||||
when ApplicationHelper::APP_HOST_LEGACY
|
||||
preferred_domain_demarches_simplifiees_fr!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class User < ApplicationRecord
|
||||
include DomainMigratableConcern
|
||||
include EmailSanitizableConcern
|
||||
include PasswordComplexityConcern
|
||||
|
||||
|
|
|
@ -386,6 +386,7 @@ Rails.application.routes.draw do
|
|||
post 'accept_merge' => 'profil#accept_merge'
|
||||
post 'refuse_merge' => 'profil#refuse_merge'
|
||||
delete 'france_connect_information' => 'profil#destroy_fci'
|
||||
patch 'preferred_domain', to: 'profil#preferred_domain'
|
||||
get 'fermeture/:path', to: 'commencer#closing_details', as: :closing_details
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue