add emailLoginView

This commit is contained in:
Satindar Dhillon 2022-07-26 22:27:16 -07:00
parent 3dd249564e
commit 463c0059fa
2 changed files with 95 additions and 1 deletions

View file

@ -0,0 +1,94 @@
import Models
import Services
import SwiftUI
import Utils
import Views
@MainActor final class EmailLoginViewModel: ObservableObject {
@Published var loginError: LoginError?
func submitCredentials(
email: String,
password: String,
authenticator: Authenticator
) {
print(email)
print(password)
print(authenticator.hasValidAuthToken)
}
}
struct EmailLoginView: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Environment(\.presentationMode) private var presentationMode
@EnvironmentObject var authenticator: Authenticator
@EnvironmentObject var dataService: DataService
@StateObject private var viewModel = EmailLoginViewModel()
@State private var email = ""
@State private var password = ""
var body: some View {
NavigationView {
VStack(spacing: 0) {
VStack(spacing: 28) {
ScrollView(showsIndicators: false) {
if horizontalSizeClass == .regular {
Spacer(minLength: 150)
}
VStack(alignment: .center, spacing: 16) {
VStack(spacing: 16) {
VStack(alignment: .leading, spacing: 6) {
Text("Email")
.font(.appFootnote)
.foregroundColor(.appGrayText)
TextField("", text: $email)
.textContentType(.emailAddress)
}
VStack(alignment: .leading, spacing: 6) {
Text("Password")
.font(.appFootnote)
.foregroundColor(.appGrayText)
TextField("", text: $password)
.textContentType(.password)
}
Button(
action: {
viewModel.submitCredentials(
email: email,
password: password,
authenticator: authenticator
)
},
label: { Text("Submit") }
)
.buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))
if let loginError = viewModel.loginError {
LoginErrorMessageView(loginError: loginError)
}
}
.textFieldStyle(StandardTextFieldStyle())
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Spacer()
}
}
.frame(maxWidth: 300)
.navigationTitle("Sign In")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .barTrailing) {
Button(
action: { presentationMode.wrappedValue.dismiss() },
label: { Image(systemName: "xmark").foregroundColor(.appGrayTextContrast) }
)
}
}
}
}
}

View file

@ -230,7 +230,7 @@ struct WelcomeView: View {
}
.padding()
.sheet(isPresented: $showEmailLoginModal) {
Text("Email Login")
EmailLoginView()
}
.sheet(isPresented: $showDebugModal) {
DebugMenuView(selectedEnvironment: $selectedEnvironment)