Class: SolidusAdmin::Users::Addresses::Component

Inherits:
BaseComponent
  • Object
show all
Includes:
Layout::PageHelpers
Defined in:
app/components/solidus_admin/users/addresses/component.rb

Instance Method Summary collapse

Constructor Details

#initialize(user:, address: nil, type: nil) ⇒ Component

Returns a new instance of Component.



6
7
8
9
10
# File 'app/components/solidus_admin/users/addresses/component.rb', line 6

def initialize(user:, address: nil, type: nil)
  @user = user
  @bill_address = bill_address(address, type)
  @ship_address = ship_address(address, type)
end

Instance Method Details

#bill_address(address, type) ⇒ Object



46
47
48
49
50
51
52
# File 'app/components/solidus_admin/users/addresses/component.rb', line 46

def bill_address(address, type)
  if address.present? && type == "bill"
    address
  else
    @user.bill_address || Spree::Address.build_default
  end
end

#form_idObject



12
13
14
# File 'app/components/solidus_admin/users/addresses/component.rb', line 12

def form_id
  @form_id ||= "#{stimulus_id}--form-#{@user.id}"
end

#ship_address(address, type) ⇒ Object



54
55
56
57
58
59
60
# File 'app/components/solidus_admin/users/addresses/component.rb', line 54

def ship_address(address, type)
  if address.present? && type == "ship"
    address
  else
    @user.ship_address || Spree::Address.build_default
  end
end

#tabsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/components/solidus_admin/users/addresses/component.rb', line 16

def tabs
  [
    {
      text: t('.account'),
      href: solidus_admin.user_path(@user),
      current: false,
    },
    {
      text: t('.addresses'),
      href: solidus_admin.addresses_user_path(@user),
      current: true,
    },
    {
      text: t('.order_history'),
      href: solidus_admin.orders_user_path(@user),
      current: false,
    },
    {
      text: t('.items'),
      href: spree.items_admin_user_path(@user),
      current: false,
    },
    {
      text: t('.store_credit'),
      href: spree.admin_user_store_credits_path(@user),
      current: false,
    },
  ]
end