Fix issue with window creation

multistore
Laurent 1 year ago
parent 6f4398ee8c
commit 2bd79445c5
  1. 39
      PadelClub/Views/Navigation/Umpire/UmpireView.swift
  2. 21
      PadelClub/Views/User/LoginView.swift
  3. 1
      PadelClub/Views/User/MainUserView.swift
  4. 31
      PadelClub/Views/User/UserCreationView.swift

@ -17,6 +17,8 @@ struct UmpireView: View {
@State private var presentSearchView: Bool = false
@State private var showSubscriptions: Bool = false
// @State var isConnected: Bool = false
var lastDataSource: String? {
dataStore.appSettings.lastDataSource
}
@ -47,18 +49,17 @@ struct UmpireView: View {
}
}
if self._isConnected() {
NavigationLink {
MainUserView()
AccountView(user: dataStore.user) { }
} label: {
LabeledContent {
if Store.main.hasToken() {
Text(dataStore.user.username)
} else {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.logoRed)
AccountRowView(userName: dataStore.user.username)
}
} else {
NavigationLink {
LoginView {_ in }
} label: {
Label("Mon compte", systemImage: "person.fill")
AccountRowView(userName: dataStore.user.username)
}
}
@ -211,6 +212,28 @@ struct UmpireView: View {
}
}
}
fileprivate func _isConnected() -> Bool {
return dataStore.user.username.count > 0 && Store.main.hasToken()
}
}
struct AccountRowView: View {
var userName: String
var body: some View {
LabeledContent {
if Store.main.hasToken() {
Text(self.userName)
} else {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.logoRed)
}
} label: {
Label("Mon compte", systemImage: "person.fill")
}
}
}
#Preview {

@ -18,11 +18,12 @@ struct LoginView: View {
@State var isLoading: Bool = false
@State var showEmailPopup: Bool = false
@State var showUserCreationForm: Bool = false
@State var showEmailValidationMessage: Bool = false
@State var showSubscriptionView: Bool = false
@State var errorText: String? = nil
@State var showSubscriptionView: Bool = false
var loginFailed: Binding<Bool> {
Binding {
errorText != nil
@ -33,8 +34,6 @@ struct LoginView: View {
}
}
var showEmailValidationMessage: Bool = false
var handler: (User) -> ()
var body: some View {
@ -64,9 +63,19 @@ struct LoginView: View {
if !self.showEmailValidationMessage {
Section {
NavigationLink("Créer un compte") {
UserCreationView()
Button(action: {
self.showUserCreationForm = true
}, label: {
Text("Créer un compte")
})
.sheet(isPresented: self.$showUserCreationForm) {
UserCreationFormView(isPresented: self.$showUserCreationForm, showEmailValidationMessage: self.$showEmailValidationMessage)
}
// NavigationLink("Créer un compte") {
// UserCreationView()
// }
Button(action: {
self.showEmailPopup = true
}, label: {

@ -31,6 +31,7 @@ struct MainUserView: View {
}
fileprivate func _checkConnection() {
Logger.log("_checkConnection")
self.isConnected = dataStore.user.username.count > 0 && Store.main.hasToken()
}

@ -10,7 +10,8 @@ import LeStorage
struct UserCreationFormView: View {
@Binding var showLoginScreen: Bool
@Binding var isPresented: Bool
@Binding var showEmailValidationMessage: Bool
@State var username: String = ""
@State var password1: String = ""
@ -39,6 +40,7 @@ struct UserCreationFormView: View {
var body: some View {
NavigationStack {
Form {
Section {
@ -89,6 +91,7 @@ struct UserCreationFormView: View {
}).disabled(!self.dataCollectAuthorized)
.frame(maxWidth: .infinity)
}
}.navigationTitle("Créez votre compte")
}
.onAppear {
self._selectCountry()
@ -152,12 +155,12 @@ struct UserCreationFormView: View {
country: self.countries[self.selectedCountryIndex])
let service = try Store.main.service()
let user: User = try await service.createAccount(user: userCreationForm)
let _: User = try await service.createAccount(user: userCreationForm)
DispatchQueue.main.async {
DataStore.shared.user = user
self.isLoading = false
self.showLoginScreen = true
self.showEmailValidationMessage = true
self.isPresented = false
}
} catch {
@ -169,24 +172,6 @@ struct UserCreationFormView: View {
}
struct UserCreationView: View {
@State var showLoginScreen: Bool = false
var body: some View {
Group {
if self.showLoginScreen {
LoginView(showEmailValidationMessage: true) { _ in }
} else {
UserCreationFormView(showLoginScreen: self.$showLoginScreen)
}
}
.navigationTitle("Créez votre compte")
}
}
#Preview {
UserCreationView()
UserCreationFormView(isPresented: .constant(true), showEmailValidationMessage: .constant(true))
}

Loading…
Cancel
Save