From 463c0059fa8e34143b2bca1e3a85f0b44354a245 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 26 Jul 2022 22:27:16 -0700 Subject: [PATCH] add emailLoginView --- .../Views/Registration/EmailLoginView.swift | 94 +++++++++++++++++++ .../Sources/App/Views/WelcomeView.swift | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 apple/OmnivoreKit/Sources/App/Views/Registration/EmailLoginView.swift diff --git a/apple/OmnivoreKit/Sources/App/Views/Registration/EmailLoginView.swift b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailLoginView.swift new file mode 100644 index 000000000..3c273784b --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailLoginView.swift @@ -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) } + ) + } + } + } + } +} diff --git a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift index 289506352..3202c6734 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift @@ -230,7 +230,7 @@ struct WelcomeView: View { } .padding() .sheet(isPresented: $showEmailLoginModal) { - Text("Email Login") + EmailLoginView() } .sheet(isPresented: $showDebugModal) { DebugMenuView(selectedEnvironment: $selectedEnvironment)