Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case contact details ux improvements 5896 #5909

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/decorators/contact_type_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ def last_time_used_with_cases(casa_case_ids)

last_contact.nil? ? "never" : "#{time_ago_in_words(last_contact.occurred_at)} ago"
end

def last_contact_timestamp(casa_case_ids)
last_contact = CaseContact.joins(:contact_types).where(casa_case_id: casa_case_ids, contact_types: {id: object.id}).order(occurred_at: :desc).first
last_contact&.occurred_at || Time.at(0)
end
end
1 change: 1 addition & 0 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CaseContact < ApplicationRecord
validate :reimbursement_only_when_miles_driven, if: :active_or_expenses?
validate :volunteer_address_when_reimbursement_wanted, if: :active_or_expenses?
validate :volunteer_address_is_valid, if: :active_or_expenses?
validates :contact_type_ids, presence: true, if: :active_or_details?

belongs_to :creator, class_name: "User"
has_one :supervisor_volunteer, -> {
Expand Down
2 changes: 1 addition & 1 deletion app/views/case_contacts/form/_contact_types.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= render(Form::MultipleSelectComponent.new(
form: form,
name: :contact_type_ids,
options: options.decorate.map { |ct| ct.hash_for_multi_select_with_cases(casa_cases&.pluck(:id)) },
options: options.decorate.sort_by { |ct| ct.last_contact_timestamp(casa_cases.pluck(:id)) }.reverse.map { |ct| ct.hash_for_multi_select_with_cases(casa_cases.pluck(:id)) },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ordering can be done in

@contact_types.order(name: :asc)

Copy link
Collaborator Author

@josephmsmith josephmsmith Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do this originally in the controller but couldn't get it to work. Any suggestions?

The decorator wasn't working correctly specifically if I remember right so the extra sorting logic there was added as a fix

selected_items: selected_items,
render_option_subtext: true
)) %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/case_contacts/form/details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</div>

<div id="enter-contact-details" class="card-style-1 pl-25 mb-10">
<h4 class="mb-3"><label>3. Record contact details</label><span class="red-letter"> *</span></h4>
<h4 class="mb-3"><label>3. Record contact details</label></h4>
<div class="">
<h5 classs="mb-3"><label>a. Was contact made?</label></h5>
<h5 classs="mb-3"><label>a. Was contact made?</label><span class="red-letter"> *</span></h5>
<div class="form-check radio-style mb-20">
<%= form.radio_button :contact_made, true,
checked: @case_contact.contact_made,
Expand All @@ -41,7 +41,7 @@
</div>

<div class="field contact-medium form-group">
<h5 classs="mb-3"><label>b. How was contact made?</label></h5>
<h5 classs="mb-3"><label>b. How was contact made?</label><span class="red-letter"> *</span></h5>
<%= form.collection_radio_buttons(:medium_type, contact_mediums, 'value', 'label') do |b| %>
<div class="form-check radio-style mb-20">
<%= b.radio_button(class: ["form-check-input", "case-contacts-form-checkbox"]) %>
Expand Down
15 changes: 15 additions & 0 deletions spec/decorators/contact_type_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@
end
end
end

describe "last_contact_timestamp" do
context "with empty array" do
it { expect(contact_type.decorate.last_contact_timestamp([])).to eq Time.at(0) }
end

context "with cases" do
let(:casa_case) { create(:casa_case, casa_org: casa_org) }
let(:casa_case_ids) { [casa_case.id] }

context "with no case contacts" do
it { expect(contact_type.decorate.last_contact_timestamp([])).to eq Time.at(0) }
end
end
end
end
Loading