Skip to content

Commit d00dc28

Browse files
authored
[improvement] Separate info from error flash notices (#149)
1 parent 8ac979f commit d00dc28

File tree

12 files changed

+64
-38
lines changed

12 files changed

+64
-38
lines changed

app/assets/stylesheets/general/_flashes.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
animation: flashesFadeIn 400ms 100ms ease-out forwards
1010
animation-delay: 0.4s
1111

12+
.flashes--error
13+
background: $flashes--error--background
14+
color: $flashes--error--text
15+
1216
.flashes__icon
1317
margin-right: 0.4em
1418

app/assets/stylesheets/general/_variables.sass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ $alert--text--error: $white_pure !default
121121
$flashes--background: hsl(51, 87%, 94%) !default
122122
$flashes--text: hsl(40, 68%, 20%) !default
123123

124+
$flashes--error--background: hsl(11, 87%, 94%) !default
125+
$flashes--error--text: hsl(0, 68%, 20%) !default
126+
124127
/*
125128
* Account header
126129
*/

app/controllers/manage/messages_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def destroy
4444

4545
def deliver
4646
if @message.automated?
47-
flash[:notice] = "Automated messages cannot be manually delivered. Only bulk messages can."
47+
flash[:error] = "Automated messages cannot be manually delivered. Only bulk messages can."
4848
return redirect_to manage_message_path(@message)
4949
end
5050
if @message.status != "drafted"
51-
flash[:notice] = "Message cannot be re-delivered"
51+
flash[:error] = "Message cannot be re-delivered"
5252
return redirect_to manage_messages_path
5353
end
5454
@message.update_attribute(:queued_at, Time.now)
@@ -96,7 +96,7 @@ def set_message
9696
def check_message_access
9797
return if @message.can_edit?
9898

99-
flash[:notice] = "Message can no longer be modified"
99+
flash[:error] = "Message can no longer be modified"
100100
redirect_to manage_message_path(@message)
101101
end
102102
end

app/controllers/manage/questionnaires_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create
3838
if user.save
3939
@questionnaire.save
4040
else
41-
flash[:notice] = user.errors.full_messages.join(", ")
41+
flash[:error] = user.errors.full_messages.join(", ")
4242
if user.errors.include?(:email)
4343
@questionnaire.errors.add(:email, user.errors[:email].join(", "))
4444
end
@@ -70,7 +70,7 @@ def check_in
7070
@questionnaire.user.update_attributes(email: email)
7171
end
7272
unless @questionnaire.valid?
73-
flash[:notice] = @questionnaire.errors.full_messages.join(", ")
73+
flash[:error] = @questionnaire.errors.full_messages.join(", ")
7474
redirect_to show_redirect_path
7575
return
7676
end
@@ -82,7 +82,7 @@ def check_in
8282
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
8383
flash[:notice] = "#{@questionnaire.full_name} no longer checked in."
8484
else
85-
flash[:notice] = "No check-in action provided!"
85+
flash[:error] = "No check-in action provided!"
8686
redirect_to show_redirect_path
8787
return
8888
end
@@ -106,7 +106,7 @@ def destroy
106106
def update_acc_status
107107
new_status = params[:questionnaire][:acc_status]
108108
if new_status.blank?
109-
flash[:notice] = "No status provided"
109+
flash[:error] = "No status provided"
110110
redirect_to(manage_questionnaire_path(@questionnaire))
111111
return
112112
end
@@ -118,7 +118,7 @@ def update_acc_status
118118
if @questionnaire.save(validate: false)
119119
flash[:notice] = "Updated acceptance status to \"#{Questionnaire::POSSIBLE_ACC_STATUS[new_status]}\""
120120
else
121-
flash[:notice] = "Failed to update acceptance status"
121+
flash[:error] = "Failed to update acceptance status"
122122
end
123123

124124
redirect_to manage_questionnaire_path(@questionnaire)

app/controllers/manage/schools_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def merge
4545
def perform_merge
4646
new_school_name = params[:school][:id]
4747
if new_school_name.blank?
48-
flash[:notice] = "Error: Must include the new school to merge into!"
48+
flash[:error] = "Error: Must include the new school to merge into!"
4949
render :merge
5050
return
5151
end
5252

5353
new_school = School.where(name: new_school_name).first
5454
if new_school.blank?
55-
flash[:notice] = "Error: School doesn't exist: #{new_school_name}"
55+
flash[:error] = "Error: School doesn't exist: #{new_school_name}"
5656
render :merge
5757
return
5858
end
@@ -68,7 +68,7 @@ def perform_merge
6868
if @school.questionnaire_count < 1
6969
@school.destroy
7070
else
71-
flash[:notice] = "*** Old school NOT deleted: #{@school.questionnaire_count} questionnaires still associated!\n"
71+
flash[:error] = "*** Old school NOT deleted: #{@school.questionnaire_count} questionnaires still associated!\n"
7272
end
7373

7474
redirect_to manage_school_path(new_school)

app/controllers/rsvps_controller.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def accept
2121
flash[:notice] = "Thank you for confirming your attendance! You're all set to attend."
2222
flash[:notice] += " See below for additional bus information." if BusList.any?
2323
else
24-
flash[:notice] = rsvp_error_notice
24+
flash[:error] = rsvp_error_notice
2525
end
2626
redirect_to rsvp_path
2727
end
@@ -31,10 +31,11 @@ def deny
3131
@questionnaire.acc_status = "rsvp_denied"
3232
@questionnaire.acc_status_author_id = current_user.id
3333
@questionnaire.acc_status_date = Time.now
34-
unless @questionnaire.save
35-
flash[:notice] = rsvp_error_notice
34+
if @questionnaire.save
35+
flash[:notice] = "Your RSVP has been updated."
36+
else
37+
flash[:error] = rsvp_error_notice
3638
end
37-
flash[:notice] = "Your RSVP has been updated." if flash[:notice].blank?
3839
redirect_to rsvp_path
3940
end
4041

@@ -43,13 +44,13 @@ def deny
4344
# rubocop:disable PerceivedComplexity
4445
def update
4546
unless @questionnaire.update_attributes(params.require(:questionnaire).permit(:agreement_accepted, :phone))
46-
flash[:notice] = @questionnaire.errors.full_messages.join(", ")
47+
flash[:error] = @questionnaire.errors.full_messages.join(", ")
4748
redirect_to rsvp_path
4849
return
4950
end
5051

5152
unless ["rsvp_confirmed", "rsvp_denied"].include? params[:questionnaire][:acc_status]
52-
flash[:notice] = "Please select a RSVP status."
53+
flash[:error] = "Please select a RSVP status."
5354
redirect_to rsvp_path
5455
return
5556
end
@@ -63,23 +64,25 @@ def update
6364
is_joining_bus = new_bus_list.present? && @questionnaire.bus_list != new_bus_list
6465
if is_joining_bus && new_bus_list.full?
6566
if @questionnaire.bus_list_id?
66-
flash[:notice] = "Sorry, that bus is full. You are still signed up for the '#{@questionnaire.bus_list.name}' bus."
67+
flash[:error] = "Sorry, that bus is full. You are still signed up for the '#{@questionnaire.bus_list.name}' bus."
6768
else
68-
flash[:notice] = "Sorry, that bus is full. You may need to arrange other plans for transportation."
69+
flash[:error] = "Sorry, that bus is full. You may need to arrange other plans for transportation."
6970
end
7071
else
7172
@questionnaire.bus_list = new_bus_list
7273
@questionnaire.bus_captain_interest = params[:questionnaire][:bus_captain_interest]
7374
end
7475

7576
unless @questionnaire.save
76-
flash[:notice] = @questionnaire.errors.full_message.join(", ")
77+
flash[:error] = @questionnaire.errors.full_message.join(", ")
7778
redirect_to rsvp_path
7879
return
7980
end
8081

81-
flash[:notice] = "Your RSVP has been updated." if flash[:notice].blank?
82-
flash[:notice] += " See below for additional bus information!" if @questionnaire.bus_list_id?
82+
if flash[:notice].blank? && flash[:error].blank?
83+
flash[:notice] = "Your RSVP has been updated."
84+
flash[:notice] += " See below for additional bus information!" if @questionnaire.bus_list_id?
85+
end
8386

8487
redirect_to rsvp_path
8588
end
@@ -103,6 +106,7 @@ def check_user_has_questionnaire
103106

104107
def require_accepted_questionnaire
105108
return if @questionnaire.can_rsvp? || @questionnaire.checked_in?
109+
106110
redirect_to new_questionnaires_path
107111
end
108112
end

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def mlh
1111
end
1212

1313
def failure
14-
flash[:notice] = "External authentication failed - try again?"
14+
flash[:error] = "External authentication failed - try again?"
1515
redirect_to new_user_session_url
1616
end
1717
end

app/views/layouts/_flashes.html.haml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
- if flash[:error].present?
2+
.flashes.flashes--error
3+
.container
4+
.form-container
5+
%span.fa.fa-info-circle.flashes__icon
6+
= flash[:error].html_safe
7+
18
- if flash[:notice].present?
29
.flashes
310
.container

app/views/layouts/manage/_flashes.html.haml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
- flash[:error] = 'This is a special error flash'
2+
- flash[:notice] = 'This is a regular notice flash'
3+
4+
- if flash[:error].present?
5+
.alert.alert-danger.mt-3
6+
%span.fa.fa-exclamation-triangle.icon-space-r-half
7+
= flash[:error].html_safe
8+
19
- if flash[:notice].present?
210
.alert.alert-info.mt-3
311
%span.fa.fa-info-circle.icon-space-r-half

test/controllers/manage/messages_controller_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,22 +303,22 @@ class Manage::MessagesControllerTest < ActionController::TestCase
303303
assert_difference('BulkMessageWorker.jobs.size', 0) do
304304
patch :deliver, params: { id: @message }
305305
end
306-
assert_match /Automated/, flash[:notice]
306+
assert_match /cannot be manually delivered/, flash[:error]
307307
assert_redirected_to manage_message_path(assigns(:message))
308308
end
309309

310310
should "not allow multiple deliveries" do
311311
patch :deliver, params: { id: @message }
312312
assert_match /queued/, flash[:notice]
313313
patch :deliver, params: { id: @message }
314-
assert_match /cannot/, flash[:notice]
314+
assert_match /cannot/, flash[:error]
315315
end
316316

317317
should "not be able to modify message after delivery" do
318318
@message.update_attribute(:delivered_at, 1.minute.ago)
319319
old_message_name = @message.name
320320
patch :update, params: { id: @message, message: { name: "New Message Name" } }
321-
assert_match /can no longer/, flash[:notice]
321+
assert_match /can no longer/, flash[:error]
322322
assert_equal old_message_name, @message.reload.name
323323
end
324324

0 commit comments

Comments
 (0)