Skip to content

Commit 51acdb3

Browse files
committed
feat: broadcast appointments list updates on save
this is the broken state. Current.user will always be nil and therefore, the edit link will fail to render for all attached clients
1 parent 210ef3e commit 51acdb3

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

app/models/appointment.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ class Appointment < ApplicationRecord
33

44
validates :requested_datetime, presence: true
55

6+
after_save_commit -> {
7+
broadcast_replace_to(
8+
"appointments_list",
9+
partial: "appointments/appointment",
10+
locals: { appointment: self }
11+
)
12+
}
13+
614
def created_by?(user)
715
created_by == user
816
end

app/views/appointments/_appointment.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<dl class="flex w-full flex-none justify-between gap-x-8 sm:w-auto">
2020
<div class="flex w-16 gap-x-2.5">
2121
<span class="sr-only">Actions</span>
22-
<%= link_to "Edit", edit_appointment_path(appointment), class: "text-xs text-indigo-500 hover:text-indigo-400", data: { turbo: false } %>
22+
<% if appointment.created_by?(Current.user) %>
23+
<%= link_to "Edit", edit_appointment_path(appointment), class: "text-xs text-indigo-500 hover:text-indigo-400", data: { turbo: false } %>
24+
<% end %>
2325
</div>
2426
</dl>
2527
</div>

app/views/appointments/index.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<%= turbo_stream_from "appointments_list" %>
2+
13
<div class="flex flex-col mx-auto">
24
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Appointments</h1>
35

0 commit comments

Comments
 (0)