Primera build enviada

This commit is contained in:
2026-01-19 14:40:43 +01:00
parent c6be398e5a
commit b03d35194f
36 changed files with 1641 additions and 561 deletions
@@ -18,7 +18,18 @@ struct AccountEditorView: View {
NavigationStack {
Form {
Section {
TextField("Account name", text: $name)
if isEditingDefaultAccount {
HStack {
Text(Account.defaultAccountName)
.foregroundColor(.secondary)
Spacer()
Image(systemName: "lock.fill")
.font(.caption)
.foregroundColor(.secondary)
}
} else {
TextField("Account name", text: $name)
}
Picker("Currency", selection: $currencyCode) {
ForEach(CurrencyPicker.commonCodes, id: \.self) { code in
Text(code).tag(code)
@@ -30,6 +41,8 @@ struct AccountEditorView: View {
if let errorMessage {
Text(errorMessage)
.foregroundColor(.negativeRed)
} else if isEditingDefaultAccount {
Text("The Default account name cannot be changed.")
}
}
@@ -67,9 +80,16 @@ struct AccountEditorView: View {
.presentationDetents([.large])
}
private var isEditingDefaultAccount: Bool {
account?.isDefaultAccount == true
}
private var isValid: Bool {
if isEditingDefaultAccount {
return true // Can only edit currency/inputMode for Default account
}
let trimmed = name.trimmingCharacters(in: .whitespaces)
return !trimmed.isEmpty && !isDuplicateName(trimmed)
return !trimmed.isEmpty && errorMessage == nil
}
private func validateName() {
@@ -78,17 +98,24 @@ struct AccountEditorView: View {
errorMessage = nil
return
}
errorMessage = isDuplicateName(trimmed) ? "An account with this name already exists." : nil
}
private func isDuplicateName(_ trimmed: String) -> Bool {
let normalized = trimmed.lowercased()
return accountRepository.accounts.contains { existing in
if let account, existing.id == account.id {
return false
// Check if trying to use reserved "Default" name for a non-default account
if trimmed.lowercased() == Account.defaultAccountName.lowercased() {
let isCreatingNew = account == nil
let isEditingNonDefault = account != nil && !account!.isDefaultAccount
if isCreatingNew || isEditingNonDefault {
errorMessage = "The name '\(Account.defaultAccountName)' is reserved."
return
}
return (existing.name).trimmingCharacters(in: .whitespaces).lowercased() == normalized
}
// Check for duplicate names
if !accountRepository.isNameAvailable(trimmed, excludingAccountId: account?.safeId) {
errorMessage = "An account with this name already exists."
return
}
errorMessage = nil
}
private func loadAccount() {
@@ -102,15 +129,17 @@ struct AccountEditorView: View {
}
private func saveAccount() {
validateName()
guard errorMessage == nil else { return }
let trimmedName = name.trimmingCharacters(in: .whitespaces)
if !isEditingDefaultAccount {
validateName()
guard errorMessage == nil else { return }
}
let trimmedName = isEditingDefaultAccount ? Account.defaultAccountName : name.trimmingCharacters(in: .whitespaces)
let enforcedFrequency: NotificationFrequency = .monthly
let enforcedCustomMonths = 1
if let account {
accountRepository.updateAccount(
account,
name: trimmedName,
name: isEditingDefaultAccount ? nil : trimmedName, // Don't update name for Default account
currency: currencyCode,
inputMode: inputMode,
notificationFrequency: enforcedFrequency,