Skip to content

Commit

Permalink
chore: added is SSO enabled checking on logistration bottom view (ope…
Browse files Browse the repository at this point in the history
…nedx#547)

Co-authored-by: Anton Yarmolenko <[email protected]>
  • Loading branch information
rnr and rnr authored Dec 5, 2024
1 parent b3e6184 commit 0f16019
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public struct StartupView: View {
}
.padding(.horizontal, isHorizontal ? 10 : 24)

LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: .startup)
Expand Down Expand Up @@ -139,7 +141,8 @@ struct StartupView_Previews: PreviewProvider {
static var previews: some View {
let vm = StartupViewModel(
router: AuthorizationRouterMock(),
analytics: CoreAnalyticsMock()
analytics: CoreAnalyticsMock(),
config: ConfigMock()
)

StartupView(viewModel: vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import Core
public class StartupViewModel: ObservableObject {
let router: AuthorizationRouter
let analytics: CoreAnalytics
let config: ConfigProtocol

@Published var searchQuery: String?

public init(
router: AuthorizationRouter,
analytics: CoreAnalytics
analytics: CoreAnalytics,
config: ConfigProtocol
) {
self.router = router
self.analytics = analytics
self.config = config
}

func logAnalytics(searchQuery: String?) {
Expand Down
32 changes: 18 additions & 14 deletions Core/Core/View/Base/LogistrationBottomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public enum LogistrationAction: Sendable {

public struct LogistrationBottomView: View {
private let action: (LogistrationAction) -> Void
private let ssoEnabled: Bool

@Environment(\.isHorizontal) private var isHorizontal

public init(_ action: @escaping (LogistrationAction) -> Void) {
public init(ssoEnabled: Bool, _ action: @escaping (LogistrationAction) -> Void) {
self.ssoEnabled = ssoEnabled
self.action = action
}

Expand All @@ -52,17 +54,19 @@ public struct LogistrationBottomView: View {
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_button")

StyledButton(
CoreLocalization.SignIn.logInWithSsoBtn,
action: {
action(.signInWithSSO)
},
color: Theme.Colors.white,
textColor: Theme.Colors.secondaryButtonTextColor,
borderColor: Theme.Colors.secondaryButtonBorderColor
)
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_withsso_button")
if ssoEnabled {
StyledButton(
CoreLocalization.SignIn.logInWithSsoBtn,
action: {
action(.signInWithSSO)
},
color: Theme.Colors.white,
textColor: Theme.Colors.secondaryButtonTextColor,
borderColor: Theme.Colors.secondaryButtonBorderColor
)
.frame(width: 100)
.accessibilityIdentifier("logistration_signin_withsso_button")
}
}
.padding(.horizontal, isHorizontal ? 0 : 0)
}
Expand All @@ -73,12 +77,12 @@ public struct LogistrationBottomView: View {
#if DEBUG
struct LogistrationBottomView_Previews: PreviewProvider {
static var previews: some View {
LogistrationBottomView {_ in }
LogistrationBottomView(ssoEnabled: false) {_ in }
.preferredColorScheme(.light)
.previewDisplayName("StartupView Light")
.loadFonts()

LogistrationBottomView {_ in }
LogistrationBottomView(ssoEnabled: false) {_ in }
.preferredColorScheme(.dark)
.previewDisplayName("StartupView Dark")
.loadFonts()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public struct CourseDetailsView: View {
}
}
if !viewModel.userloggedIn {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public struct DiscoveryView: View {
}.accessibilityAction {}

if !viewModel.userloggedIn {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: .discovery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public struct DiscoveryWebview: View {
}

if !viewModel.userloggedIn, !isLoading {
LogistrationBottomView { buttonAction in
LogistrationBottomView(
ssoEnabled: viewModel.config.uiComponents.samlSSOLoginEnabled
) { buttonAction in
switch buttonAction {
case .signIn:
viewModel.router.showLoginScreen(sourceScreen: sourceScreen)
Expand Down
3 changes: 2 additions & 1 deletion OpenEdX/DI/ScreenAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class ScreenAssembly: Assembly {
container.register(StartupViewModel.self) { @MainActor r in
StartupViewModel(
router: r.resolve(AuthorizationRouter.self)!,
analytics: r.resolve(CoreAnalytics.self)!
analytics: r.resolve(CoreAnalytics.self)!,
config: r.resolve(ConfigProtocol.self)!
)
}

Expand Down

0 comments on commit 0f16019

Please sign in to comment.