rubyforgood / casa

Volunteer management system for nonprofit CASA, which serves foster youth in counties across America.
https://casavolunteertracking.org/
MIT License
304 stars 472 forks source link

Improve Volunteer Assignment when creating a new case #5757

Closed elasticspoon closed 2 months ago

elasticspoon commented 4 months ago

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

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:

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.

wandergithub commented 3 months ago

can I work on this?

bcastillo32 commented 3 months ago

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 :)

wandergithub commented 3 months ago

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.

kenny-luong commented 3 months ago

Happy to work on this

kenny-luong commented 2 months ago

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

elasticspoon commented 2 months ago

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?

kenny-luong commented 2 months ago

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 commented 2 months ago

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?

elasticspoon commented 2 months ago

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 commented 2 months ago

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.

kenny-luong commented 2 months ago

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
elasticspoon commented 2 months ago

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

kenny-luong commented 2 months ago

I've opened a PR for this issue

github-actions[bot] commented 2 months ago

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