Skip to content

Commit

Permalink
[iOS] - Added Error Views for Premium Disconnected (uplift to 1.68.x) (
Browse files Browse the repository at this point in the history
…#24370)

Uplift of #24325 (squashed) to beta
  • Loading branch information
brave-builds authored Jul 9, 2024
1 parent fb5881b commit 1344de3
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 2 deletions.
24 changes: 24 additions & 0 deletions ios/brave-ios/Sources/AIChat/AIChatStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@ extension Strings {
comment:
"The title shown on limit reached error view, which is suggesting user to change default model"
)
public static let accountSessionExpiredDescription = NSLocalizedString(
"aichat.accountSessionExpiredDescription",
tableName: "BraveLeo",
bundle: .module,
value:
"Your Brave account session has expired. Please visit your account page to refresh, then come back to use premium features.",
comment:
"The description for the error message when the user's session has expired"
)
public static let newChatActionTitle = NSLocalizedString(
"aichat.newChatActionTitle",
tableName: "BraveLeo",
bundle: .module,
value: "New Chat",
comment: "The title for button that starts a new chat"
)
public static let refreshCredentialsActionTitle = NSLocalizedString(
"aichat.refreshCredentialsActionTitle",
tableName: "BraveLeo",
bundle: .module,
value: "Refresh",
comment: "The title for button that refreshes user credentials"
)
public static let networkErrorViewTitle = NSLocalizedString(
"aichat.networkErrorViewTitle",
tableName: "BraveLeo",
Expand All @@ -39,6 +55,14 @@ extension Strings {
value: "Retry",
comment: "The title for button for re-try"
)
public static let busyErrorDescription = NSLocalizedString(
"aichat.busyErrorDescription",
tableName: "BraveLeo",
bundle: .module,
value: "Leo is too busy right now. Please try again in a few minutes.",
comment:
"The title for view that shows when leo is too busy (active disconnected) and the user is premium"
)
public static let feedbackSuccessAnswerLikedTitle = NSLocalizedString(
"aichat.feedbackSuccessAnswerLikedTitle",
tableName: "BraveLeo",
Expand Down
26 changes: 24 additions & 2 deletions ios/brave-ios/Sources/AIChat/Components/AIChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,31 @@ public struct AIChatView: View {
@ViewBuilder
private func apiErrorViews(for model: AIChatViewModel) -> some View {
let isPremiumAccess = model.currentModel.access == .premium
let isPremium = model.premiumStatus == .active || model.premiumStatus == .activeDisconnected
let isPremium = model.premiumStatus == .active
let isPremiumDisconnected = model.premiumStatus == .activeDisconnected

if isPremiumAccess && isPremiumDisconnected {
if let subscriptionState = BraveStoreSDK.shared.leoSubscriptionStatus?.state,
subscriptionState != .expired && subscriptionState != .revoked
{
// Purchased via AppStore
AIChatBusyErrorView {
Task { @MainActor in
if let orderId = Preferences.AIChat.subscriptionOrderId.value {
try? await BraveSkusSDK.shared.fetchCredentials(orderId: orderId, for: .leo)
}

if isPremiumAccess && !isPremium {
model.retryLastRequest()
}
}
} else {
// Purchased via Desktop
AIChatSessionExpiredErrorView {
openURL(URL.Brave.braveLeoRefreshCredentials)
dismiss()
}
}
} else if isPremiumAccess && !isPremium {
AIChatPremiumUpsellView(
upsellType: .premium,
upgradeAction: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import DesignSystem
import SwiftUI

struct AIChatBusyErrorView: View {
var retryAction: () -> Void

var body: some View {
HStack(alignment: .top, spacing: 0.0) {
Image(braveSystemName: "leo.warning.triangle-filled")
.foregroundStyle(Color(braveSystemName: .systemfeedbackWarningIcon))
.padding([.bottom, .trailing])

VStack(alignment: .leading, spacing: 0.0) {
Text(Strings.AIChat.busyErrorDescription)
.font(.callout)
.foregroundColor(Color(braveSystemName: .systemfeedbackWarningText))
.padding(.bottom)

Button(
action: {
retryAction()
},
label: {
Text(Strings.AIChat.retryActionTitle)
.font(.body.weight(.semibold))
.foregroundColor(Color(.white))
.padding()
.foregroundStyle(.white)
.background(
Color(braveSystemName: .buttonBackground),
in: Capsule()
)
}
)
.buttonStyle(.plain)
}
}
.padding()
.background(Color(braveSystemName: .systemfeedbackWarningBackground))
.clipShape(RoundedRectangle(cornerRadius: 8.0, style: .continuous))
}
}

#if DEBUG
struct AIChatBusyErrorView_Preview: PreviewProvider {
static var previews: some View {
AIChatBusyErrorView {
print("Retry")
}
.previewLayout(.sizeThatFits)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import DesignSystem
import SwiftUI

struct AIChatSessionExpiredErrorView: View {
var refreshSession: () -> Void

var body: some View {
HStack(alignment: .top, spacing: 0.0) {
Image(braveSystemName: "leo.warning.triangle-filled")
.foregroundStyle(Color(braveSystemName: .systemfeedbackWarningIcon))
.padding([.bottom, .trailing])

VStack(alignment: .leading, spacing: 0.0) {
Text(Strings.AIChat.accountSessionExpiredDescription)
.font(.callout)
.foregroundColor(Color(braveSystemName: .systemfeedbackWarningText))
.padding(.bottom)

Button(
action: {
refreshSession()
},
label: {
Text(Strings.AIChat.refreshCredentialsActionTitle)
.font(.body.weight(.semibold))
.foregroundColor(Color(.white))
.padding()
.foregroundStyle(.white)
.background(
Color(braveSystemName: .buttonBackground),
in: Capsule()
)
}
)
.buttonStyle(.plain)
}
}
.padding()
.background(Color(braveSystemName: .systemfeedbackWarningBackground))
.clipShape(RoundedRectangle(cornerRadius: 8.0, style: .continuous))
}
}

#if DEBUG
struct AIChatSessionExpiredErrorView_Preview: PreviewProvider {
static var previews: some View {
AIChatSessionExpiredErrorView {
print("Refresh Credentials")
}
.previewLayout(.sizeThatFits)
}
}
#endif

0 comments on commit 1344de3

Please sign in to comment.