83 lines
2.9 KiB
Swift
83 lines
2.9 KiB
Swift
import SwiftUI
|
|
|
|
struct LoginView: View {
|
|
@EnvironmentObject var authViewModel: AuthViewModel
|
|
@State private var email = ""
|
|
@State private var password = ""
|
|
@State private var showRegister = false
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
VStack(spacing: 24) {
|
|
Spacer()
|
|
VStack(spacing: 8) {
|
|
Image(systemName: "bell.badge.fill")
|
|
.font(.system(size: 60))
|
|
.foregroundStyle(.red)
|
|
Text("Mayday")
|
|
.font(.largeTitle.bold())
|
|
Text("Мониторинг и уведомления")
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
VStack(spacing: 16) {
|
|
TextField("Email", text: $email)
|
|
.textFieldStyle(.roundedBorder)
|
|
.textContentType(.emailAddress)
|
|
.keyboardType(.emailAddress)
|
|
.autocorrectionDisabled()
|
|
.textInputAutocapitalization(.never)
|
|
|
|
SecureField("Пароль", text: $password)
|
|
.textFieldStyle(.roundedBorder)
|
|
.textContentType(.password)
|
|
}
|
|
|
|
if let error = authViewModel.error {
|
|
Text(error)
|
|
.foregroundStyle(.red)
|
|
.font(.footnote)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
|
|
Button {
|
|
Task { await authViewModel.login(email: email, password: password) }
|
|
} label: {
|
|
if authViewModel.isLoading {
|
|
ProgressView()
|
|
.frame(maxWidth: .infinity)
|
|
} else {
|
|
Text("Войти")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(email.isEmpty || password.isEmpty || authViewModel.isLoading)
|
|
|
|
Button("Нет аккаунта? Зарегистрироваться") {
|
|
showRegister = true
|
|
}
|
|
.font(.footnote)
|
|
|
|
#if DEBUG
|
|
Button {
|
|
Task { await authViewModel.enterPreviewMode() }
|
|
} label: {
|
|
Label("Демо-режим", systemImage: "play.circle.fill")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.padding(.top, 8)
|
|
#endif
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.navigationDestination(isPresented: $showRegister) {
|
|
RegisterView()
|
|
}
|
|
}
|
|
}
|
|
}
|