The personal finance app for everyone
Fix merchant editing (#2349)
Zach Gollwitzer9afc50a1469b
diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rbindex 01531a47..1798056f 100644--- a/app/controllers/family_merchants_controller.rb+++ b/app/controllers/family_merchants_controller.rb@@ -4,19 +4,19 @@ class FamilyMerchantsController < ApplicationControllerdef index@breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ]- @merchants = Current.family.merchants.alphabetically+ @family_merchants = Current.family.merchants.alphabeticallyrender layout: "settings"enddef new- @merchant = FamilyMerchant.new(family: Current.family)+ @family_merchant = FamilyMerchant.new(family: Current.family)enddef create- @merchant = FamilyMerchant.new(merchant_params.merge(family: Current.family))+ @family_merchant = FamilyMerchant.new(merchant_params.merge(family: Current.family))- if @merchant.save+ if @family_merchant.saverespond_to do |format|format.html { redirect_to family_merchants_path, notice: t(".success") }format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) }@@ -30,7 +30,7 @@ class FamilyMerchantsController < ApplicationControllerenddef update- @merchant.update!(merchant_params)+ @family_merchant.update!(merchant_params)respond_to do |format|format.html { redirect_to family_merchants_path, notice: t(".success") }format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) }@@ -38,14 +38,13 @@ class FamilyMerchantsController < ApplicationControllerenddef destroy- @merchant.destroy!+ @family_merchant.destroy!redirect_to family_merchants_path, notice: t(".success")endprivate-def set_merchant- @merchant = Current.family.merchants.find(params[:id])+ @family_merchant = Current.family.merchants.find(params[:id])enddef merchant_paramsdiff --git a/app/views/family_merchants/_form.html.erb b/app/views/family_merchants/_form.html.erbindex db5bd085..f0680ab5 100644--- a/app/views/family_merchants/_form.html.erb+++ b/app/views/family_merchants/_form.html.erb@@ -6,6 +6,7 @@<% if family_merchant.errors.any? %><%= render "shared/form_errors", model: family_merchant %><% end %>+<div class="w-fit m-auto mb-4"><%= render partial: "shared/color_avatar", locals: { name: family_merchant.name, color: family_merchant.color } %></div>diff --git a/app/views/family_merchants/index.html.erb b/app/views/family_merchants/index.html.erbindex 7438aa2b..a65efeb0 100644--- a/app/views/family_merchants/index.html.erb+++ b/app/views/family_merchants/index.html.erb@@ -10,17 +10,17 @@</header><div class="bg-container rounded-xl shadow-border-xs p-4">- <% if @merchants.any? %>+ <% if @family_merchants.any? %><div class="rounded-xl bg-container-inset space-y-1 p-1"><div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase"><p><%= t(".title") %></p><span class="text-subdued">·</span>- <p><%= @merchants.count %></p>+ <p><%= @family_merchants.count %></p></div><div class="bg-container rounded-lg shadow-border-xs"><div class="overflow-hidden rounded-lg">- <%= render partial: "family_merchants/family_merchant", collection: @merchants, spacer_template: "shared/ruler" %>+ <%= render partial: "family_merchants/family_merchant", collection: @family_merchants, spacer_template: "shared/ruler" %></div></div></div>diff --git a/app/views/family_merchants/new.html.erb b/app/views/family_merchants/new.html.erbindex fa9da88f..044ae422 100644--- a/app/views/family_merchants/new.html.erb+++ b/app/views/family_merchants/new.html.erb@@ -1,6 +1,6 @@<%= render DialogComponent.new do |dialog| %><% dialog.with_header(title: t(".title")) %><% dialog.with_body do %>- <%= render "form", family_merchant: @merchant %>+ <%= render "form", family_merchant: @family_merchant %><% end %><% end %>diff --git a/app/views/merchants/_merchant.html.erb b/app/views/merchants/_merchant.html.erbdeleted file mode 100644index 964a7fff..00000000--- a/app/views/merchants/_merchant.html.erb+++ /dev/null@@ -1,29 +0,0 @@-<%# locals: (merchant:) %>--<div class="flex justify-between items-center p-4 bg-container">- <div class="flex w-full items-center gap-2.5">- <% if merchant.icon_url %>- <div class="w-8 h-8 rounded-full flex justify-center items-center">- <%= image_tag merchant.icon_url, class: "w-8 h-8 rounded-full" %>- </div>- <% else %>- <%= render partial: "shared/color_avatar", locals: { name: merchant.name, color: merchant.color } %>- <% end %>-- <p class="text-primary text-sm truncate">- <%= merchant.name %>- </p>- </div>- <div class="justify-self-end">- <%= render MenuComponent.new do |menu| %>- <% menu.with_item(variant: "link", text: t(".edit"), href: edit_merchant_path(merchant), icon: "pencil", data: { turbo_frame: "modal" }) %>- <% menu.with_item(- variant: "button",- text: t(".delete"),- href: merchant_path(merchant),- icon: "trash-2",- method: :delete,- confirm: CustomConfirm.for_resource_deletion(merchant.name)) %>- <% end %>- </div>-</div>