Skip to content

Commit 1c14077

Browse files
authored
Fix flash invitation related flash messages (#970)
1 parent 75554e4 commit 1c14077

File tree

7 files changed

+52
-34
lines changed

7 files changed

+52
-34
lines changed

app/controllers/grant_reviewers/invitations/reminders_controller.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ def index
66
.with_inviter
77
.where(grant_id: @grant.id)
88
.open
9-
if @open_invitations.any?
10-
send_reminder_emails
11-
flash[:notice] = 'Reminder emails have been sent to those who have not yet responded.'
12-
else
13-
flash[:warning] = 'There are no open reviewer invitations for this grant. No reminders have been sent'
9+
respond_to do |format|
10+
if @open_invitations.any?
11+
send_reminder_emails
12+
format.html { redirect_to grant_invitations_url(@grant), notice: 'Reminder emails have been sent to those who have not yet responded.' }
13+
else
14+
format.html { redirect_to grant_invitations_url(@grant), alert: 'There are no open reviewer invitations for this grant. No reminders have been sent' }
15+
end
1416
end
15-
redirect_back fallback_location: grant_invitations_path(@grant)
1617
end
1718

1819
def show
1920
invitation = GrantReviewer::Invitation.find(params[:id])
2021

21-
if invitation.present? && invitation.invitee.nil?
22-
send_reminder_email(invitation)
23-
flash[:success] = "A reminder has been sent to #{invitation.email}."
24-
else
25-
flash[:warning] = 'A reminder could not be sent to the selected email address.'
22+
respond_to do |format|
23+
if invitation.present? && invitation.invitee.nil?
24+
send_reminder_email(invitation)
25+
format.html { redirect_to grant_invitations_url(@grant), notice: "A reminder has been sent to #{invitation.email}." }
26+
else
27+
format.html { redirect_to grant_invitations_url(@grant), alert: 'A reminder could not be sent to the selected email address.' }
28+
end
2629
end
27-
28-
redirect_back fallback_location: grant_invitations_path(@grant)
2930
end
3031

3132
private

app/controllers/grant_reviewers/invitations_controller.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@ def update;end
1313

1414
def create
1515
invitation = GrantReviewer::Invitation.new(grant: @grant, inviter: current_user, email: params[:email])
16-
if invitation.save
17-
GrantReviewerInvitationMailer.invite(invitation: invitation, grant: @grant, inviter: current_user).deliver_now
18-
flash[:alert] = "Invitation to #{invitation.email} has been sent. #{helpers.link_to 'View all invitations', grant_invitations_path(@grant)}"
19-
else
20-
flash[:warning] = invitation.errors.full_messages
16+
17+
respond_to do |format|
18+
if invitation.save
19+
GrantReviewerInvitationMailer.invite(invitation: invitation, grant: @grant, inviter: current_user).deliver_now
20+
format.html { redirect_to grant_reviewers_url(@grant), notice: "Invitation to #{invitation.email} has been sent. #{helpers.link_to 'View all invitations', grant_invitations_path(@grant)}" }
21+
else
22+
format.html { redirect_to grant_reviewers_url(@grant), warning: invitation.errors.full_messages }
23+
end
2124
end
22-
redirect_back fallback_location: grant_reviewers_path(@grant)
2325
end
2426

2527
def destroy
2628
invitation = GrantReviewer::Invitation.find(params[:id])
2729

28-
if invitation.invitee.nil? && invitation.destroy
29-
flash[:success] = "The invitation to #{invitation.email} has been deleted."
30-
else
31-
flash[:warning] = "Could not delete the invitation to #{invitation.email}."
30+
respond_to do |format|
31+
if invitation.invitee.nil? && invitation.destroy
32+
format.html { redirect_to grant_reviewers_url(@grant), notice: "The invitation to #{invitation.email} has been deleted." }
33+
else
34+
format.html { redirect_to grant_reviewers_url(@grant), warning: "Could not delete the invitation to #{invitation.email}." }
35+
end
3236
end
33-
34-
redirect_back fallback_location: grant_reviewers_path(@grant)
3537
end
3638

3739
private

app/controllers/grant_reviewers_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ def index
1515
def create
1616
authorize @grant, :edit?
1717

18-
email = grant_reviewer_params[:reviewer_email].downcase.strip
18+
email = grant_reviewer_params[:reviewer_email].downcase.strip
1919
reviewer = User.find_by(email: email)
2020

21-
if reviewer.nil?
21+
# TODO: catch this any other way
22+
if email.blank?
23+
flash[:alert] = 'Please enter a valid email address.'
24+
elsif reviewer.nil?
2225
flash[:alert] = "Could not find a user with the email: #{email}. #{helpers.link_to 'Invite them to be a reviewer', invite_grant_reviewers_path(@grant, email: email), method: :post, data: { confirm: "An email will be sent to #{email}. You will be notified when they accept or opt out."} }"
2326
else
2427
grant_reviewer = GrantReviewer.create(grant: @grant, reviewer: reviewer)
28+
2529
if grant_reviewer.errors.none?
2630
flash[:success] = "Added #{helpers.full_name(grant_reviewer.reviewer)} as reviewer."
2731
else
2832
flash[:alert] = grant_reviewer.errors.full_messages
2933
end
30-
3134
end
3235

3336
redirect_to grant_reviewers_path(@grant)

app/views/grant_reviewers/index.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
%div{ style: 'display: inline-block' }
2828
= form_for :grant_reviewer, url: grant_reviewers_path(@grant) do |f|
2929
.input-group
30-
= f.email_field :reviewer_email, placeholder: 'Email', class: 'input-group-field'
30+
= f.email_field :reviewer_email, placeholder: 'Email', class: 'input-group-field', required: true
3131
.input-group-button
3232
= f.submit 'Look Up', class: 'button small'
3333
%li
@@ -140,4 +140,4 @@
140140
window.attachEvent("onload", downloadJSAtOnload);
141141
} else {
142142
window.onload = downloadJSAtOnload;
143-
}
143+
}

app/views/grant_reviewers/invitations/_invitation.html.haml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
- if invitation.confirmed_at.nil?
1212
%ul.dropdown.menu{ data: { "dropdown-menu": '' } }
1313
%li.text
14-
= link_to 'Manage', '#', id: "manage-#{dom_id(invitation)}"
14+
= link_to 'Manage', '', id: "manage-#{dom_id(invitation)}"
1515
%ul.menu
1616
%li
17-
= link_to 'Send Reminder', grant_invitation_reminder_url(grant.id, invitation)
18-
= link_to 'Delete', grant_invitation_path(grant.id, invitation), method: :delete, data: { confirm: 'This inviation will be deleted and the recipient will need to be invited again.' }
17+
= link_to 'Send Reminder', grant_invitation_reminder_url(grant.id, invitation), data: {turbo: false}
18+
= link_to 'Delete', grant_invitation_path(grant.id, invitation), method: :delete, data: { turbo: false, confirm: 'This inviation will be deleted and the recipient will need to be invited again.' }
1919

app/views/grant_reviewers/invitations/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Actions:
3232
- if @has_open_invitations
3333
%li
34-
= link_to 'Send Reminder to All Invited Reviewers', grant_invitation_reminders_path(@grant)
34+
= link_to 'Send Reminder to All Invited Reviewers', grant_invitation_reminders_path(@grant), data: {turbo: false}
3535
%li
3636
= link_to 'Back to Reviewers', grant_reviewers_path(@grant)
3737

spec/system/grant_reviewers/grant_reviewer_invitations_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@
8787

8888
expect(page).to have_content "#{registered_reviewer_invitation.email} has been deleted"
8989
end
90+
91+
it 'displays a reminder email confirmation message' do
92+
invite_dom_id = "manage-#{dom_id(saml_reviewer_invitation)}"
93+
page.find("##{invite_dom_id}").hover
94+
expect(page).to have_link('Send Reminder')
95+
end
96+
97+
it 'displays a delete invitation confirmation message' do
98+
invite_dom_id = "manage-#{dom_id(saml_reviewer_invitation)}"
99+
page.find("##{invite_dom_id}").hover
100+
expect(page).to have_link('Delete')
101+
end
90102
end
91103

92104
context 'confirmed invites' do

0 commit comments

Comments
 (0)