diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 244072f8..ad2cd8b7 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -2,7 +2,7 @@ class AccountsController < ApplicationController
layout "with_sidebar"
include Filterable
- before_action :set_account, only: %i[ show update destroy sync ]
+ before_action :set_account, only: %i[ show destroy sync update ]
def index
@accounts = Current.family.accounts
@@ -32,26 +32,9 @@ class AccountsController < ApplicationController
@valuation_series = @account.valuations.to_series
end
- def edit
- end
-
def update
- if @account.update(account_params.except(:accountable_type))
-
- @account.sync_later if account_params[:is_active] == "1" && @account.can_sync?
-
- respond_to do |format|
- format.html { redirect_to accounts_path, notice: t(".success") }
- format.turbo_stream do
- render turbo_stream: [
- turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "success", content: { body: t(".success") } }),
- turbo_stream.replace("account_#{@account.id}", partial: "accounts/account", locals: { account: @account })
- ]
- end
- end
- else
- render "show", status: :unprocessable_entity
- end
+ @account.update! account_params.except(:accountable_type)
+ redirect_back_or_to account_path(@account), notice: t(".success")
end
def create
@@ -62,7 +45,7 @@ class AccountsController < ApplicationController
@valuation = @account.valuations.new(date: account_params[:start_date] || Date.today, value: @account.balance, currency: @account.currency)
@valuation.save!
- redirect_to accounts_path, notice: t(".success")
+ redirect_to account_path(@account), notice: t(".success")
else
render "new", status: :unprocessable_entity
end
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 722a11a9..814ebf13 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -9,7 +9,8 @@ class ImportsController < ApplicationController
end
def new
- @import = Import.new
+ account = Current.family.accounts.find_by(id: params[:account_id])
+ @import = Import.new account: account
end
def edit
diff --git a/app/views/accounts/_account.html.erb b/app/views/accounts/_account.html.erb
index c8eb02ae..ed3fc6fd 100644
--- a/app/views/accounts/_account.html.erb
+++ b/app/views/accounts/_account.html.erb
@@ -4,18 +4,20 @@
">
<%= account.name[0].upcase %>
- ">
- <%= account.name %>
-
+ <%= link_to account.name, account, class: [(account.is_active ? "text-gray-900" : "text-gray-400"), "text-sm font-medium hover:underline"], data: { turbo_frame: "_top" } %>
">
<%= format_money account.balance_money %>
- <%= form_with model: account, method: :patch, html: { class: "flex items-center", data: { turbo_frame: "_top" } } do |form| %>
+
+ <%= form_with model: account,
+ namespace: account.id,
+ builder: ActionView::Helpers::FormBuilder,
+ data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
- <%= form.check_box :is_active, class: "sr-only peer", id: "is_active_#{account.id}", onchange: "this.form.requestSubmit();" %>
-
+ <%= form.check_box :is_active, { class: "sr-only peer", data: { "auto-submit-form-target": "auto" } } %>
+ <%= form.label :is_active, " ".html_safe, class: "maybe-switch" %>
<% end %>
diff --git a/app/views/accounts/_header.html.erb b/app/views/accounts/_header.html.erb
new file mode 100644
index 00000000..f8c8eb3e
--- /dev/null
+++ b/app/views/accounts/_header.html.erb
@@ -0,0 +1,21 @@
+
+ <%= t(".accounts") %>
+
+
+ <%= contextual_menu do %>
+
+ <%= link_to accounts_path(return_to: summary_accounts_path),
+ class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg font-normal" do %>
+ <%= lucide_icon "settings", class: "w-5 h-5 text-gray-500" %>
+ <%= t(".manage") %>
+ <% end %>
+
+
+ <% end %>
+
+ <%= link_to new_account_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %>
+ <%= lucide_icon("plus", class: "w-5 h-5") %>
+
<%= t(".new") %>
+ <% end %>
+
+
diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb
index edbfcd21..15b8c2f5 100644
--- a/app/views/accounts/show.html.erb
+++ b/app/views/accounts/show.html.erb
@@ -15,27 +15,30 @@
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
-
-
-
-
- <%= button_to account_path(@account),
- method: :delete,
- class: "block w-full py-2 text-red-600 hover:text-red-800 flex items-center",
- data: {
- turbo_confirm: {
- title: t(".confirm_title"),
- body: t(".confirm_body_html"),
- accept: t(".confirm_accept", name: @account.name)
- }
- } do %>
- <%= lucide_icon("trash-2", class: "w-5 h-5 mr-2") %> Delete account
- <% end %>
-
+
+ <%= contextual_menu do %>
+
+ <%= link_to new_import_path(account_id: @account.id),
+ class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg" do %>
+ <%= lucide_icon "download", class: "w-5 h-5 text-gray-500" %>
+
+ <%= t(".import") %>
+ <% end %>
+
+ <%= button_to account_path(@account),
+ 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_html"),
+ accept: t(".confirm_accept", name: @account.name)
+ }
+ } do %>
+ <%= lucide_icon("trash-2", class: "w-5 h-5 mr-2") %> Delete account
+ <% end %>
-
+ <% end %>
<%= turbo_frame_tag "sync_message" do %>
diff --git a/app/views/accounts/summary.html.erb b/app/views/accounts/summary.html.erb
index 6ad213ad..e8603f8d 100644
--- a/app/views/accounts/summary.html.erb
+++ b/app/views/accounts/summary.html.erb
@@ -1,11 +1,6 @@
-
-
Accounts
- <%= link_to new_account_path, class: "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") %>
- <%= t(".new") %>
- <% end %>
-
+
+ <%= render "header" %>
<% if @accounts.empty? %>
<%= render "shared/no_account_empty_state" %>
diff --git a/app/views/pages/dashboard/transactions/_transaction.html.erb b/app/views/pages/dashboard/transactions/_transaction.html.erb
index b8dbc57b..49fc3be3 100644
--- a/app/views/pages/dashboard/transactions/_transaction.html.erb
+++ b/app/views/pages/dashboard/transactions/_transaction.html.erb
@@ -1,5 +1,5 @@
-
+
<%= render "transactions/name", transaction: transaction %>
diff --git a/app/views/settings/_nav.html.erb b/app/views/settings/_nav.html.erb
index 3c283f9e..9c93f1e2 100644
--- a/app/views/settings/_nav.html.erb
+++ b/app/views/settings/_nav.html.erb
@@ -1,5 +1,5 @@
- <%= link_to root_path, class: "flex items-center gap-1 text-gray-900 font-medium text-sm" do %>
+ <%= link_to return_to_path(params), class: "flex items-center gap-1 text-gray-900 font-medium text-sm" do %>
<%= lucide_icon "chevron-left", class: "w-5 h-5 text-gray-500" %>
Back
<% end %>
diff --git a/app/views/transactions/_name.html.erb b/app/views/transactions/_name.html.erb
index 6f27f324..09bc09dd 100644
--- a/app/views/transactions/_name.html.erb
+++ b/app/views/transactions/_name.html.erb
@@ -1,9 +1,9 @@
<%= content_tag :div, class: ["flex items-center gap-2"] do %>
-
+
<%= transaction.name[0].upcase %>
-
+
<% if transaction.new_record? %>
<%= content_tag :p, transaction.name %>
<% else %>
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
index c31074cf..3e04a625 100644
--- a/app/views/transactions/_transaction.html.erb
+++ b/app/views/transactions/_transaction.html.erb
@@ -4,7 +4,9 @@
class: "maybe-checkbox maybe-checkbox--light",
data: { id: transaction.id, "bulk-select-target": "row", action: "bulk-select#toggleRowSelection" } %>
- <%= render "transactions/name", transaction: transaction %>
+
+ <%= render "transactions/name", transaction: transaction %>
+
@@ -13,6 +15,7 @@
<%= link_to transaction.account.name,
account_path(transaction.account),
+ data: { turbo_frame: "_top" },
class: ["col-span-3 hover:underline"] %>
diff --git a/config/locales/views/account/en.yml b/config/locales/views/accounts/en.yml
similarity index 92%
rename from config/locales/views/account/en.yml
rename to config/locales/views/accounts/en.yml
index 38248678..9728b7fc 100644
--- a/config/locales/views/account/en.yml
+++ b/config/locales/views/accounts/en.yml
@@ -12,6 +12,10 @@ en:
success: New account created successfully
destroy:
success: Account deleted successfully
+ header:
+ accounts: Accounts
+ manage: Manage accounts
+ new: New account
index:
new_account: New account
new:
@@ -35,6 +39,7 @@ en:
/>
After deletion, there is no way you'll be able to restore the account
information because you'll need to add it as a new account.
"
confirm_title: Delete account?
+ import: Import transactions
sync_message_missing_rates: Since exchange rates haven't been synced, balance
graphs may not reflect accurate values.
sync_message_unknown_error: An error has occurred during the sync.
@@ -44,4 +49,4 @@ en:
cannot_sync: Account cannot be synced at the moment
success: Account sync started
update:
- success: Account updated successfully
+ success: Account updated
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index d84369c9..9173e904 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -16,10 +16,21 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_response :ok
end
+ test "should update account" do
+ patch account_url(@account), params: {
+ account: {
+ is_active: "0"
+ }
+ }
+
+ assert_redirected_to account_url(@account)
+ assert_equal "Account updated", flash[:notice]
+ end
+
test "should create account" do
assert_difference -> { Account.count }, +1 do
post accounts_path, params: { account: { accountable_type: "Account::Credit" } }
- assert_redirected_to accounts_url
+ assert_redirected_to account_url(Account.order(:created_at).last)
end
end