Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thejonroberts committed Sep 21, 2024
1 parent 2745911 commit c4d7583
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/javascript/controllers/casa_nested_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export default class extends NestedForm {
}

/* Adds item to the form. Item will not be created until form submission. */
add = (e) => {
add (e) {
super.add(e)
}

/* Creates a new record for the added item (before submission). */
addAndCreate = (e) => {
addAndCreate (e) {
this.add(e)
const items = this.element.querySelectorAll(this.wrapperSelectorValue)
const addedItem = items[items.length - 1]
Expand Down Expand Up @@ -128,7 +128,7 @@ export default class extends NestedForm {
}

/* Destroys a record when removing the item (before submission). */
destroyAndRemove = (e) => {
destroyAndRemove (e) {
const wrapper = e.target.closest(this.wrapperSelectorValue)
const recordId = this.getRecordId(wrapper)
if (wrapper.dataset.newRecord === 'false' && (recordId.length > 0)) {
Expand Down
7 changes: 3 additions & 4 deletions app/javascript/controllers/case_contact_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Controller } from '@hotwired/stimulus'
// Connects to data-controller="case-contact-form"
export default class extends Controller {
static targets = [
'expenseAmount',
'expenseDescribe',
'expenseDestroy',
'milesDriven',
'volunteerAddress',
Expand All @@ -17,8 +15,9 @@ export default class extends Controller {
}

clearExpenses = () => {
// mark for destruction. autosave has already created the record.
// if submitted, it will be destroyed. if autosaved, it will be removed by nested form controller.
// mark for destruction. autosave has already created the records.
// if autosaved, nested form controller will remove destroy: true items
// if form submitted, it will be destroyed.
this.expenseDestroyTargets.forEach(el => (el.value = '1'))
}

Expand Down
4 changes: 1 addition & 3 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ def active_or_notes?
notes? || active?
end

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

# TODO: is this used?
accepts_nested_attributes_for :casa_case
accepts_nested_attributes_for :contact_topic_answers, allow_destroy: true,
reject_if: proc { |attrs| attrs["contact_topic_id"].blank? && attrs["value"].blank? } # .notes sent without topic_id, but must have a value.

Expand Down
3 changes: 0 additions & 3 deletions app/views/shared/_additional_expense_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
value: number_with_precision(form.object.other_expense_amount, precision: 2),
placeholder: "0", min: "0", max: 1000, step: 0.01,
class: ["form-control", "expense-amount-input"],
data: { case_contact_form_target: "expenseAmount" },
) %>
</div>
</div>
Expand All @@ -22,14 +21,12 @@
<%= form.text_area(:other_expenses_describe,
placeholder: "Enter additional details",
class: ["form-control", "expense-describe-input"],
data: { case_contact_form_target: "expenseDescribe" },
) %>
</div>
<div class="flex-shrink-1">
<button type="button"
class="remove-expense-button mt-4 btn btn-sm danger-btn-outline btn-hover"
data-action="casa-nested-form#destroyAndRemove">
<!--data-action="casa-nested-form#remove">-->
Remove
</button>
</div>
Expand Down
1 change: 0 additions & 1 deletion spec/requests/additional_expenses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
subject { post additional_expenses_path, params:, as: :json }

it "creates a new AdditionalExpense and responds created" do
puts params
expect { subject }.to change(AdditionalExpense, :count).by(1)
expect(response).to have_http_status(:created)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/system/case_contacts/contact_topic_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def notes_section
notes_section.find_button(text: "Delete", match: :first).click
end

expect(notes_section).to have_select(class: topic_select_class, count: 1, visible: :all)

click_on "Submit"
}
.to change(ContactTopicAnswer, :count).by(-1)
Expand Down

0 comments on commit c4d7583

Please sign in to comment.