From 9afc50a1469bd0bed626ae9a0894b8cdda1db89e Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 9 Jun 2025 10:50:56 -0400 Subject: [PATCH] Fix merchant editing (#2349) --- .../family_merchants_controller.rb | 15 +++++----- app/views/family_merchants/_form.html.erb | 1 + app/views/family_merchants/index.html.erb | 6 ++-- app/views/family_merchants/new.html.erb | 2 +- app/views/merchants/_merchant.html.erb | 29 ------------------- 5 files changed, 12 insertions(+), 41 deletions(-) delete mode 100644 app/views/merchants/_merchant.html.erb diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rb index 01531a47..1798056f 100644 --- a/app/controllers/family_merchants_controller.rb +++ b/app/controllers/family_merchants_controller.rb @@ -4,19 +4,19 @@ class FamilyMerchantsController < ApplicationController def index @breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ] - @merchants = Current.family.merchants.alphabetically + @family_merchants = Current.family.merchants.alphabetically render layout: "settings" end def new - @merchant = FamilyMerchant.new(family: Current.family) + @family_merchant = FamilyMerchant.new(family: Current.family) end def 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.save 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) } @@ -30,7 +30,7 @@ class FamilyMerchantsController < ApplicationController end def 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 < ApplicationController end def destroy - @merchant.destroy! + @family_merchant.destroy! redirect_to family_merchants_path, notice: t(".success") end private - def set_merchant - @merchant = Current.family.merchants.find(params[:id]) + @family_merchant = Current.family.merchants.find(params[:id]) end def merchant_params diff --git a/app/views/family_merchants/_form.html.erb b/app/views/family_merchants/_form.html.erb index 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 %> +
<%= render partial: "shared/color_avatar", locals: { name: family_merchant.name, color: family_merchant.color } %>
diff --git a/app/views/family_merchants/index.html.erb b/app/views/family_merchants/index.html.erb index 7438aa2b..a65efeb0 100644 --- a/app/views/family_merchants/index.html.erb +++ b/app/views/family_merchants/index.html.erb @@ -10,17 +10,17 @@
- <% if @merchants.any? %> + <% if @family_merchants.any? %>

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

· -

<%= @merchants.count %>

+

<%= @family_merchants.count %>

- <%= 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" %>
diff --git a/app/views/family_merchants/new.html.erb b/app/views/family_merchants/new.html.erb index 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.erb deleted file mode 100644 index 964a7fff..00000000 --- a/app/views/merchants/_merchant.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<%# locals: (merchant:) %> - -
-
- <% if merchant.icon_url %> -
- <%= image_tag merchant.icon_url, class: "w-8 h-8 rounded-full" %> -
- <% else %> - <%= render partial: "shared/color_avatar", locals: { name: merchant.name, color: merchant.color } %> - <% end %> - -

- <%= merchant.name %> -

-
-
- <%= 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 %> -
-