feat(healthchat): advertise the account status in settings

Pending approval and an incomplete profile were only visible in the
members tab, which a new user has no reason to open.
This commit is contained in:
Sedat Qaja
2026-10-09 14:39:33 +02:00
parent b70e77f7c5
commit d01d04846a
22 changed files with 349 additions and 2 deletions
+4
View File
@@ -15,6 +15,7 @@ final nonisolated class AppHooks: AppHooksProtocol {
func configure(with userSession: UserSessionProtocol?) async {
await userSessionHook.configure(with: userSession)
await extendedProfileSectionHook.configure(with: userSession)
await settingsScreenHook.configure(with: userSession)
}
@AppHook(default: DefaultAppSettingsHook())
@@ -50,6 +51,9 @@ final nonisolated class AppHooks: AppHooksProtocol {
@AppHook(default: DefaultHomeTabsHook())
var homeTabsHook: HomeTabsHookProtocol
@AppHook(default: DefaultSettingsScreenHook())
var settingsScreenHook: SettingsScreenHookProtocol
@AppHook(default: DefaultUserDetailsEditScreenHook())
var userDetailsEditScreenHook: UserDetailsEditScreenHookProtocol
@@ -0,0 +1,53 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import Observation
/// Loads the own account's status for the banners that advertise it.
@Observable
final class HealthChatAccountStatusLoader {
private(set) var status: HealthChatAccountStatus = .unknown
/// The load kicked off on creation — await this in tests before asserting.
@ObservationIgnored private(set) var loadingTask: Task<Void, Never>?
init(apiService: HealthChatAPIServiceProtocol) {
loadingTask = Task { await load(from: apiService) }
}
/// Creates a loader with a fixed status, for previews.
init(status: HealthChatAccountStatus) {
self.status = status
}
// MARK: - Private
private func load(from apiService: HealthChatAPIServiceProtocol) async {
// Every failure below leaves the status unknown: a banner must not report an error.
guard case let .success(profile) = await apiService.ownProfile() else {
return
}
guard profile.isApproved else {
status = .pendingApproval
return
}
guard case let .success(completeness) = await apiService.profileCompleteness() else {
return
}
// The server words the hint itself; without one there is nothing to show.
guard !completeness.isComplete, let message = completeness.message else {
status = .ok
return
}
status = .incompleteProfile(message: message)
}
}
@@ -0,0 +1,67 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Compound
import SwiftUI
/// The account status advertised in the app's settings. Renders nothing while loading,
/// for approved accounts with a complete profile, and when the status can't be read.
///
/// Neither banner is dismissible — both resolve server-side.
struct HealthChatAccountStatusSection: View {
// Owned by the hook, not the view: the settings screen rebuilds this section on
// every body pass, and a view-owned loader would fire a request each time.
private let loader: HealthChatAccountStatusLoader
private let completeProfileAction: () -> Void
init(loader: HealthChatAccountStatusLoader, completeProfileAction: @escaping () -> Void = { }) {
self.loader = loader
self.completeProfileAction = completeProfileAction
}
var body: some View {
switch loader.status {
case .unknown, .ok:
EmptyView()
case .pendingApproval:
Section {
ListRow(label: .default(title: HealthChatL10n.screenMemberDirectoryPendingTitle,
description: HealthChatL10n.screenMemberDirectoryPendingApproval,
icon: \.time),
kind: .label)
}
case .incompleteProfile(let message):
Section {
ListRow(label: .default(title: HealthChatL10n.commonProfileIncomplete,
description: message,
icon: \.info),
kind: .label)
ListRow(label: .action(title: HealthChatL10n.actionCompleteProfile, icon: \.userProfile),
kind: .button(action: completeProfileAction))
}
}
}
}
// MARK: - Previews
struct HealthChatAccountStatusSection_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
Form {
HealthChatAccountStatusSection(loader: .init(status: .pendingApproval))
}
.compoundList()
.previewDisplayName("Pending approval")
Form {
HealthChatAccountStatusSection(loader: .init(status: .incompleteProfile(message: "Bitte vervollständigen Sie Ihr Profil, bevor Sie die Benutzersuche verwenden")))
}
.compoundList()
.previewDisplayName("Incomplete profile")
}
}
@@ -18,6 +18,7 @@ extension AppHooks {
registerCompoundHook(HealthChatCompoundHook())
registerExtendedProfileSectionHook(HealthChatExtendedProfileSectionHook())
registerHomeTabsHook(HealthChatHomeTabsHook())
registerSettingsScreenHook(HealthChatSettingsScreenHook())
registerUserDetailsEditScreenHook(HealthChatUserDetailsEditScreenHook())
#endif
}
@@ -0,0 +1,36 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
#if IS_MAIN_APP
// Conforming to the nonisolated hook protocol would infer nonisolated, but the
// service is main-actor state — the hook's requirements are all @MainActor anyway.
@MainActor
final class HealthChatSettingsScreenHook: SettingsScreenHookProtocol {
/// One load per session — the settings screen asks for this section on every body pass.
private var statusLoader: HealthChatAccountStatusLoader?
// Constructed during hook registration, before the main actor is reachable.
nonisolated init() { }
func configure(with userSession: UserSessionProtocol?) async {
statusLoader = userSession.map {
let apiService = HealthChatAPIService(tokenProvider: HealthChatOpenIDTokenProvider(clientProxy: $0.clientProxy))
return HealthChatAccountStatusLoader(apiService: apiService)
}
}
func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView? {
guard let statusLoader else {
return nil
}
return AnyView(HealthChatAccountStatusSection(loader: statusLoader,
completeProfileAction: completeProfileAction))
}
}
#endif
@@ -0,0 +1,25 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
nonisolated protocol SettingsScreenHookProtocol: Sendable {
@MainActor func configure(with userSession: UserSessionProtocol?) async
/// An extra Form section rendered between the user and the account sections,
/// advertising whatever is holding the account back.
/// - Parameter completeProfileAction: Opens the own profile editor.
@MainActor func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView?
}
struct DefaultSettingsScreenHook: SettingsScreenHookProtocol {
func configure(with userSession: UserSessionProtocol?) async { }
func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView? {
nil
}
}