Extract calculate winners button to a component

This way we remove some duplication.
This commit is contained in:
Javi Martín
2021-08-21 22:56:02 +02:00
parent f4b338b65f
commit 4a42804a7d
6 changed files with 45 additions and 35 deletions

View File

@@ -0,0 +1,30 @@
class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
attr_reader :budget, :from_investments
def initialize(budget, from_investments: false)
@budget = budget
@from_investments = from_investments
end
private
def display_button?
budget.balloting_or_later?
end
def text
if budget.investments.winners.empty?
t("admin.budgets.winners.calculate")
else
t("admin.budgets.winners.recalculate")
end
end
def html_class
if from_investments
"button hollow float-right clear"
else
"button hollow"
end
end
end