Membership Fee 6 - UI Components & LiveViews closes #280 #304

Open
moritz wants to merge 65 commits from feature/280_membership_fee_ui into main
Showing only changes of commit 75dc7056ae - Show all commits

View file

@ -44,6 +44,7 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
field={@form[:amount]}
label={gettext("Amount")}
required
phx-debounce="blur"
/>
moritz marked this conversation as resolved

Interval is neccessary to create a fee type, but it is not marked as required. So when I leave it out there is no error message but my fee type is not created.

Interval is neccessary to create a fee type, but it is not marked as required. So when I leave it out there is no error message but my fee type is not created.
<div class="form-control">
@ -257,11 +258,15 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
def handle_event("confirm_amount_change", _params, socket) do
# Update form with pending amount and hide warning
# Preserve all existing form values (name, description, etc.)
form = socket.assigns.form
existing_values = get_existing_form_values(form)
updated_form =
if socket.assigns.pending_amount do
AshPhoenix.Form.validate(form, %{"amount" => socket.assigns.pending_amount})
# Merge existing values with confirmed amount to preserve all fields
merged_params = Map.put(existing_values, "amount", socket.assigns.pending_amount)
AshPhoenix.Form.validate(form, merged_params)
else
form
end
@ -357,7 +362,20 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
# Checks if amount changed and updates socket assigns accordingly
defp check_amount_change(socket, params) do
if socket.assigns.membership_fee_type && Map.has_key?(params, "amount") do
handle_amount_change(socket, params["amount"], socket.assigns.membership_fee_type.amount)
# Get current amount from form and new amount from params
current_form_amount = get_existing_form_values(socket.assigns.form)["amount"]
new_amount_str = params["amount"]
# Only check amount change if amount field is actually being changed in this validation
# This prevents re-triggering the warning when other fields (name, description) are edited
if current_form_amount != new_amount_str do
handle_amount_change(socket, new_amount_str, socket.assigns.membership_fee_type.amount)
else
# Amount didn't change in this validation - keep current warning state
# If warning was already confirmed (pending_amount is nil and show_amount_warning is false), keep it hidden
# If warning is shown but not confirmed, keep it shown
socket
end
else
socket
end
@ -379,8 +397,17 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
end
# Shows amount change warning with affected member count
# Only calculates count if warning is being shown for the first time (false -> true)
defp show_amount_warning(socket, old_amount, new_amount, new_amount_str) do
affected_count = get_affected_member_count(socket.assigns.membership_fee_type.id)
# Only calculate count if warning is not already shown (optimization)
affected_count =
if socket.assigns.show_amount_warning do
# Warning already shown, reuse existing count
socket.assigns.affected_member_count
else
# Warning being shown for first time, calculate count
get_affected_member_count(socket.assigns.membership_fee_type.id)
end
socket
|> assign(:show_amount_warning, true)