Skip to content

Commit

Permalink
feat: send invitation emails - fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Apr 8, 2024
1 parent a6579cc commit a18e8da
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/accounts/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/mailers/account_mailer.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
default from: Kiqr::Config.default_from_email
layout "mailer"
end
8 changes: 8 additions & 0 deletions app/views/account_mailer/invitation_email.text.erb
Original file line number Diff line number Diff line change
@@ -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") %>
13 changes: 13 additions & 0 deletions app/views/layouts/kiqr/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/kiqr/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
2 changes: 1 addition & 1 deletion app/views/users/invitations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<p><%= t(".guest_instructions", team_name: @team.name) %></p>
<div class="flex justify-center items-center gap-x-4">
<%= link_to "Sign in", new_user_session_path, class: "button" %>
or
<%= t(".or") %>
<%= link_to "Create account", new_user_session_path, class: "button alt" %>
</div>
<% end %>
Expand Down
9 changes: 8 additions & 1 deletion config/locales/kiqr.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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!"
7 changes: 7 additions & 0 deletions test/mailers/account_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class AccountMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end
6 changes: 6 additions & 0 deletions test/mailers/previews/account_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a18e8da

Please sign in to comment.