Class: Postnhost::Onboarding::Steps::ChooseLanguages

Inherits:
Base show all
Defined in:
app/services/postnhost/onboarding/steps/choose_languages.rb

Constant Summary

Constants inherited from Base

Base::LANGUAGE_OPTIONS, Base::SITE_COPY_KEYS

Instance Attribute Summary

Attributes inherited from Base

#params, #session

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from BaseService

call

Constructor Details

This class inherits a constructor from Postnhost::Onboarding::Steps::Base

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/postnhost/onboarding/steps/choose_languages.rb', line 5

def call
  return  unless pending_user

  options_by_locale = LANGUAGE_OPTIONS.index_by { |option| option[:html_lang] }
  locales = selected_locales
  default_locale = selected_default_locale
  payload = language_selection_payload(locales:, default_locale:)

  return render_show(**payload, alert: "Select at least one language.") if locales.empty?
  return render_show(**payload, alert: "Choose valid languages.") if locales.any? { |locale| !options_by_locale.key?(locale) }

  return render_show(**payload, alert: "Default language must be one of the selected languages.") unless locales.include?(default_locale)

  replace_languages!(locales:, default_locale:, options_by_locale:)
  advance_session(locales:, default_locale:)
  redirect_onboarding
end