mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
The "Add $1,531.25" CTA used to open the contribution modal with an empty amount field — label was a hint, not a default. Now passes the catch-up amount via ?amount= and the contributions controller seeds @contribution.amount from params. One click brings the user to the modal already populated. Adds a secondary text link below the primary CTA: "Or adjust your target" → opens the edit modal (Turbo frame). Behavioural-econ choice architecture: gives the rebaseline path explicitly so users who can't realistically catch up don't feel forced into the contribution. Trade-off: lets the alert respect autonomy — commit or recalibrate, both fine. Action paralysis kept low by visual hierarchy (primary button vs muted text link).
65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
class GoalContributionsController < ApplicationController
|
|
before_action :set_goal
|
|
before_action :set_contribution, only: :destroy
|
|
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
|
|
|
def new
|
|
@contribution = @goal.goal_contributions.new(
|
|
contributed_at: Date.current,
|
|
currency: @goal.currency,
|
|
source: "manual",
|
|
amount: params[:amount].presence
|
|
)
|
|
end
|
|
|
|
def create
|
|
@contribution = @goal.goal_contributions.new(contribution_params.merge(source: "manual"))
|
|
@contribution.account = lookup_account(params.dig(:goal_contribution, :account_id))
|
|
@contribution.currency = @goal.currency
|
|
|
|
if @contribution.save
|
|
flash[:notice] = t(".success")
|
|
respond_to do |format|
|
|
format.html { redirect_to goal_path(@goal) }
|
|
format.turbo_stream do
|
|
render turbo_stream: turbo_stream.action(:redirect, goal_path(@goal))
|
|
end
|
|
end
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @contribution.initial?
|
|
redirect_to goal_path(@goal), alert: t(".initial_not_deletable")
|
|
return
|
|
end
|
|
|
|
@contribution.destroy!
|
|
redirect_to goal_path(@goal), notice: t(".success")
|
|
end
|
|
|
|
private
|
|
def set_goal
|
|
@goal = Current.family.goals.find(params[:goal_id])
|
|
end
|
|
|
|
def set_contribution
|
|
@contribution = @goal.goal_contributions.find(params[:id])
|
|
end
|
|
|
|
def contribution_params
|
|
params.require(:goal_contribution).permit(:amount, :contributed_at, :notes)
|
|
end
|
|
|
|
def lookup_account(id)
|
|
return nil if id.blank?
|
|
@goal.linked_accounts.find_by(id: id)
|
|
end
|
|
|
|
def record_not_found
|
|
redirect_to goals_path, alert: t("goals.errors.not_found")
|
|
end
|
|
end
|