Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build feedback survey upon JSON
Browse files Browse the repository at this point in the history
vegaro committed Jun 26, 2024
1 parent 3dd2fb0 commit 5c0f3f4
Showing 5 changed files with 177 additions and 22 deletions.
37 changes: 37 additions & 0 deletions RevenueCatUI/CustomerCenter/Data/FeedbackSurveyData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// 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
//
// FeedbackSurveyData.swift
//
//
// Created by Cesar de la Vega on 14/6/24.
//

import Foundation
import RevenueCat

#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
class FeedbackSurveyData: ObservableObject {

var configuration: CustomerCenterConfigData.HelpPath.FeedbackSurvey
var action: (() -> Void)

init(configuration: CustomerCenterConfigData.HelpPath.FeedbackSurvey, action: @escaping (() -> Void)) {
self.configuration = configuration
self.action = action
}

}

#endif
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ class ManageSubscriptionsViewModel: ObservableObject {
private(set) var configuration: CustomerCenterConfigData?
@Published
var showRestoreAlert: Bool = false
@Published
var feedbackSurveyData: FeedbackSurveyData?

@Published
var state: CustomerCenterViewState {
didSet {
@@ -113,7 +116,17 @@ class ManageSubscriptionsViewModel: ObservableObject {
}

#if os(iOS) || targetEnvironment(macCatalyst)
func handleAction(for path: CustomerCenterConfigData.HelpPath) async {
func determineFlow(for path: CustomerCenterConfigData.HelpPath) {
if case let .feedbackSurvey(feedbackSurvey) = path.detail {
self.feedbackSurveyData = FeedbackSurveyData(configuration: feedbackSurvey) { [weak self] in
self?.performAction(for: path)
}
} else {
performAction(for: path)
}
}

func performAction(for path: CustomerCenterConfigData.HelpPath) async {
switch path.type {
case .missingPurchase:
self.showRestoreAlert = true
71 changes: 71 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/FeedbackSurveyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// 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
//
// FeedbackSurveyView.swift
//
//
// Created by Cesar de la Vega on 12/6/24.
//

import RevenueCat
import SwiftUI

#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
struct FeedbackSurveyView: View {

@ObservedObject
var feedbackSurveyData: FeedbackSurveyData

var body: some View {
VStack {
Text("Why are you cancelling?")
.font(.title)
.padding()

Spacer()

FeedbackSurveyButtonsView(options: feedbackSurveyData.configuration.options,
action: feedbackSurveyData.action)
}
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
struct FeedbackSurveyButtonsView: View {

let options: [CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option]
let action: (() -> Void)

var body: some View {
VStack(spacing: 16) {
ForEach(options, id: \.id) { option in
Button(option.title) {
Task {
self.action()
}
}
.buttonStyle(ManageSubscriptionsButtonStyle())
}
}
}

}

#endif
74 changes: 53 additions & 21 deletions RevenueCatUI/CustomerCenter/Views/ManageSubscriptionsView.swift
Original file line number Diff line number Diff line change
@@ -38,28 +38,43 @@ struct ManageSubscriptionsView: View {
}

var body: some View {
VStack {
if viewModel.isLoaded {
HeaderView(viewModel: viewModel)

if let subscriptionInformation = self.viewModel.subscriptionInformation {
SubscriptionDetailsView(subscriptionInformation: subscriptionInformation,
refundRequestStatusMessage: viewModel.refundRequestStatusMessage)
NavigationView {
VStack {
if viewModel.isLoaded {
HeaderView(viewModel: viewModel)

if let subscriptionInformation = self.viewModel.subscriptionInformation {
SubscriptionDetailsView(subscriptionInformation: subscriptionInformation,
refundRequestStatusMessage: viewModel.refundRequestStatusMessage)
}

Spacer()

ManageSubscriptionsButtonsView(viewModel: viewModel)

} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
}

Spacer()

ManageSubscriptionsButtonsView(viewModel: viewModel)
} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
if let feedbackSurveyData = viewModel.feedbackSurveyData {
NavigationLink(
destination: FeedbackSurveyView(feedbackSurveyData: feedbackSurveyData)
.onDisappear {
viewModel.feedbackSurveyData = nil
},
isActive: .constant(true)
) {
EmptyView()
}
}
}
}
.task {
await loadInformationIfNeeded()
.task {
await loadInformationIfNeeded()
}
.navigationBarTitleDisplayMode(.inline)
}
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@@ -88,10 +103,27 @@ struct HeaderView: View {
private(set) var viewModel: ManageSubscriptionsViewModel

var body: some View {
Text(headerTitle)
.font(.title)
.padding()
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
private extension HeaderView {

private var headerTitle: String {
if let configuration = viewModel.configuration {
Text(configuration.title)
.font(.title)
.padding()
return configuration.title
} else if viewModel.subscriptionInformation != nil {
return "Your subscription details"
} else {
return "Something went wrong"
}
}

@@ -158,7 +190,7 @@ struct ManageSubscriptionsButtonsView: View {
}
ForEach(filteredPaths, id: \.id) { path in
AsyncButton(action: {
await self.viewModel.handleAction(for: path)
self.viewModel.determineFlow(for: path)
}, label: {
Text(path.title)
})
2 changes: 2 additions & 0 deletions RevenueCatUI/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -28,3 +28,5 @@
"We applied the previously purchased items to your account. Sorry for the inconvenience." = "We applied the previously purchased items to your account. Sorry for the inconvenience."
"Dismiss" = "Dismiss"
"We couldn’t find any additional purchases under this account. \n\nContact support for assistance if you think this is an error." = "We couldn’t find any additional purchases under this account. \n\nContact support for assistance if you think this is an error."
"Your subscription details" = "Your subscription details"
"Something went wrong" = "Something went wrong"

0 comments on commit 5c0f3f4

Please sign in to comment.