Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncap additional expenses and allow delete #5908

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions app/javascript/__tests__/add_additional_expense.test.js

This file was deleted.

1 change: 0 additions & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require('select2')(window.jQuery)
require('@rails/ujs').start()
require('@rails/activestorage').start()
require('bootstrap-datepicker')
require('./src/add_additional_expense')
require('./src/add_to_calendar_button')
require('./src/case_contact')
require('./src/case_emancipation')
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import SidebarController from './sidebar_controller'
import SidebarGroupController from './sidebar_group_controller'

import TruncatedTextController from './truncated_text_controller'

import NestedForm from 'stimulus-rails-nested-form'

application.register('alert', AlertController)
application.register('autosave', AutosaveController)
application.register('disable-form', DisableFormController)
Expand All @@ -42,3 +45,4 @@ application.register('select-all', SelectAllController)
application.register('sidebar', SidebarController)
application.register('sidebar-group', SidebarGroupController)
application.register('truncated-text', TruncatedTextController)
application.register('nested-form', NestedForm)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to access the nested form controller until I added this - not sure if there is a more standard way to do this. I realize the rest of the imports in here are all local

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The court_order_form_controller.js uses it, too. But it loads it directly. This is the right thing to do for your use case.

11 changes: 0 additions & 11 deletions app/javascript/src/add_additional_expense.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def active_or_expenses?
status == "expenses" || active?
end

accepts_nested_attributes_for :additional_expenses, reject_if: :all_blank
accepts_nested_attributes_for :additional_expenses, reject_if: :all_blank, allow_destroy: true
validates_associated :additional_expenses

accepts_nested_attributes_for :casa_case
Expand Down
2 changes: 1 addition & 1 deletion app/values/case_contact_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(params)
:volunteer_address,
contact_type_ids: [],
draft_case_ids: [],
additional_expenses_attributes: %i[id other_expense_amount other_expenses_describe],
additional_expenses_attributes: %i[id other_expense_amount other_expenses_describe _destroy],
contact_topic_answers_attributes: %i[id value selected]
)
if params.dig(:case_contact, :duration_minutes)
Expand Down
96 changes: 19 additions & 77 deletions app/views/case_contacts/form/expenses.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact expenses", step: @page, total_steps: @total_pages)) %>

<div>
<%= form_with(model: @case_contact, url: wizard_path(nil, case_contact_id: @case_contact.id), local: true, id: "casa-contact-form", class: "component-validated-form") do |form| %>
<%= form_with(model: @case_contact, data: { controller: "nested-form", nested_form_wrapper_selector_value: ".nested-form-wrapper"}, url: wizard_path(nil, case_contact_id: @case_contact.id), local: true, id: "casa-contact-form", class: "component-validated-form") do |form| %>
<%= render "/shared/error_messages", resource: @case_contact %>

<div class="card-style-1 pl-25 mb-10 pr-50">
Expand Down Expand Up @@ -59,87 +59,29 @@
<div class="other-expenses">
<ol>
<% @case_contact.decorate.additional_expenses_count %>
<% if @case_contact.additional_expenses.any? %>
<%= form.fields_for :additional_expenses do |ff| %>
<li>
<div class="expense-container row">
<div class="input-style-1 col-sm-3">
<h5><%= form.label :additional_expense, "a. Expense amount" %></h5>
<div class="input-group">
<span class="dollar-sign">
<%= ff.number_field :other_expense_amount,
placeholder: "0",
class: "form-control other-expense-amount",
min: "0", max: 1000, step: 0.01 %>
</span>
</div>
</div>
<div class="input-style-1 col">
<h5><%= form.label :other_expenses_describe, "b. Expense details" %></h5>
<%= ff.text_field :other_expenses_describe,
placeholder: "Enter additional details",
class: "form-control other-expenses-describe" %>
</div>
</div>
</li>
<% end %>
<% end %>
<% if @case_contact.decorate.additional_expenses_count < 10 %>
<%= form.fields_for :additional_expenses, AdditionalExpense.new do |ff| %>
<li>
<div class="expense-container row">
<div class="input-style-1 col-sm-3">
<h5><%= form.label :additional_expense, "a. Expense amount" %></h5>
<div class="input-group">
<span class="dollar-sign">
<%= ff.number_field :other_expense_amount,
placeholder: "0",
class: "form-control other-expense-amount",
min: "0", max: 1000, step: 0.01 %>
</span>
</div>
</div>
<div class="input-style-1 col">
<h5><%= form.label :other_expenses_describe, "b. Expense details" %></h5>
<%= ff.text_field :other_expenses_describe,
placeholder: "Enter additional details",
class: "form-control other-expenses-describe" %>
</div>
</div>
</li>
<% end %>
<% (9 - @case_contact.decorate.additional_expenses_count).times do |i| %>
<%= form.fields_for :additional_expenses, AdditionalExpense.new do |ff| %>
<div class="expense-container row d-none" id="<%= if @case_contact.decorate.additional_expenses_count === 0
then "expense" + (i + 2).to_s
else "expense" + ((@case_contact.decorate.additional_expenses_count) + (i + 2)).to_s
end %>">
<div class="input-style-1 col-sm-3">
<h5><%= form.label :additional_expense, "a. Expense amount" %></h5>
<div class="input-group">
<span class="dollar-sign">
<%= ff.number_field :other_expense_amount,
placeholder: "0",
class: "form-control other-expense-amount",
min: "0", max: 1000, step: 0.01 %>
</span>
</div>
</div>
<div class="input-style-1 col">
<h5><%= form.label :other_expenses_describe, "b. Expense details" %></h5>
<%= ff.text_field :other_expenses_describe,
placeholder: "Enter additional details",
class: "form-control other-expenses-describe" %>
</div>
</div>
<% if form.object.additional_expenses.any? %>
<% form.object.additional_expenses.each do |expense| %>
<%= form.fields_for :additional_expenses, expense do |f| %>
<%= render "shared/additional_expense_form", form: f, new_record: false %>
<% end %>
<% end %>
<% else %>
<%= form.fields_for :additional_expenses, AdditionalExpense.new do |f| %>
<%= render "shared/additional_expense_form", form: f, new_record: true %>
<% end %>
<% end %>
<template data-nested-form-target="template">
<%= form.fields_for :additional_expenses, AdditionalExpense.new, child_index: "NEW_RECORD" do |f| %>
<%= render "shared/additional_expense_form", form: f %>
<% end %>
</template>
<div data-nested-form-target="target"></div>
</ol>

<% if @case_contact.decorate.additional_expenses_count < 10 %>
<button type="button" class="btn-sm main-btn primary-btn-outline btn-hover" id="add-another-expense">+ Add Another Expense</button>
<% end %>
<button type="button" class="btn-sm main-btn primary-btn-outline btn-hover" data-action="nested-form#add" id="add-another-expense">
<i class="lni lni-plus mr-10"></i> Add Another Expense
</button>

</div>
</div>
<% end %>
Expand Down
27 changes: 27 additions & 0 deletions app/views/shared/_additional_expense_form.html.erb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a huge deal, but I'd say get rid of the a and b. With multiple expenses it becomes confusing.
Screenshot 2024-07-23 at 6 59 24 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, just saw this, will take those out

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="nested-form-wrapper">
<li>
<div class="expense-container row" data-index="<%= form.index %>">
<div class="input-style-1 col-sm-3">
<h5><%= form.label :additional_expense, "a. Expense amount" %></h5>
<div class="input-group">
<span class="dollar-sign">
<%= form.number_field :other_expense_amount,
placeholder: "0",
class: "form-control other-expense-amount",
min: "0", max: 1000, step: 0.01 %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After saving and coming back to edit, I get an expense in the form with only one cent place.
Screenshot 2024-07-23 at 7 01 16 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schoork added number_with_precision to the field, let me know if this display is ok:
Screen Shot 2024-07-23 at 1 12 11 PM

</span>
</div>
</div>
<div class="input-style-1 col">
<h5><%= form.label :other_expenses_describe, "b. Expense details" %></h5>
<%= form.text_field :other_expenses_describe,
placeholder: "Enter additional details",
class: "form-control other-expenses-describe" %>
</div>
<div class="input-style-1 col">
<button type="button" class="align-self-center main-btn danger-btn btn-hover btn-sm remove-expense-button mt-15" data-action="nested-form#remove"> Delete</button>
</div>
</div>
</li>
<%= form.hidden_field :_destroy %>
</div>
Loading