mirror of
https://github.com/we-promise/sure.git
synced 2026-05-24 21:14:56 +00:00
- Add Provider::Metadata registry with static display data (region, kind, tier, maturity, logo) for all 11 providers - Add Settings::ProviderCard ViewComponent rendering logo square, name, Beta/Alpha pill, meta line (region · type · tier), tagline, and Connect link - Add connect_form action + route (GET /settings/providers/:key/connect_form) that opens the existing panel partial or config form in a DS::Dialog drawer - Replace the Available accordion loop with a 2-column responsive card grid; empty state when all providers are connected - Fix layout override: use turbo_rails/frame layout for frame requests so the drawer response is not wrapped in the full settings layout (was causing Turbo to pick the empty outer drawer frame instead of the filled one) - Add SyncAllProvidersJob and last_sync_all_attempted_at migration (sync-all throttle support) - Unify Connected + Action needed into a single "Your connections" section; items with warn/err status auto-open - Fix Enable Banking grouping: items with expired sessions were returning :off (Available) instead of :warn (Your connections); gate now checks any? instead of any?(&:session_valid?) - Add reconsent_required locale key for fully-expired EB sessions - Surface Beta/Alpha maturity pills on connected provider accordion rows via new badge: param on settings_section helper - Add i18n taglines for all 11 providers; add connect and empty_available keys Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
180 lines
6.9 KiB
Ruby
180 lines
6.9 KiB
Ruby
module SettingsHelper
|
|
SETTINGS_ORDER = [
|
|
# General section
|
|
{ name: "Accounts", path: :accounts_path },
|
|
{ name: "Bank Sync", path: :settings_providers_path },
|
|
{ name: "Preferences", path: :settings_preferences_path },
|
|
{ name: "Appearance", path: :settings_appearance_path },
|
|
{ name: "Profile Info", path: :settings_profile_path },
|
|
{ name: "Security", path: :settings_security_path },
|
|
{ name: "Payment", path: :settings_payment_path, condition: :not_self_hosted? },
|
|
# Transactions section
|
|
{ name: "Categories", path: :categories_path },
|
|
{ name: "Tags", path: :tags_path },
|
|
{ name: "Rules", path: :rules_path },
|
|
{ name: "Merchants", path: :family_merchants_path },
|
|
{ name: "Recurring", path: :recurring_transactions_path },
|
|
# Advanced section
|
|
{ name: "AI Prompts", path: :settings_ai_prompts_path, condition: :admin_user? },
|
|
{ name: "LLM Usage", path: :settings_llm_usage_path, condition: :admin_user? },
|
|
{ name: "API Key", path: :settings_api_key_path, condition: :admin_user? },
|
|
{ name: "Self-Hosting", path: :settings_hosting_path, condition: :self_hosted_and_admin? },
|
|
{ name: "Imports", path: :imports_path, condition: :admin_user? },
|
|
{ name: "Exports", path: :family_exports_path, condition: :admin_user? },
|
|
# More section
|
|
{ name: "Guides", path: :settings_guides_path },
|
|
{ name: "What's new", path: :changelog_path },
|
|
{ name: "Feedback", path: :feedback_path }
|
|
]
|
|
|
|
def adjacent_setting(current_path, offset)
|
|
visible_settings = SETTINGS_ORDER.select { |setting| setting[:condition].nil? || send(setting[:condition]) }
|
|
current_index = visible_settings.index { |setting| send(setting[:path]) == current_path }
|
|
return nil unless current_index
|
|
|
|
adjacent_index = current_index + offset
|
|
return nil if adjacent_index < 0 || adjacent_index >= visible_settings.size
|
|
|
|
adjacent = visible_settings[adjacent_index]
|
|
|
|
render partial: "settings/settings_nav_link_large", locals: {
|
|
path: send(adjacent[:path]),
|
|
direction: offset > 0 ? "next" : "previous",
|
|
title: adjacent[:name]
|
|
}
|
|
end
|
|
|
|
def settings_section(title:, subtitle: nil, collapsible: false, open: true, auto_open_param: nil, status: nil, meta: nil, actions: nil, badge: nil, &block)
|
|
content = capture(&block)
|
|
render partial: "settings/section", locals: { title: title, subtitle: subtitle, content: content, collapsible: collapsible, open: open, auto_open_param: auto_open_param, status: status, meta: meta, actions: actions, badge: badge }
|
|
end
|
|
|
|
def provider_summary(provider_key)
|
|
key = provider_key.to_s.downcase
|
|
|
|
case key
|
|
when "plaid"
|
|
plaid_configured = @provider_configurations&.find { |c| c.provider_key.to_s.casecmp("plaid").zero? }&.configured?
|
|
plaid_configured ? { status: :ok } : { status: :off }
|
|
when "simplefin"
|
|
return { status: :off } unless @simplefin_items&.any?
|
|
sync_based_summary(key)
|
|
when "lunchflow"
|
|
return { status: :off } unless @lunchflow_items&.any?
|
|
sync_based_summary(key)
|
|
when "enable_banking"
|
|
return { status: :off } unless @enable_banking_items&.any?
|
|
enable_banking_summary
|
|
when "coinstats"
|
|
return { status: :off } unless @coinstats_items&.any?
|
|
sync_based_summary(key)
|
|
when "mercury"
|
|
return { status: :off } unless @mercury_items&.any?
|
|
sync_based_summary(key)
|
|
when "coinbase"
|
|
return { status: :off } unless @coinbase_items&.any?
|
|
sync_based_summary(key)
|
|
when "binance"
|
|
return { status: :off } unless @binance_items&.any?
|
|
sync_based_summary(key)
|
|
when "snaptrade"
|
|
configured_item = @snaptrade_items&.find(&:credentials_configured?)
|
|
return { status: :off } unless configured_item
|
|
unless configured_item.user_registered?
|
|
return { status: :warn, meta: t("settings.providers.meta.registration_needed") }
|
|
end
|
|
sync_based_summary(key)
|
|
when "indexa_capital"
|
|
return { status: :off } unless @indexa_capital_items&.any?
|
|
sync_based_summary(key)
|
|
when "sophtron"
|
|
return { status: :off } unless @sophtron_items&.any?
|
|
sync_based_summary(key)
|
|
else
|
|
{ status: :off }
|
|
end
|
|
end
|
|
|
|
def settings_nav_footer
|
|
previous_setting = adjacent_setting(request.path, -1)
|
|
next_setting = adjacent_setting(request.path, 1)
|
|
|
|
content_tag :div, class: "hidden md:flex flex-row justify-between gap-4" do
|
|
concat(previous_setting)
|
|
concat(next_setting)
|
|
end
|
|
end
|
|
|
|
def settings_nav_footer_mobile
|
|
previous_setting = adjacent_setting(request.path, -1)
|
|
next_setting = adjacent_setting(request.path, 1)
|
|
|
|
content_tag :div, class: "md:hidden flex flex-col gap-4 pb-[env(safe-area-inset-bottom)]" do
|
|
concat(previous_setting)
|
|
concat(next_setting)
|
|
end
|
|
end
|
|
|
|
private
|
|
def sync_based_summary(provider_key)
|
|
health = @provider_sync_health&.dig(provider_key) || {}
|
|
last_synced_at = health[:last_synced_at]
|
|
|
|
base = if health[:error]
|
|
{ status: :err, meta: t("settings.providers.meta.sync_error") }
|
|
elsif health[:stale]
|
|
{ status: :warn, meta: t("settings.providers.meta.no_recent_sync") }
|
|
elsif last_synced_at.present?
|
|
{ status: :ok, meta: t("settings.providers.meta.last_synced", time: time_ago_in_words(last_synced_at)) }
|
|
else
|
|
{ status: :ok }
|
|
end
|
|
|
|
base.merge(last_synced_at: last_synced_at)
|
|
end
|
|
|
|
def enable_banking_summary
|
|
health = @provider_sync_health&.dig("enable_banking") || {}
|
|
last_synced_at = health[:last_synced_at]
|
|
|
|
return { status: :err, meta: t("settings.providers.meta.sync_error"), last_synced_at: nil } if health[:error]
|
|
|
|
valid_items = @enable_banking_items&.select(&:session_valid?) || []
|
|
|
|
# All items have expired/missing sessions — need re-authorization
|
|
if valid_items.empty?
|
|
return { status: :warn, meta: t("settings.providers.meta.reconsent_required"), last_synced_at: last_synced_at }
|
|
end
|
|
|
|
expiring = valid_items.find do |item|
|
|
item.session_expires_at.present? && item.session_expires_at < 7.days.from_now
|
|
end
|
|
|
|
if expiring
|
|
days = [ ((expiring.session_expires_at - Time.current) / 1.day).ceil, 1 ].max
|
|
return { status: :warn, meta: t("settings.providers.meta.reconsent_needed", count: days), last_synced_at: last_synced_at }
|
|
end
|
|
|
|
return { status: :warn, meta: t("settings.providers.meta.no_recent_sync"), last_synced_at: last_synced_at } if health[:stale]
|
|
|
|
if last_synced_at.present?
|
|
{ status: :ok, meta: t("settings.providers.meta.last_synced", time: time_ago_in_words(last_synced_at)), last_synced_at: last_synced_at }
|
|
else
|
|
{ status: :ok, last_synced_at: nil }
|
|
end
|
|
end
|
|
|
|
def not_self_hosted?
|
|
!self_hosted?
|
|
end
|
|
|
|
# Helper used by SETTINGS_ORDER conditions
|
|
def admin_user?
|
|
Current.user&.admin?
|
|
end
|
|
|
|
def self_hosted_and_admin?
|
|
self_hosted? && admin_user?
|
|
end
|
|
end
|