| 1 | import SwiftUI |
| 2 | |
| 3 | /// The paired team and this device: who you are, until when, and Sign out, |
| 4 | /// which revokes the device on the server. |
| 5 | public struct AccountScreen: View { |
| 6 | let model: EquipoAppModel |
| 7 | let session: EquipoSession |
| 8 | @State private var confirming = false |
| 9 | public init(model: EquipoAppModel, session: EquipoSession) { self.model = model; self.session = session } |
| 10 | public var body: some View { |
| 11 | Form { |
| 12 | Section(String(localized: "account.team", bundle: .module)) { |
| 13 | LabeledContent(String(localized: "account.team_name", bundle: .module), value: session.teamName) |
| 14 | LabeledContent(String(localized: "account.address", bundle: .module), value: session.origin.host ?? session.origin.absoluteString) |
| 15 | if let me = session.me { LabeledContent(String(localized: "account.signed_in_as", bundle: .module), value: me.address) } |
| 16 | } |
| 17 | Section(String(localized: "account.device", bundle: .module)) { |
| 18 | LabeledContent(String(localized: "account.device_name", bundle: .module), value: session.account.label) |
| 19 | if let expires = session.account.credential?.expiresAt { |
| 20 | LabeledContent(String(localized: "account.until", bundle: .module), value: expires.formatted(date: .long, time: .omitted)) |
| 21 | } |
| 22 | } |
| 23 | MarkdownNotices() |
| 24 | if session.account.oficinaIdentity != nil { |
| 25 | EquipoOficinaAccountMenu(app: model, model: model.oficina.model) |
| 26 | } else { |
| 27 | Section { |
| 28 | Button(String(localized: "account.sign_out", bundle: .module), role: .destructive) { confirming = true } |
| 29 | } footer: { Text(String(localized: "account.sign_out_footer", bundle: .module)) } |
| 30 | } |
| 31 | } |
| 32 | .formStyle(.grouped) |
| 33 | .confirmationDialog(String(localized: "account.sign_out_confirm", bundle: .module), isPresented: $confirming) { |
| 34 | Button(String(localized: "account.sign_out", bundle: .module), role: .destructive) { Task { await model.signOut() } } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |