Complete subtype selection for SimpleFin accounts

- Add subtype database columns to all accountable models
- Create Stimulus controller for dynamic subtype dropdown interaction
- Add delegation from Account to accountable subtype for clean API access
- Update SimpleFin account setup form with working subtype selection
- Fix account display to show proper subtype labels instead of generic "Cash"

Users can now select both account type and subtype during SimpleFin import,
and the selected subtypes are properly saved and displayed in the UI.
This commit is contained in:
Sholom Ber
2025-08-07 13:23:28 -04:00
parent 81924815fc
commit dbcbf89f4b
6 changed files with 160 additions and 11 deletions

View File

@@ -0,0 +1,43 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["subtypeContainer"]
static values = { accountId: String }
connect() {
console.log('Account type selector connected for account:', this.accountIdValue)
// Show initial subtype dropdown based on current selection
this.updateSubtype()
}
updateSubtype(event) {
const selectElement = this.element.querySelector('select[name^="account_types"]')
const selectedType = selectElement ? selectElement.value : ''
const container = this.subtypeContainerTarget
const accountId = this.accountIdValue
console.log('Updating subtype for account:', accountId, 'Selected type:', selectedType)
// Hide all subtype selects
const subtypeSelects = container.querySelectorAll('.subtype-select')
subtypeSelects.forEach(select => {
select.style.display = 'none'
// Clear the name attribute so it doesn't get submitted
const selectElement = select.querySelector('select')
if (selectElement) {
selectElement.removeAttribute('name')
}
})
// Show the relevant subtype select
const relevantSubtype = container.querySelector(`[data-type="${selectedType}"]`)
if (relevantSubtype) {
relevantSubtype.style.display = 'block'
// Re-add the name attribute so it gets submitted
const selectElement = relevantSubtype.querySelector('select')
if (selectElement) {
selectElement.setAttribute('name', `account_subtypes[${accountId}]`)
}
}
}
}