import SwiftUI struct AddSetView: View { @Environment(\.dismiss) var dismiss @ObservedObject var addSetViewModel: AddSetViewModel var body: some View { NavigationView { VStack(spacing: 20) { HStack { Text("Name:") .font(.headline) TextField("Magician's Force", text: $addSetViewModel.name) .textFieldStyle(RoundedBorderTextFieldStyle()) } HStack { Text("Code:") .font(.headline) TextField("MFC", text: $addSetViewModel.code) .textFieldStyle(RoundedBorderTextFieldStyle()) .textInputAutocapitalization(.characters) .autocorrectionDisabled() } DatePicker( "Release Date:", selection: $addSetViewModel.releaseDate, displayedComponents: [.date] ) .font(.headline) HStack { Text("Number of Cards:") TextField("", value: $addSetViewModel.numberOfCards, formatter: NumberFormatter()) .keyboardType(.numberPad) .textFieldStyle(.roundedBorder) } .font(.headline) Button(action: { Task { do { let _: () = try await addSetViewModel.add() // Adding this new set to records } catch { print(error.localizedDescription) } } dismiss() }, label: { Text("Add") .font(.headline) .foregroundColor(.white) .padding() .frame(maxWidth: .infinity) .background(isEmptyFields(name: addSetViewModel.name, code: addSetViewModel.code) ? Color.gray : Color.blue) .cornerRadius(10) }) } .padding() .navigationTitle("New set") } } }