feat(ui): wire admin add-account endpoint into Chart of Accounts
Surface the existing POST /api/v1/admin/accounts endpoint in the UI: a super-user-only 'Add Account' button on the Chart of Accounts card opens a dialog for the hierarchical account name + optional description, posts with the wallet admin key (require_super_user), then reloads accounts. Client-side prefix validation mirrors the server's _VALID_ACCOUNT_PREFIXES. No currency input — an Open directive does not require currency constraints. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
788a9998f6
commit
9dd46e818c
2 changed files with 103 additions and 1 deletions
|
|
@ -69,6 +69,12 @@ window.app = Vue.createApp({
|
|||
userWalletId: '',
|
||||
loading: false
|
||||
},
|
||||
addAccountDialog: {
|
||||
show: false,
|
||||
name: '',
|
||||
description: '',
|
||||
loading: false
|
||||
},
|
||||
receivableDialog: {
|
||||
show: false,
|
||||
selectedUser: '',
|
||||
|
|
@ -566,6 +572,45 @@ window.app = Vue.createApp({
|
|||
this.syncingAccounts = false
|
||||
}
|
||||
},
|
||||
showAddAccountDialog() {
|
||||
this.addAccountDialog.name = ''
|
||||
this.addAccountDialog.description = ''
|
||||
this.addAccountDialog.show = true
|
||||
},
|
||||
async submitAddAccount() {
|
||||
const name = (this.addAccountDialog.name || '').trim()
|
||||
const validPrefixes = ['Assets:', 'Liabilities:', 'Equity:', 'Income:', 'Expenses:']
|
||||
if (!validPrefixes.some(p => name.startsWith(p))) {
|
||||
this.$q.notify({
|
||||
type: 'warning',
|
||||
message: `Account name must start with one of: ${validPrefixes.join(', ')}`
|
||||
})
|
||||
return
|
||||
}
|
||||
this.addAccountDialog.loading = true
|
||||
try {
|
||||
const {data} = await LNbits.api.request(
|
||||
'POST',
|
||||
'/libra/api/v1/admin/accounts',
|
||||
this.g.user.wallets[0].adminkey,
|
||||
{
|
||||
name,
|
||||
description: this.addAccountDialog.description || null
|
||||
}
|
||||
)
|
||||
this.$q.notify({
|
||||
type: 'positive',
|
||||
message: `Account ${data.account_name} created` +
|
||||
(data.synced_to_libra_db ? '' : ' (sync pending)')
|
||||
})
|
||||
this.addAccountDialog.show = false
|
||||
await this.loadAccounts()
|
||||
} catch (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
} finally {
|
||||
this.addAccountDialog.loading = false
|
||||
}
|
||||
},
|
||||
showSettingsDialog() {
|
||||
this.settingsDialog.libraWalletId = this.settings?.libra_wallet_id || ''
|
||||
this.settingsDialog.favaUrl = this.settings?.fava_url || 'http://localhost:3333'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue