Skip to content

Commit

Permalink
revert linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mludowise-stripe committed Sep 24, 2024
1 parent 7a80c9b commit e92d527
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Foundation

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
Expand All @@ -28,7 +28,7 @@ struct OnboardingSettings: Equatable {
var skipTermsOfService: ToggleOption = .default
var fieldOption: FieldOption = .default
var futureRequirement: FutureRequirement = .default

var accountCollectionOptions: AccountCollectionOptions {
var accountCollectionOptions: AccountCollectionOptions = .init()
switch fieldOption {
Expand All @@ -40,7 +40,7 @@ struct OnboardingSettings: Equatable {
case .eventuallyDue:
accountCollectionOptions.fields = .eventuallyDue
}

switch futureRequirement {
case .default:
// Default set nothing
Expand All @@ -50,19 +50,19 @@ struct OnboardingSettings: Equatable {
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:
Expand All @@ -74,16 +74,16 @@ struct OnboardingSettings: Equatable {
}
}
}

enum FieldOption: String, CaseIterable, Identifiable {
var id: String {
self.rawValue
}

case `default`
case currentlyDue
case eventuallyDue

var displayLabel: String {
switch self {
case .default:
Expand All @@ -95,16 +95,16 @@ struct OnboardingSettings: Equatable {
}
}
}

enum ToggleOption: String, CaseIterable, Identifiable {
var id: String {
self.rawValue
}

case `default`
case `false`
case `true`

var displayLabel: String {
switch self {
case .default:
Expand All @@ -115,7 +115,7 @@ struct OnboardingSettings: Equatable {
return "True"
}
}

var boolValue: Bool? {
switch self {
case .default:
Expand All @@ -126,6 +126,6 @@ struct OnboardingSettings: Equatable {
return true
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@
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
Expand All @@ -74,7 +74,7 @@ struct OnboardingSettingsView: View {
}
.environment(\.horizontalSizeClass, .compact)
}

func isValidURL(_ url: String) -> Bool {
URL(string: url)?.isValid == true || url.isEmpty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class AppSettings {
static let appearanceIdKey = "AppearanceId"

static let selectedMerchantKey = "SelectedMerchant"

static let onboardingTermsOfServiceURL = "OnboardingTermsOfServiceURL"
static let onboardingrecipientTermsOfServiceString = "OnboardingrecipientTermsOfServiceString"
static let onboardingPrivacyPolicyString = "OnboardingPrivacyPolicyString"

static let onboardingSkipTermsOfService = "OnboardingSkipTermsOfService"
static let onboardingFieldOption = "OnboardingFieldOption"
static let onboardingFutureRequirements = "OnboardingFutureRequirements"
Expand All @@ -28,7 +28,7 @@ class AppSettings {
static let shared = AppSettings()

let defaults = UserDefaults.standard

var selectedServerBaseURL: String {
get {
defaults.string(forKey: Constants.serverBaseURLKey) ??
Expand All @@ -41,30 +41,31 @@ class AppSettings {

var appearanceId: String? {
get {
defaults.string(forKey: Constants.appearanceIdKey)
defaults.string(forKey: Constants.appearanceIdKey) ??
nil
}
set {
defaults.setValue(newValue, forKey: Constants.appearanceIdKey)
}
}

var onboardingSettings: OnboardingSettings {
get {
let settings = OnboardingSettings(
fullTermsOfServiceString: defaults.string(forKey: Constants.onboardingTermsOfServiceURL),
recipientTermsOfServiceString: defaults.string(forKey: Constants.onboardingrecipientTermsOfServiceString),
privacyPolicyString: defaults.string(forKey: Constants.onboardingPrivacyPolicyString),
skipTermsOfService: .init(rawValue: defaults.string(forKey: Constants.onboardingSkipTermsOfService)) ?? .default,
fieldOption: .init(rawValue: defaults.string(forKey: Constants.onboardingFieldOption)) ?? .default,
futureRequirement: .init(rawValue: defaults.string(forKey: Constants.onboardingFutureRequirements)) ?? .default
skipTermsOfService: .init(rawValue: defaults.string(forKey:Constants.onboardingSkipTermsOfService)) ?? .default,
fieldOption: .init(rawValue: defaults.string(forKey:Constants.onboardingFieldOption)) ?? .default,
futureRequirement: .init(rawValue: defaults.string(forKey:Constants.onboardingFutureRequirements)) ?? .default
)
return settings
}
set {
defaults.setValue(newValue.fullTermsOfServiceString, forKey: Constants.onboardingTermsOfServiceURL)
defaults.setValue(newValue.recipientTermsOfServiceString, forKey: Constants.onboardingrecipientTermsOfServiceString)
defaults.setValue(newValue.privacyPolicyString, forKey: Constants.onboardingPrivacyPolicyString)

defaults.setValue(newValue.skipTermsOfService.rawValue, forKey: Constants.onboardingSkipTermsOfService)
defaults.setValue(newValue.fieldOption.rawValue, forKey: Constants.onboardingFieldOption)
defaults.setValue(newValue.futureRequirement.rawValue, forKey: Constants.onboardingFutureRequirements)
Expand Down

0 comments on commit e92d527

Please sign in to comment.