Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/time_regs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create
authorize! @time_reg

if @time_reg.save
redirect_back(fallback_location: time_regs_path, date: @time_reg.date_worked)
redirect_to time_regs_path(date: @time_reg.date_worked)
else
set_assigned_tasks
render :new_modal, status: :unprocessable_entity, formats: [ :html, :turbo_stream ]
Expand All @@ -64,7 +64,7 @@ def create
def update
authorize! @time_reg
if @time_reg.update(time_reg_params.except(:project_id, :minutes_string))
redirect_back(fallback_location: time_regs_path, date: @time_reg.date_worked)
redirect_to time_regs_path(date: @time_reg.date_worked)
else
set_assigned_tasks
render :edit_modal, status: :unprocessable_entity, formats: [ :html, :turbo_stream ]
Expand All @@ -74,7 +74,7 @@ def update
def destroy
authorize! @time_reg
@time_reg.discard!
redirect_back(fallback_location: time_regs_path, date: @time_reg.date_worked)
redirect_to time_regs_path(date: @time_reg.date_worked)

rescue ActiveRecord::RecordNotDestroyed
flash[:alert] = "Unable to delete time registration"
Expand Down
17 changes: 17 additions & 0 deletions app/javascript/controllers/flatpickr_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ export default class extends Flatpickr {
connect() {
super.connect();
this.updateWidth();

// Handle Turbo Morph by reinitializing flatpickr
document.addEventListener('turbo:morph', this.handleTurboMorph);
}

disconnect() {
super.disconnect();
document.removeEventListener('turbo:morph', this.handleTurboMorph);
}

handleTurboMorph = () => {
// Reinitialize flatpickr after Turbo Morph
if (this.fp) {
this.fp.destroy();
}
super.connect();
this.updateWidth();
}

change(selectedDates, dateStr, instance) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/time_regs/_date_picker.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_with url: root_path, method: :get, class: "flex items-stretch" do |form| %>
<%= form.text_field :date, value: @chosen_date, class: "flex text-sm md:text-base px-1 md:px-2 cursor-pointer border-none text-center hover:text-primary-600 z-10 focus:ring-0 font-medium",
<%= form.text_field :date, id: "date_picker_input", value: @chosen_date.iso8601, class: "flex text-sm md:text-base px-1 md:px-2 cursor-pointer border-none text-center hover:text-primary-600 z-10 focus:ring-0 font-medium",
data: {
controller: "flatpickr",
flatpickr_auto_submit_value: true,
Expand Down