Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent Users From Deleting All Vehicles #276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Basic-Car-Maintenance/Shared/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,22 @@
}
}
},
"Can't Delete Last Vehicle" : {
"localizations" : {
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Невозможно удалить последний автомобиль"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Son Araç Silinemiyor"
}
}
}
},
"Cancel" : {
"localizations" : {
"be" : {
Expand Down Expand Up @@ -3934,6 +3950,9 @@
}
}
},
"The last vehicle can't be deleted. Please add a new vehicle before removing this one." : {
"comment" : "Alert message preventing users from deleting their last vehicle"
},
"The title of the event" : {
"comment" : "Maintenance event title text field label placeholder",
"localizations" : {
Expand Down Expand Up @@ -4413,7 +4432,14 @@
}
},
"Update Vehicle Info" : {

"localizations" : {
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Araç Bilgilerini Güncelle"
}
}
}
},
"Vehicle" : {
"comment" : "Maintenance event vehicle picker header",
Expand Down
14 changes: 13 additions & 1 deletion Basic-Car-Maintenance/Shared/Settings/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@State private var viewModel: SettingsViewModel
@State private var isShowingAddVehicle = false
@State private var showDeleteVehicleError = false
@State private var showDeleteVehicleAlert = false
@State private var showAddVehicleError = false
@State private var errorDetails: Error?
@State private var copiedAppVersion: Bool = false
Expand Down Expand Up @@ -117,7 +118,11 @@
Button(role: .destructive) {
Task {
do {
try await viewModel.deleteVehicle(vehicle)
if viewModel.vehicles.count > 1 {
try await viewModel.deleteVehicle(vehicle)
} else {
showDeleteVehicleAlert = true
}
} catch {
errorDetails = error
showDeleteVehicleError = true
Expand All @@ -141,7 +146,7 @@
}

Button {
// TODO: Show Paywall

Check warning on line 149 in Basic-Car-Maintenance/Shared/Settings/Views/SettingsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

TODOs should be resolved (Show Paywall) (todo)
// Show paywall if adding more than 1 vehicle, or show the `isShowingAddVehicle` view
isShowingAddVehicle = true
} label: {
Expand Down Expand Up @@ -240,6 +245,13 @@
comment: "Label to display error details.")
}
}
.alert("Can't Delete Last Vehicle", isPresented: $showDeleteVehicleAlert) {
Button("OK", role: .cancel) {
showDeleteVehicleAlert = false
}
} message: {
Text("The last vehicle can't be deleted. Please add a new vehicle before removing this one.", comment: "Alert message preventing users from deleting their last vehicle")

Check warning on line 253 in Basic-Car-Maintenance/Shared/Settings/Views/SettingsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line should be 110 characters or less; currently it has 185 characters (line_length)
}
.navigationTitle(Text("Settings", comment: "Label to display settings."))
.task {
await viewModel.getVehicles()
Expand All @@ -248,7 +260,7 @@
.onChange(of: scenePhase) { _, newScenePhase in
guard case .active = newScenePhase else { return }

// TODO: Show Paywall

Check warning on line 263 in Basic-Car-Maintenance/Shared/Settings/Views/SettingsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

TODOs should be resolved (Show Paywall) (todo)

guard let action = actionService.action,
action == .addVehicle
Expand Down
Loading