From 96cf534d0a2c7ba8f4e0e6175c389533eda76f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 21 Dec 2022 18:10:50 +0700 Subject: [PATCH] Refactor settings routes and menu Use sub controllers/routes for the sections --- app/controllers/settings/profile_controller.rb | 6 ++++++ app/controllers/settings/security_controller.rb | 13 +++++++++++++ app/controllers/settings_controller.rb | 10 +++++----- app/views/settings/index.html.erb | 1 - app/views/settings/profile/index.html.erb | 9 +++++++++ app/views/{ => settings}/security/index.html.erb | 0 app/views/shared/_main_nav.html.erb | 4 ++-- app/views/shared/_sidenav_settings.html.erb | 7 ++++--- config/routes.rb | 9 +++++---- 9 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 app/controllers/settings/profile_controller.rb create mode 100644 app/controllers/settings/security_controller.rb delete mode 100644 app/views/settings/index.html.erb create mode 100644 app/views/settings/profile/index.html.erb rename app/views/{ => settings}/security/index.html.erb (100%) diff --git a/app/controllers/settings/profile_controller.rb b/app/controllers/settings/profile_controller.rb new file mode 100644 index 0000000..23bdee5 --- /dev/null +++ b/app/controllers/settings/profile_controller.rb @@ -0,0 +1,6 @@ +class Settings::ProfileController < SettingsController + + def index + end + +end diff --git a/app/controllers/settings/security_controller.rb b/app/controllers/settings/security_controller.rb new file mode 100644 index 0000000..2ae0bb7 --- /dev/null +++ b/app/controllers/settings/security_controller.rb @@ -0,0 +1,13 @@ +class Settings::SecurityController < SettingsController + + def index + end + + def reset_password + current_user.send_reset_password_instructions + sign_out current_user + msg = "We have sent you an email with a link to reset your password." + redirect_to check_your_email_path, notice: msg + end + +end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index ba639d2..d2fc3e5 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -1,13 +1,13 @@ class SettingsController < ApplicationController before_action :require_user_signed_in + before_action :set_current_section def index end - def reset_password - current_user.send_reset_password_instructions - sign_out current_user - msg = "We have sent you an email with a link to reset your password." - redirect_to check_your_email_path, notice: msg + private + + def set_current_section + @current_section = :settings end end diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb deleted file mode 100644 index c8c990b..0000000 --- a/app/views/settings/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -

Settings

diff --git a/app/views/settings/profile/index.html.erb b/app/views/settings/profile/index.html.erb new file mode 100644 index 0000000..b6cc307 --- /dev/null +++ b/app/views/settings/profile/index.html.erb @@ -0,0 +1,9 @@ +<%= render HeaderComponent.new(title: "Settings") %> + +<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/sidenav_settings') do %> +
+

Profile

+

+

+
+<% end %> diff --git a/app/views/security/index.html.erb b/app/views/settings/security/index.html.erb similarity index 100% rename from app/views/security/index.html.erb rename to app/views/settings/security/index.html.erb diff --git a/app/views/shared/_main_nav.html.erb b/app/views/shared/_main_nav.html.erb index 90e4428..de5b8eb 100644 --- a/app/views/shared/_main_nav.html.erb +++ b/app/views/shared/_main_nav.html.erb @@ -6,5 +6,5 @@ class: main_nav_class(@current_section, :invitations) %> <%= link_to "Wallet", wallet_path, class: main_nav_class(@current_section, :wallet) %> -<%= link_to "Settings", security_path, - class: main_nav_class(@current_section, :security) %> +<%= link_to "Settings", settings_profile_path, + class: main_nav_class(@current_section, :settings) %> diff --git a/app/views/shared/_sidenav_settings.html.erb b/app/views/shared/_sidenav_settings.html.erb index c57c90b..ff32ae8 100644 --- a/app/views/shared/_sidenav_settings.html.erb +++ b/app/views/shared/_sidenav_settings.html.erb @@ -1,9 +1,10 @@ <%= render SidenavLinkComponent.new( - name: "Account", path: "#", icon: "user", disabled: true + name: "Profile", path: settings_profile_path, icon: "user", + active: current_page?(settings_profile_path) ) %> <%= render SidenavLinkComponent.new( - name: "Password", path: security_path, icon: "key", - active: current_page?(security_path) + name: "Security", path: settings_security_path, icon: "key", + active: current_page?(settings_security_path) ) %> <%= render SidenavLinkComponent.new( name: "Security", path: "#", icon: "shield", disabled: true diff --git a/config/routes.rb b/config/routes.rb index 5791972..222408b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,10 +10,11 @@ Rails.application.routes.draw do match 'signup/:step', to: 'signup#steps', as: :signup_steps, via: [:get, :post] post 'signup_validate', to: 'signup#validate' - get 'settings', to: 'settings#index' - post 'settings_reset_password', to: 'settings#reset_password' - - get 'security', to: 'security#index' + namespace :settings do + get 'profile', to: 'profile#index' + get 'security', to: 'security#index' + post 'reset_password', to: 'security#reset_password' + end namespace :contributions do root to: 'donations#index'