2025-07-18 05:52:18 -04:00
|
|
|
class UI::AccountPage < ApplicationComponent
|
|
|
|
attr_reader :account, :chart_view, :chart_period
|
|
|
|
|
2025-07-18 17:56:25 -04:00
|
|
|
renders_one :activity_feed, ->(feed_data:, pagy:, search:) { UI::Account::ActivityFeed.new(feed_data: feed_data, pagy: pagy, search: search) }
|
|
|
|
|
2025-07-18 05:52:18 -04:00
|
|
|
def initialize(account:, chart_view: nil, chart_period: nil, active_tab: nil)
|
|
|
|
@account = account
|
|
|
|
@chart_view = chart_view
|
|
|
|
@chart_period = chart_period
|
|
|
|
@active_tab = active_tab
|
|
|
|
end
|
|
|
|
|
2025-07-18 17:56:25 -04:00
|
|
|
def id
|
|
|
|
dom_id(account, :container)
|
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_channel
|
|
|
|
account
|
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_refresh!
|
|
|
|
Turbo::StreamsChannel.broadcast_replace_to(broadcast_channel, target: id, renderable: self, layout: false)
|
|
|
|
end
|
|
|
|
|
2025-07-18 05:52:18 -04:00
|
|
|
def title
|
|
|
|
account.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def subtitle
|
|
|
|
return nil unless account.property?
|
|
|
|
|
|
|
|
account.property.address
|
|
|
|
end
|
|
|
|
|
|
|
|
def active_tab
|
|
|
|
tabs.find { |tab| tab == @active_tab&.to_sym } || tabs.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def tabs
|
|
|
|
case account.accountable_type
|
|
|
|
when "Investment"
|
|
|
|
[ :activity, :holdings ]
|
|
|
|
when "Property", "Vehicle", "Loan"
|
|
|
|
[ :activity, :overview ]
|
|
|
|
else
|
|
|
|
[ :activity ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-07-18 17:56:25 -04:00
|
|
|
def tab_content_for(tab)
|
2025-07-18 05:52:18 -04:00
|
|
|
case tab
|
|
|
|
when :activity
|
2025-07-18 17:56:25 -04:00
|
|
|
activity_feed
|
2025-07-18 05:52:18 -04:00
|
|
|
when :holdings, :overview
|
|
|
|
# Accountable is responsible for implementing the partial in the correct folder
|
2025-07-18 17:56:25 -04:00
|
|
|
render "#{account.accountable_type.downcase.pluralize}/tabs/#{tab}", account: account
|
2025-07-18 05:52:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|