From dd583206ee2d410d342c4e6ddab409b8bde71fe2 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Fri, 31 Oct 2025 13:41:44 +0100 Subject: [PATCH] Allow changes to the Account name --- app/controllers/account/settings_controller.rb | 11 +++++++++++ app/javascript/controllers/form_controller.js | 2 +- app/models/account.rb | 2 ++ app/views/account/settings/_name.html.erb | 9 +++++++++ app/views/account/settings/show.html.erb | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/views/account/settings/_name.html.erb diff --git a/app/controllers/account/settings_controller.rb b/app/controllers/account/settings_controller.rb index 6b08abba2..29a037ab5 100644 --- a/app/controllers/account/settings_controller.rb +++ b/app/controllers/account/settings_controller.rb @@ -1,6 +1,17 @@ class Account::SettingsController < ApplicationController + before_action def show @account = Account.sole @users = User.active.alphabetically end + + def update + Account.sole.update!(account_params) + redirect_to account_settings_path + end + + private + def account_params + params.expect account: %i[ name ] + end end diff --git a/app/javascript/controllers/form_controller.js b/app/javascript/controllers/form_controller.js index db1602feb..68d6b554b 100644 --- a/app/javascript/controllers/form_controller.js +++ b/app/javascript/controllers/form_controller.js @@ -20,7 +20,7 @@ export default class extends Controller { const input = this.hasInputTarget ? this.inputTarget : null if (input) { - const value = (input.value || "").trim() + const value = (input.value || "").trim() if (value.length === 0) { event.preventDefault() } diff --git a/app/models/account.rb b/app/models/account.rb index 38f67d0da..357d0cc29 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -5,6 +5,8 @@ class Account < ApplicationRecord after_create :create_join_code + validates :name, presence: true + class << self def create_with_admin_user(account:, owner:) create!(**account).tap do diff --git a/app/views/account/settings/_name.html.erb b/app/views/account/settings/_name.html.erb new file mode 100644 index 000000000..475b92924 --- /dev/null +++ b/app/views/account/settings/_name.html.erb @@ -0,0 +1,9 @@ +
+

Name

+ <%= form_with model: account, url: account_settings_path, method: :put, scope: :account, data: { controller: "form" }, class: "flex" do |form| %> + <%= form.text_field :name, required: true, class: "input input--transparent full-width", data: { action: "input->form#disableSubmitWhenInvalid" } %> + <%= form.button data: { form_target: "submit" }, disabled: form.object do %> + Save + <% end %> + <% end %> +
diff --git a/app/views/account/settings/show.html.erb b/app/views/account/settings/show.html.erb index eed15ec7e..d71ca55d9 100644 --- a/app/views/account/settings/show.html.erb +++ b/app/views/account/settings/show.html.erb @@ -7,4 +7,5 @@
<%= render "account/settings/users", users: @users %> <%= render "account/settings/entropy_configuration", account: @account %> + <%= render "account/settings/name", account: @account %>