Skip to content

Commit 368caab

Browse files
authored
Merge pull request #919 from amatsuda/notificatons_page
Extract notifications setting to its dedicated page
2 parents 5a785b6 + da740e3 commit 368caab

File tree

7 files changed

+74
-28
lines changed

7 files changed

+74
-28
lines changed

app/assets/stylesheets/modules/forms.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@ input[type="checkbox"].boolean {
9090
gap: 10px;
9191
align-items: center;
9292
}
93+
94+
.form-group span.radio {
95+
margin-right: 1rem;
96+
}

app/controllers/profiles_controller.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,27 @@ def update
2626
end
2727
end
2828

29+
def notifications
30+
end
31+
32+
def update_notifications
33+
if current_user.update(notifications_params)
34+
flash[:info] = 'Notification preferences updated.'
35+
redirect_to notifications_profile_path
36+
else
37+
render :notifications, status: :unprocessable_entity
38+
end
39+
end
40+
2941
private
3042

3143
def user_params
3244
params.require(:user).permit(:bio, :gender, :ethnicity, :country, :name,
33-
:email, :password, :password_confirmation,
34-
teammates_attributes: [:id, :notification_preference])
45+
:email, :password, :password_confirmation)
46+
end
47+
48+
def notifications_params
49+
params.require(:user).permit(teammates_attributes: [:id, :notification_preference])
3550
end
3651

3752
def incomplete_profile_msg

app/views/layouts/nav/_user_dropdown.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
= link_to edit_profile_path, class: 'dropdown-item' do
88
%i.bi.bi-person-fill
99
%span My Profile
10+
- if current_user.teammates.loaded? ? current_user.teammates.any? : current_user.teammates.exists?
11+
%li
12+
= link_to notifications_profile_path, class: 'dropdown-item' do
13+
%i.bi.bi-bell-fill
14+
%span Notifications
1015
%li
1116
= link_to destroy_user_session_path, data: {turbo: true, turbo_method: :delete}, class: 'dropdown-item' do
1217
%i.bi.bi-box-arrow-right

app/views/profiles/edit.html.haml

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@
2222
.form-group
2323
= f.label :name
2424
= f.text_field :name, class: 'form-control', placeholder: 'Your name', autofocus: true
25+
= f.input :bio, as: :text, input_html: {rows: 7, maxlength: 500, placeholder: 'Enter your bio'}, hint: 'Bio is limited to 500 characters.'
26+
27+
.widget
28+
.widget-header
29+
%i.bi.bi-image
30+
%h3 Profile Icon Image
31+
.widget-content
2532
%p
26-
= f.label :bio
27-
= f.text_area :bio, class: 'form-control', placeholder: 'Enter your bio', rows: 7, maxlength: 500
28-
%p.help-block Bio is limited to 500 characters.
33+
Add or change your profile icon image by visiting
34+
= link_to('Gravatar', 'https://en.gravatar.com/connect/', target: "_blank")
2935

3036
%fieldset.col-md-6
3137
.widget
@@ -61,31 +67,14 @@
6167
%i{class: "bi bi-#{provider}"}
6268
= "Connect #{name}"
6369

64-
%fieldset.col-md-6
65-
.widget
66-
.widget-header
67-
%i.bi.bi-lock
68-
%h3 Profile Icon Image
69-
.widget-content
70-
%p
71-
Add or change your profile icon image by visiting
72-
= link_to('Gravatar', 'https://en.gravatar.com/connect/', target: "_blank")
73-
74-
- if current_user.teammates.present?
70+
- if current_user.teammates.loaded? ? current_user.teammates.any? : current_user.teammates.exists?
7571
.widget
7672
.widget-header
7773
%i.bi.bi-envelope-fill
78-
%h3
79-
Notifications
80-
%span.ms-2{role: 'button', data: {bs_toggle: 'popover', bs_placement: 'left', bs_content: notification_preferences_tooltip, bs_html: 'true'}}
81-
%i.bi.bi-question-circle
74+
%h3 Notifications
8275
.widget-content
83-
= f.simple_fields_for :teammates do |fields|
84-
- teammate = fields.object
85-
%b= teammate.event.name
86-
= fields.input :notification_preference,
87-
collection: Teammate::NOTIFICATION_PREFERENCES.invert,
88-
as: :radio_buttons, wrapper: 'horizontal_radio_and_checkboxes', label: false
76+
%p
77+
= link_to 'Manage notification preferences', notifications_profile_path
8978

9079
.row
9180
.col-md-12.form-submit
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.row
2+
.col-md-12
3+
%header.page-header
4+
%h1 Notification Preferences
5+
6+
= simple_form_for current_user, url: notifications_profile_path, method: :patch, html: {role: 'form'} do |f|
7+
.row
8+
%fieldset.col-md-8
9+
.widget
10+
.widget-header
11+
%i.bi.bi-envelope-fill
12+
%h3
13+
Notifications
14+
%span.ms-2{role: 'button', data: {bs_toggle: 'popover', bs_placement: 'left', bs_content: notification_preferences_tooltip, bs_html: 'true'}}
15+
%i.bi.bi-question-circle
16+
.widget-content
17+
- if current_user.teammates.loaded? ? current_user.teammates.any? : current_user.teammates.exists?
18+
= f.simple_fields_for :teammates do |fields|
19+
- teammate = fields.object
20+
%b= teammate.event.name
21+
= fields.input :notification_preference,
22+
collection: Teammate::NOTIFICATION_PREFERENCES.invert,
23+
as: :radio_buttons, wrapper: 'horizontal_radio_and_checkboxes', label: false
24+
- else
25+
%p You are not a member of any event teams.
26+
27+
.row
28+
.col-md-12.form-submit
29+
= link_to 'Back to Profile', edit_profile_path, class: 'btn btn-secondary'
30+
%button.float-end.btn.btn-success.btn-lg{type: "submit"} Save

config/routes.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
44
mount ActionCable.server => '/cable'
55

6-
resource :profile, only: [:show, :edit, :update]
6+
resource :profile, only: [:show, :edit, :update] do
7+
get :notifications
8+
patch :notifications, action: :update_notifications
9+
end
710
get '/my-proposals' => 'proposals#index', as: :proposals
811

912
resources :notifications, only: [:index, :show] do

spec/system/profile_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
scenario 'A user updates their event email preference' do
3838
teammate = create(:teammate, role: 'organizer', user: user, state: Teammate::ACCEPTED)
3939
visit(event_path(teammate.event))
40-
visit(edit_profile_path)
40+
visit(notifications_profile_path)
4141
choose(Teammate::NOTIFICATION_PREFERENCES[Teammate::MENTIONS])
4242
click_button 'Save'
4343
click_link 'Dashboard'

0 commit comments

Comments
 (0)