Browse Source

show the user the group they originally selected if possible when editing group

else fallback to any (oldest) org in the group
pull/3075/head
Samuel 2 months ago
parent
commit
653e3e9956
  1. 15
      app/models/organisation.rb
  2. 2
      app/views/organisations/edit.html.erb

15
app/models/organisation.rb

@ -258,6 +258,21 @@ class Organisation < ApplicationRecord
Organisation.visible.where(group:).order(:created_at).first
end
# Shown on the edit organisation page to indicate which group member the user initially entered, if possible
def selected_group_member
return nil if oldest_group_member.nil?
# find organisation by group_member_id if it exists
selected_group = Organisation.visible.find_by(id: group_member_id)
# ensure that its still in the same group
if selected_group.present? && selected_group.group == group
selected_group
else
oldest_group_member
end
end
private
def validate_profit_status

2
app/views/organisations/edit.html.erb

@ -42,7 +42,7 @@
:id,
:name,
label: { text: "Search for an organisation that is part of the same group as this organisation", size: "m" },
options: { disabled: [""], selected: @organisation.oldest_group_member&.id || "" },
options: { disabled: [""], selected: @organisation.selected_group_member&.id || "" },
"data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %>
<%= f.govuk_radio_button :group_member, false, label: { text: "No" } %>

Loading…
Cancel
Save