1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-07 14:35:23 +02:00

Update properties controller to use new creational and update balance methods

This commit is contained in:
Zach Gollwitzer 2025-07-09 22:28:07 -04:00
parent d459ebdad8
commit 25f0c78c47
17 changed files with 500 additions and 144 deletions

View file

@ -2,6 +2,6 @@
<div class="flex flex-col gap-0.5 w-[156px] shrink-0">
<%= render "properties/form_tab", label: "Overview", href: account.new_record? ? nil : edit_property_path(@account), active: active_tab == "overview" %>
<%= render "properties/form_tab", label: "Value", href: account.new_record? ? nil : balances_property_path(@account), active: active_tab == "value" %>
<%= render "properties/form_tab", label: "Details", href: account.new_record? ? nil : details_property_path(@account), active: active_tab == "details" %>
<%= render "properties/form_tab", label: "Address", href: account.new_record? ? nil : address_property_path(@account), active: active_tab == "address" %>
</div>

View file

@ -0,0 +1,30 @@
<%# locals: (form:, account:) %>
<div class="flex flex-col gap-2">
<%= form.text_field :name,
label: "Name",
placeholder: "Vacation home",
required: true %>
<%= form.money_field :current_estimated_value,
label: "Current estimated value",
label_tooltip: "The estimated market value of your property. This number can often be found on sites like Zillow or Redfin, and is never an exact number.",
placeholder: Money.new(0, form.object.currency || Current.family.currency),
value: account.balance,
required: true,
sync_currency: true %>
<%= form.money_field :purchase_price,
label: "Purchase price",
label_tooltip: "The amount you paid when you purchased the property. Leave blank if unknown.",
placeholder: Money.new(0, form.object.currency || Current.family.currency),
value: account.opening_balance,
sync_currency: true %>
<%= form.date_field :purchase_date,
label: "Purchase date",
label_tooltip: "The date you purchased the property. This helps track your property's value over time.",
value: account.opening_date %>
<%= form.hidden_field :current_cash_balance, value: 0 %>
</div>

View file

@ -1,30 +0,0 @@
<%= render DialogComponent.new do |dialog| %>
<% dialog.with_header(title: "Enter property manually") %>
<% dialog.with_body do %>
<div class="flex gap-4">
<%= render "properties/form_tabs", account: @account, active_tab: "value" %>
<!-- Right content area with form -->
<div class="flex-1">
<%= styled_form_with model: @account, url: update_balances_property_path(@account), method: :patch do |form| %>
<div class="flex flex-col gap-4 min-h-[320px]">
<%= render "properties/form_alert", notice: @success_message, error: @error_message %>
<%= form.money_field :balance,
label: "Estimated market value",
label_tooltip: "The estimated market value of your property. This number can often be found on sites like Zillow or Redfin, and is never an exact number.",
placeholder: "0" %>
</div>
<!-- Next button -->
<div class="flex justify-end mt-4">
<%= render ButtonComponent.new(
text: @account.active? ? "Save" : "Next",
variant: "primary",
) %>
</div>
<% end %>
</div>
</div>
<% end %>
<% end %>

View file

@ -0,0 +1,50 @@
<%= render DialogComponent.new do |dialog| %>
<% dialog.with_header(title: "Enter property manually") %>
<% dialog.with_body do %>
<div class="flex gap-4">
<!-- Left sidebar with tabs -->
<%= render "properties/form_tabs", account: @account, active_tab: "details" %>
<!-- Right content area with form -->
<div class="flex-1">
<%= styled_form_with model: @account, url: update_details_property_path(@account), method: :patch do |form| %>
<div class="flex flex-col gap-4 min-h-[320px]">
<%= render "properties/form_alert", notice: @success_message, error: @error_message %>
<%= form.select :subtype,
options_for_select(Property::SUBTYPES.map { |k, v| [v[:long], k] }, @account.subtype),
{ label: "Property type" },
{ class: "form-field__input" } %>
<%= form.fields_for :accountable do |property_form| %>
<div class="flex items-center gap-2">
<%= property_form.number_field :area_value,
label: "Area",
placeholder: "1200",
min: 0 %>
<%= property_form.select :area_unit,
[["Square Feet", "sqft"], ["Square Meters", "sqm"]],
{ label: "Area unit", selected: @account.accountable.area_unit } %>
</div>
<%= property_form.number_field :year_built,
label: "Year built",
placeholder: "2000",
step: 1,
min: 1800,
max: Date.current.year %>
<% end %>
</div>
<!-- Next/Save button -->
<div class="flex justify-end mt-4">
<%= render ButtonComponent.new(
text: @account.active? ? "Save" : "Next",
variant: "primary",
) %>
</div>
<% end %>
</div>
</div>
<% end %>
<% end %>

View file

@ -10,7 +10,7 @@
<%= styled_form_with model: @account, url: property_path(@account), method: :patch do |form| %>
<div class="flex flex-col gap-2 min-h-[320px]">
<%= render "properties/form_alert", notice: @success_message, error: @error_message %>
<%= render "properties/overview_fields", form: form %>
<%= render "properties/property_overview_fields", form: form, account: @account %>
</div>
<!-- Save button -->

View file

@ -10,7 +10,7 @@
<%= styled_form_with model: @account, url: properties_path do |form| %>
<div class="flex flex-col gap-2 min-h-[320px]">
<%= render "properties/form_alert", notice: @success_message, error: @error_message %>
<%= render "properties/overview_fields", form: form %>
<%= render "properties/property_overview_fields", form: form, account: @account %>
</div>
<!-- Create button -->

View file

@ -7,7 +7,7 @@
end
currency = Money::Currency.new(currency_value || options[:default_currency] || "USD") %>
<div class="form-field <%= options[:container_class] %>" data-controller="money-field">
<div class="form-field <%= options[:container_class] %>" data-controller="money-field" <%= "data-money-field-sync-currency-value=\"true\"" if options[:sync_currency] %>>
<% if options[:label_tooltip] %>
<div class="form-field__header">
<%= form.label options[:label] || t(".label"), class: "form-field__label" do %>