diff --git a/app/controllers/assignments/toggles_controller.rb b/app/controllers/assignments/toggles_controller.rb index a2285b35e..08562dde4 100644 --- a/app/controllers/assignments/toggles_controller.rb +++ b/app/controllers/assignments/toggles_controller.rb @@ -1,6 +1,10 @@ class Assignments::TogglesController < ApplicationController include BubbleScoped, BucketScoped + def new + render partial: "bubbles/sidebar/assignment", locals: { bubble: @bubble } + end + def create new_assignee_ids = Array(params[:assignee_id]) current_assignees = @bubble.assignees @@ -14,7 +18,15 @@ class Assignments::TogglesController < ApplicationController @bubble.toggle_assignment(assignee) unless current_assignees.include?(assignee) end - redirect_to @bubble + @bubble.assignees.reload + + respond_to do |format| + format.turbo_stream do + render turbo_stream: turbo_stream.replace([ @bubble, :assignees ], + partial: "bubbles/assignees", + locals: { bubble: @bubble }) + end + end end private diff --git a/app/views/bubbles/_assignees.html.erb b/app/views/bubbles/_assignees.html.erb new file mode 100644 index 000000000..d6af2a636 --- /dev/null +++ b/app/views/bubbles/_assignees.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag bubble, :assignees do %> +
+ <% bubble.assignees.each do |assignee| %> + <%= avatar_tag assignee, loading: :lazy, class: "avatar" %> + <% end %> + +
+ + + <%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) %> +
+
+<% end %> diff --git a/app/views/bubbles/_people.html.erb b/app/views/bubbles/_people.html.erb index daf4e311f..68268ce55 100644 --- a/app/views/bubbles/_people.html.erb +++ b/app/views/bubbles/_people.html.erb @@ -6,12 +6,7 @@
Assigned -
- <% bubble.assignees.each do |assignee| %> - <%= avatar_tag assignee, loading: :lazy, class: "avatar" %> - <% end %> - <%= render "bubbles/sidebar/assignment", bubble: bubble, users: bubble.bucket.users.active %> -
+ <%= render "bubbles/assignees", bubble: bubble %>
- \ No newline at end of file + diff --git a/app/views/bubbles/sidebar/_assignment.html.erb b/app/views/bubbles/sidebar/_assignment.html.erb index 8610cf086..1c6f223b4 100644 --- a/app/views/bubbles/sidebar/_assignment.html.erb +++ b/app/views/bubbles/sidebar/_assignment.html.erb @@ -1,26 +1,23 @@ -
- +<% cache [bubble, bubble.bucket] do %> + <%= turbo_frame_tag bubble, :assignment do %> + + Assign this to… - - Assign this to… + <%= form_with url: bucket_bubble_assignment_toggles_path(bubble.bucket, bubble), class: "flex flex-column full-width popup__list", data: { controller: "form" } do |form| %> + <% bubble.bucket.users.active.sort_by(&:name).each do |user| %> + + <% end %> <% end %> - <% end %> - -
+ + <% end %> +<% end %> diff --git a/test/controllers/assignments/toggles_controller_test.rb b/test/controllers/assignments/toggles_controller_test.rb index 6579ad0df..3a1d4fcdb 100644 --- a/test/controllers/assignments/toggles_controller_test.rb +++ b/test/controllers/assignments/toggles_controller_test.rb @@ -5,15 +5,21 @@ class Assignments::TogglesControllerTest < ActionDispatch::IntegrationTest sign_in_as :kevin end + test "new" do + get new_bucket_bubble_assignment_toggle_url(buckets(:writebook), bubbles(:logo)) + + assert_response :success + end + test "create" do assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: false, to: true do - post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id } + post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id }, as: :turbo_stream end - assert_redirected_to bubbles(:logo) + assert_response :success assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: true, to: false do - post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id } + post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id }, as: :turbo_stream end - assert_redirected_to bubbles(:logo) + assert_response :success end end