diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index 0bbad7abe..d462d98bb 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -394,13 +394,6 @@ class TransactionsController < ApplicationController end end - def update_preferences - Current.user.update_transactions_preferences(preferences_params) - head :ok - rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved - head :unprocessable_entity - end - def exchange_rate account = Current.family.accounts.find(params[:account_id]) currency_from = params[:currency] @@ -584,10 +577,6 @@ class TransactionsController < ApplicationController Current.session.prev_transaction_page_params end - def preferences_params - params.require(:preferences).permit(collapsed_sections: {}) - end - # Helper methods for convert_to_trade def resolve_security_for_conversion diff --git a/app/javascript/controllers/transactions_section_controller.js b/app/javascript/controllers/transactions_section_controller.js deleted file mode 100644 index 67915a549..000000000 --- a/app/javascript/controllers/transactions_section_controller.js +++ /dev/null @@ -1,96 +0,0 @@ -import { Controller } from "@hotwired/stimulus"; - -export default class extends Controller { - static targets = ["content", "chevron", "button"]; - static values = { - sectionKey: String, - collapsed: Boolean, - }; - - connect() { - if (this.collapsedValue) { - this.collapse(false); - } - } - - toggle(event) { - event.preventDefault(); - if (this.collapsedValue) { - this.expand(); - } else { - this.collapse(); - } - } - - handleToggleKeydown(event) { - // Handle Enter and Space keys for keyboard accessibility - if (event.key === "Enter" || event.key === " ") { - event.preventDefault(); - event.stopPropagation(); - this.toggle(event); - } - } - - collapse(persist = true) { - this.contentTarget.classList.add("hidden"); - this.chevronTarget.classList.add("-rotate-90"); - this.collapsedValue = true; - if (this.hasButtonTarget) { - this.buttonTarget.setAttribute("aria-expanded", "false"); - } - if (persist) { - this.savePreference(true); - } - } - - expand() { - this.contentTarget.classList.remove("hidden"); - this.chevronTarget.classList.remove("-rotate-90"); - this.collapsedValue = false; - if (this.hasButtonTarget) { - this.buttonTarget.setAttribute("aria-expanded", "true"); - } - this.savePreference(false); - } - - async savePreference(collapsed) { - const preferences = { - collapsed_sections: { - [this.sectionKeyValue]: collapsed, - }, - }; - - const csrfToken = document.querySelector('meta[name="csrf-token"]'); - if (!csrfToken) { - console.error( - "[Transactions Section] CSRF token not found. Cannot save preferences.", - ); - return; - } - - try { - const response = await fetch("/transactions/update_preferences", { - method: "PATCH", - headers: { - "Content-Type": "application/json", - "X-CSRF-Token": csrfToken.content, - }, - body: JSON.stringify({ preferences }), - }); - - if (!response.ok) { - const errorData = await response.json().catch(() => ({})); - console.error( - "[Transactions Section] Failed to save preferences:", - response.status, - errorData, - ); - } - } catch (error) { - console.error( - "[Transactions Section] Network error saving preferences:", - error, - ); - } - } -} diff --git a/app/models/user.rb b/app/models/user.rb index efc435b3b..e068a3a4c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -385,10 +385,6 @@ class User < ApplicationRecord end # Transactions preferences management - def transactions_section_collapsed?(section_key) - preferences&.dig("transactions_collapsed_sections", section_key) == true - end - def show_split_grouped? preferences&.dig("show_split_grouped") != false end @@ -405,24 +401,6 @@ class User < ApplicationRecord preferences&.dig("preview_features_enabled") == true end - def update_transactions_preferences(prefs) - transaction do - lock! - - updated_prefs = (preferences || {}).deep_dup - prefs.each do |key, value| - if value.is_a?(Hash) - updated_prefs["transactions_#{key}"] ||= {} - updated_prefs["transactions_#{key}"] = updated_prefs["transactions_#{key}"].merge(value) - else - updated_prefs["transactions_#{key}"] = value - end - end - - update!(preferences: updated_prefs) - end - end - private def apply_ui_layout_defaults self.ui_layout = (ui_layout.presence || self.class.default_ui_layout) diff --git a/config/routes.rb b/config/routes.rb index f6ffcd6ba..8f3e79116 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -481,7 +481,6 @@ Rails.application.routes.draw do collection do delete :clear_filter - patch :update_preferences end member do