diff --git a/app/controllers/organizations/pets_controller.rb b/app/controllers/organizations/pets_controller.rb
index 68462993d..43d0243ee 100644
--- a/app/controllers/organizations/pets_controller.rb
+++ b/app/controllers/organizations/pets_controller.rb
@@ -40,7 +40,10 @@ def create
def update
if pet_in_same_organization?(@pet.organization_id) && @pet.update(pet_params)
- redirect_to @pet, notice: "Pet updated successfully."
+ respond_to do |format|
+ format.html { redirect_to @pet, notice: "Pet updated successfully." }
+ format.turbo_stream if params[:pet][:toggle] == "true"
+ end
else
render :edit, status: :unprocessable_entity
end
@@ -95,6 +98,7 @@ def pet_params
:weight_unit,
:species,
:placement_type,
+ :toggle,
images: [],
files: [])
end
diff --git a/app/models/pet.rb b/app/models/pet.rb
index c0fb7749c..b8deb0a19 100644
--- a/app/models/pet.rb
+++ b/app/models/pet.rb
@@ -77,6 +77,8 @@ class Pet < ApplicationRecord
scope :adopted, -> { Pet.includes(:match).where.not(match: {id: nil}) }
scope :unadopted, -> { Pet.includes(:match).where(match: {id: nil}) }
+ attr_writer :toggle
+
# check if pet has any applications with adoption pending status
def has_adoption_pending?
adopter_applications.any? { |app| app.status == "adoption_pending" }
diff --git a/app/views/organizations/pets/_pause_toggle.html.erb b/app/views/organizations/pets/_pause_toggle.html.erb
new file mode 100644
index 000000000..5ef873deb
--- /dev/null
+++ b/app/views/organizations/pets/_pause_toggle.html.erb
@@ -0,0 +1,12 @@
+
>
+ <%= form_with model: pet do |form| %>
+
+
+ <%= form.hidden_field :application_paused, value: false %>
+ <%= form.hidden_field :toggle, value: 'true' %>
+ <%= form.check_box :application_paused,{ class: "form-check-input",
+ role: "switch", id: "flexSwitchCheckChecked", onchange: "this.form.requestSubmit()"}, true, false %>
+
+
+ <% end %>
+
diff --git a/app/views/organizations/pets/index.html.erb b/app/views/organizations/pets/index.html.erb
index 86eefdfa6..ace533ff0 100644
--- a/app/views/organizations/pets/index.html.erb
+++ b/app/views/organizations/pets/index.html.erb
@@ -1,11 +1,9 @@
<% breadcrumb :dashboard_pets %>
-
<%= render "components/dashboard/page" do |p| %>
<% p.header_title t(".our_pets") %>
<% p.actions do %>
<%= link_to t('.create_pet'), new_pet_path, class: "btn btn-primary" %>
<% end %>
-
<% p.content do %>
@@ -38,7 +36,6 @@
<% end %>
-
@@ -52,7 +49,7 @@
Sex |
Breed |
Weight |
- Status |
+ Pause Applications |
|
@@ -85,7 +82,7 @@
<%= "#{pet.weight_from} - #{pet.weight_to} #{pet.weight_unit}" %>
- <%= pet.application_paused == false ? t('.application.active') : t('.application.paused') %>
+ <%= render 'pause_toggle', pet: pet %>
|
<% if current_user.staff_account %>
@@ -101,15 +98,6 @@
<%= link_to pet_path(pet), class: 'dropdown-item' do %>
Copy link
<% end %>
- <% if pet.application_paused %>
- <%= button_to pet, method: :put, class: 'dropdown-item', params: {pet: {application_paused: false }} do %>
- Resume applications
- <% end %>
- <% else %>
- <%= button_to pet, method: :put, class: 'dropdown-item', params: {pet: {application_paused: true}} do %>
- Pause applications
- <% end %>
- <% end %>
<%= button_to pet, method: :delete, class: 'dropdown-item', data: { turbo_confirm: t('.are_you_sure_delete') } do %>
Delete
<% end %>
diff --git a/app/views/organizations/pets/update.turbo_stream.erb b/app/views/organizations/pets/update.turbo_stream.erb
new file mode 100644
index 000000000..ff88e2d4d
--- /dev/null
+++ b/app/views/organizations/pets/update.turbo_stream.erb
@@ -0,0 +1,2 @@
+<%= turbo_stream.replace "pet_pause_toggle_#{@pet.id}", partial: "pause_toggle",
+locals: {pet: @pet} %>
diff --git a/test/controllers/organizations/pets_controller_test.rb b/test/controllers/organizations/pets_controller_test.rb
index 3d8adfb46..882cfddcf 100644
--- a/test/controllers/organizations/pets_controller_test.rb
+++ b/test/controllers/organizations/pets_controller_test.rb
@@ -43,4 +43,18 @@ class Organizations::PetsControllerTest < ActionDispatch::IntegrationTest
assert_equal URI.decode_www_form(URI.parse(request.url).query).join("="), "active_tab=files"
end
end
+
+ test "update application paused should respond with turbo_stream when toggled on pets page" do
+ patch url_for(@pet), params: {pet: {application_paused: true, toggle: "true"}}, as: :turbo_stream
+
+ assert_equal Mime[:turbo_stream], response.media_type
+ assert_response :success
+ end
+
+ test "update application paused should respond with html when not on pets page" do
+ patch url_for(@pet), params: {pet: {application_paused: true}}, as: :turbo_stream
+
+ assert_equal Mime[:html], response.media_type
+ assert_response :redirect
+ end
end
|