Sha256: ea996d70effd673d91ae7e031700e24b7d6ae83e6e87a3ed6a93e2dd8a8b733a

Contents?: true

Size: 678 Bytes

Versions: 1

Compression:

Stored size: 678 Bytes

Contents

# frozen_string_literal: true

class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent
  STATUSES = {
    available: :green,
    discontinued: :yellow,
    deleted: :red,
    unavailable: :yellow
  }.freeze

  def self.from_product(product)
    status =
      if product.deleted?
        :deleted
      elsif product.discontinued?
        :discontinued
      elsif product.available?
        :available
      else
        :unavailable
      end

    new(status:)
  end

  def initialize(status:)
    @status = status
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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