Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka Admin iOS9// File : ImmoKaAdmin/Features/DashboardView.swift10// Description : tableau de bord — ce qui demande une action (demandes en11// attente, signalements ouverts, courrier non lu), puis les12// chiffres du service. Tirer pour rafraîchir.13// Module : ImmoKaAdmin14// Repository : https://git.spboucher.ai/immo-ka-admin-ios15// Project Website : https://www.immo-ka.com16// Created : 2026-11-3017// Last Modified : 2026-11-3018//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : None specified (no license file in this repository)84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import SwiftUI9293struct DashboardView: View {94 @Environment(AdminSession.self) private var session95 @Environment(Navigator.self) private var nav96 @State private var unreadMail: Int?97 @State private var failure: String?9899 var body: some View {100 ScrollView {101 if let me = session.me {102 VStack(alignment: .leading, spacing: 24) {103 VStack(alignment: .leading, spacing: 4) {104 Text(verbatim: "Bonjour, \(me.admin.name)").font(.editorial(26)).foregroundStyle(Theme.ink)105 Text(verbatim: Fmt.dateTime(Date())).font(.footnote).foregroundStyle(Theme.ink3)106 }107 if let failure { ErrorBanner(text: failure) }108 section("À traiter") {109 ActionRow(symbol: "person.text.rectangle", title: "Demandes de courtiers en attente", count: me.stats.courtiersEnAttente, id: "dashboard.pending") { nav.tab = .brokers }110 Divider().overlay(Theme.line)111 ActionRow(symbol: "flag", title: "Signalements ouverts", count: me.stats.signalementsOuverts, id: "dashboard.reports") { nav.tab = .reports }112 if me.mail {113 Divider().overlay(Theme.line)114 ActionRow(symbol: "envelope", title: "Courriels non lus", count: unreadMail, id: "dashboard.mail") { nav.tab = .mail }115 }116 }117 section("Le service") {118 LazyVGrid(columns: [GridItem(.adaptive(minimum: 136), spacing: 12, alignment: .topLeading)], alignment: .leading, spacing: 16) {119 stat(me.stats.comptes, "comptes")120 stat(me.stats.verifies, "comptes vérifiés")121 stat(me.stats.sessions, "sessions ouvertes")122 stat(me.stats.favoris, "favoris gardés")123 stat(me.stats.recherches, "recherches enregistrées")124 stat(me.stats.courtiersApprouves, "courtiers approuvés")125 }126 .padding(.vertical, 6)127 }128 }129 .padding(20)130 .frame(maxWidth: 820, alignment: .leading)131 .frame(maxWidth: .infinity)132 }133 }134 .background(Theme.bg)135 .navigationTitle("Tableau de bord")136 .navigationBarTitleDisplayMode(.inline)137 .refreshable { await load() }138 .task { await load() }139 .accessibilityIdentifier("dashboard")140 }141142 private func load() async {143 do {144 try await session.load()145 failure = nil146 if session.me?.mail == true {147 unreadMail = (try? await session.call { try await $0.mailboxes() })?.reduce(0) { $0 + $1.unreadInbox }148 }149 } catch {150 if session.isSignedIn { failure = AdminError.message(error) }151 }152 }153154 private func section<C: View>(_ title: String, @ViewBuilder _ content: () -> C) -> some View {155 VStack(alignment: .leading, spacing: 8) {156 Text(title).font(.caption.weight(.semibold)).tracking(0.8).textCase(.uppercase).foregroundStyle(Theme.ink3).accessibilityAddTraits(.isHeader)157 VStack(alignment: .leading, spacing: 0) { content() }.cardStyle(padding: 14)158 }159 }160161 private func stat(_ n: Int, _ label: String) -> some View {162 VStack(alignment: .leading, spacing: 2) {163 Text(Fmt.int(n)).font(.display(24)).monospacedDigit().foregroundStyle(Theme.ink)164 Text(label).font(.footnote).foregroundStyle(Theme.ink2)165 }166 .frame(maxWidth: .infinity, alignment: .leading)167 .accessibilityElement(children: .combine)168 }169}170171private struct ActionRow: View {172 let symbol: String173 let title: String174 let count: Int?175 let id: String176 let action: () -> Void177 var body: some View {178 Button(action: action) {179 HStack(spacing: 12) {180 Image(systemName: symbol).foregroundStyle(Theme.brand).frame(width: 26).accessibilityHidden(true)181 Text(title).font(.subheadline).foregroundStyle(Theme.ink).multilineTextAlignment(.leading)182 Spacer(minLength: 8)183 if let count {184 Text(Fmt.int(count)).font(.subheadline.weight(.bold)).monospacedDigit()185 .foregroundStyle(count > 0 ? Color.white : Theme.ink3)186 .padding(.horizontal, 9).frame(minWidth: 28, minHeight: 26)187 .background(count > 0 ? Theme.accentUI : Theme.surface2, in: Capsule())188 } else {189 Text("—").foregroundStyle(Theme.ink3)190 }191 Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3).accessibilityHidden(true)192 }193 .frame(minHeight: 44)194 .contentShape(Rectangle())195 }196 .buttonStyle(.plain)197 .accessibilityElement(children: .ignore)198 .accessibilityLabel(count.map { "\(title) : \(Fmt.int($0))" } ?? title)199 .accessibilityAddTraits(.isButton)200 .accessibilityIdentifier(id)201 }202}203