// // AccountView.swift // iosApp // // Created by Iván on 15/02/22. // Copyright © 2022 orgName. All rights reserved. // import SwiftUI struct AccountView: View { @StateObject var accountViewModel = AccountViewModel() @EnvironmentObject var rootViewModel: RootViewModel var body: some View { List { Section { // MARK: - Name if let name = accountViewModel.user?.name { HStack { Text("username") Spacer() Text(name).foregroundColor(.secondaryLabel) } } // MARK: - E-mail if let email = accountViewModel.user?.email { HStack { Text("email") Spacer() Text(email).foregroundColor(.secondaryLabel) } } // MARK: - Unique ID if let uid = accountViewModel.user?.id { HStack { Text("unique-id") Spacer() Text("\(uid)").foregroundColor(.secondaryLabel) } } // MARK: - Administrator if let admin = accountViewModel.user?.administrator { HStack { Text("admin") Spacer() Text("\(admin)").foregroundColor(.secondaryLabel) } } // MARK: - Server URL if let server = UserDefaults.standard.string(forKey: "server-url") { HStack { Text("server-url") Spacer() Text(server).foregroundColor(.secondaryLabel) } } } Section { // MARK: - Sign out Button { rootViewModel.signOut() } label: { Label("signout", systemImage: "rectangle.portrait.and.arrow.right") .foregroundColor(.systemRed) } } }.onAppear { accountViewModel.fetchUserInfo() } } }