-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add edit/update views for appointment
we are not checking who is allowed to edit in the appointment partial yet
- Loading branch information
Showing
6 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
class AppointmentsController < ApplicationController | ||
helper_method :appointments | ||
helper_method :appointments, :appointment | ||
|
||
def index | ||
before_action :check_created_by, only: [:edit, :update] | ||
|
||
def update | ||
if appointment.update(appointment_params) | ||
redirect_to appointments_path, notice: "Appointment updated!" | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_created_by | ||
unless appointment.created_by?(Current.user) | ||
redirect_to appointments_path, alert: "Can't modify appointment - you are not the creator." | ||
end | ||
end | ||
|
||
def appointment_params | ||
params.require(:appointment).permit( | ||
:requested_datetime, | ||
:notes | ||
) | ||
end | ||
|
||
def appointment | ||
@appointment ||= Appointment.find(params[:id]) | ||
end | ||
|
||
def appointments | ||
@appointments ||= Appointment.all | ||
@appointments ||= Appointment.includes(:created_by).all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
<div> | ||
<%= appointment.requested_datetime %> | ||
<%= appointment.notes %> | ||
<%= appointment.created_by_user_id %> | ||
</div> | ||
<%= turbo_frame_tag(appointment) do %> | ||
<div class="flex flex-wrap items-center justify-between gap-x-6 gap-y-4 py-5 sm:flex-nowrap"> | ||
<div> | ||
<p class="text-sm/6 font-semibold text-gray-900"> | ||
<a href="#" class="hover:underline">Requested Time - <%= appointment.requested_datetime.strftime("%B %-d %Y at %I:%H%P") %></a> | ||
</p> | ||
<div class="mt-1 flex flex-col text-xs/5"> | ||
<p class="text-gray-400"> | ||
<%= truncate(appointment.notes, length: 40) %> | ||
</p> | ||
<div class="flex gap-x-4 text-gray-500"> | ||
<a href="#" class="hover:underline"><%= appointment.created_by.email_address %></a> | ||
<time datetime="<%= appointment.updated_at %>"> | ||
<%= distance_of_time_in_words_to_now(appointment.updated_at, include_seconds: false) %> ago | ||
</time> | ||
</div> | ||
</div> | ||
</div> | ||
<dl class="flex w-full flex-none justify-between gap-x-8 sm:w-auto"> | ||
<div class="flex w-16 gap-x-2.5"> | ||
<span class="sr-only">Actions</span> | ||
<%= link_to "Edit", edit_appointment_path(appointment), class: "text-xs text-indigo-500 hover:text-indigo-400", data: { turbo: false } %> | ||
</div> | ||
</dl> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="flex flex-col mx-auto"> | ||
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Edit Appointment</h1> | ||
|
||
<%= form_for appointment, html: { class: "mt-12" } do |f| %> | ||
<div class="flex flex-col gap-y-4"> | ||
<div class="flex flex-col"> | ||
<%= f.label :requested_datetime, class: "font-semibold" %> | ||
<%= f.datetime_field :requested_datetime %> | ||
</div> | ||
|
||
<div class="flex flex-col"> | ||
<%= f.label :notes, class: "font-semibold" %> | ||
<%= f.text_area :notes, cols: 40, rows: 10 %> | ||
</div> | ||
|
||
<%= f.submit class: "rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<h1>Appointments</h1> | ||
<div class="flex flex-col mx-auto"> | ||
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Appointments</h1> | ||
|
||
<%= render appointments, as: :appointment %> | ||
<div role="list" class="flex flex-col divide-y divide-gray-100"> | ||
<%= render appointments, as: :appointment %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters