2025-04-14 11:40:34 -04:00
|
|
|
class TransactionCategoriesController < ApplicationController
|
2025-04-18 11:39:58 -04:00
|
|
|
include ActionView::RecordIdentifier
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
def update
|
|
|
|
@entry = Current.family.entries.transactions.find(params[:transaction_id])
|
|
|
|
@entry.update!(entry_params)
|
|
|
|
|
2025-04-18 11:39:58 -04:00
|
|
|
transaction = @entry.transaction
|
|
|
|
|
|
|
|
if needs_rule_notification?(transaction)
|
|
|
|
flash[:cta] = {
|
|
|
|
type: "category_rule",
|
|
|
|
category_id: transaction.category_id,
|
|
|
|
category_name: transaction.category.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
transaction.lock_saved_attributes!
|
|
|
|
@entry.lock_saved_attributes!
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_back_or_to transaction_path(@entry) }
|
|
|
|
format.turbo_stream do
|
2025-04-18 11:39:58 -04:00
|
|
|
render turbo_stream: [
|
|
|
|
turbo_stream.replace(
|
|
|
|
dom_id(transaction, :category_menu),
|
|
|
|
partial: "categories/menu",
|
|
|
|
locals: { transaction: transaction }
|
|
|
|
),
|
|
|
|
*flash_notification_stream_items
|
|
|
|
]
|
2025-04-14 11:40:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def entry_params
|
|
|
|
params.require(:entry).permit(:entryable_type, entryable_attributes: [ :id, :category_id ])
|
|
|
|
end
|
2025-04-18 11:39:58 -04:00
|
|
|
|
|
|
|
def needs_rule_notification?(transaction)
|
|
|
|
return false if Current.user.rule_prompts_disabled
|
|
|
|
|
|
|
|
if Current.user.rule_prompt_dismissed_at.present?
|
|
|
|
time_since_last_rule_prompt = Time.current - Current.user.rule_prompt_dismissed_at
|
|
|
|
return false if time_since_last_rule_prompt < 1.day
|
|
|
|
end
|
|
|
|
|
|
|
|
transaction.saved_change_to_category_id? &&
|
|
|
|
transaction.eligible_for_category_rule?
|
|
|
|
end
|
2025-04-14 11:40:34 -04:00
|
|
|
end
|