From e893f09986ae63bf95818c4dac71fb85a7621c71 Mon Sep 17 00:00:00 2001 From: Joseph Smith Date: Thu, 11 Jul 2024 09:34:50 -0400 Subject: [PATCH 1/5] Edited mandatory fields html Removed asterisk from record contact details heading Added asterisks to subheadings to help users understand what needs to be filled out. (better user experience) --- app/views/case_contacts/form/details.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/case_contacts/form/details.html.erb b/app/views/case_contacts/form/details.html.erb index 049fbd6d53..aeee3956fb 100644 --- a/app/views/case_contacts/form/details.html.erb +++ b/app/views/case_contacts/form/details.html.erb @@ -19,9 +19,9 @@
-

*

+

-
+
*
<%= form.radio_button :contact_made, true, checked: @case_contact.contact_made, @@ -41,7 +41,7 @@
-
+
*
<%= form.collection_radio_buttons(:medium_type, contact_mediums, 'value', 'label') do |b| %>
<%= b.radio_button(class: ["form-check-input", "case-contacts-form-checkbox"]) %> From 3c0f7c45d13be8c14229686b53da9236ea7bdc62 Mon Sep 17 00:00:00 2001 From: Joseph Smith Date: Sun, 14 Jul 2024 16:45:04 -0400 Subject: [PATCH 2/5] Enhanced multiple select component to sort by last updated time when user selects contact type on new contact page - modified '_contact_types.html.erb' to sort by last_contact_time - updated ContactTypeDecorator with last_contact_timestamp method to obtain last contact or default to a time in past if no contacts Change was made in order to ensure that 'ContactType' options are displayed for users in a way that allows them to quickly access recently used contact types vs scrolling through all options. --- app/decorators/contact_type_decorator.rb | 5 +++++ app/views/case_contacts/form/_contact_types.html.erb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/decorators/contact_type_decorator.rb b/app/decorators/contact_type_decorator.rb index 808a90d5d0..a5e3a3ca47 100644 --- a/app/decorators/contact_type_decorator.rb +++ b/app/decorators/contact_type_decorator.rb @@ -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 diff --git a/app/views/case_contacts/form/_contact_types.html.erb b/app/views/case_contacts/form/_contact_types.html.erb index 1f91e5f1d1..8365bbf83f 100644 --- a/app/views/case_contacts/form/_contact_types.html.erb +++ b/app/views/case_contacts/form/_contact_types.html.erb @@ -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)) }, selected_items: selected_items, render_option_subtext: true )) %> From f3cee804c9730c0ff1846375fc7a9193c85cd821 Mon Sep 17 00:00:00 2001 From: Joseph Smith Date: Sun, 14 Jul 2024 17:01:00 -0400 Subject: [PATCH 3/5] added last contact timestamp rspec testing --- spec/decorators/contact_type_decorator_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/decorators/contact_type_decorator_spec.rb b/spec/decorators/contact_type_decorator_spec.rb index 3da2daea62..fc5fc34f92 100644 --- a/spec/decorators/contact_type_decorator_spec.rb +++ b/spec/decorators/contact_type_decorator_spec.rb @@ -46,4 +46,20 @@ 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 From efbae6b95cf439cdc89ab0d1204114139fedcdfe Mon Sep 17 00:00:00 2001 From: Joseph Smith Date: Mon, 15 Jul 2024 15:30:44 -0400 Subject: [PATCH 4/5] lint --- app/decorators/contact_type_decorator.rb | 2 +- spec/decorators/contact_type_decorator_spec.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/decorators/contact_type_decorator.rb b/app/decorators/contact_type_decorator.rb index a5e3a3ca47..d5ad16232a 100644 --- a/app/decorators/contact_type_decorator.rb +++ b/app/decorators/contact_type_decorator.rb @@ -17,7 +17,7 @@ def last_time_used_with_cases(casa_case_ids) 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 = 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 diff --git a/spec/decorators/contact_type_decorator_spec.rb b/spec/decorators/contact_type_decorator_spec.rb index fc5fc34f92..a3a62b3f4e 100644 --- a/spec/decorators/contact_type_decorator_spec.rb +++ b/spec/decorators/contact_type_decorator_spec.rb @@ -61,5 +61,4 @@ end end end - end From c6e1f0aad26caf3ccc84af55d90c08ebf6590095 Mon Sep 17 00:00:00 2001 From: Joseph Smith Date: Tue, 16 Jul 2024 21:40:12 -0400 Subject: [PATCH 5/5] Added validation to case_contact model Added server side validation to the contact model in order to ensure that "Contact Type" is filled out as required field when user submits a new case contact details form --- app/models/case_contact.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/case_contact.rb b/app/models/case_contact.rb index 213c55d1be..2bc85d759d 100644 --- a/app/models/case_contact.rb +++ b/app/models/case_contact.rb @@ -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, -> {