Class: Crm::ContactCardComponent

Inherits:
ApplicationComponent show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
app/components/crm/contact_card_component.rb

Overview

Displays a contact or customer card with profile image, contact info, and contact points.
Used in customer contacts tab and other places where contact cards are displayed.

Examples:

Basic usage

<%= render Crm::ContactCardComponent.new(contact: @customer) %>

With return path

<%= render Crm::ContactCardComponent.new(contact: @contact, return_path: customer_path(@customer)) %>

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Constructor Details

#initialize(contact:, return_path: nil, contact_points: nil, communication_options: {}, role: nil, note: nil, agreement_participant: nil) ⇒ ContactCardComponent

Returns a new instance of ContactCardComponent.

Parameters:

  • contact (Customer, Contact)

    The party to display

  • return_path (String) (defaults to: nil)

    Path to return to after editing

  • contact_points (Array) (defaults to: nil)

    Optional override for contact points

  • communication_options (Hash) (defaults to: {})

    Options for communication actions

  • role (String) (defaults to: nil)

    Optional role/title override

  • note (String) (defaults to: nil)

    Optional note to display

  • agreement_participant (Object) (defaults to: nil)

    Optional agreement participant info



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/crm/contact_card_component.rb', line 23

def initialize(
  contact:,
  return_path: nil,
  contact_points: nil,
  communication_options: {},
  role: nil,
  note: nil,
  agreement_participant: nil
)
  super()
  @contact = contact
  @return_path_override = return_path
  @contact_points = contact_points || contact.contact_points
  @communication_options = communication_options
  @role = role.presence || (contact.respond_to?(:job_title) ? contact.job_title : nil)
  @note = note
  @agreement_participant = agreement_participant

  # Trigger lazy profile image lookup if needed
  enqueue_profile_image_lookup
end

Instance Method Details

#before_renderObject

Called before rendering - set up values that depend on helpers



46
47
48
# File 'app/components/crm/contact_card_component.rb', line 46

def before_render
  @return_path = @return_path_override || helpers.polymorphic_path(contact, tab: 'contacts')
end

#enqueue_profile_image_lookupObject

Queue profile image lookup for parties without images (lazy backfill)



51
52
53
54
55
56
# File 'app/components/crm/contact_card_component.rb', line 51

def enqueue_profile_image_lookup
  return if contact.profile_image_id.present?
  return if contact.inactive?

  PartyProfileImageWorker.perform_async(contact.id)
end