mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
Fix merchant editing (#2349)
This commit is contained in:
parent
0063921de9
commit
9afc50a146
5 changed files with 12 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue