small design fixes for invites
This commit is contained in:
parent
66b7b7e27a
commit
2a553940d4
4 changed files with 19 additions and 25 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class InvitationsController < ApplicationController
|
class InvitationsController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
@ -14,35 +13,32 @@ class InvitationsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
render 'invitations/new', layout: false
|
render "invitations/new", layout: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
emails = inviter_params[:emails].split(',').map(&:strip).uniq
|
emails = inviter_params[:emails].split(",").map(&:strip).uniq
|
||||||
|
|
||||||
valid_emails, invalid_emails = emails.partition { |email| valid_email?(email) }
|
valid_emails, invalid_emails = emails.partition {|email| valid_email?(email) }
|
||||||
|
|
||||||
session[:valid_email_invites] = valid_emails
|
session[:valid_email_invites] = valid_emails
|
||||||
session[:invalid_email_invites] = invalid_emails
|
session[:invalid_email_invites] = invalid_emails
|
||||||
|
|
||||||
unless valid_emails.empty?
|
unless valid_emails.empty?
|
||||||
Workers::Mail::InviteEmail.perform_async(valid_emails.join(','),
|
Workers::Mail::InviteEmail.perform_async(valid_emails.join(","), current_user.id, inviter_params)
|
||||||
current_user.id,
|
|
||||||
inviter_params)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if emails.empty?
|
if emails.empty?
|
||||||
flash[:error] = t('invitations.create.empty')
|
flash[:error] = t("invitations.create.empty")
|
||||||
elsif invalid_emails.empty?
|
elsif invalid_emails.empty?
|
||||||
flash[:notice] = t('invitations.create.sent', :emails => valid_emails.join(', '))
|
flash[:notice] = t("invitations.create.sent", emails: valid_emails.join(", "))
|
||||||
elsif valid_emails.empty?
|
elsif valid_emails.empty?
|
||||||
flash[:error] = t('invitations.create.rejected') + invalid_emails.join(', ')
|
flash[:error] = t("invitations.create.rejected", emails: invalid_emails.join(", "))
|
||||||
else
|
else
|
||||||
flash[:error] = t('invitations.create.sent', :emails => valid_emails.join(', '))
|
flash[:error] = t("invitations.create.sent", emails: valid_emails.join(", ")) + ". " +
|
||||||
flash[:error] << '. '
|
t("invitations.create.rejected", emails: invalid_emails.join(", "))
|
||||||
flash[:error] << t('invitations.create.rejected') + invalid_emails.join(', ')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
@ -57,9 +53,9 @@ class InvitationsController < ApplicationController
|
||||||
def html_safe_string_from_session_array(key)
|
def html_safe_string_from_session_array(key)
|
||||||
return "" unless session[key].present?
|
return "" unless session[key].present?
|
||||||
return "" unless session[key].respond_to?(:join)
|
return "" unless session[key].respond_to?(:join)
|
||||||
value = session[key].join(', ').html_safe
|
value = session[key].join(", ").html_safe
|
||||||
session[key] = nil
|
session[key] = nil
|
||||||
return value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def inviter_params
|
def inviter_params
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
.col-sm-10
|
.col-sm-10
|
||||||
= text_field_tag 'email_inviter[emails]', @invalid_emails, title: t('.comma_separated_plz'),
|
= text_field_tag 'email_inviter[emails]', @invalid_emails, title: t('.comma_separated_plz'),
|
||||||
placeholder: 'foo@bar.com, max@foo.com...', class: "form-control"
|
placeholder: 'foo@bar.com, max@foo.com...', class: "form-control"
|
||||||
#already_sent
|
#already_sent
|
||||||
= t('invitations.create.note_already_sent', emails: @valid_emails) unless @valid_emails.empty?
|
= t("invitations.create.note_already_sent", emails: @valid_emails) unless @valid_emails.empty?
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
%label.col-sm-2.control-label{ for: 'email_inviter_locale' }
|
%label.col-sm-2.control-label{ for: 'email_inviter_locale' }
|
||||||
|
|
|
||||||
|
|
@ -556,7 +556,7 @@ en:
|
||||||
invitations:
|
invitations:
|
||||||
create:
|
create:
|
||||||
sent: "Invitations have been sent to: %{emails}"
|
sent: "Invitations have been sent to: %{emails}"
|
||||||
rejected: "The following email addresses had problems: "
|
rejected: "The following email addresses had problems: %{emails}"
|
||||||
no_more: "You have no more invitations."
|
no_more: "You have no more invitations."
|
||||||
empty: "Please enter at least one email address."
|
empty: "Please enter at least one email address."
|
||||||
note_already_sent: "Invitations have already been sent to: %{emails}"
|
note_already_sent: "Invitations have already been sent to: %{emails}"
|
||||||
|
|
|
||||||
|
|
@ -81,10 +81,10 @@ describe InvitationsController, :type => :controller do
|
||||||
expect(response).to redirect_to @referer
|
expect(response).to redirect_to @referer
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'flashes an error' do
|
it "flashes an error" do
|
||||||
post :create, @invite
|
post :create, @invite
|
||||||
|
|
||||||
expected = I18n.t('invitations.create.rejected') + @emails.split(',').join(', ')
|
expected = I18n.t("invitations.create.rejected", emails: @emails.split(",").join(", "))
|
||||||
expect(flash[:error]).to eq(expected)
|
expect(flash[:error]).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -108,12 +108,10 @@ describe InvitationsController, :type => :controller do
|
||||||
expect(response).to redirect_to @referer
|
expect(response).to redirect_to @referer
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'flashes a notice' do
|
it "flashes a notice" do
|
||||||
post :create, @invite
|
post :create, @invite
|
||||||
expected = I18n.t('invitations.create.sent', :emails =>
|
expected = I18n.t("invitations.create.sent", emails: @valid_emails.split(",").join(", ")) + ". " +
|
||||||
@valid_emails.split(',').join(', ')) +
|
I18n.t("invitations.create.rejected", emails: @invalid_emails.split(",").join(", "))
|
||||||
'. ' + I18n.t('invitations.create.rejected') +
|
|
||||||
@invalid_emails.split(',').join(', ')
|
|
||||||
expect(flash[:error]).to eq(expected)
|
expect(flash[:error]).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue