Skip to content

Commit 1fb4732

Browse files
committed
Refactored the settings page into multiple pages
The previous page was becoming too long, now we have a sidebar with separate sections so it is easier to understand.
1 parent 5b23b06 commit 1fb4732

37 files changed

Lines changed: 608 additions & 470 deletions

app/assets/stylesheets/components/settings.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,52 @@
131131
.settings-google-svg {
132132
display: block;
133133
}
134+
135+
/* Settings sidebar navigation */
136+
.settings-nav {
137+
display: flex;
138+
flex-direction: column;
139+
gap: var(--spacing-2);
140+
padding: var(--spacing-4) 0;
141+
}
142+
143+
.settings-nav-link {
144+
display: flex;
145+
align-items: center;
146+
gap: var(--spacing-3);
147+
padding: var(--spacing-3) var(--spacing-4);
148+
border-radius: var(--border-radius-md);
149+
text-decoration: none;
150+
color: var(--color-text-primary);
151+
transition: background-color var(--transition-fast);
152+
font-weight: var(--font-weight-medium);
153+
}
154+
155+
.settings-nav-link:hover {
156+
background-color: var(--color-bg-hover);
157+
}
158+
159+
.settings-nav-link.active {
160+
background-color: var(--color-primary-100);
161+
color: var(--color-primary-700);
162+
font-weight: var(--font-weight-semibold);
163+
}
164+
165+
.settings-nav-link.danger {
166+
color: var(--color-danger-text);
167+
}
168+
169+
.settings-nav-link.danger:hover {
170+
background-color: var(--color-danger-bg-hover);
171+
}
172+
173+
.settings-nav-link i {
174+
width: 20px;
175+
text-align: center;
176+
}
177+
178+
.settings-nav-divider {
179+
height: 1px;
180+
background-color: var(--color-border);
181+
margin: var(--spacing-2) 0;
182+
}

app/controllers/account_deletions_controller.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/controllers/emails_controller.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/controllers/omniauth_callbacks_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def google_oauth2
1919
if linking && current_user
2020
if identity
2121
if identity.user_id != current_user.id
22-
return redirect_to settings_path, alert: 'That Google account is already linked to another user.'
22+
return redirect_to settings_account_path, alert: 'That Google account is already linked to another user.'
2323
end
24-
return redirect_to settings_path, notice: 'That Google account is already linked to your account.'
24+
return redirect_to settings_account_path, notice: 'That Google account is already linked to your account.'
2525
else
2626
if Alias.by_email(email).where.not(user_id: [nil, current_user.id]).exists?
27-
return redirect_to settings_path, alert: 'Email is linked to another account. Delete that account first to release it.'
27+
return redirect_to settings_account_path, alert: 'Email is linked to another account. Delete that account first to release it.'
2828
end
2929

3030
aliases = Alias.by_email(email).where(user_id: [nil, current_user.id])
@@ -53,7 +53,7 @@ def google_oauth2
5353
end
5454

5555
identity.update!(last_used_at: Time.current, email: email, raw_info: auth.to_json)
56-
return redirect_to settings_path, notice: 'Google account linked.'
56+
return redirect_to settings_account_path, notice: 'Google account linked.'
5757
end
5858

5959
if identity

app/controllers/passwords_controller.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
class PasswordsController < ApplicationController
2-
before_action :require_authentication, only: [:update_current]
3-
42
def new
53
end
64

@@ -32,19 +30,4 @@ def update
3230
render :edit, status: :unprocessable_entity
3331
end
3432
end
35-
36-
def update_current
37-
user = current_user
38-
if user.password_digest.present?
39-
unless user.authenticate(params[:current_password])
40-
return redirect_to settings_path, alert: "Current password is incorrect"
41-
end
42-
end
43-
44-
if user.update(password: params[:password], password_confirmation: params[:password_confirmation])
45-
redirect_to settings_path, notice: "Password updated."
46-
else
47-
redirect_to settings_path, alert: user.errors.full_messages.to_sentence
48-
end
49-
end
5033
end

app/controllers/read_status_imports_controller.rb

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module Settings
4+
class AccountsController < Settings::BaseController
5+
def show
6+
@aliases = current_user.person&.aliases&.order(:email) || []
7+
@identities = current_user.identities.order(:provider, :email, :uid)
8+
@default_alias_id = current_user.person&.default_alias_id
9+
end
10+
11+
private
12+
13+
def active_settings_section
14+
:account
15+
end
16+
end
17+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Settings
4+
class BaseController < ApplicationController
5+
before_action :require_authentication
6+
layout 'settings'
7+
8+
helper_method :active_settings_section
9+
10+
private
11+
12+
def active_settings_section
13+
:account
14+
end
15+
end
16+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Settings
4+
class DeletionsController < Settings::BaseController
5+
def show
6+
end
7+
8+
def create
9+
unless params[:confirmation].to_s.strip == "DELETE"
10+
return redirect_to settings_deletion_path, alert: "Please type DELETE to confirm."
11+
end
12+
13+
perform_deletion!(current_user)
14+
reset_session
15+
redirect_to root_path, notice: 'Your account has been deleted.'
16+
end
17+
18+
private
19+
20+
def active_settings_section
21+
:deletion
22+
end
23+
24+
def perform_deletion!(user)
25+
Identity.where(user_id: user.id).delete_all
26+
UserToken.where(user_id: user.id).delete_all
27+
user.aliases.update_all(user_id: nil, verified_at: nil)
28+
user.update!(password_digest: nil, deleted_at: Time.current)
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)