Files
element-x-ios/ElementX/Sources/AppHooks/HealthChat/HealthChatAccountStatusSection.swift
T
Sedat Qaja d9524130fa 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.
2026-10-19 09:17:36 +02:00

68 lines
2.5 KiB
Swift

//
// 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")
}
}