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

Account Settings Cleanup - Support / FAQ / Email (2U) #198

Merged
merged 18 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
44 changes: 41 additions & 3 deletions Core/Core/Configuration/Config/AgreementConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,55 @@ import Foundation
private enum AgreementKeys: String {
case privacyPolicyURL = "PRIVACY_POLICY_URL"
case tosURL = "TOS_URL"
case cookiePolicyURL = "COOKIE_POLICY_URL"
case dataSellContentURL = "DATA_SELL_CONSENT_URL"
case supportedLanguages = "SUPPORTED_LANGUAGES"
}

public class AgreementConfig: NSObject {
public var privacyPolicyURL: URL?
public var tosURL: URL?

public var cookiePolicyURL: URL?
public var dataSellContentURL: URL?
public var supportedLanguages: [String]?

init(dictionary: [String: AnyObject]) {
privacyPolicyURL = (dictionary[AgreementKeys.privacyPolicyURL.rawValue] as? String).flatMap(URL.init)
tosURL = (dictionary[AgreementKeys.tosURL.rawValue] as? String).flatMap(URL.init)
supportedLanguages = dictionary[AgreementKeys.supportedLanguages.rawValue] as? [String]
cookiePolicyURL = (dictionary[AgreementKeys.cookiePolicyURL.rawValue] as? String).flatMap(URL.init)
dataSellContentURL = (dictionary[AgreementKeys.dataSellContentURL.rawValue] as? String).flatMap(URL.init)

super.init()

if let tosURL = dictionary[AgreementKeys.tosURL.rawValue] as? String {
self.tosURL = URL(string: completePath(url: tosURL))
}

if let privacyPolicyURL = dictionary[AgreementKeys.privacyPolicyURL.rawValue] as? String {
self.privacyPolicyURL = URL(string: completePath(url: privacyPolicyURL))
}
}

private func completePath(url: String) -> String {
let langCode = String(Locale.preferredLanguages.first?.prefix(2) ?? "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hardcoding the prefix isn't a good option. I guess you can use the following code to get the desired code

let langCode: String
        if #available(iOS 16, *) {
            langCode = Locale.current.language.languageCode?.identifier ?? ""
        } else {
            langCode = Locale.current.languageCode ?? ""
        }

if let supportedLanguages = supportedLanguages,
!supportedLanguages.contains(langCode) {
return url
}

let URL = URL(string: url)
let host = URL?.host ?? ""
let components = url.components(separatedBy: host)

if components.count != 2 {
return url
}

if let firstComponent = components.first, let lastComponent = components.last {
return "\(firstComponent)\(host)/\(langCode)\(lastComponent)"
}

return url
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct the indentation.

}

private let key = "AGREEMENT_URLS"
Expand Down
15 changes: 14 additions & 1 deletion Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public protocol ConfigProtocol {
var tokenType: TokenType { get }
var feedbackEmail: String { get }
var appStoreLink: String { get }
var faq: URL? { get }
var platformName: String { get }
var agreement: AgreementConfig { get }
var firebase: FirebaseConfig { get }
Expand All @@ -38,6 +39,7 @@ private enum ConfigKeys: String {
case platformName = "PLATFORM_NAME"
case organizationCode = "ORGANIZATION_CODE"
case appstoreID = "APP_STORE_ID"
case faq = "FAQ_URL"
}

public class Config {
Expand Down Expand Up @@ -137,6 +139,14 @@ extension Config: ConfigProtocol {
public var appStoreLink: String {
"itms-apps://itunes.apple.com/app/id\(appStoreId)?mt=8"
}

public var faq: URL? {
guard let urlString = string(for: ConfigKeys.faq.rawValue),
let url = URL(string: urlString) else {
return nil
}
return url
}
}

// Mark - For testing and SwiftUI preview
Expand All @@ -151,7 +161,10 @@ public class ConfigMock: Config {
"WHATS_NEW_ENABLED": false,
"AGREEMENT_URLS": [
"PRIVACY_POLICY_URL": "https://www.example.com/privacy",
"TOS_URL": "https://www.example.com/tos"
"TOS_URL": "https://www.example.com/tos",
"DATA_SELL_CONSENT_URL": "https://www.example.com/sell",
"COOKIE_POLICY_URL": "https://www.example.com/cookie",
"SUPPORTED_LANGUAGES": ["es"]
],
"GOOGLE": [
"ENABLED": true,
Expand Down
8 changes: 7 additions & 1 deletion Core/CoreTests/Configuration/ConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class ConfigTests: XCTestCase {
"WHATS_NEW_ENABLED": true,
"AGREEMENT_URLS": [
"PRIVACY_POLICY_URL": "https://www.example.com/privacy",
"TOS_URL": "https://www.example.com/tos"
"TOS_URL": "https://www.example.com/tos",
"DATA_SELL_CONSENT_URL": "https://www.example.com/sell",
"COOKIE_POLICY_URL": "https://www.example.com/cookie",
"SUPPORTED_LANGUAGES": ["es"]
],
"FIREBASE": [
"ENABLED": true,
Expand Down Expand Up @@ -73,6 +76,9 @@ class ConfigTests: XCTestCase {

XCTAssertEqual(config.agreement.privacyPolicyURL, URL(string: "https://www.example.com/privacy"))
XCTAssertEqual(config.agreement.tosURL, URL(string: "https://www.example.com/tos"))
XCTAssertEqual(config.agreement.cookiePolicyURL, URL(string: "https://www.example.com/cookie"))
XCTAssertEqual(config.agreement.dataSellContentURL, URL(string: "https://www.example.com/sell"))
XCTAssertEqual(config.agreement.supportedLanguages, ["es"])
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving the AgreementConfig tests to a different file, like to AgreementConfigTests? Thoughts?

}

func testFirebaseConfigInitialization() {
Expand Down
12 changes: 12 additions & 0 deletions Profile/Profile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
02F3BFE7292539850051930C /* ProfileRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F3BFE6292539850051930C /* ProfileRouter.swift */; };
0796C8C929B7905300444B05 /* ProfileBottomSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0796C8C829B7905300444B05 /* ProfileBottomSheet.swift */; };
25B36FF48C1307888A3890DA /* Pods_App_Profile.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEA369C38362C1A91A012F70 /* Pods_App_Profile.framework */; };
BAD9CA3F2B29BF5C00DE790A /* ProfileSupportInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAD9CA3E2B29BF5C00DE790A /* ProfileSupportInfo.swift */; };
E8264C634DD8AD314ECE8905 /* Pods_App_Profile_ProfileTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C85ADF87135E03275A980E07 /* Pods_App_Profile_ProfileTests.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -94,6 +95,7 @@
9D125F82E0EAC4B6C0CE280F /* Pods-App-Profile-ProfileTests.releaseprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Profile-ProfileTests.releaseprod.xcconfig"; path = "Target Support Files/Pods-App-Profile-ProfileTests/Pods-App-Profile-ProfileTests.releaseprod.xcconfig"; sourceTree = "<group>"; };
A9F98CD65D1F657EB8F9EA59 /* Pods-App-Profile.releasedev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Profile.releasedev.xcconfig"; path = "Target Support Files/Pods-App-Profile/Pods-App-Profile.releasedev.xcconfig"; sourceTree = "<group>"; };
B3F05DC21379BD4FE1AFCCF1 /* Pods-App-Profile.debugprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Profile.debugprod.xcconfig"; path = "Target Support Files/Pods-App-Profile/Pods-App-Profile.debugprod.xcconfig"; sourceTree = "<group>"; };
BAD9CA3E2B29BF5C00DE790A /* ProfileSupportInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileSupportInfo.swift; sourceTree = "<group>"; };
BEA369C38362C1A91A012F70 /* Pods_App_Profile.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App_Profile.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C85ADF87135E03275A980E07 /* Pods_App_Profile_ProfileTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App_Profile_ProfileTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F52EFE7DC07BE68B9A302DAF /* Pods-App-Profile.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Profile.debug.xcconfig"; path = "Target Support Files/Pods-App-Profile/Pods-App-Profile.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,6 +137,7 @@
0203DC3D29AE79F80017BD05 /* Profile */ = {
isa = PBXGroup;
children = (
BAD9CA402B29D6CD00DE790A /* Subviews */,
02D0FD072AD695E10020D752 /* UserProfile */,
021D924528DC634300ACC565 /* ProfileView.swift */,
021D925128DC918D00ACC565 /* ProfileViewModel.swift */,
Expand Down Expand Up @@ -342,6 +345,14 @@
path = ../Pods;
sourceTree = "<group>";
};
BAD9CA402B29D6CD00DE790A /* Subviews */ = {
isa = PBXGroup;
children = (
BAD9CA3E2B29BF5C00DE790A /* ProfileSupportInfo.swift */,
);
path = Subviews;
sourceTree = "<group>";
};
C456081FB065DCEDAB8119E4 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -563,6 +574,7 @@
021D924E28DC88BB00ACC565 /* ProfileRepository.swift in Sources */,
0796C8C929B7905300444B05 /* ProfileBottomSheet.swift in Sources */,
021D924C28DC884A00ACC565 /* ProfileEndpoint.swift in Sources */,
BAD9CA3F2B29BF5C00DE790A /* ProfileSupportInfo.swift in Sources */,
020306C82932B13F000949EA /* EditProfileView.swift in Sources */,
0262149229AE57A1008BD75A /* DeleteAccountView.swift in Sources */,
02D0FD092AD698380020D752 /* UserProfileView.swift in Sources */,
Expand Down
Loading