Skip to content

Commit

Permalink
feat: Added login and register capability in discovery for pre login …
Browse files Browse the repository at this point in the history
…exploration (#202)

* feat: added login and register capebility in discovery for pre login exploration

* refactor: address review feedback

* fix: fix broken tests

* fix: linking authorization framework with discovery framework

* refactor: address review feedback

* refactor: address review feedback

* fix: fix broken tests after changes

* refactor: address review feedback

* refactor: changing LogistrationBottomView style from model to closure and moving it to Core

* refactor: address review feedback

* refactor: decouple Authorization and Discovery module, remove unused imports

* refactor: removing unused imports
  • Loading branch information
saeedbashir authored Dec 19, 2023
1 parent f81aefa commit 65b1ecc
Show file tree
Hide file tree
Showing 42 changed files with 854 additions and 640 deletions.
4 changes: 0 additions & 4 deletions Authorization/Authorization.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
DE843D6BB1B9DDA398494890 /* Pods_App_Authorization.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47BCFB7C19382EECF15131B6 /* Pods_App_Authorization.framework */; };
E03261642AE64676002CA7EB /* StartupViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03261632AE64676002CA7EB /* StartupViewModel.swift */; };
E03261662AE64AF4002CA7EB /* StartupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03261652AE64AF4002CA7EB /* StartupView.swift */; };
E03261682AE9F156002CA7EB /* LogistrationBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03261672AE9F156002CA7EB /* LogistrationBottomView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -84,7 +83,6 @@
BADB3F542AD6DFC3004D5CFA /* SocialAuthViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialAuthViewModel.swift; sourceTree = "<group>"; };
E03261632AE64676002CA7EB /* StartupViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartupViewModel.swift; sourceTree = "<group>"; };
E03261652AE64AF4002CA7EB /* StartupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartupView.swift; sourceTree = "<group>"; };
E03261672AE9F156002CA7EB /* LogistrationBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogistrationBottomView.swift; sourceTree = "<group>"; };
E78971D8E6ED2116BBF9FD66 /* Pods-App-Authorization.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Authorization.release.xcconfig"; path = "Target Support Files/Pods-App-Authorization/Pods-App-Authorization.release.xcconfig"; sourceTree = "<group>"; };
F52826C68AEA1CF4769389EA /* Pods-App-Authorization.releasestage.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Authorization.releasestage.xcconfig"; path = "Target Support Files/Pods-App-Authorization/Pods-App-Authorization.releasestage.xcconfig"; sourceTree = "<group>"; };
F5802BBA113276950ABCD9B3 /* Pods-App-Authorization.releaseprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Authorization.releaseprod.xcconfig"; path = "Target Support Files/Pods-App-Authorization/Pods-App-Authorization.releaseprod.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -284,7 +282,6 @@
children = (
E03261632AE64676002CA7EB /* StartupViewModel.swift */,
E03261652AE64AF4002CA7EB /* StartupView.swift */,
E03261672AE9F156002CA7EB /* LogistrationBottomView.swift */,
);
path = Startup;
sourceTree = "<group>";
Expand Down Expand Up @@ -505,7 +502,6 @@
02066B462906D72F00F4307E /* SignUpViewModel.swift in Sources */,
E03261642AE64676002CA7EB /* StartupViewModel.swift in Sources */,
02A2ACDB2A4B016100FBBBBB /* AuthorizationAnalytics.swift in Sources */,
E03261682AE9F156002CA7EB /* LogistrationBottomView.swift in Sources */,
025F40E029D1E2FC0064C183 /* ResetPasswordView.swift in Sources */,
020C31CB290BF49900D6DEA2 /* FieldsView.swift in Sources */,
0770DE4E28D0A677006D8A5D /* SignInView.swift in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions Authorization/Authorization/Presentation/Login/SignInView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public struct SignInView: View {
)
HStack {
if !viewModel.config.features.startupScreenEnabled {
Button(AuthLocalization.SignIn.registerBtn) {
viewModel.trackSignUpClicked()
viewModel.router.showRegisterScreen()
Button(CoreLocalization.SignIn.registerBtn) {
viewModel.router.showRegisterScreen(sourceScreen: viewModel.sourceScreen)
}.foregroundColor(Theme.Colors.accentColor)

Spacer()
Expand All @@ -121,7 +120,7 @@ public struct SignInView: View {
.padding(20)
}.frame(maxWidth: .infinity)
} else {
StyledButton(AuthLocalization.SignIn.logInBtn) {
StyledButton(CoreLocalization.SignIn.logInBtn) {
Task {
await viewModel.login(username: email, password: password)
}
Expand Down Expand Up @@ -192,7 +191,8 @@ struct SignInView_Previews: PreviewProvider {
router: AuthorizationRouterMock(),
config: ConfigMock(),
analytics: AuthorizationAnalyticsMock(),
validator: Validator()
validator: Validator(),
sourceScreen: .default
)

SignInView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SignInViewModel: ObservableObject {
@Published private(set) var isShowProgress = false
@Published private(set) var showError: Bool = false
@Published private(set) var showAlert: Bool = false
let sourceScreen: LogistrationSourceScreen

var errorMessage: String? {
didSet {
withAnimation {
Expand All @@ -45,13 +47,15 @@ public class SignInViewModel: ObservableObject {
router: AuthorizationRouter,
config: ConfigProtocol,
analytics: AuthorizationAnalytics,
validator: Validator
validator: Validator,
sourceScreen: LogistrationSourceScreen
) {
self.interactor = interactor
self.router = router
self.config = config
self.analytics = analytics
self.validator = validator
self.sourceScreen = sourceScreen
}

var socialAuthEnabled: Bool {
Expand All @@ -77,7 +81,7 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(username: username, password: password)
analytics.setUserID("\(user.id)")
analytics.userLogin(method: .password)
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
failure(error)
}
Expand Down Expand Up @@ -108,7 +112,7 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(externalToken: externalToken, backend: backend)
analytics.setUserID("\(user.id)")
analytics.userLogin(method: authMethod)
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
failure(error, authMethod: authMethod)
}
Expand Down Expand Up @@ -138,10 +142,6 @@ public class SignInViewModel: ObservableObject {
}
}

func trackSignUpClicked() {
analytics.signUpClicked()
}

func trackForgotPasswordClicked() {
analytics.forgotPasswordClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct SignUpView: View {
VStack(alignment: .center) {
ZStack {
HStack {
Text(AuthLocalization.SignIn.registerBtn)
Text(CoreLocalization.SignIn.registerBtn)
.titleSettings(color: Theme.Colors.white)
}
VStack {
Expand Down Expand Up @@ -177,7 +177,8 @@ struct SignUpView_Previews: PreviewProvider {
analytics: AuthorizationAnalyticsMock(),
config: ConfigMock(),
cssInjector: CSSInjectorMock(),
validator: Validator()
validator: Validator(),
sourceScreen: .default
)

SignUpView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SignUpViewModel: ObservableObject {
@Published var scrollTo: Int?
@Published var showError: Bool = false
@Published var thirdPartyAuthSuccess: Bool = false
let sourceScreen: LogistrationSourceScreen

var errorMessage: String? {
didSet {
withAnimation {
Expand All @@ -43,14 +45,16 @@ public class SignUpViewModel: ObservableObject {
analytics: AuthorizationAnalytics,
config: ConfigProtocol,
cssInjector: CSSInjector,
validator: Validator
validator: Validator,
sourceScreen: LogistrationSourceScreen
) {
self.interactor = interactor
self.router = router
self.analytics = analytics
self.config = config
self.cssInjector = cssInjector
self.validator = validator
self.sourceScreen = sourceScreen
}

var socialAuthEnabled: Bool {
Expand Down Expand Up @@ -114,7 +118,7 @@ public class SignUpViewModel: ObservableObject {
analytics.setUserID("\(user.id)")
analytics.registrationSuccess()
isShowProgress = false
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)

} catch let error {
isShowProgress = false
Expand Down Expand Up @@ -171,7 +175,7 @@ public class SignUpViewModel: ObservableObject {
analytics.setUserID("\(user.id)")
analytics.userLogin(method: authMethod)
isShowProgress = false
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch {
update(fullName: response.name, email: response.email)
self.externalToken = response.token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct ResetPasswordView: View {
.multilineTextAlignment(.center)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.bottom, 20)
StyledButton(AuthLocalization.SignIn.logInBtn) {
StyledButton(CoreLocalization.SignIn.logInBtn) {
viewModel.router.backToRoot(animated: true)
}
.padding(.top, 30)
Expand Down
23 changes: 17 additions & 6 deletions Authorization/Authorization/Presentation/Startup/StartupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public struct StartupView: View {
.padding(.top, 1)
TextField(AuthLocalization.Startup.searchPlaceholder, text: $searchQuery, onCommit: {
if searchQuery.isEmpty { return }
viewModel.router.showDiscoveryScreen(searchQuery: searchQuery, fromStartupScreen: true)
viewModel.router.showDiscoveryScreen(
searchQuery: searchQuery,
sourceScreen: .startup
)
})
.autocapitalization(.none)
.autocorrectionDisabled()
Expand All @@ -71,7 +74,10 @@ public struct StartupView: View {
)

Button {
viewModel.router.showDiscoveryScreen(searchQuery: searchQuery, fromStartupScreen: true)
viewModel.router.showDiscoveryScreen (
searchQuery: searchQuery,
sourceScreen: .startup
)
} label: {
Text(AuthLocalization.Startup.exploreAllCourses)
.underline()
Expand All @@ -83,7 +89,14 @@ public struct StartupView: View {
}
.padding(.horizontal, isHorizontal ? 10 : 24)

LogistrationBottomView(viewModel: viewModel)
LogistrationBottomView { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: .startup)
case .register:
viewModel.router.showRegisterScreen(sourceScreen: .startup)
}
}
}
.padding(.top, 10)
.padding(.bottom, 2)
Expand All @@ -106,9 +119,7 @@ public struct StartupView: View {
struct StartupView_Previews: PreviewProvider {
static var previews: some View {
let vm = StartupViewModel(
interactor: AuthInteractor.mock,
router: AuthorizationRouterMock(),
analytics: AuthorizationAnalyticsMock()
router: AuthorizationRouterMock()
)

StartupView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ import Core

public class StartupViewModel: ObservableObject {
let router: AuthorizationRouter
private let interactor: AuthInteractorProtocol
private let analytics: AuthorizationAnalytics
@Published var searchQuery: String?

public init(
interactor: AuthInteractorProtocol,
router: AuthorizationRouter,
analytics: AuthorizationAnalytics
router: AuthorizationRouter
) {
self.interactor = interactor
self.router = router
self.analytics = analytics
}

func tracksignUpClicked() {
analytics.signUpClicked()
}
}
4 changes: 0 additions & 4 deletions Authorization/Authorization/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,13 @@ public enum AuthLocalization {
public static let emailOrUsername = AuthLocalization.tr("Localizable", "SIGN_IN.EMAIL_OR_USERNAME", fallback: "Email or username")
/// Forgot password?
public static let forgotPassBtn = AuthLocalization.tr("Localizable", "SIGN_IN.FORGOT_PASS_BTN", fallback: "Forgot password?")
/// Sign in
public static let logInBtn = AuthLocalization.tr("Localizable", "SIGN_IN.LOG_IN_BTN", fallback: "Sign in")
/// Localizable.strings
/// Authorization
///
/// Created by Vladimir Chekyrta on 13.09.2022.
public static let logInTitle = AuthLocalization.tr("Localizable", "SIGN_IN.LOG_IN_TITLE", fallback: "Sign in")
/// Password
public static let password = AuthLocalization.tr("Localizable", "SIGN_IN.PASSWORD", fallback: "Password")
/// Register
public static let registerBtn = AuthLocalization.tr("Localizable", "SIGN_IN.REGISTER_BTN", fallback: "Register")
/// Welcome back! Please authorize to continue.
public static let welcomeBack = AuthLocalization.tr("Localizable", "SIGN_IN.WELCOME_BACK", fallback: "Welcome back! Please authorize to continue.")
}
Expand Down
2 changes: 0 additions & 2 deletions Authorization/Authorization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"SIGN_IN.EMAIL" = "Email";
"SIGN_IN.EMAIL_OR_USERNAME" = "Email or username";
"SIGN_IN.PASSWORD" = "Password";
"SIGN_IN.REGISTER_BTN" = "Register";
"SIGN_IN.FORGOT_PASS_BTN" = "Forgot password?";
"SIGN_IN.LOG_IN_BTN" = "Sign in";

"ERROR.INVALID_EMAIL_ADDRESS" = "Invalid email address";
"ERROR.INVALID_PASSWORD_LENGHT" = "Invalid password lenght";
Expand Down
2 changes: 0 additions & 2 deletions Authorization/Authorization/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"SIGN_IN.WELCOME_BACK" = "З поверненням! Авторизуйтесь, щоб продовжити.";
"SIGN_IN.EMAIL" = "Пошта";
"SIGN_IN.PASSWORD" = "Пароль";
"SIGN_IN.REGISTER_BTN" = "Реєстрація";
"SIGN_IN.FORGOT_PASS_BTN" = "Забули пароль?";
"SIGN_IN.LOG_IN_BTN" = "Увійти";

"ERROR.INVALID_EMAIL_ADDRESS" = "невірна адреса електронної пошти";
"ERROR.INVALID_PASSWORD_LENGHT" = "Пароль занадто короткий або занадто довгий";
Expand Down
Loading

0 comments on commit 65b1ecc

Please sign in to comment.