Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Customer Center] Hack week: add contact support button to customer center #4641

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-22
x86_64-linux

Expand Down
4 changes: 4 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@
77BA1AB32CCBB6EE009BF0EA /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77BA1AB22CCBB6EE009BF0EA /* RootView.swift */; };
805B60C97993B311CEC93EAF /* ProductsFetcherSK2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3628C1F100BB3C1782860D24 /* ProductsFetcherSK2.swift */; };
80E80EF226970E04008F245A /* ReceiptFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E80EF026970DC3008F245A /* ReceiptFetcher.swift */; };
875481962D2F1EB100D5CEAD /* ContactSupportButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875481952D2F1EB100D5CEAD /* ContactSupportButton.swift */; };
8834AFA52C2B9375005A72FE /* PresentIfNeededTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 887A62222C1D168B00E1A461 /* PresentIfNeededTests.swift */; };
887A5FBD2C1D036200E1A461 /* RevenueCatUIDev.h in Headers */ = {isa = PBXBuildFile; fileRef = 887A5FBC2C1D036200E1A461 /* RevenueCatUIDev.h */; settings = {ATTRIBUTES = (Public, ); }; };
887A60672C1D037000E1A461 /* PaywallError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 887A5FC72C1D037000E1A461 /* PaywallError.swift */; };
Expand Down Expand Up @@ -2016,6 +2017,7 @@
77BA1AB22CCBB6EE009BF0EA /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; };
80E80EF026970DC3008F245A /* ReceiptFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptFetcher.swift; sourceTree = "<group>"; };
84C3F1AC1D7E1E64341D3936 /* Pods_RevenueCat_PurchasesTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RevenueCat_PurchasesTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
875481952D2F1EB100D5CEAD /* ContactSupportButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactSupportButton.swift; sourceTree = "<group>"; };
887A5FB42C1D024300E1A461 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
887A5FBA2C1D036200E1A461 /* RevenueCatUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RevenueCatUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
887A5FBC2C1D036200E1A461 /* RevenueCatUIDev.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RevenueCatUIDev.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3604,6 +3606,7 @@
C3AD12BB2C6EA69D00A4F86F /* SubscriptionDetailsView.swift */,
77372D982C6F8C7B008E59D3 /* AppUpdateWarningView.swift */,
352304892D0A0F2B003971A4 /* ErrorView.swift */,
875481952D2F1EB100D5CEAD /* ContactSupportButton.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -6580,6 +6583,7 @@
887A60C02C1D037000E1A461 /* AsyncButton.swift in Sources */,
887A60892C1D037000E1A461 /* PaywallPurchasesType.swift in Sources */,
2C8EC71B2CCDD43900D6CCF8 /* ComponentViewState.swift in Sources */,
875481962D2F1EB100D5CEAD /* ContactSupportButton.swift in Sources */,
77089F9E2CD39EC100848CD5 /* ShadowModifier.swift in Sources */,
3537566F2C382C2800A1B8D6 /* WrongPlatformView.swift in Sources */,
887A60C22C1D037000E1A461 /* ErrorDisplay.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions RevenueCatUI/CustomerCenter/URLUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ enum URLUtilities {
}

static func canOpenURL(_ url: URL) -> Bool {
#if DEBUG
return true
#else
guard !Self.isAppExtension,
let application = Self.sharedUIApplication else {
return false
}
return application.canOpenURL(url)
#endif
Comment on lines +68 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about this part - shouldn't it still be false for app extensions even when in debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hack to make this return true in SwiftUI previews. Otherwise it would just return false since previews can't open URLs.

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import RevenueCat
#if DEBUG

convenience init(
purchaseInformation: PurchaseInformation,
purchaseInformation: PurchaseInformation?,
configuration: CustomerCenterConfigData
) {
self.init(customerCenterActionHandler: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ManageSubscriptionsViewModel: ObservableObject {
@Published
var loadingPath: CustomerCenterConfigData.HelpPath?
@Published
private(set) var supportInformation: CustomerCenterConfigData.Support?
@Published
var promotionalOfferData: PromotionalOfferData?
@Published
var inAppBrowserURL: IdentifiableURL?
Expand Down
52 changes: 52 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/ContactSupportButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ContactSupportButton.swift
//
// Created by Engin Kurutepe on 08.01.25.

import SwiftUI
import RevenueCat

#if os(iOS)

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct ContactSupportButton: View {
@Environment(\.openURL)
private var openURL
@Environment(\.localization)
private var localization: CustomerCenterConfigData.Localization
let support: CustomerCenterConfigData.Support?

var body: some View {
if let supportURL {
Button(localization.commonLocalizedString(for: .contactSupport)) {
Task {
openURL(supportURL)
}
}
} else {
EmptyView()
}
}

private var supportURL: URL? {
guard let support else { return nil }
let subject = self.localization.commonLocalizedString(for: .defaultSubject)
let body = support.calculateBody(self.localization)
return URLUtilities.createMailURLIfPossible(email: support.email,
subject: subject,
body: body)
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct ManageSubscriptionsView: View {
private var localization: CustomerCenterConfigData.Localization
@Environment(\.colorScheme)
private var colorScheme
@Environment(\.supportInformation)
private var supportInformation

@StateObject
private var viewModel: ManageSubscriptionsViewModel
Expand Down Expand Up @@ -81,7 +83,6 @@ struct ManageSubscriptionsView: View {
var content: some View {
ZStack {
List {

if let purchaseInformation = self.viewModel.purchaseInformation {
Section {
SubscriptionDetailsView(
Expand All @@ -91,6 +92,8 @@ struct ManageSubscriptionsView: View {
Section {
ManageSubscriptionsButtonsView(viewModel: self.viewModel,
loadingPath: self.$viewModel.loadingPath)

ContactSupportButton(support: supportInformation)
} header: {
if let subtitle = self.viewModel.screen.subtitle {
Text(subtitle)
Expand Down Expand Up @@ -170,6 +173,7 @@ struct ManageSubscriptionsView_Previews: PreviewProvider {
customerCenterActionHandler: nil)
.environment(\.localization, CustomerCenterConfigTestData.customerCenterData.localization)
.environment(\.appearance, CustomerCenterConfigTestData.customerCenterData.appearance)
.environment(\.supportInformation, CustomerCenterConfigTestData.customerCenterData.support)
}.preferredColorScheme(colorScheme)
.previewDisplayName("Monthly renewing - \(colorScheme)")

Expand All @@ -182,6 +186,7 @@ struct ManageSubscriptionsView_Previews: PreviewProvider {
customerCenterActionHandler: nil)
.environment(\.localization, CustomerCenterConfigTestData.customerCenterData.localization)
.environment(\.appearance, CustomerCenterConfigTestData.customerCenterData.appearance)
.environment(\.supportInformation, CustomerCenterConfigTestData.customerCenterData.support)
}.preferredColorScheme(colorScheme)
.previewDisplayName("Yearly expiring - \(colorScheme)")
}
Expand Down
2 changes: 2 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/NoSubscriptionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct NoSubscriptionsView: View {
showRestoreAlert = true
}
.restorePurchasesAlert(isPresented: $showRestoreAlert)

ContactSupportButton(support: configuration.support)
}

}
Expand Down
20 changes: 3 additions & 17 deletions RevenueCatUI/CustomerCenter/Views/WrongPlatformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ struct WrongPlatformView: View {
@Environment(\.openURL)
private var openURL

private var supportURL: URL? {
guard let supportInformation = self.supportInformation else { return nil }
let subject = self.localization.commonLocalizedString(for: .defaultSubject)
let body = supportInformation.calculateBody(self.localization)
return URLUtilities.createMailURLIfPossible(email: supportInformation.email,
subject: subject,
body: body)
}

init(screen: CustomerCenterConfigData.Screen? = nil,
purchaseInformation: PurchaseInformation) {
self.screen = screen
Expand Down Expand Up @@ -88,14 +79,9 @@ struct WrongPlatformView: View {
}
}
}
if let url = supportURL {
Section {
AsyncButton {
openURL(url)
} label: {
Text(localization.commonLocalizedString(for: .contactSupport))
}
}

Section {
ContactSupportButton(support: supportInformation)
}
}
.toolbar {
Expand Down