mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 14:49:38 +02:00
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
97 lines
2.8 KiB
Ruby
97 lines
2.8 KiB
Ruby
module AccountableResource
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
include ScrollFocusable
|
|
|
|
before_action :set_account, only: [ :show, :edit, :update, :destroy ]
|
|
before_action :set_link_token, only: :new
|
|
end
|
|
|
|
class_methods do
|
|
def permitted_accountable_attributes(*attrs)
|
|
@permitted_accountable_attributes = attrs if attrs.any?
|
|
@permitted_accountable_attributes ||= [ :id ]
|
|
end
|
|
end
|
|
|
|
def new
|
|
@account = Current.family.accounts.build(
|
|
currency: Current.family.currency,
|
|
accountable: accountable_type.new
|
|
)
|
|
end
|
|
|
|
def show
|
|
@q = params.fetch(:q, {}).permit(:search)
|
|
entries = @account.entries.search(@q).reverse_chronological
|
|
|
|
set_focused_record(entries, params[:focused_record_id])
|
|
|
|
@pagy, @entries = pagy(entries, limit: params[:per_page] || "10", params: ->(params) { params.except(:focused_record_id) })
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def create
|
|
@account = Current.family.accounts.create_and_sync(account_params.except(:return_to))
|
|
redirect_to account_params[:return_to].presence || @account, notice: t("accounts.create.success", type: accountable_type.name.underscore.humanize)
|
|
end
|
|
|
|
def update
|
|
@account.update_with_sync!(account_params.except(:return_to))
|
|
redirect_back_or_to @account, notice: t("accounts.update.success", type: accountable_type.name.underscore.humanize)
|
|
end
|
|
|
|
def destroy
|
|
@account.destroy_later
|
|
redirect_to accounts_path, notice: t("accounts.destroy.success", type: accountable_type.name.underscore.humanize)
|
|
end
|
|
|
|
private
|
|
def set_link_token
|
|
@us_link_token = Current.family.get_link_token(
|
|
webhooks_url: plaid_us_webhooks_url,
|
|
redirect_url: accounts_url,
|
|
accountable_type: accountable_type.name,
|
|
region: :us
|
|
)
|
|
|
|
if Current.family.eu?
|
|
@eu_link_token = Current.family.get_link_token(
|
|
webhooks_url: plaid_eu_webhooks_url,
|
|
redirect_url: accounts_url,
|
|
accountable_type: accountable_type.name,
|
|
region: :eu
|
|
)
|
|
end
|
|
end
|
|
|
|
def plaid_us_webhooks_url
|
|
return webhooks_plaid_url if Rails.env.production?
|
|
|
|
ENV.fetch("DEV_WEBHOOKS_URL", root_url.chomp("/")) + "/webhooks/plaid"
|
|
end
|
|
|
|
def plaid_eu_webhooks_url
|
|
return webhooks_plaid_eu_url if Rails.env.production?
|
|
|
|
ENV.fetch("DEV_WEBHOOKS_URL", root_url.chomp("/")) + "/webhooks/plaid_eu"
|
|
end
|
|
|
|
def accountable_type
|
|
controller_name.classify.constantize
|
|
end
|
|
|
|
def set_account
|
|
@account = Current.family.accounts.find(params[:id])
|
|
end
|
|
|
|
def account_params
|
|
params.require(:account).permit(
|
|
:name, :is_active, :balance, :subtype, :currency, :accountable_type, :return_to,
|
|
accountable_attributes: self.class.permitted_accountable_attributes
|
|
)
|
|
end
|
|
end
|