-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[StripeConnect] Onboarding settings. (#4039)
## Summary Adds settings for configuring onboarding component. https://jira.corp.stripe.com/browse/MXMOBILE-2484 ## Demo https://github.com/user-attachments/assets/2374c93d-426a-467e-9fac-98d6a07fdd7b
- Loading branch information
1 parent
e997557
commit d94be4c
Showing
11 changed files
with
352 additions
and
14 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
14 changes: 14 additions & 0 deletions
14
Example/StripeConnectExample/StripeConnectExample/Helpers/URL+Valid.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,14 @@ | ||
// | ||
// URL+Valid.swift | ||
// StripeConnect Example | ||
// | ||
// Created by Chris Mays on 9/20/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension URL { | ||
var isValid: Bool { | ||
UIApplication.shared.canOpenURL(self) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
131 changes: 131 additions & 0 deletions
131
...nnectExample/StripeConnectExample/Settings/Components/Onboarding/OnboardingSettings.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,131 @@ | ||
// | ||
// OnboardingSettings.swift | ||
// StripeConnect Example | ||
// | ||
// Created by Chris Mays on 9/20/24. | ||
// | ||
|
||
import Foundation | ||
@_spi(PrivateBetaConnect) import StripeConnect | ||
|
||
struct OnboardingSettings: Equatable { | ||
var fullTermsOfServiceString: String = "" | ||
|
||
var fullTermsOfServiceUrl: URL? { | ||
!fullTermsOfServiceString.isEmpty ? URL(string: fullTermsOfServiceString) : nil | ||
} | ||
|
||
var recipientTermsOfServiceString: String = "" | ||
var recipientTermsOfServiceUrl: URL? { | ||
!recipientTermsOfServiceString.isEmpty ? URL(string: recipientTermsOfServiceString) : nil | ||
} | ||
|
||
var privacyPolicyString: String = "" | ||
var privacyPolicyUrl: URL? { | ||
!privacyPolicyString.isEmpty ? URL(string: privacyPolicyString) : nil | ||
} | ||
|
||
var skipTermsOfService: ToggleOption = .default | ||
var fieldOption: FieldOption = .default | ||
var futureRequirement: FutureRequirement = .default | ||
|
||
var accountCollectionOptions: AccountCollectionOptions { | ||
var accountCollectionOptions: AccountCollectionOptions = .init() | ||
switch fieldOption { | ||
case .default: | ||
// Default set nothing | ||
break | ||
case .currentlyDue: | ||
accountCollectionOptions.fields = .currentlyDue | ||
case .eventuallyDue: | ||
accountCollectionOptions.fields = .eventuallyDue | ||
} | ||
|
||
switch futureRequirement { | ||
case .default: | ||
// Default set nothing | ||
break | ||
case .omit: | ||
accountCollectionOptions.futureRequirements = .omit | ||
case .include: | ||
accountCollectionOptions.futureRequirements = .include | ||
} | ||
|
||
return accountCollectionOptions | ||
} | ||
|
||
enum FutureRequirement: String, CaseIterable, Identifiable { | ||
var id: String { | ||
self.rawValue | ||
} | ||
|
||
case `default` | ||
case omit | ||
case include | ||
|
||
var displayLabel: String { | ||
switch self { | ||
case .default: | ||
return "Default" | ||
case .omit: | ||
return "Omit" | ||
case .include: | ||
return "Include" | ||
} | ||
} | ||
} | ||
|
||
enum FieldOption: String, CaseIterable, Identifiable { | ||
var id: String { | ||
self.rawValue | ||
} | ||
|
||
case `default` | ||
case currentlyDue | ||
case eventuallyDue | ||
|
||
var displayLabel: String { | ||
switch self { | ||
case .default: | ||
return "Default" | ||
case .currentlyDue: | ||
return "Currently due" | ||
case .eventuallyDue: | ||
return "Eventually due" | ||
} | ||
} | ||
} | ||
|
||
enum ToggleOption: String, CaseIterable, Identifiable { | ||
var id: String { | ||
self.rawValue | ||
} | ||
|
||
case `default` | ||
case `false` | ||
case `true` | ||
|
||
var displayLabel: String { | ||
switch self { | ||
case .default: | ||
return "Default" | ||
case .false: | ||
return "False" | ||
case .true: | ||
return "True" | ||
} | ||
} | ||
|
||
var boolValue: Bool? { | ||
switch self { | ||
case .default: | ||
return nil | ||
case .false: | ||
return false | ||
case .true: | ||
return true | ||
} | ||
} | ||
|
||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...tExample/StripeConnectExample/Settings/Components/Onboarding/OnboardingSettingsView.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,81 @@ | ||
// | ||
// OnboardingSettings.swift | ||
// StripeConnect Example | ||
// | ||
// Created by Chris Mays on 9/20/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct OnboardingSettingsView: View { | ||
|
||
@Environment(\.dismiss) var dismiss | ||
|
||
@Binding var onboardingSettings: OnboardingSettings | ||
|
||
var saveEnabled: Bool { | ||
AppSettings.shared.onboardingSettings != onboardingSettings | ||
&& isValidURL(onboardingSettings.fullTermsOfServiceString) | ||
&& isValidURL(onboardingSettings.recipientTermsOfServiceString) | ||
&& isValidURL( onboardingSettings.privacyPolicyString) | ||
} | ||
|
||
var body: some View { | ||
List { | ||
Section { | ||
TextInput(label: "Full terms of service", placeholder: "https://example.com", text: $onboardingSettings.fullTermsOfServiceString, isValid: isValidURL(onboardingSettings.fullTermsOfServiceString)) | ||
TextInput(label: "Recipient terms of service", placeholder: "https://example.com", text: $onboardingSettings.recipientTermsOfServiceString, isValid: isValidURL(onboardingSettings.recipientTermsOfServiceString)) | ||
TextInput(label: "Privacy policy", placeholder: "https://example.com", text: $onboardingSettings.privacyPolicyString, isValid: isValidURL( onboardingSettings.privacyPolicyString)) | ||
|
||
Picker("Skip terms of service", selection: $onboardingSettings.skipTermsOfService) { | ||
ForEach(OnboardingSettings.ToggleOption.allCases) { option in | ||
Text(option.displayLabel) | ||
.tag(option) | ||
} | ||
} | ||
|
||
Picker("Field option", selection: $onboardingSettings.fieldOption) { | ||
ForEach(OnboardingSettings.FieldOption.allCases) { option in | ||
Text(option.displayLabel) | ||
.tag(option) | ||
} | ||
} | ||
|
||
Picker("Future requirements", selection: $onboardingSettings.futureRequirement) { | ||
ForEach(OnboardingSettings.FutureRequirement.allCases) { option in | ||
Text(option.displayLabel) | ||
.tag(option) | ||
} | ||
} | ||
|
||
Button { | ||
onboardingSettings = .init() | ||
AppSettings.shared.onboardingSettings = onboardingSettings | ||
} label: { | ||
Text("Reset to defaults") | ||
} | ||
} header: { | ||
} | ||
.textInputAutocapitalization(.never) | ||
} | ||
.listStyle(.insetGrouped) | ||
.navigationTitle("Onboarding Settings") | ||
.navigationBarTitleDisplayMode(.inline) | ||
.toolbar { | ||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button { | ||
AppSettings.shared.onboardingSettings = onboardingSettings | ||
dismiss() | ||
} label: { | ||
Text("Save") | ||
} | ||
.disabled(!saveEnabled) | ||
} | ||
} | ||
.environment(\.horizontalSizeClass, .compact) | ||
} | ||
|
||
func isValidURL(_ url: String) -> Bool { | ||
URL(string: url)?.isValid == true || url.isEmpty | ||
} | ||
} |
Oops, something went wrong.