2024-12-20 11:37:26 -05:00
|
|
|
<%# locals: (category:, categories:) %>
|
|
|
|
|
2024-08-27 17:06:41 -04:00
|
|
|
<div data-controller="color-avatar">
|
2025-01-30 14:35:30 -03:00
|
|
|
<%= styled_form_with model: category, class: "space-y-4" do |f| %>
|
2024-08-27 17:06:41 -04:00
|
|
|
<section class="space-y-4">
|
|
|
|
<div class="w-fit m-auto">
|
|
|
|
<%= render partial: "shared/color_avatar", locals: { name: category.name, color: category.color } %>
|
|
|
|
</div>
|
2024-12-20 11:37:26 -05:00
|
|
|
|
2025-01-30 16:49:31 -05:00
|
|
|
<div class="flex gap-2 items-center justify-center" data-color-avatar-target="selection">
|
2024-06-20 08:15:09 -04:00
|
|
|
<% Category::COLORS.each do |color| %>
|
2024-08-27 17:06:41 -04:00
|
|
|
<label class="relative">
|
|
|
|
<%= f.radio_button :color, color, class: "sr-only peer", data: { action: "change->color-avatar#handleColorChange" } %>
|
|
|
|
<div class="w-6 h-6 rounded-full cursor-pointer peer-checked:ring-2 peer-checked:ring-offset-2 peer-checked:ring-blue-500" style="background-color: <%= color %>"></div>
|
|
|
|
</label>
|
2024-05-02 07:24:31 -06:00
|
|
|
<% end %>
|
2024-08-27 17:06:41 -04:00
|
|
|
</div>
|
2024-12-20 11:37:26 -05:00
|
|
|
|
|
|
|
<% if category.errors.any? %>
|
|
|
|
<%= render "shared/form_errors", model: category %>
|
|
|
|
<% end %>
|
|
|
|
|
2025-01-16 14:36:37 -05:00
|
|
|
<div class="flex flex-wrap gap-2 justify-center mb-4">
|
2025-01-30 16:49:31 -05:00
|
|
|
|
2025-01-16 14:36:37 -05:00
|
|
|
<% Category.icon_codes.each do |icon| %>
|
|
|
|
<label class="relative">
|
|
|
|
<%= f.radio_button :lucide_icon, icon, class: "sr-only peer" %>
|
|
|
|
<div class="p-1 rounded cursor-pointer hover:bg-gray-100 peer-checked:bg-gray-100 border-1 border-transparent peer-checked:border-gray-500">
|
|
|
|
<%= lucide_icon icon, class: "w-5 h-5" %>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
|
2024-12-20 11:37:26 -05:00
|
|
|
<div class="space-y-2">
|
2025-01-16 14:36:37 -05:00
|
|
|
<%= f.select :classification, [["Income", "income"], ["Expense", "expense"]], { label: "Classification" }, required: true %>
|
2024-12-20 11:37:26 -05:00
|
|
|
<%= f.text_field :name, placeholder: t(".placeholder"), required: true, autofocus: true, label: "Name", data: { color_avatar_target: "name" } %>
|
2025-01-30 14:35:30 -03:00
|
|
|
<% unless category.parent? %>
|
2025-01-30 16:49:31 -05:00
|
|
|
<%= f.select :parent_id, categories.pluck(:name, :id), { include_blank: "(unassigned)", label: "Parent category (optional)" }, disabled: category.parent?, data: { action: "change->color-avatar#handleParentChange" } %>
|
2025-01-30 14:35:30 -03:00
|
|
|
<% end %>
|
2024-08-27 17:06:41 -04:00
|
|
|
</div>
|
|
|
|
</section>
|
2024-05-02 07:24:31 -06:00
|
|
|
|
|
|
|
<section>
|
|
|
|
<%= hidden_field_tag :transaction_id, params[:transaction_id] %>
|
2024-08-27 17:06:41 -04:00
|
|
|
<%= f.submit %>
|
2024-05-02 07:24:31 -06:00
|
|
|
</section>
|
2024-08-27 17:06:41 -04:00
|
|
|
<% end %>
|
|
|
|
</div>
|