1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Add ability to delete Account (#582)

* Add ability to delete Account

Issue #571

* Fix ActiveJob::DeserializationError in AccountSyncJob when an account doesn't exists

* Use custom confirm modal for account deletion

* Revert "Fix ActiveJob::DeserializationError in AccountSyncJob when an account doesn't exists"

This reverts commit 8dbf634819.
This commit is contained in:
Mattia 2024-03-31 23:36:54 +02:00 committed by GitHub
parent 7fa77b4fd7
commit f6540c03ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 7 deletions

View file

@ -1,6 +1,7 @@
class AccountsController < ApplicationController
include Filterable
before_action :authenticate_user!
before_action :set_account, only: %i[ show update destroy sync ]
def new
@account = Account.new(
@ -10,7 +11,6 @@ class AccountsController < ApplicationController
end
def show
@account = Current.family.accounts.find(params[:id])
@balance_series = @account.series(period: @period)
@valuation_series = @account.valuations.to_series
end
@ -19,8 +19,6 @@ class AccountsController < ApplicationController
end
def update
@account = Current.family.accounts.find(params[:id])
if @account.update(account_params.except(:accountable_type))
@account.sync_later if account_params[:is_active] == "1"
@ -50,8 +48,12 @@ class AccountsController < ApplicationController
end
end
def destroy
@account.destroy!
redirect_to accounts_path, notice: t(".success")
end
def sync
@account = Current.family.accounts.find(params[:id])
@account.sync_later
respond_to do |format|
@ -67,6 +69,10 @@ class AccountsController < ApplicationController
private
def set_account
@account = Current.family.accounts.find(params[:id])
end
def account_params
params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype, :is_active)
end

View file

@ -6,7 +6,6 @@ class Account < ApplicationRecord
broadcasts_refreshes
belongs_to :family
has_many :balances, dependent: :destroy
has_many :valuations, dependent: :destroy
has_many :transactions, dependent: :destroy

View file

@ -17,9 +17,18 @@
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
</div>
</div>
<div class="cursor-not-allowed">
<div class="relative cursor-pointer" data-controller="dropdown">
<div class="flex hover:bg-gray-100 p-2 rounded" data-action="click->dropdown#toggleMenu">
<%= lucide_icon("more-horizontal", class: "w-5 h-5 text-gray-500") %>
</div>
<div class="absolute z-10 top-10 right-0 border border-alpha-black-25 bg-white rounded-lg shadow-xs hidden" data-dropdown-target="menu">
<div class="w-48 px-3 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= 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("custom_turbo_confirm.account_destroy.title"), body: t("custom_turbo_confirm.account_destroy.body_html"), accept: t("custom_turbo_confirm.account_destroy.accept", name: @account.name) } } do %>
<%= lucide_icon("trash-2", class: "w-5 h-5 mr-2") %> Delete account
<% end %>
</div>
</div>
</div>
</div>
</div>
<%= turbo_frame_tag "sync_message" do %>

View file

@ -3,6 +3,8 @@ en:
accounts:
create:
success: New account created successfully
destroy:
success: Account deleted successfully
index:
new_account: New account
new:

View file

@ -1,6 +1,14 @@
---
en:
custom_turbo_confirm:
account_destroy:
accept: Delete "%{name}"
body_html: "<p>By deleting this account, you will erase its value history, affecting
various aspects of your overall account. This action will have a direct impact
on your net worth calculations and the account graphs.</p><br /> <p>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.</p>"
title: Delete account?
default:
accept: Confirm
body_html: "<p>You will not be able to undo this decision</p>"