diff --git a/app/controllers/accounts/invitations_controller.rb b/app/controllers/accounts/invitations_controller.rb index 112a842..2cc716d 100644 --- a/app/controllers/accounts/invitations_controller.rb +++ b/app/controllers/accounts/invitations_controller.rb @@ -11,7 +11,7 @@ def new def create @invitation = current_account.account_invitations.new(invitation_params) if @invitation.save - # AccountMailer.invitation_email(@invitation).deliver_later + AccountMailer.invitation_email(@invitation).deliver_later redirect_to invitations_path(account_id: current_account), notice: t(".invitation_sent", email: @invitation.email) else render :new, status: :unprocessable_entity diff --git a/app/mailers/account_mailer.rb b/app/mailers/account_mailer.rb new file mode 100644 index 0000000..4b79d02 --- /dev/null +++ b/app/mailers/account_mailer.rb @@ -0,0 +1,7 @@ +class AccountMailer < ApplicationMailer + def invitation_email(invitation) + @invitation = invitation + @account = invitation.account + mail to: invitation.email, subject: t(".subject", team_name: @account.name) + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3c34c81..9a23378 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" + default from: Kiqr::Config.default_from_email layout "mailer" end diff --git a/app/views/account_mailer/invitation_email.text.erb b/app/views/account_mailer/invitation_email.text.erb new file mode 100644 index 0000000..95c1a0a --- /dev/null +++ b/app/views/account_mailer/invitation_email.text.erb @@ -0,0 +1,8 @@ +<%= t(".welcome", app_name: Kiqr::Config.app_name) %> +======================================= + +<%= t(".instructions", team_name: @account.name, app_name: Kiqr::Config.app_name) %> + +<%= user_invitation_url(@invitation) %> + +<%= t(".thanks") %> diff --git a/app/views/layouts/kiqr/mailer.html.erb b/app/views/layouts/kiqr/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/app/views/layouts/kiqr/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/kiqr/mailer.text.erb b/app/views/layouts/kiqr/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/kiqr/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/users/invitations/show.html.erb b/app/views/users/invitations/show.html.erb index 8eae6fb..598b7f1 100644 --- a/app/views/users/invitations/show.html.erb +++ b/app/views/users/invitations/show.html.erb @@ -21,7 +21,7 @@

<%= t(".guest_instructions", team_name: @team.name) %>

<%= link_to "Sign in", new_user_session_path, class: "button" %> - or + <%= t(".or") %> <%= link_to "Create account", new_user_session_path, class: "button alt" %>
<% end %> diff --git a/config/locales/kiqr.en.yml b/config/locales/kiqr.en.yml index c04ce9c..6ff2cb1 100644 --- a/config/locales/kiqr.en.yml +++ b/config/locales/kiqr.en.yml @@ -81,7 +81,7 @@ en: title: "Invite a user" description: "Invite a user to your team" box_title: "Invite a user to your team" - instructions: "Enter the email address of the user you want to invite to your team." + instructions: "Enter the email address of the user you want to invite to your team. Anyone with the link can join your team, so be careful who you share it with." back_to_members: "Back to team members" form: email: @@ -184,6 +184,7 @@ en: instructions: "You've been invited to join team %{team_name}. Choose whether you want to accept or decline the invitation." sign_up: "Create a new account" sign_in: "Sign in" + or: "or" two_factor: show: title: "Two-factor authentication" @@ -221,3 +222,9 @@ en: label: "One-time password" placeholder: "Enter the 6-digit code" verify_button: "Verify configuration" + account_mailer: + invitation_email: + welcome: "Welcome to %{app_name}" + subject: "You've been invited to join team %{team_name}" + instructions: "You have been invited to join team %{team_name} on %{app_name}. Please follow the link below to accept or decline the invitation." + thanks: "Thank you and have a great day!" diff --git a/test/mailers/account_mailer_test.rb b/test/mailers/account_mailer_test.rb new file mode 100644 index 0000000..a03f361 --- /dev/null +++ b/test/mailers/account_mailer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class AccountMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/mailers/previews/account_mailer_preview.rb b/test/mailers/previews/account_mailer_preview.rb new file mode 100644 index 0000000..1c005d1 --- /dev/null +++ b/test/mailers/previews/account_mailer_preview.rb @@ -0,0 +1,6 @@ +# Preview all emails at http://localhost:3000/rails/mailers/kiqr/account_mailer +class AccountMailerPreview < ActionMailer::Preview + def invitation_email + AccountMailer.invitation_email(AccountInvitation.first) + end +end