Sha256: a0176afd5a18e862ade78874962be43d8fa31cfb7c9075063c38133bde96ba7a

Contents?: true

Size: 624 Bytes

Versions: 2

Compression:

Stored size: 624 Bytes

Contents

# frozen_string_literal: true

class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent
  COLORS = {
    available: :green,
    discontinued: :red
  }.freeze

  # @param product [Spree::Product]
  def initialize(product:)
    @product = product
  end

  def call
    render component('ui/badge').new(
      name: t(".#{status}"),
      color: COLORS.fetch(status)
    )
  end

  # @return [Symbol]
  #   :available when the product is available
  #   :discontinued when the product is not available
  def status
    if @product.available?
      :available
    else
      :discontinued
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_admin-0.0.2 app/components/solidus_admin/products/status/component.rb
solidus_admin-0.0.1 app/components/solidus_admin/products/status/component.rb