-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add institution management and account editing controls (#868)
* Add institution management * Allow user to select institution on create or edit * Improve redirect behavior * Final cleanup * i18n normalization
- Loading branch information
Showing
36 changed files
with
456 additions
and
68 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,35 @@ | ||
class InstitutionsController < ApplicationController | ||
before_action :set_institution, except: %i[ new create ] | ||
|
||
def new | ||
@institution = Institution.new | ||
end | ||
|
||
def create | ||
Current.family.institutions.create!(institution_params) | ||
redirect_to accounts_path, notice: t(".success") | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@institution.update!(institution_params) | ||
redirect_to accounts_path, notice: t(".success") | ||
end | ||
|
||
def destroy | ||
@institution.destroy! | ||
redirect_to accounts_path, notice: t(".success") | ||
end | ||
|
||
private | ||
|
||
def institution_params | ||
params.require(:institution).permit(:name, :logo) | ||
end | ||
|
||
def set_institution | ||
@institution = Current.family.institutions.find(params[:id]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module InstitutionsHelper | ||
def institution_logo(institution) | ||
institution.logo.attached? ? institution.logo : institution.logo_url | ||
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
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,7 @@ | ||
class Institution < ApplicationRecord | ||
belongs_to :family | ||
has_many :accounts, dependent: :nullify | ||
has_one_attached :logo | ||
|
||
scope :alphabetically, -> { order(name: :asc) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%# locals: (accounts:) %> | ||
<% accounts.group_by(&:accountable_type).each do |group, accounts| %> | ||
<div class="bg-gray-25 p-1 rounded-xl"> | ||
<div class="flex items-center px-4 py-2 text-xs font-medium text-gray-500"> | ||
<p><%= to_accountable_title(Accountable.from_type(group)) %></p> | ||
<span class="text-gray-400 mx-2">·</span> | ||
<p><%= accounts.count %></p> | ||
<p class="ml-auto"><%= format_money accounts.sum(&:balance_money) %></p> | ||
</div> | ||
<div class="bg-white"> | ||
<% accounts.each do |account| %> | ||
<%= render account %> | ||
<% end %> | ||
</div> | ||
</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,11 @@ | ||
<div class="flex justify-center items-center h-[800px] text-sm"> | ||
<div class="text-center flex flex-col items-center max-w-[300px]"> | ||
<%= tag.p t(".no_accounts"), class: "text-gray-900 mb-1 font-medium" %> | ||
<%= tag.p t(".empty_message"), class: "text-gray-500 mb-4" %> | ||
<%= link_to new_account_path, class: "w-fit flex text-white text-sm font-medium items-center gap-1 bg-gray-900 rounded-lg p-2 pr-3", data: { turbo_frame: "modal" } do %> | ||
<%= lucide_icon("plus", class: "w-5 h-5") %> | ||
<span><%= t(".new_account") %></span> | ||
<% end %> | ||
</div> | ||
</div> |
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,69 @@ | ||
<%# locals: (institution:) %> | ||
|
||
<details open class="group bg-white p-4 border border-alpha-black-25 shadow-xs rounded-xl"> | ||
<summary class="flex items-center gap-2 focus-visible:outline-none"> | ||
<%= lucide_icon "chevron-right", class: "group-open:transform group-open:rotate-90 text-gray-500 w-5" %> | ||
|
||
<div class="flex items-center justify-center h-8 w-8 bg-blue-600/10 rounded-full bg-black/5"> | ||
<% if institution_logo(institution) %> | ||
<%= image_tag institution_logo(institution), class: "rounded-full h-full w-full" %> | ||
<% else %> | ||
<div class="flex items-center justify-center"> | ||
<%= tag.p institution.name.first.upcase, class: "text-blue-600 text-xs font-medium" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to institution.name, edit_institution_path(institution), data: { turbo_frame: :modal }, class: "text-sm font-medium text-gray-900 ml-1 mr-auto hover:underline" %> | ||
<%= contextual_menu do %> | ||
<div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5"> | ||
<%= link_to new_account_path(institution_id: institution.id), | ||
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg", | ||
data: { turbo_frame: :modal } do %> | ||
<%= lucide_icon "plus", class: "w-5 h-5 text-gray-500" %> | ||
|
||
<span><%= t(".add_account_to_institution") %></span> | ||
<% end %> | ||
<%= link_to edit_institution_path(institution), | ||
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg", | ||
data: { turbo_frame: :modal } do %> | ||
<%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %> | ||
|
||
<span><%= t(".edit") %></span> | ||
<% end %> | ||
<%= button_to institution_path(institution), | ||
method: :delete, | ||
class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg", | ||
data: { | ||
turbo_confirm: { | ||
title: t(".confirm_title"), | ||
body: t(".confirm_body"), | ||
accept: t(".confirm_accept") | ||
} | ||
} do %> | ||
<%= lucide_icon "trash-2", class: "w-5 h-5" %> | ||
|
||
<span><%= t(".delete") %></span> | ||
<% end %> | ||
</div> | ||
|
||
<% end %> | ||
</summary> | ||
|
||
<div class="space-y-4 mt-4"> | ||
<% if institution.accounts.any? %> | ||
<%= render "accountable_group", accounts: institution.accounts %> | ||
<% else %> | ||
<div class="p-4 flex flex-col gap-3 items-center justify-center"> | ||
<p class="text-gray-500 text-sm">There are no accounts in this financial institution</p> | ||
<%= link_to new_account_path(institution_id: institution.id), class: "w-fit flex text-white text-sm font-medium items-center gap-1 bg-gray-900 rounded-lg p-1.5 pr-2", data: { turbo_frame: "modal" } do %> | ||
<%= lucide_icon("plus", class: "w-4 h-4") %> | ||
<span><%= t(".new_account") %></span> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</details> |
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,17 @@ | ||
<%# locals: (accounts:) %> | ||
|
||
<details open class="group bg-white p-4 border border-alpha-black-25 shadow-xs rounded-xl"> | ||
<summary class="flex items-center gap-2 focus-visible:outline-none"> | ||
<%= lucide_icon "chevron-right", class: "group-open:transform group-open:rotate-90 text-gray-500 w-5" %> | ||
|
||
<div class="flex items-center justify-center h-8 w-8 rounded-full bg-black/5"> | ||
<%= lucide_icon("folder-pen", class: "w-5 h-5 text-gray-500") %> | ||
</div> | ||
|
||
<span class="mr-auto text-sm font-medium text-gray-900"><%= t(".other_accounts") %></span> | ||
</summary> | ||
|
||
<div class="space-y-4 mt-4"> | ||
<%= render "accountable_group", accounts: accounts %> | ||
</div> | ||
</details> |
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,21 @@ | ||
<%= modal do %> | ||
<article class="mx-auto w-full p-4 space-y-4 min-w-[350px]"> | ||
<header class="flex justify-between"> | ||
<h2 class="font-medium text-xl"><%= t(".edit", account: @account.name) %></h2> | ||
<%= lucide_icon "x", class: "w-5 h-5 text-gray-500", data: { action: "click->modal#close" } %> | ||
</header> | ||
|
||
<%= form_with model: @account, data: { turbo_frame: "_top" } do |f| %> | ||
<%= f.text_field :name, label: "Name" %> | ||
|
||
<div class="relative"> | ||
<%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %> | ||
<%= link_to new_institution_path do %> | ||
<%= lucide_icon "plus", class: "text-gray-700 hover:text-gray-500 w-4 h-4 absolute right-3 top-2" %> | ||
<% end %> | ||
</div> | ||
|
||
<%= f.submit %> | ||
<% end %> | ||
</article> | ||
<% end %> |
Oops, something went wrong.