diff --git a/app/javascript/controllers/savings_goal_stepper_controller.js b/app/javascript/controllers/savings_goal_stepper_controller.js index 796ee058f..b4faa2990 100644 --- a/app/javascript/controllers/savings_goal_stepper_controller.js +++ b/app/javascript/controllers/savings_goal_stepper_controller.js @@ -15,6 +15,9 @@ export default class extends Controller { "step2Circle", "stepperLine", "modalSubtitle", + "nameInput", + "amountInput", + "avatarPreview", "linkedAccountCheckbox", "initialContributionAmount", "initialContributionAccountSelect", @@ -23,7 +26,6 @@ export default class extends Controller { "reviewAccounts", "reviewSuggested", "footerLeftButton", - "footerLeftLabel", "footerRightButton", "submitButton", ]; @@ -91,6 +93,14 @@ export default class extends Controller { this.updateReview(); } + nameChanged() { + if (!this.hasAvatarPreviewTarget || !this.hasNameInputTarget) return; + const name = this.nameInputTarget.value.trim(); + const initial = name ? name.charAt(0).toUpperCase() : "?"; + const inner = this.avatarPreviewTarget.querySelector('[data-testid="savings-goal-avatar"]'); + if (inner) inner.textContent = initial; + } + validateStep1() { const requiredInputs = this.step1PanelTarget.querySelectorAll( 'input[name="savings_goal[name]"], input[name="savings_goal[target_amount]"]' @@ -163,9 +173,12 @@ export default class extends Controller { } updateFooter() { - if (this.hasFooterLeftLabelTarget) { - this.footerLeftLabelTarget.textContent = - this.currentStep === 1 ? this.cancelLabelValue : this.backLabelValue; + if (this.hasFooterLeftButtonTarget) { + const labelSpan = this.footerLeftButtonTarget.querySelector("span"); + if (labelSpan) { + labelSpan.textContent = + this.currentStep === 1 ? this.cancelLabelValue : this.backLabelValue; + } } if (this.hasFooterRightButtonTarget) { const labelSpan = this.footerRightButtonTarget.querySelector("span"); diff --git a/app/views/savings_goals/_form_stepper.html.erb b/app/views/savings_goals/_form_stepper.html.erb index 1f29bfae6..064ef1446 100644 --- a/app/views/savings_goals/_form_stepper.html.erb +++ b/app/views/savings_goals/_form_stepper.html.erb @@ -27,9 +27,9 @@
-
- - <%= render DS::FilledIcon.new(variant: :container, icon: "target", size: "lg", rounded: false) %> +
+ + <%= render Savings::GoalAvatarComponent.new(name: savings_goal.name, color: savings_goal.color, size: "md") %> <%= f.text_field :name, placeholder: t("savings_goals.form_stepper.step1.fields.name_placeholder"), @@ -160,13 +160,14 @@
- + <%= render DS::Button.new( + variant: "ghost", + text: t("savings_goals.form_stepper.cancel"), + data: { + savings_goal_stepper_target: "footerLeftButton", + action: "click->savings-goal-stepper#footerLeft" + } + ) %> <%= render DS::Button.new( text: t("savings_goals.form_stepper.continue"), variant: "primary", diff --git a/app/views/savings_goals/new.html.erb b/app/views/savings_goals/new.html.erb index 3b445a0aa..9fc55b7e6 100644 --- a/app/views/savings_goals/new.html.erb +++ b/app/views/savings_goals/new.html.erb @@ -2,7 +2,7 @@ <% dialog.with_header(custom_header: true) do %>
- <%= render DS::FilledIcon.new(variant: :container, icon: "target", size: "lg", rounded: false) %> + <%= render DS::FilledIcon.new(variant: :container, icon: "target", size: "md", rounded: true) %>

<%= t(".heading") %>