casa icon indicating copy to clipboard operation
casa copied to clipboard

Improve Volunteer Assignment when creating a new case

Open elasticspoon opened this issue 1 year ago • 12 comments

What type(s) of user does this feature affect?

  • supervisors
  • admins
  • volunteers

Description

Include the “Assign a New Volunteer” select input at the end of the “New CASA Case” form (casa_cases/new). This dropdown should be optional.

Image

Change “Assign a New Volunteer” to “Assign a Volunteer to Case” on the edit page (/casa_cases/:id/edit)

Image

Additional changes:

  • The existing “Assign a New Volunteer” select input is missing the caret icon (/casa_cases/:id/edit)
  • Make sure these dropdowns are styled the same way as other select inputs

How to access the QA site

Login Details:
Link to QA site

Login Emails:

password for all users: 12345678

Questions? Join Slack!

We highly recommend that you join us in slack #casa channel to ask questions quickly. And discord for office hours (currently Tuesday 5-7pm Pacific), stakeholder news, and upcoming new issues.

elasticspoon avatar May 27 '24 06:05 elasticspoon

can I work on this?

wandergithub avatar Jun 01 '24 18:06 wandergithub

can I work on this?

Hi @wandergithub sorry for just seeing this - would you still like to work on this feature? This is a highly sought-after improvement by our stakeholders :)

bcastillo32 avatar Jun 14 '24 02:06 bcastillo32

I've been trying but can't manage to create the volunteer assignment when creating the new case. So I think It went over my capacity. If someone solves this please give me a mention I want to see what I was missing.

wandergithub avatar Jun 14 '24 03:06 wandergithub

Happy to work on this

kenny-luong avatar Jun 27 '24 22:06 kenny-luong

Is there a way for to tell that the list of possible volunteers is the correct list?

kenny-luong avatar Jul 01 '24 19:07 kenny-luong

Is there a way for to tell that the list of possible volunteers is the correct list?

In what sense? How to test that the content of the dropdown is correct?

elasticspoon avatar Jul 01 '24 19:07 elasticspoon

Is there a way for to tell that the list of possible volunteers is the correct list?

In what sense? How to test that the content of the dropdown is correct?

Yeah. I just want to make sure that the dropdown is actually showing the correct volunteers.

kenny-luong avatar Jul 01 '24 20:07 kenny-luong

So obviously a volunteer assignment will fail if a case fails to be created but what if the volunteer assignment fails? Should the case still be created?

kenny-luong avatar Jul 01 '24 21:07 kenny-luong

Yeah. I just want to make sure that the dropdown is actually showing the correct volunteers.

That would depend on the type of spec that you are using in a request spec you could

# use nokogiri
html = Nokogiri::HTML(response.body)
select_options = html.css("css selector for values in dropdown").map(&:text)
expect(select_options).to match_array(expected_options)

# directly search for the text string
expect(page.body).to include("Option Text for the select option")

# search for the HTML element
expect(page.body).to include("<option value="some value">Some Value</option>")

in a system spec you could use an all matcher and loop over it to ensure the text in each select is correct.

https://github.com/rubyforgood/casa/blob/f1187e110824c3ebb11f57bfc8669d355c14dfc1/spec/system/court_dates/edit_spec.rb#L46 https://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders#all-instance_method

TLDR

find all the option tags under the select (it maybe be hidden away by the facier js dropdown), check the text content in them.

elasticspoon avatar Jul 01 '24 22:07 elasticspoon

So obviously a volunteer assignment will fail if a case fails to be created but what if the volunteer assignment fails? Should the case still be created?

don't worry about that case. the volunteer is getting assigned in the same transaction as the case creation (because the volunteer part is being passed in as nested attributes). if either part fails the whole thing will roll back.

elasticspoon avatar Jul 01 '24 22:07 elasticspoon

So obviously a volunteer assignment will fail if a case fails to be created but what if the volunteer assignment fails? Should the case still be created?

don't worry about that case. the volunteer is getting assigned in the same transaction as the case creation (because the volunteer part is being passed in as nested attributes). if either part fails the whole thing will roll back.

Oh interesting. I may be performing the volunteer assignment incorrectly then.

What is the preferred way that we assign volunteers to a case?

For reference, this is what I am currently doing

  # app/controllers/casa_cases_controller.rb
  def create
   # ...
    if @casa_case.save
      assign_volunteer_to_case if assigned_volunteer_id

      respond_to do |format|
        format.html { redirect_to @casa_case, notice: "CASA case was successfully created." }
        format.json { render json: @casa_case, status: :created }
      end
    else
    # ...
   end
   
   def assign_volunteer_to_case
    volunteer.case_assignments.new(casa_case_id: @casa_case.id, volunteer_id: assigned_volunteer_id).save!
  end

kenny-luong avatar Jul 01 '24 22:07 kenny-luong

You should be able to pass that all in within the request params. The assignment itself should happen as part of either an update or create request

sorta like this

https://github.com/rubyforgood/casa/blob/f1187e110824c3ebb11f57bfc8669d355c14dfc1/app/views/case_contacts/form/details.html.erb#L73 https://github.com/rubyforgood/casa/blob/f1187e110824c3ebb11f57bfc8669d355c14dfc1/app/values/case_contact_parameters.rb#L18

for reference

https://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

elasticspoon avatar Jul 01 '24 22:07 elasticspoon

I've opened a PR for this issue

kenny-luong avatar Jul 04 '24 18:07 kenny-luong

This issue has been inactive for 246 hours (10.25 days) and will be unassigned after 114 more hours (4.75 days). If you have questions, please

If you are still working on this, comment here to tell the bot to give you more time

github-actions[bot] avatar Jul 15 '24 00:07 github-actions[bot]