mirror of
https://github.com/we-promise/sure.git
synced 2026-04-28 00:14:23 +00:00
Add user-friendly toggle for auto-rule creation prompts
Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Agent-Logs-Url: https://github.com/we-promise/sure/sessions/3fa633b4-7cdf-4320-8e6d-83e2cb2c5e49
This commit is contained in:
@@ -108,7 +108,7 @@ class UsersController < ApplicationController
|
||||
def user_params
|
||||
params.require(:user).permit(
|
||||
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at,
|
||||
:show_sidebar, :default_period, :default_account_order, :show_ai_sidebar, :ai_enabled, :theme, :set_onboarding_preferences_at, :set_onboarding_goals_at, :locale,
|
||||
:show_sidebar, :default_period, :default_account_order, :show_ai_sidebar, :ai_enabled, :theme, :set_onboarding_preferences_at, :set_onboarding_goals_at, :locale, :rule_prompts_enabled,
|
||||
family_attributes: [ :name, :currency, :country, :date_format, :timezone, :locale, :month_start_day, :moniker, :id ],
|
||||
goals: []
|
||||
)
|
||||
|
||||
@@ -311,6 +311,15 @@ class User < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# Virtual attribute for UI: inverts rule_prompts_disabled for a more intuitive toggle
|
||||
def rule_prompts_enabled
|
||||
!rule_prompts_disabled
|
||||
end
|
||||
|
||||
def rule_prompts_enabled=(value)
|
||||
self.rule_prompts_disabled = !ActiveModel::Type::Boolean.new.cast(value)
|
||||
end
|
||||
|
||||
# Transactions preferences management
|
||||
def transactions_section_collapsed?(section_key)
|
||||
preferences&.dig("transactions_collapsed_sections", section_key) == true
|
||||
|
||||
@@ -56,3 +56,17 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= settings_section title: t(".automation_title"), subtitle: t(".automation_subtitle") do %>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="space-y-1">
|
||||
<p class="text-sm"><%= t(".rule_prompts_label") %></p>
|
||||
<p class="text-secondary text-sm"><%= t(".rule_prompts_hint") %></p>
|
||||
</div>
|
||||
|
||||
<%= styled_form_with model: @user, data: { controller: "auto-submit-form" } do |form| %>
|
||||
<%= form.hidden_field :redirect_to, value: "preferences" %>
|
||||
<%= form.toggle :rule_prompts_enabled, data: { auto_submit_form_target: "auto" } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -54,6 +54,10 @@ en:
|
||||
month_start_day: Budget month starts on
|
||||
month_start_day_hint: Set when your budget month starts (e.g., payday)
|
||||
month_start_day_warning: Your budgets and MTD calculations will use this custom start day instead of the 1st of each month.
|
||||
automation_title: Automation
|
||||
automation_subtitle: Control automatic behavior
|
||||
rule_prompts_label: Auto-suggest rules when categorizing
|
||||
rule_prompts_hint: Show a prompt to create a rule when you assign a category to a transaction
|
||||
profiles:
|
||||
destroy:
|
||||
cannot_remove_self: You cannot remove yourself from the account.
|
||||
|
||||
@@ -501,4 +501,28 @@ class UserTest < ActiveSupport::TestCase
|
||||
assert_not Family.exists?(family.id)
|
||||
assert_not ActiveStorage::Attachment.exists?(export_attachment_id)
|
||||
end
|
||||
|
||||
test "rule_prompts_enabled returns inverse of rule_prompts_disabled" do
|
||||
@user.rule_prompts_disabled = false
|
||||
assert @user.rule_prompts_enabled
|
||||
|
||||
@user.rule_prompts_disabled = true
|
||||
assert_not @user.rule_prompts_enabled
|
||||
end
|
||||
|
||||
test "setting rule_prompts_enabled updates rule_prompts_disabled" do
|
||||
@user.rule_prompts_enabled = true
|
||||
assert_not @user.rule_prompts_disabled
|
||||
|
||||
@user.rule_prompts_enabled = false
|
||||
assert @user.rule_prompts_disabled
|
||||
end
|
||||
|
||||
test "rule_prompts_enabled= coerces string values correctly" do
|
||||
@user.rule_prompts_enabled = "1"
|
||||
assert_not @user.rule_prompts_disabled
|
||||
|
||||
@user.rule_prompts_enabled = "0"
|
||||
assert @user.rule_prompts_disabled
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user