2024-02-23 14:05:12 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SwitchDomainBannerComponent < ApplicationComponent
|
|
|
|
attr_reader :user
|
|
|
|
|
|
|
|
def initialize(user:)
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
|
|
|
return false unless helpers.switch_domain_enabled?(request)
|
2024-03-18 19:31:57 +01:00
|
|
|
return false if user&.preferred_domain_demarches_gouv_fr? && requested_from_new_domain?
|
2024-02-23 14:05:12 +01:00
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_switch?
|
|
|
|
helpers.auto_switch_domain?(request, user.present?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def manual_switch?
|
|
|
|
helpers.app_host_legacy?(request) && user.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_host_url
|
|
|
|
helpers.url_for(url_options)
|
|
|
|
end
|
|
|
|
|
2024-03-18 19:31:57 +01:00
|
|
|
def requested_from_new_domain?
|
|
|
|
Current.host == ApplicationHelper::APP_HOST
|
2024-02-23 14:05:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def url_options
|
|
|
|
request.params.except(:switch_domain).merge(host: ApplicationHelper::APP_HOST)
|
|
|
|
end
|
|
|
|
end
|