1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Fix merchant editing (#2349)

This commit is contained in:
Zach Gollwitzer 2025-06-09 10:50:56 -04:00 committed by GitHub
parent 0063921de9
commit 9afc50a146
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 41 deletions

View file

@ -4,19 +4,19 @@ class FamilyMerchantsController < ApplicationController
def index def index
@breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ] @breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ]
@merchants = Current.family.merchants.alphabetically @family_merchants = Current.family.merchants.alphabetically
render layout: "settings" render layout: "settings"
end end
def new def new
@merchant = FamilyMerchant.new(family: Current.family) @family_merchant = FamilyMerchant.new(family: Current.family)
end end
def create 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| respond_to do |format|
format.html { redirect_to family_merchants_path, notice: t(".success") } format.html { redirect_to family_merchants_path, notice: t(".success") }
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) } format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) }
@ -30,7 +30,7 @@ class FamilyMerchantsController < ApplicationController
end end
def update def update
@merchant.update!(merchant_params) @family_merchant.update!(merchant_params)
respond_to do |format| respond_to do |format|
format.html { redirect_to family_merchants_path, notice: t(".success") } format.html { redirect_to family_merchants_path, notice: t(".success") }
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) } format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, family_merchants_path) }
@ -38,14 +38,13 @@ class FamilyMerchantsController < ApplicationController
end end
def destroy def destroy
@merchant.destroy! @family_merchant.destroy!
redirect_to family_merchants_path, notice: t(".success") redirect_to family_merchants_path, notice: t(".success")
end end
private private
def set_merchant def set_merchant
@merchant = Current.family.merchants.find(params[:id]) @family_merchant = Current.family.merchants.find(params[:id])
end end
def merchant_params def merchant_params

View file

@ -6,6 +6,7 @@
<% if family_merchant.errors.any? %> <% if family_merchant.errors.any? %>
<%= render "shared/form_errors", model: family_merchant %> <%= render "shared/form_errors", model: family_merchant %>
<% end %> <% end %>
<div class="w-fit m-auto mb-4"> <div class="w-fit m-auto mb-4">
<%= render partial: "shared/color_avatar", locals: { name: family_merchant.name, color: family_merchant.color } %> <%= render partial: "shared/color_avatar", locals: { name: family_merchant.name, color: family_merchant.color } %>
</div> </div>

View file

@ -10,17 +10,17 @@
</header> </header>
<div class="bg-container rounded-xl shadow-border-xs p-4"> <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="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"> <div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
<p><%= t(".title") %></p> <p><%= t(".title") %></p>
<span class="text-subdued">&middot;</span> <span class="text-subdued">&middot;</span>
<p><%= @merchants.count %></p> <p><%= @family_merchants.count %></p>
</div> </div>
<div class="bg-container rounded-lg shadow-border-xs"> <div class="bg-container rounded-lg shadow-border-xs">
<div class="overflow-hidden rounded-lg"> <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> </div>
</div> </div>

View file

@ -1,6 +1,6 @@
<%= render DialogComponent.new do |dialog| %> <%= render DialogComponent.new do |dialog| %>
<% dialog.with_header(title: t(".title")) %> <% dialog.with_header(title: t(".title")) %>
<% dialog.with_body do %> <% dialog.with_body do %>
<%= render "form", family_merchant: @merchant %> <%= render "form", family_merchant: @family_merchant %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -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>