-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create member invites (still missing the user part)
- Loading branch information
Showing
17 changed files
with
288 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Accounts::InvitationsController < ApplicationController | ||
def index | ||
@invitations = current_account.account_invitations | ||
@account = current_account | ||
end | ||
|
||
def new | ||
@invitation = current_account.account_invitations.new | ||
end | ||
|
||
def create | ||
@invitation = current_account.account_invitations.new(invitation_params) | ||
if @invitation.save | ||
# 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 | ||
end | ||
end | ||
|
||
def destroy | ||
@invitation = current_account.account_invitations.find_puid!(params[:id]) | ||
@invitation.destroy | ||
redirect_to invitations_path, notice: t(".deleted") | ||
end | ||
|
||
private | ||
|
||
def invitation_params | ||
params.require(:account_invitation).permit(:email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AccountInvitation < ApplicationRecord | ||
# This will generate a public_uid for the model when it is created. | ||
# Use this public_uidas a unique public identifier for the model. | ||
# To find a model by its public_uid, use the following method: | ||
# Account.find_puid('xxxxxxxx') | ||
# Learn more: https://github.com/equivalent/public_uid | ||
include PublicUid::ModelConcern | ||
|
||
belongs_to :account, inverse_of: :account_invitations, counter_cache: true | ||
|
||
validates :email, presence: true, format: {with: URI::MailTo::EMAIL_REGEXP} | ||
validates :email, uniqueness: {scope: :account_id, message: I18n.t("accounts.invitations.new.form.errors.email.taken")} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= simple_form_for(account, url: form_submit_path, method: form_method) do |f| %> | ||
<%= f.input :name, placeholder: (account.personal? ? t(".name.personal") : t(".name.team")), required: true, autofocus: true %> | ||
<%#= f.input :custom_field %> | ||
<div class="mt-4 flex justify-between items-center"> | ||
<%= f.button :submit, account.persisted? ? t(".button.save") : t(".button.create") %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<% title t(".title") %> | ||
<%= render(PageLayouts::Settings::Component.new( | ||
title: t(".title"), | ||
description: t(".description") | ||
)) do %> | ||
<div class="box"> | ||
<header class="border-b pb-4 mb-4"> | ||
<h3 class="font-bold text-primary uppercase"><%= t(".box_title", team_name: @account.name) %></h3> | ||
</header> | ||
|
||
<% if @invitations.any? %> | ||
<div class="prose dark:prose-invert"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th><%= t(".table.email") %></th> | ||
<th><%= t(".table.sent_at") %></th> | ||
<th class="text-right"><%= t(".table.actions") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @invitations.each do |invitation| %> | ||
<tr> | ||
<td><%= invitation.email %></td> | ||
<td><%= invitation.created_at %></td> | ||
<td class="text-right"> | ||
<%= button_to t(".table.remove"), invitation_path(id: invitation), class: "button xs danger", method: :delete, data: { confirm: t(".confirm_delete", email: invitation.email), turbo_confirm: t(".confirm_delete", email: invitation.email) } %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
<% else %> | ||
<p><%= t(".no_invitations") %></p> | ||
<% end %> | ||
</div> | ||
<div class="mt-6 flex justify-start gap-x-6 items-center"> | ||
<%= link_to members_path, class: "button alt" do %> | ||
<i class="fa fa-arrow-left"></i> <%= t(".buttons.back") %> | ||
<% end %> | ||
<%= link_to t(".buttons.invite"), new_invitation_path, class: "button" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<% title t(".title") %> | ||
<%= render(PageLayouts::Settings::Component.new( | ||
title: t(".title"), | ||
description: t(".description") | ||
)) do %> | ||
<div class="box"> | ||
<header class="border-b pb-4 mb-4"> | ||
<h3 class="font-bold text-primary uppercase"><%= t(".box_title") %></h3> | ||
</header> | ||
|
||
<div class="prose dark:prose-invert"> | ||
<p><%= t(".instructions") %></p> | ||
|
||
<%= simple_form_for(@invitation, url: invitations_path) do |f| %> | ||
<%= f.input :email, placeholder: t(".form.email.placeholder"), required: true, autofocus: true %> | ||
<div class="mt-4 flex justify-between items-center"> | ||
<%= f.button :submit, t(".form.submit") %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="mt-6 flex justify-start gap-x-6 items-center"> | ||
<%= link_to members_path, class: "button alt" do %> | ||
<i class="fa fa-arrow-left"></i> <%= t(".back_to_members") %> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateAccountInvitations < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :account_invitations do |t| | ||
t.string :public_uid, index: {unique: true} | ||
t.references :account, null: false, foreign_key: true | ||
t.string :email, null: false | ||
t.timestamps | ||
end | ||
|
||
add_column :accounts, :account_invitations_count, :integer, default: 0 | ||
add_index :account_invitations, :email | ||
add_index :account_invitations, [:account_id, :email], unique: true | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.