diff --git a/app/assets/javascripts/initializers/initializePodcastPlayback.js b/app/assets/javascripts/initializers/initializePodcastPlayback.js index 41b3e3eea..0e71aa256 100644 --- a/app/assets/javascripts/initializers/initializePodcastPlayback.js +++ b/app/assets/javascripts/initializers/initializePodcastPlayback.js @@ -475,7 +475,9 @@ function initializePodcastPlayback() { function handlePodcastMessages(event) { const message = JSON.parse(event.detail); - if (message.namespace !== 'podcast') { return } + if (message.namespace !== 'podcast') { + return; + } var currentState = currentAudioState(); switch (message.action) { @@ -506,7 +508,7 @@ function initializePodcastPlayback() { if (deviceType !== 'web') { Runtime.podcastMessage = (msg) => { window.ForemMobile.injectNativeMessage('podcast', msg); - } + }; } } diff --git a/app/controllers/admin/creator_settings_controller.rb b/app/controllers/admin/creator_settings_controller.rb index 9631d1432..004089b90 100644 --- a/app/controllers/admin/creator_settings_controller.rb +++ b/app/controllers/admin/creator_settings_controller.rb @@ -4,6 +4,14 @@ module Admin invite_only_mode logo primary_brand_color_hex public].freeze def new + @creator_settings_form = CreatorSettingsForm.new( + community_name: ::Settings::Community.community_name, + public: ::Settings::UserExperience.public, + invite_only_mode: ::Settings::Authentication.invite_only_mode, + primary_brand_color_hex: ::Settings::UserExperience.primary_brand_color_hex, + checked_code_of_conduct: current_user.checked_code_of_conduct, + checked_terms_and_conditions: current_user.checked_terms_and_conditions, + ) @max_file_size = LogoUploader::MAX_FILE_SIZE @logo_allowed_types = (LogoUploader::CONTENT_TYPE_ALLOWLIST + LogoUploader::EXTENSION_ALLOWLIST.map { |extension| ".#{extension}" }).join(",") @@ -11,27 +19,21 @@ module Admin def create extra_authorization - ActiveRecord::Base.transaction do - ::Settings::Community.community_name = settings_params[:community_name] - ::Settings::UserExperience.primary_brand_color_hex = settings_params[:primary_brand_color_hex] - ::Settings::Authentication.invite_only_mode = settings_params[:invite_only] - ::Settings::UserExperience.public = settings_params[:public] - if settings_params[:logo] - logo_uploader = upload_logo(settings_params[:logo]) - ::Settings::General.original_logo = logo_uploader.url - ::Settings::General.resized_logo = logo_uploader.resized_logo.url - end - end + @creator_settings_form = CreatorSettingsForm.new(settings_params) current_user.update!( - saw_onboarding: true, - checked_code_of_conduct: settings_params[:checked_code_of_conduct], - checked_terms_and_conditions: settings_params[:checked_terms_and_conditions], + checked_code_of_conduct: @creator_settings_form.checked_code_of_conduct, + checked_terms_and_conditions: @creator_settings_form.checked_terms_and_conditions, ) - redirect_to root_path - rescue StandardError => e - flash.now[:error] = e.message - render new_admin_creator_setting_path + @creator_settings_form.save + + if @creator_settings_form.success + current_user.update!(saw_onboarding: true) + redirect_to root_path + else + flash[:error] = @creator_settings_form.errors.full_messages + redirect_to new_admin_creator_setting_path + end end private @@ -41,13 +43,7 @@ module Admin end def settings_params - params.permit(ALLOWED_PARAMS) - end - - def upload_logo(image) - LogoUploader.new.tap do |uploader| - uploader.store!(image) - end + params.require(:creator_settings_form).permit(ALLOWED_PARAMS) end end end diff --git a/app/forms/creator_settings_form.rb b/app/forms/creator_settings_form.rb new file mode 100644 index 000000000..43cc173f2 --- /dev/null +++ b/app/forms/creator_settings_form.rb @@ -0,0 +1,53 @@ +class CreatorSettingsForm + include ActiveModel::Model + include ActiveModel::Attributes + + attribute :checked_code_of_conduct, :boolean, default: false + attribute :checked_terms_and_conditions, :boolean, default: false + attribute :community_name, :string + attribute :invite_only_mode, :boolean + attribute :logo + attribute :primary_brand_color_hex, :string + attribute :public, :boolean + + validates :community_name, + :primary_brand_color_hex, presence: true + + validates :checked_code_of_conduct, inclusion: { in: [true, false] } + validates :checked_terms_and_conditions, inclusion: { in: [true, false] } + validates :invite_only_mode, inclusion: { in: [true, false] } + validates :public, inclusion: { in: [true, false] } + + attr_accessor :success + + def save + if valid? + begin + ::Settings::Community.community_name = community_name + ::Settings::UserExperience.primary_brand_color_hex = primary_brand_color_hex + ::Settings::Authentication.invite_only_mode = invite_only_mode + ::Settings::UserExperience.public = public + + if logo + logo_uploader = upload_logo(logo) + ::Settings::General.original_logo = logo_uploader.url + ::Settings::General.resized_logo = logo_uploader.resized_logo.url + end + @success = true + rescue StandardError => e + errors.add(:base, e.message) + @success = false + end + else + @success = false + end + end + + private + + def upload_logo(image) + LogoUploader.new.tap do |uploader| + uploader.store!(image) + end + end +end diff --git a/app/javascript/onboarding/components/Navigation.jsx b/app/javascript/onboarding/components/Navigation.jsx index d68a9d7ec..ec3c6f7e4 100644 --- a/app/javascript/onboarding/components/Navigation.jsx +++ b/app/javascript/onboarding/components/Navigation.jsx @@ -52,15 +52,8 @@ export class Navigation extends Component { } render() { - const { - next, - prev, - hideNext, - hidePrev, - disabled, - canSkip, - className, - } = this.props; + const { next, prev, hideNext, hidePrev, disabled, canSkip, className } = + this.props; return (