Skip to content

Commit

Permalink
skeleton to select partner_id in slack
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Mar 10, 2025
1 parent b9e1625 commit 53f6b5d
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion app/services/slack_services/signal_association_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ def payload
contact_info = @user.phone
contact_info += " - #{@user.email}" if @user.email.present?

options = partners.map { |partner|
{
text: {
type: "plain_text",
text: partner.name,
emoji: true
},
value: "partner-id-#{partner.id}"
}
}

{
blocks: [
{ type: "divider" },
Expand Down Expand Up @@ -47,7 +58,37 @@ def payload
},
url: link_to_user(@user.id)
}]
}
},
{
type: "input",
element: {
type: "static_select",
placeholder: {
type: "plain_text",
text: "Sélectionner l'association",
emoji: true
},
options: options,
action_id: "static_select-action"
},
label: {
type: "plain_text",
text: "Choisir",
emoji: true
}
},
{
type: "actions",
elements: [{
type: "button",
text: {
type: "plain_text",
text: "N'est pas une association",
emoji: true
},
url: link_to_user(@user.id)
}]
},
]
}
end
Expand All @@ -58,5 +99,20 @@ def payload_adds
channel: webhook('channel-associations'),
}
end

private

def partners
return [] unless @user.latitude && @user.longitude

bounding_box_sql = Geocoder::Sql.within_bounding_box(*box, :latitude, :longitude)

Partner.where(bounding_box_sql).order(:name)
end

def box
# Geocoder::Calculations.bounding_box([@user.latitude, @user.longitude], @user.travel_distance, units: :km)
Geocoder::Calculations.bounding_box([@user.latitude, @user.longitude], 100, units: :km)
end
end
end

0 comments on commit 53f6b5d

Please sign in to comment.