aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Session/AccountView.swift
blob: 4ca453a3a574acc4913ac9a4601404392dc7e202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
//  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()
        }
    }
}