Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka Admin iOS9// File : LouKaAdmin/Features/ManagersView.swift10// Description : demandes d'accès des gestionnaires — liste par état,11// détail, décisions (approuver, refuser et suspendre avec12// motif transmis au demandeur, rétablir, remettre en13// attente), rattachement à un gestionnaire de l'annuaire,14// fiche personnalisée (aperçu, masquer, rétablir). Toute15// décision est confirmée. Tout ce que le demandeur a écrit16// est du texte brut.17// Module : LouKaAdmin18// Repository : https://git.spboucher.ai/lou-ka-admin-ios19// Project Website : https://www.lou-ka.com20// Created : 2026-11-3021// Last Modified : 2026-11-3022//23// =============================================================================24// AUTHOR & PROFESSIONAL AFFILIATION25// =============================================================================26//27// Author : Simon-Pierre Boucher28// Position : Professor of Finance29// Institution : Université du Québec en Outaouais (UQO)30// Department : Département des sciences administratives31// Organization : SP Boucher32//33// Website : https://spboucher.ai34// Git : https://git.spboucher.ai35//36// =============================================================================37// OFFICIAL CONTACT DIRECTORY38// =============================================================================39//40// General : info@spboucher.ai41// Professional : contact@spboucher.ai42// Direct : simon@spboucher.ai43// Research : research@spboucher.ai44// Development : dev@spboucher.ai45// Support : support@spboucher.ai46// Security/Admin : admin@spboucher.ai47// Notifications : notifications@spboucher.ai48//49// Preferred Contact: support@spboucher.ai50//51// =============================================================================52// COPYRIGHT & INTELLECTUAL PROPERTY53// =============================================================================54//55// Copyright (c) 202656// Simon-Pierre Boucher57//58// All rights reserved where applicable.59//60// This file is governed by the applicable project license,61// copyright notices, institutional agreements and relevant law.62//63// Unless expressly authorized by the applicable license or64// rights holder, copying, redistribution, sublicensing,65// publication and commercial exploitation are not permitted.66//67// Existing third-party rights and notices remain unaffected.68//69// =============================================================================70// CONFIDENTIALITY & SECURITY71// =============================================================================72//73// Classification : Public74// Distribution : Public repository; use is governed by the project license75// Security Contact : admin@spboucher.ai76//77// Access to this source does not independently grant permission78// to redistribute or disclose confidential materials.79//80// Do not embed credentials, private keys, access tokens,81// certificates or confidential personal information.82//83// =============================================================================84// LICENSE & MAINTENANCE85// =============================================================================86//87// License : None specified (no license file in this repository)88// Maintainer : Simon-Pierre Boucher89// Technical Contact: dev@spboucher.ai90//91// =============================================================================92// END OF SP BOUCHER SOURCE HEADER93// =============================================================================9495import SwiftUI9697struct ManagersView: View {98 @Environment(AdminSession.self) private var session99 @State private var filter: ManagerFilter = {100 ManagerFilter(rawValue: UserDefaults.standard.string(forKey: "LKManagers") ?? "") ?? .pending101 }()102 @State private var items: [ManagerRequest]?103 @State private var failure: String?104105 var body: some View {106 VStack(spacing: 0) {107 Picker("État des demandes", selection: $filter) {108 ForEach(ManagerFilter.allCases) { Text($0.label).tag($0) }109 }110 .pickerStyle(.menu)111 .frame(maxWidth: .infinity, alignment: .leading)112 .padding(.horizontal, 12).padding(.vertical, 4)113 .accessibilityIdentifier("managers.filter")114 Divider().overlay(Theme.line)115 Loadable(value: items, failure: failure, retry: { Task { await load() } }) { items in116 List {117 if items.isEmpty {118 EmptyState(symbol: "checkmark.circle", title: filter == .pending ? "Aucune demande en attente" : "Aucune demande dans cet état").listRowBackground(Color.clear)119 }120 ForEach(items) { r in121 NavigationLink(value: r) { ManagerRow(request: r) }.accessibilityIdentifier("managers.row")122 }123 }124 .listStyle(.plain)125 .refreshable { await load() }126 }127 }128 .background(Theme.bg)129 .navigationTitle("Gestionnaires")130 .navigationBarTitleDisplayMode(.inline)131 // la demande voyage avec la navigation : son détail reste à l'écran quand une décision la sort de la liste132 .navigationDestination(for: ManagerRequest.self) { r in133 ManagerDetailView(request: r) { Task { await load() } }134 }135 .task(id: filter) { items = nil; await load() }136 }137138 private func load() async {139 do {140 items = try await session.call { try await $0.managers(filter) }141 failure = nil142 try? await session.load()143 } catch {144 if items == nil { failure = AdminError.message(error) }145 }146 }147}148149private struct ManagerRow: View {150 let request: ManagerRequest151 var body: some View {152 VStack(alignment: .leading, spacing: 5) {153 HStack(alignment: .firstTextBaseline) {154 Text(verbatim: request.company.isEmpty ? "Entreprise non nommée" : request.company).font(.subheadline.weight(.semibold)).foregroundStyle(Theme.ink).lineLimit(2)155 Spacer(minLength: 8)156 request.status.tag157 }158 Text(verbatim: [request.name, request.email].filter { !$0.isEmpty }.joined(separator: " · ")).font(.footnote).foregroundStyle(Theme.ink2).lineLimit(2)159 HStack(spacing: 8) {160 Text(verbatim: "demandé le \(Fmt.dateTime(request.requestedAt))").font(.caption).foregroundStyle(Theme.ink3)161 if !request.inDirectory { StatusTag(label: "Hors annuaire", symbol: "questionmark.circle", tone: .warn) }162 }163 }164 .padding(.vertical, 3)165 .accessibilityElement(children: .combine)166 }167}168169/// Décision demandée, en attente de confirmation.170private struct PendingDecision: Identifiable {171 var action: ManagerAction172 var id: String { action.rawValue }173}174175struct ManagerDetailView: View {176 @State var request: ManagerRequest177 var changed: () -> Void178 @Environment(AdminSession.self) private var session179 @Environment(Navigator.self) private var nav180 @State private var deciding: PendingDecision?181 @State private var attaching = false182 @State private var failure: String?183184 var body: some View {185 Form {186 if let failure { Section { ErrorBanner(text: failure).listRowInsets(EdgeInsets()) } }187 Section {188 HStack { Text("État").foregroundStyle(Theme.ink); Spacer(); request.status.tag }189 .accessibilityElement(children: .combine)190 .accessibilityIdentifier("manager.status")191 if let reason = request.reason {192 VStack(alignment: .leading, spacing: 3) {193 Text("Motif transmis").font(.caption).foregroundStyle(Theme.ink3)194 PlainText(text: reason, color: Theme.ink)195 }196 }197 InfoRow(label: "Demande", value: Fmt.dateTime(request.requestedAt))198 InfoRow(label: "Adresse confirmée", value: Fmt.dateTime(request.verifiedAt))199 if request.decidedAt != nil { InfoRow(label: "Décision", value: "\(Fmt.dateTime(request.decidedAt))\(request.decidedBy.map { "\npar \($0)" } ?? "")") }200 InfoRow(label: "Dernière connexion", value: Fmt.relative(request.lastLogin))201 }202 Section("Personne") {203 InfoRow(label: "Nom", value: request.name.isEmpty ? "—" : request.name)204 if let t = request.title { InfoRow(label: "Fonction", value: t) }205 InfoRow(label: "Courriel", value: request.email)206 if let p = request.phone { InfoRow(label: "Téléphone", value: p) }207 }208 Section {209 InfoRow(label: "Entreprise", value: request.company.isEmpty ? "—" : request.company)210 if let w = request.website {211 if let u = safeWebURL(w) {212 LabeledContent("Site") { Link(destination: u) { Text(verbatim: w).multilineTextAlignment(.trailing) } }213 } else {214 InfoRow(label: "Site", value: w)215 }216 }217 if let d = request.domain { InfoRow(label: "Domaine du courriel", value: d) }218 } header: {219 Text("Entreprise déclarée")220 } footer: {221 Text("L'adresse courriel du demandeur doit être au domaine du site de l'entreprise. Vérifiez que le site est bien celui de l'entreprise avant d'approuver.")222 }223 Section {224 if let dir = request.directory, let sid = request.sourceID {225 InfoRow(label: "Gestionnaire", value: dir.name)226 InfoRow(label: "Identifiant", value: sid)227 if let n = dir.listings { InfoRow(label: "Logements", value: Fmt.int(n)) }228 if let w = dir.website { InfoRow(label: "Site connu de Lou-Ka", value: w) }229 NavigationLink { FicheView(sourceID: sid, name: dir.name) } label: { Label("Fiche personnalisée", systemImage: "doc.richtext") }230 .accessibilityIdentifier("manager.fiche")231 } else {232 Label("Cette demande n'est rattachée à aucun gestionnaire de l'annuaire.", systemImage: "questionmark.circle").font(.subheadline).foregroundStyle(Theme.ink2)233 }234 Button { attaching = true } label: { Label(request.sourceID == nil ? "Rattacher à un gestionnaire de l'annuaire" : "Changer le rattachement", systemImage: "link") }235 .accessibilityIdentifier("manager.attach")236 } header: {237 Text("Annuaire")238 } footer: {239 if !request.canBeApproved { Text("Une demande doit être rattachée à un gestionnaire de l'annuaire avant d'être approuvée.") }240 }241 Section("Décision") {242 ForEach(ManagerAction.available(for: request.status), id: \.rawValue) { action in243 Button(role: action.isDestructive ? .destructive : nil) { deciding = PendingDecision(action: action) } label: {244 Label(action.title, systemImage: symbol(action))245 }246 .disabled(action == .approve && !request.canBeApproved)247 .accessibilityIdentifier("manager.action.\(action.rawValue)")248 }249 }250 }251 .navigationTitle(request.company.isEmpty ? "Demande" : request.company)252 .navigationBarTitleDisplayMode(.inline)253 .sheet(item: $deciding) { d in254 DecisionSheet(request: request, action: d.action) { reason in255 try await session.call { try await $0.decide(accountID: request.accountID, action: d.action, reason: reason) }256 await reload()257 nav.show(done(d.action))258 }259 }260 .sheet(isPresented: $attaching) {261 DirectorySearchSheet(company: request.company) { manager in262 try await session.call { try await $0.decide(accountID: request.accountID, action: .attach, sourceID: manager.sourceID) }263 await reload()264 nav.show("Demande rattachée à \(manager.name)")265 }266 }267 }268269 private func symbol(_ a: ManagerAction) -> String {270 switch a {271 case .approve: "checkmark.seal"272 case .refuse: "xmark.octagon"273 case .suspend: "pause.circle"274 case .restore: "arrow.uturn.backward.circle"275 case .backToPending: "hourglass"276 case .attach: "link"277 }278 }279280 private func done(_ a: ManagerAction) -> String {281 switch a {282 case .approve: "Demande approuvée"283 case .refuse: "Demande refusée"284 case .suspend: "Accès suspendu"285 case .restore: "Accès rétabli"286 case .backToPending: "Demande remise en attente"287 case .attach: "Rattachement modifié"288 }289 }290291 /// Relit la demande après une décision (elle a pu changer d'état, donc de liste).292 private func reload() async {293 if let fresh = try? await session.call({ try await $0.managers(.all) }).first(where: { $0.accountID == request.accountID }) { request = fresh }294 changed()295 }296}297298/// Confirmation d'une décision ; motif obligatoire pour refuser ou suspendre.299private struct DecisionSheet: View {300 let request: ManagerRequest301 let action: ManagerAction302 var submit: (String?) async throws -> Void303 @Environment(\.dismiss) private var dismiss304 @State private var reason = ""305 @State private var busy = false306 @State private var failure: String?307308 private var ready: Bool { !action.needsReason || !reason.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }309310 var body: some View {311 NavigationStack {312 Form {313 if let failure { Section { ErrorBanner(text: failure).listRowInsets(EdgeInsets()) } }314 Section {315 InfoRow(label: "Entreprise", value: request.company)316 InfoRow(label: "Demandeur", value: [request.name, request.email].filter { !$0.isEmpty }.joined(separator: "\n"))317 } footer: {318 Text(consequence)319 }320 if action.needsReason {321 Section {322 TextField("Motif", text: $reason, axis: .vertical).lineLimit(3...8).accessibilityIdentifier("decision.reason")323 } header: {324 Text("Motif (obligatoire)")325 } footer: {326 Text("Le motif est transmis tel quel au demandeur, par courriel et dans son compte.")327 }328 }329 }330 .navigationTitle(action.title)331 .navigationBarTitleDisplayMode(.inline)332 .toolbar {333 ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() }.accessibilityIdentifier("decision.cancel") }334 // dans la barre : toujours visible, quelle que soit la hauteur de la feuille335 ToolbarItem(placement: .confirmationAction) {336 Button {337 busy = true; failure = nil338 Task {339 defer { busy = false }340 do { try await submit(action.needsReason ? reason : nil); dismiss() } catch { failure = AdminError.message(error) }341 }342 } label: {343 if busy { ProgressView() } else { Text(action.title).fontWeight(.semibold) }344 }345 .tint(action.isDestructive ? Theme.bad : Theme.brand)346 .disabled(!ready || busy)347 .accessibilityLabel("\(action.title) la demande")348 .accessibilityIdentifier("decision.confirm")349 }350 }351 }352 .presentationDetents([.medium, .large])353 }354355 private var consequence: String {356 switch action {357 case .approve: "Le demandeur pourra modifier la fiche de cette entreprise et répondre aux messages des chercheurs de logement. Il en est avisé par courriel."358 case .refuse: "La demande est refusée. Le demandeur en est avisé par courriel, avec votre motif."359 case .suspend: "L'accès au portail est suspendu tout de suite. Le gestionnaire en est avisé par courriel, avec votre motif."360 case .restore: "L'accès au portail est rétabli. Le gestionnaire en est avisé par courriel."361 case .backToPending: "La demande revient dans la liste des demandes en attente ; l'accès au portail est fermé d'ici là."362 case .attach: "Seul le rattachement change."363 }364 }365}366367/// Recherche dans l'annuaire pour rattacher une demande.368private struct DirectorySearchSheet: View {369 let company: String370 var choose: (DirectoryManager) async throws -> Void371 @Environment(AdminSession.self) private var session372 @Environment(\.dismiss) private var dismiss373 @State private var query = ""374 @State private var results: [DirectoryManager] = []375 @State private var searching = false376 @State private var candidate: DirectoryManager?377 @State private var failure: String?378 @State private var busy = false379380 var body: some View {381 NavigationStack {382 List {383 if let failure { ErrorBanner(text: failure).listRowInsets(EdgeInsets()) }384 if results.isEmpty && !searching {385 Text(query.count < 2 ? "Écrivez au moins deux lettres du nom du gestionnaire." : "Aucun gestionnaire de l'annuaire ne correspond.")386 .font(.subheadline).foregroundStyle(Theme.ink3)387 }388 ForEach(results) { m in389 Button { candidate = m } label: {390 VStack(alignment: .leading, spacing: 2) {391 Text(verbatim: m.name).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)392 Text(verbatim: [m.sourceID, m.domain, m.listings.map { Fmt.plural($0, "logement", "logements") }].compactMap { $0 }.joined(separator: " · ")).font(.caption).foregroundStyle(Theme.ink3)393 }394 }395 .disabled(busy)396 .accessibilityIdentifier("directory.row")397 }398 }399 .listStyle(.plain)400 .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always), prompt: "Nom du gestionnaire")401 .navigationTitle("Rattacher")402 .navigationBarTitleDisplayMode(.inline)403 .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() } } }404 .task(id: query) {405 let q = query.trimmingCharacters(in: .whitespaces)406 guard q.count >= 2 else { results = []; return }407 searching = true408 try? await Task.sleep(for: .milliseconds(300))409 if Task.isCancelled { return }410 results = (try? await session.api.searchDirectory(q)) ?? []411 searching = false412 }413 .onAppear { if query.isEmpty { query = String(company.prefix(24)) } }414 .alert("Rattacher la demande ?", isPresented: Binding(get: { candidate != nil }, set: { if !$0 { candidate = nil } }), presenting: candidate) { m in415 Button("Rattacher") {416 busy = true; failure = nil417 Task {418 defer { busy = false }419 do { try await choose(m); dismiss() } catch { failure = AdminError.message(error) }420 }421 }422 Button("Annuler", role: .cancel) {}423 } message: { m in424 Text(verbatim: "La demande de « \(company) » sera rattachée à « \(m.name) » (\(m.sourceID)).")425 }426 }427 }428}429430// MARK: - Fiche personnalisée431432struct FicheView: View {433 let sourceID: String434 let name: String435 @Environment(AdminSession.self) private var session436 @Environment(Navigator.self) private var nav437 @State private var fiche: AdminFiche?438 @State private var failure: String?439 @State private var showDraft = false440 @State private var hiding = false441 @State private var confirmRestore = false442 @State private var actionError: String?443444 var body: some View {445 Loadable(value: fiche, failure: failure, retry: { Task { await load() } }) { f in446 Form {447 if let actionError { Section { ErrorBanner(text: actionError).listRowInsets(EdgeInsets()) } }448 Section {449 HStack {450 Text("Visibilité")451 Spacer()452 if f.hidden { StatusTag(label: "Masquée", symbol: "eye.slash", tone: .bad) }453 else if f.published != nil { StatusTag(label: "Publiée", symbol: "eye", tone: .good) }454 else { StatusTag(label: "Jamais publiée", symbol: "doc", tone: .neutral) }455 }456 .accessibilityElement(children: .combine)457 if f.hidden, let r = f.hiddenReason {458 VStack(alignment: .leading, spacing: 3) { Text("Motif du masquage").font(.caption).foregroundStyle(Theme.ink3); PlainText(text: r, color: Theme.ink) }459 }460 if f.publishedAt != nil { InfoRow(label: "Publiée le", value: Fmt.dateTime(f.publishedAt)) }461 if f.draftUpdatedAt != nil { InfoRow(label: "Brouillon modifié le", value: Fmt.dateTime(f.draftUpdatedAt)) }462 if f.dirty { Label("Le brouillon diffère de la version publiée.", systemImage: "pencil.line").font(.footnote).foregroundStyle(Theme.ink2) }463 InfoRow(label: "Images téléversées", value: Fmt.int(f.mediaCount))464 if f.hidden {465 Button { confirmRestore = true } label: { Label("Rétablir la fiche", systemImage: "eye") }.accessibilityIdentifier("fiche.restore")466 } else if f.published != nil {467 Button(role: .destructive) { hiding = true } label: { Label("Masquer la fiche", systemImage: "eye.slash") }.accessibilityIdentifier("fiche.hide")468 }469 } footer: {470 Text("Masquer retire la fiche personnalisée du site et des applications ; le gestionnaire garde son accès et ses messages.")471 }472 if !f.team.isEmpty {473 Section("Comptes approuvés de l'entreprise") {474 ForEach(f.team) { m in475 VStack(alignment: .leading, spacing: 2) {476 Text(verbatim: m.name.isEmpty ? m.email : m.name).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)477 Text(verbatim: [m.title, m.email].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · ")).font(.caption).foregroundStyle(Theme.ink3)478 }479 .accessibilityElement(children: .combine)480 }481 }482 }483 Section {484 Picker("Version", selection: $showDraft) { Text("Publiée").tag(false); Text("Brouillon").tag(true) }.pickerStyle(.segmented)485 .accessibilityIdentifier("fiche.version")486 }487 if let c = showDraft ? f.draft : f.published, !c.isEmpty {488 FicheContentSections(content: c)489 } else {490 Section { Text(showDraft ? "Le brouillon est vide." : "Aucune version publiée.").font(.subheadline).foregroundStyle(Theme.ink3) }491 }492 }493 .refreshable { await load() }494 }495 .navigationTitle(name)496 .navigationBarTitleDisplayMode(.inline)497 .task { await load() }498 .sheet(isPresented: $hiding) {499 ReasonSheet(title: "Masquer la fiche", prompt: "Motif du masquage", footer: "La fiche de « \(name) » disparaît du site et des applications dès maintenant. Le motif est consigné au journal.", confirm: "Masquer") { reason in500 try await session.call { try await $0.hideFiche(sourceID: sourceID, hidden: true, reason: reason) }501 await load()502 nav.show("Fiche masquée")503 }504 }505 .alert("Rétablir la fiche ?", isPresented: $confirmRestore) {506 Button("Rétablir") {507 actionError = nil508 Task {509 do { try await session.call { try await $0.hideFiche(sourceID: sourceID, hidden: false, reason: "") }; await load(); nav.show("Fiche rétablie") }510 catch { actionError = AdminError.message(error) }511 }512 }513 Button("Annuler", role: .cancel) {}514 } message: {515 Text(verbatim: "La fiche publiée de « \(name) » redevient visible sur le site et dans les applications.")516 }517 }518519 private func load() async {520 do { fiche = try await session.call { try await $0.fiche(sourceID: sourceID) }; failure = nil } catch { if fiche == nil { failure = AdminError.message(error) } }521 }522}523524/// Contenu d'une fiche, pour relecture : tout est du texte brut, aucun lien n'est cliquable.525private struct FicheContentSections: View {526 let content: FicheContent527 var body: some View {528 let c = content529 if c.tagline != nil || c.about != nil {530 Section("Présentation") {531 if let t = c.tagline { PlainText(text: t, font: .headline, color: Theme.ink) }532 if let a = c.about { PlainText(text: a) }533 if let f = c.founded { InfoRow(label: "Fondée en", value: String(f)) }534 if !c.languages.isEmpty { InfoRow(label: "Langues", value: c.languages.joined(separator: ", ")) }535 }536 }537 if c.phone != nil || c.email != nil || c.website != nil || c.bookingURL != nil || c.address != nil || !c.hours.isEmpty || !c.social.isEmpty {538 Section("Coordonnées et liens") {539 if let v = c.phone { InfoRow(label: "Téléphone", value: v) }540 if let v = c.email { InfoRow(label: "Courriel", value: v) }541 if let v = c.website { InfoRow(label: "Site", value: v) }542 if let v = c.bookingURL { InfoRow(label: "Rendez-vous", value: v) }543 if let v = c.address { InfoRow(label: "Adresse", value: v) }544 ForEach(c.hours) { InfoRow(label: $0.title, value: $0.text) }545 ForEach(c.social) { InfoRow(label: $0.title, value: $0.text) }546 }547 }548 pairs("Chiffres clés", c.highlights)549 if !c.services.isEmpty { Section("Services") { ForEach(c.services, id: \.self) { PlainText(text: $0, color: Theme.ink) } } }550 pairs("Politiques", c.policies)551 pairs("Questions fréquentes", c.faq)552 pairs("Équipe", c.team)553 if !c.galleryCaptions.isEmpty { Section("Légendes de la galerie") { ForEach(c.galleryCaptions, id: \.self) { PlainText(text: $0) } } }554 if c.autoReply != nil || c.responseTime != nil {555 Section("Messagerie") {556 if let r = c.responseTime { InfoRow(label: "Délai annoncé", value: r) }557 if let a = c.autoReply { VStack(alignment: .leading, spacing: 3) { Text("Réponse automatique").font(.caption).foregroundStyle(Theme.ink3); PlainText(text: a) } }558 }559 }560 pairs("Réponses rapides", c.quickReplies)561 }562563 @ViewBuilder564 private func pairs(_ title: String, _ items: [FicheContent.Pair]) -> some View {565 if !items.isEmpty {566 Section(title) {567 ForEach(items) { p in568 VStack(alignment: .leading, spacing: 3) {569 if !p.title.isEmpty { PlainText(text: p.title, font: .subheadline.weight(.semibold), color: Theme.ink) }570 if !p.text.isEmpty { PlainText(text: p.text) }571 }572 }573 }574 }575 }576}577578/// Feuille d'un motif obligatoire, avec confirmation.579struct ReasonSheet: View {580 let title: String581 let prompt: String582 let footer: String583 let confirm: String584 var submit: (String) async throws -> Void585 @Environment(\.dismiss) private var dismiss586 @State private var reason = ""587 @State private var busy = false588 @State private var failure: String?589590 var body: some View {591 NavigationStack {592 Form {593 if let failure { Section { ErrorBanner(text: failure).listRowInsets(EdgeInsets()) } }594 Section {595 TextField(prompt, text: $reason, axis: .vertical).lineLimit(3...8).accessibilityIdentifier("reason.text")596 } header: {597 Text("\(prompt) (obligatoire)")598 } footer: {599 Text(verbatim: footer)600 }601 }602 .navigationTitle(title)603 .navigationBarTitleDisplayMode(.inline)604 .toolbar {605 ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() } }606 ToolbarItem(placement: .confirmationAction) {607 Button {608 busy = true; failure = nil609 Task {610 defer { busy = false }611 do { try await submit(reason); dismiss() } catch { failure = AdminError.message(error) }612 }613 } label: {614 if busy { ProgressView() } else { Text(confirm).fontWeight(.semibold) }615 }616 .tint(Theme.bad)617 .disabled(reason.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || busy)618 .accessibilityIdentifier("reason.confirm")619 }620 }621 }622 .presentationDetents([.medium, .large])623 }624}625