Add delete confirmation dialogs for clients, projects, and time entries

- Add confirmation alert when deleting clients with warning about
deleted dependencies (projects and time entries)
- Add confirmation alert when deleting projects with warning about
deleted time entries
- Add confirmation alert when deleting time entries
- All alerts include item name and emphasize action cannot be undone
This commit is contained in:
2026-02-20 15:32:40 +01:00
parent f42de3353c
commit a39f8b07df
3 changed files with 45 additions and 12 deletions

View File

@@ -3,6 +3,8 @@ import SwiftUI
struct ClientsView: View {
@StateObject private var viewModel = ClientsViewModel()
@State private var showAddClient = false
@State private var clientToDelete: Client?
@State private var showDeleteConfirmation = false
var body: some View {
NavigationStack {
@@ -52,13 +54,22 @@ struct ClientsView: View {
ClientRow(client: client)
}
.onDelete { indexSet in
Task {
for index in indexSet {
await viewModel.deleteClient(viewModel.clients[index])
}
if let index = indexSet.first {
clientToDelete = viewModel.clients[index]
showDeleteConfirmation = true
}
}
}
.alert("Delete Client?", isPresented: $showDeleteConfirmation, presenting: clientToDelete) { client in
Button("Cancel", role: .cancel) {}
Button("Delete", role: .destructive) {
Task {
await viewModel.deleteClient(client)
}
}
} message: { client in
Text("This will permanently delete '\(client.name)' and all related projects and time entries. This action cannot be undone.")
}
.refreshable {
await viewModel.loadClients()
}