Extract link to toggle selection to a component

This commit is contained in:
Javi Martín
2021-08-20 01:50:15 +02:00
parent 5251fbadd9
commit 3cebce9a29
9 changed files with 35 additions and 25 deletions

View File

@@ -0,0 +1 @@
<%= link_to_toggle_proposal_selection %>

View File

@@ -0,0 +1,26 @@
class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
attr_reader :proposal
def initialize(proposal)
@proposal = proposal
end
def link_to_toggle_proposal_selection
if proposal.selected?
button_text = t("admin.proposals.index.selected")
html_class = "button expanded"
else
button_text = t("admin.proposals.index.select")
html_class = "button hollow expanded"
end
case proposal.class.to_s
when "Proposal"
path = toggle_selection_admin_proposal_path(proposal)
when "Legislation::Proposal"
path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
end
link_to button_text, path, remote: true, method: :patch, class: html_class
end
end