-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
RevenueCatUI/CustomerCenter/Data/CustomerCenterStatus.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// 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 | ||
// | ||
// CustomerCenterStatus.swift | ||
// | ||
// Created by Cesar de la Vega on 6/7/24. | ||
|
||
import Foundation | ||
|
||
public enum CustomerCenterStatus { | ||
|
||
case promotionalOffer | ||
case canceledSubscription | ||
case contactSupport | ||
case refundRequest | ||
case changePlan | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
RevenueCatUI/CustomerCenter/Views/CustomerCenterCompletionHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// 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 | ||
// | ||
// CustomerCenterCompletionHandler.swift | ||
// | ||
// Created by Cesar de la Vega on 6/7/24. | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
final class CustomerCenterCompletionHandler: ObservableObject { | ||
|
||
@Published | ||
fileprivate(set) var customerCenterResult: CustomerCenterResult? | ||
|
||
static func `default`() -> Self { | ||
return .init() | ||
} | ||
|
||
func supportContacted() { | ||
self.customerCenterResult = CustomerCenterResult(status: .contactSupport) | ||
} | ||
|
||
} | ||
|
||
struct CustomerCenterResult: Equatable { | ||
|
||
var status: CustomerCenterStatus | ||
// swiftlint:disable:next todo | ||
// TODO: store error | ||
|
||
init(status: CustomerCenterStatus) { | ||
self.status = status | ||
} | ||
|
||
init?(status: CustomerCenterStatus?) { | ||
guard let status else { return nil } | ||
self.init(status: status) | ||
} | ||
|
||
} | ||
|
||
struct CustomerCenterResultPreferenceKey: PreferenceKey { | ||
|
||
static var defaultValue: CustomerCenterResult? | ||
|
||
static func reduce(value: inout CustomerCenterResult?, nextValue: () -> CustomerCenterResult?) { | ||
value = nextValue() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
RevenueCatUI/CustomerCenter/Views/View+CustomerCenterCompleted.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// 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 | ||
// | ||
// View+CustomerCenterCompleted.swift | ||
// | ||
// Created by Cesar de la Vega on 6/7/24. | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public typealias CustomerCenterCompletedHandler = @MainActor @Sendable (_ status: CustomerCenterStatus) -> Void | ||
|
||
extension View { | ||
|
||
public func onCustomerCenterCompleted( | ||
_ handler: @escaping CustomerCenterCompletedHandler | ||
) -> some View { | ||
return self.modifier(CustomerCenterCompletedViewModifier(handler: handler)) | ||
} | ||
|
||
} | ||
|
||
private struct CustomerCenterCompletedViewModifier: ViewModifier { | ||
|
||
let handler: CustomerCenterCompletedHandler | ||
|
||
init(handler: @escaping CustomerCenterCompletedHandler) { | ||
self.handler = handler | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content.onPreferenceChange(CustomerCenterResultPreferenceKey.self) { result in | ||
if let result { | ||
self.handler(result.status) | ||
} | ||
} | ||
} | ||
|
||
} |