diff --git a/app/components/goals/avatar_component.html.erb b/app/components/goals/avatar_component.html.erb index 1c210577a..7cb9d7a09 100644 --- a/app/components/goals/avatar_component.html.erb +++ b/app/components/goals/avatar_component.html.erb @@ -1,6 +1,10 @@ - diff --git a/app/components/goals/avatar_component.rb b/app/components/goals/avatar_component.rb index b95d2ca2d..562edfee0 100644 --- a/app/components/goals/avatar_component.rb +++ b/app/components/goals/avatar_component.rb @@ -16,20 +16,30 @@ class Goals::AvatarComponent < ApplicationComponent PALETTE[Digest::MD5.hexdigest(name).to_i(16) % PALETTE.size] end - def initialize(goal: nil, name: nil, color: nil, size: "md") + def initialize(goal: nil, name: nil, color: nil, icon: nil, size: "md") @goal = goal @name = name || goal&.name @color = color || goal&.color || Goal::COLORS.first + @icon = icon || goal&.icon @size = SIZES.key?(size) ? size : "md" end - attr_reader :color + attr_reader :color, :icon def initial return "?" if @name.blank? @name.strip.first&.upcase || "?" end + def icon_size + case @size + when "sm" then "xs" + when "md" then "sm" + when "lg" then "md" + when "xl" then "xl" + end + end + def box_classes SIZES[@size][:box] end diff --git a/app/controllers/goals_controller.rb b/app/controllers/goals_controller.rb index 3105a4c9a..10f456693 100644 --- a/app/controllers/goals_controller.rb +++ b/app/controllers/goals_controller.rb @@ -154,11 +154,11 @@ class GoalsController < ApplicationController end def goal_params - params.require(:goal).permit(:name, :target_amount, :target_date, :color, :notes) + params.require(:goal).permit(:name, :target_amount, :target_date, :color, :icon, :notes) end def goal_update_params - params.require(:goal).permit(:name, :target_amount, :target_date, :color, :notes) + params.require(:goal).permit(:name, :target_amount, :target_date, :color, :icon, :notes) end def lookup_accounts(ids) diff --git a/app/javascript/controllers/category_controller.js b/app/javascript/controllers/color_icon_picker_controller.js similarity index 100% rename from app/javascript/controllers/category_controller.js rename to app/javascript/controllers/color_icon_picker_controller.js diff --git a/app/models/goal.rb b/app/models/goal.rb index b17deda73..ae819e79c 100644 --- a/app/models/goal.rb +++ b/app/models/goal.rb @@ -2,11 +2,14 @@ class Goal < ApplicationRecord include AASM, Monetizable COLORS = Category::COLORS + ICONS = Category.icon_codes # Virtual attributes used by the create-modal stepper to capture an # optional initial contribution alongside the goal create payload. attr_accessor :initial_contribution_amount, :initial_contribution_account_id + validates :icon, inclusion: { in: ICONS, allow_nil: true } + belongs_to :family has_many :goal_accounts, dependent: :destroy has_many :linked_accounts, through: :goal_accounts, source: :account diff --git a/app/views/categories/_color_avatar.html.erb b/app/views/categories/_color_avatar.html.erb index b8cde18ae..8e690c3b8 100644 --- a/app/views/categories/_color_avatar.html.erb +++ b/app/views/categories/_color_avatar.html.erb @@ -1,7 +1,7 @@ <%# locals: (category:) %> <%= icon(category.lucide_icon, size: "2xl", color: "current") %> diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index 1577f8eb4..115a7d61e 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -1,39 +1,39 @@ <%# locals: (category:, categories:) %> -
+
<%= styled_form_with model: category, class: "space-y-4" do |f| %>
<%= render partial: "color_avatar", locals: { category: category } %> -
+
<%= icon("pen", size: "sm") %> -
-
"> -
+
+
"> +

Color

-
+
<% Category::COLORS.each do |color| %> <% end %>
-
diff --git a/app/views/goals/_color_picker.html.erb b/app/views/goals/_color_picker.html.erb index 35d3d9481..cc152c80c 100644 --- a/app/views/goals/_color_picker.html.erb +++ b/app/views/goals/_color_picker.html.erb @@ -1,17 +1,64 @@ -<%# locals: (form:, colors:) %> -
- - <%= icon "chevron-right", size: "sm", class: "group-open:rotate-90 transition-transform" %> - - <%= t("goals.form_stepper.step1.fields.color") %> - +<%# locals: (form:, colors:, icons:) %> +
+
+ + <% if form.object.icon.present? %> + <%= icon(form.object.icon, color: "current", size: "md") %> + <% else %> + <%= form.object.name.to_s.strip.first&.upcase || "?" %> + <% end %> + -
- <% colors.each do |c| %> - - <% end %> +
+ + <%= icon("pen", size: "xs") %> + + +
+
+
+

Color

+
+ <% colors.each do |c| %> + + <% end %> + +
+ +
+ +
+

Icon

+
+ <% icons.each do |icon_name| %> + + <% end %> +
+
+
+
-
+
diff --git a/app/views/goals/_form_edit.html.erb b/app/views/goals/_form_edit.html.erb index 47bc918e5..236a3b3b7 100644 --- a/app/views/goals/_form_edit.html.erb +++ b/app/views/goals/_form_edit.html.erb @@ -50,7 +50,7 @@
- <%= render "color_picker", form: f, colors: Goal::COLORS %> + <%= render "color_picker", form: f, colors: Goal::COLORS, icons: Goal::ICONS %> <%= f.text_area :notes, label: t("goals.form_stepper.step1.fields.notes"), diff --git a/app/views/goals/_form_stepper.html.erb b/app/views/goals/_form_stepper.html.erb index 7f87a5873..0e921ecc1 100644 --- a/app/views/goals/_form_stepper.html.erb +++ b/app/views/goals/_form_stepper.html.erb @@ -33,10 +33,10 @@
-
- - <%= render Goals::AvatarComponent.new(name: goal.name, color: goal.color, size: "md") %> - +
+
+ <%= render "color_picker", form: f, colors: Goal::COLORS, icons: Goal::ICONS %> +
<%= f.text_field :name, placeholder: t("goals.form_stepper.step1.fields.name_placeholder"), autofocus: true, @@ -104,7 +104,6 @@ placeholder: t("goals.form_stepper.step1.fields.notes_placeholder") %> <% end %> - <%= render "color_picker", form: f, colors: Goal::COLORS %>