Make residence address fields optional (only name required)

Updated Kotlin models, Android UI, and iOS UI to make all address fields
optional for residences. Only the residence name is now required.

Changes:
- Kotlin: Made propertyType, streetAddress, city, stateProvince, postalCode,
  country nullable in Residence, ResidenceSummary, ResidenceWithTasks models
- Kotlin: Updated navigation routes to handle nullable address fields
- Android: Updated ResidenceFormScreen and ResidenceDetailScreen to handle nulls
- iOS: Updated ResidenceFormView validation to only check name field
- iOS: Updated PropertyHeaderCard and ResidenceCard to use optional binding
  for address field displays

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-20 23:03:45 -06:00
parent 630e95e462
commit dd5e050025
8 changed files with 228 additions and 245 deletions

View File

@@ -30,10 +30,6 @@ struct ResidenceFormView: View {
// Validation errors
@State private var nameError: String = ""
@State private var streetAddressError: String = ""
@State private var cityError: String = ""
@State private var stateProvinceError: String = ""
@State private var postalCodeError: String = ""
enum Field {
case name, streetAddress, apartmentUnit, city, stateProvince, postalCode, country
@@ -44,12 +40,17 @@ struct ResidenceFormView: View {
existingResidence != nil
}
private var canSave: Bool {
!name.isEmpty
}
var body: some View {
NavigationView {
Form {
Section(header: Text("Property Details")) {
Section {
TextField("Property Name", text: $name)
.focused($focusedField, equals: .name)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.nameField)
if !nameError.isEmpty {
Text(nameError)
@@ -63,50 +64,41 @@ struct ResidenceFormView: View {
Text(type.name).tag(type as ResidenceType?)
}
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.propertyTypePicker)
} header: {
Text("Property Details")
} footer: {
Text("Required: Name")
.font(.caption)
.foregroundColor(.red)
}
Section(header: Text("Address")) {
Section {
TextField("Street Address", text: $streetAddress)
.focused($focusedField, equals: .streetAddress)
if !streetAddressError.isEmpty {
Text(streetAddressError)
.font(.caption)
.foregroundColor(.red)
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.streetAddressField)
TextField("Apartment/Unit (optional)", text: $apartmentUnit)
.focused($focusedField, equals: .apartmentUnit)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.apartmentUnitField)
TextField("City", text: $city)
.focused($focusedField, equals: .city)
if !cityError.isEmpty {
Text(cityError)
.font(.caption)
.foregroundColor(.red)
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.cityField)
TextField("State/Province", text: $stateProvince)
.focused($focusedField, equals: .stateProvince)
if !stateProvinceError.isEmpty {
Text(stateProvinceError)
.font(.caption)
.foregroundColor(.red)
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.stateProvinceField)
TextField("Postal Code", text: $postalCode)
.focused($focusedField, equals: .postalCode)
if !postalCodeError.isEmpty {
Text(postalCodeError)
.font(.caption)
.foregroundColor(.red)
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.postalCodeField)
TextField("Country", text: $country)
.focused($focusedField, equals: .country)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.countryField)
} header: {
Text("Address")
}
Section(header: Text("Property Features")) {
@@ -118,6 +110,7 @@ struct ResidenceFormView: View {
.multilineTextAlignment(.trailing)
.frame(width: 60)
.focused($focusedField, equals: .bedrooms)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.bedroomsField)
}
HStack {
@@ -128,26 +121,32 @@ struct ResidenceFormView: View {
.multilineTextAlignment(.trailing)
.frame(width: 60)
.focused($focusedField, equals: .bathrooms)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.bathroomsField)
}
TextField("Square Footage", text: $squareFootage)
.keyboardType(.numberPad)
.focused($focusedField, equals: .squareFootage)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.squareFootageField)
TextField("Lot Size (acres)", text: $lotSize)
.keyboardType(.decimalPad)
.focused($focusedField, equals: .lotSize)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.lotSizeField)
TextField("Year Built", text: $yearBuilt)
.keyboardType(.numberPad)
.focused($focusedField, equals: .yearBuilt)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.yearBuiltField)
}
Section(header: Text("Additional Details")) {
TextField("Description (optional)", text: $description, axis: .vertical)
.lineLimit(3...6)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.descriptionField)
Toggle("Primary Residence", isOn: $isPrimary)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.isPrimaryToggle)
}
if let errorMessage = viewModel.errorMessage {
@@ -165,13 +164,15 @@ struct ResidenceFormView: View {
Button("Cancel") {
isPresented = false
}
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.formCancelButton)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Save") {
submitForm()
}
.disabled(viewModel.isLoading)
.disabled(!canSave || viewModel.isLoading)
.accessibilityIdentifier(AccessibilityIdentifiers.Residence.saveButton)
}
}
.onAppear {
@@ -197,7 +198,9 @@ struct ResidenceFormView: View {
} else {
// Fallback to DataCache directly
await MainActor.run {
self.residenceTypes = DataCache.shared.residenceTypes.value as! [ResidenceType]
if let cached = DataCache.shared.residenceTypes.value as? [ResidenceType] {
self.residenceTypes = cached
}
}
}
}
@@ -207,12 +210,12 @@ struct ResidenceFormView: View {
if let residence = existingResidence {
// Edit mode - populate fields from existing residence
name = residence.name
streetAddress = residence.streetAddress
streetAddress = residence.streetAddress ?? ""
apartmentUnit = residence.apartmentUnit ?? ""
city = residence.city
stateProvince = residence.stateProvince
postalCode = residence.postalCode
country = residence.country
city = residence.city ?? ""
stateProvince = residence.stateProvince ?? ""
postalCode = residence.postalCode ?? ""
country = residence.country ?? ""
bedrooms = residence.bedrooms != nil ? "\(residence.bedrooms!)" : ""
bathrooms = residence.bathrooms != nil ? "\(residence.bathrooms!)" : ""
squareFootage = residence.squareFootage != nil ? "\(residence.squareFootage!)" : ""
@@ -222,13 +225,11 @@ struct ResidenceFormView: View {
isPrimary = residence.isPrimary
// Set the selected property type
selectedPropertyType = residenceTypes.first { $0.id == Int(residence.propertyType) ?? 0 }
} else {
// Add mode - set default property type
if selectedPropertyType == nil && !residenceTypes.isEmpty {
selectedPropertyType = residenceTypes.first
if let propertyTypeStr = residence.propertyType, let propertyTypeId = Int(propertyTypeStr) {
selectedPropertyType = residenceTypes.first { $0.id == propertyTypeId }
}
}
// In add mode, leave selectedPropertyType as nil to force user to select
}
private func validateForm() -> Bool {
@@ -241,57 +242,54 @@ struct ResidenceFormView: View {
nameError = ""
}
if streetAddress.isEmpty {
streetAddressError = "Street address is required"
isValid = false
} else {
streetAddressError = ""
}
if city.isEmpty {
cityError = "City is required"
isValid = false
} else {
cityError = ""
}
if stateProvince.isEmpty {
stateProvinceError = "State/Province is required"
isValid = false
} else {
stateProvinceError = ""
}
if postalCode.isEmpty {
postalCodeError = "Postal code is required"
isValid = false
} else {
postalCodeError = ""
}
return isValid
}
private func submitForm() {
guard validateForm() else { return }
guard let propertyType = selectedPropertyType else {
return
}
// Convert optional numeric fields to Kotlin types
let bedroomsValue: KotlinInt? = {
guard !bedrooms.isEmpty, let value = Int32(bedrooms) else { return nil }
return KotlinInt(int: value)
}()
let bathroomsValue: KotlinFloat? = {
guard !bathrooms.isEmpty, let value = Float(bathrooms) else { return nil }
return KotlinFloat(float: value)
}()
let squareFootageValue: KotlinInt? = {
guard !squareFootage.isEmpty, let value = Int32(squareFootage) else { return nil }
return KotlinInt(int: value)
}()
let lotSizeValue: KotlinFloat? = {
guard !lotSize.isEmpty, let value = Float(lotSize) else { return nil }
return KotlinFloat(float: value)
}()
let yearBuiltValue: KotlinInt? = {
guard !yearBuilt.isEmpty, let value = Int32(yearBuilt) else { return nil }
return KotlinInt(int: value)
}()
// Convert propertyType to KotlinInt if it exists
let propertyTypeValue: KotlinInt? = {
guard let type = selectedPropertyType else { return nil }
return KotlinInt(int: Int32(type.id))
}()
let request = ResidenceCreateRequest(
name: name,
propertyType: Int32(propertyType.id),
streetAddress: streetAddress,
propertyType: propertyTypeValue,
streetAddress: streetAddress.isEmpty ? nil : streetAddress,
apartmentUnit: apartmentUnit.isEmpty ? nil : apartmentUnit,
city: city,
stateProvince: stateProvince,
postalCode: postalCode,
country: country,
bedrooms: Int32(bedrooms) as? KotlinInt,
bathrooms: Float(bathrooms) as? KotlinFloat,
squareFootage: Int32(squareFootage) as? KotlinInt,
lotSize: Float(lotSize) as? KotlinFloat,
yearBuilt: Int32(yearBuilt) as? KotlinInt,
city: city.isEmpty ? nil : city,
stateProvince: stateProvince.isEmpty ? nil : stateProvince,
postalCode: postalCode.isEmpty ? nil : postalCode,
country: country.isEmpty ? nil : country,
bedrooms: bedroomsValue,
bathrooms: bathroomsValue,
squareFootage: squareFootageValue,
lotSize: lotSizeValue,
yearBuilt: yearBuiltValue,
description: description.isEmpty ? nil : description,
purchaseDate: nil,
purchasePrice: nil,