mirror of
https://github.com/we-promise/sure.git
synced 2026-04-10 07:44:48 +00:00
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:
@@ -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}]`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user