diff --git a/app/controllers/registrar/account_controller.rb b/app/controllers/registrar/account_controller.rb index 2c942aed7..1bcf9e468 100644 --- a/app/controllers/registrar/account_controller.rb +++ b/app/controllers/registrar/account_controller.rb @@ -2,16 +2,23 @@ class Registrar class AccountController < BaseController skip_authorization_check - helper_method :linked_users + def show; end - def show - @user = current_registrar_user + def edit + @registrar = current_registrar_user.registrar + end + + def update + @registrar = current_registrar_user.registrar + @registrar.update!(registrar_params) + + redirect_to registrar_account_path, notice: t('.saved') end private - def linked_users - current_registrar_user.linked_users + def registrar_params + params.require(:registrar).permit(:billing_email) end end -end +end \ No newline at end of file diff --git a/app/views/registrar/account/_details.html.erb b/app/views/registrar/account/_details.html.erb new file mode 100644 index 000000000..9e35da899 --- /dev/null +++ b/app/views/registrar/account/_details.html.erb @@ -0,0 +1,16 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
<%= Registrar.human_attribute_name :billing_email %>
+
<%= registrar.billing_email %>
+
+
+ + +
diff --git a/app/views/registrar/account/_form.html.erb b/app/views/registrar/account/_form.html.erb new file mode 100644 index 000000000..c2bb6aa82 --- /dev/null +++ b/app/views/registrar/account/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for @registrar, url: registrar_account_path, method: :patch, html: { class: 'form-horizontal' } do |f| %> + <%= render 'form_errors', target: @registrar %> + +
+
+ <%= f.label :billing_email %> +
+ +
+ <%= f.email_field :billing_email, autofocus: true, class: 'form-control' %> +
+
+ +
+ +
+
+ <%= f.submit t('.submit_btn'), class: 'btn btn-success' %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/registrar/account/edit.html.erb b/app/views/registrar/account/edit.html.erb new file mode 100644 index 000000000..20aa88d2d --- /dev/null +++ b/app/views/registrar/account/edit.html.erb @@ -0,0 +1,10 @@ + + + + +<%= render 'form' %> \ No newline at end of file diff --git a/app/views/registrar/account/show.html.erb b/app/views/registrar/account/show.html.erb index d6a90d64c..53218d1f7 100644 --- a/app/views/registrar/account/show.html.erb +++ b/app/views/registrar/account/show.html.erb @@ -3,7 +3,13 @@
-
- <%= render 'linked_users', linked_users: linked_users %> +
+ <%= render 'details', registrar: current_registrar_user.registrar %>
+ +
+
+ <%= render 'linked_users', linked_users: current_registrar_user.linked_users %> +
+
\ No newline at end of file diff --git a/config/locales/registrar/account.en.yml b/config/locales/registrar/account.en.yml index 42e0de6de..94d4783d5 100644 --- a/config/locales/registrar/account.en.yml +++ b/config/locales/registrar/account.en.yml @@ -4,6 +4,19 @@ en: show: header: Your account + edit: + header: Edit your account + + form: + submit_btn: Save changes + + update: + saved: Your account has been updated + + details: + header: Details + edit_btn: Edit + linked_users: header: Linked users switch_btn: Switch diff --git a/config/routes.rb b/config/routes.rb index 23ac67a50..216946a08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,7 @@ Rails.application.routes.draw do resources :account_activities put 'current_user/switch/:new_user_id', to: 'current_user#switch', as: :switch_current_user - resource :account, controller: :account, only: :show + resource :account, controller: :account, only: %i[show edit update] resources :domains do collection do diff --git a/test/system/registrar_area/account_test.rb b/test/system/registrar_area/account_test.rb new file mode 100644 index 000000000..438de2629 --- /dev/null +++ b/test/system/registrar_area/account_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class RegistrarAccountTest < ApplicationSystemTestCase + setup do + @registrar = registrars(:bestnames) + sign_in users(:api_bestnames) + end + + def test_updates_account + new_billing_email = 'new@registrar.test' + assert_not_equal new_billing_email, @registrar.billing_email + + visit registrar_account_path + click_on 'Edit' + + fill_in 'Billing email', with: new_billing_email + click_on 'Save changes' + + assert_text 'Your account has been updated' + assert_text new_billing_email + end +end \ No newline at end of file