Skip to content

Commit 5b16aa3

Browse files
feat: recover password ui and viewModel (#2856)
1 parent 78fba0d commit 5b16aa3

File tree

9 files changed

+543
-12
lines changed

9 files changed

+543
-12
lines changed

feature/auth/src/commonMain/composeResources/values/strings.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,19 @@
146146

147147
<string name="feature_otp_required_error">OTP is required</string>
148148
<string name="feature_otp_invalid_error">Enter valid OTP</string>
149+
150+
<!--Recover Password-->
151+
<string name="feature_recover_now_title">Recover Now</string>
152+
<string name="feature_recover_now_message">Forgot your password, don’t worry!, we got you covered. Reset your password now!</string>
153+
<string name="feature_recover_now_phone_number_label">Phone Number</string>
154+
<string name="feature_recover_now_email_label">Email</string>
155+
<string name="feature_recover_now_verifying">Verifying</string>
156+
<string name="feature_recover_now_email_required">Email is Required</string>
157+
<string name="feature_recover_now_phone_number_required">Phone number is Required</string>
158+
<string name="feature_recover_now_email_format_error">Invalid Email</string>
159+
<string name="feature_recover_now_phone_number_error">Invalid Phone Number</string>
160+
<string name="feature_recover_now_invalid_phone_number_error">Phone number can not contain letters or symbols</string>
161+
<string name="feature_recover_now_remember_your_password">Remember your password?</string>
162+
<string name="feature_recover_now_log_in">Log in!</string>
163+
149164
</resources>

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/di/AuthModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.koin.core.module.dsl.viewModelOf
1313
import org.koin.dsl.module
1414
import org.mifos.mobile.feature.auth.login.LoginViewModel
1515
import org.mifos.mobile.feature.auth.otpAuthentication.OtpAuthenticationViewModel
16+
import org.mifos.mobile.feature.auth.recoverPassword.RecoverPasswordViewModel
1617
import org.mifos.mobile.feature.auth.registration.RegistrationViewModel
1718
import org.mifos.mobile.feature.auth.uploadId.UploadIdViewModel
1819

@@ -21,4 +22,5 @@ val AuthModule = module {
2122
viewModelOf(::RegistrationViewModel)
2223
viewModelOf(::UploadIdViewModel)
2324
viewModelOf(::OtpAuthenticationViewModel)
25+
viewModelOf(::RecoverPasswordViewModel)
2426
}

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/login/LogInNavigation.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ fun NavController.navigateToLoginScreen(navOptions: NavOptions? = null) {
2929
fun NavGraphBuilder.loginDestination(
3030
navigateToRegisterScreen: () -> Unit,
3131
navigateToPasscodeScreen: () -> Unit,
32+
navigateToForgotPasswordScreen: () -> Unit,
3233
) {
3334
composableWithStayTransitions<LoginRoute> {
3435
LoginScreen(
3536
navigateToRegisterScreen = navigateToRegisterScreen,
3637
navigateToPasscodeScreen = navigateToPasscodeScreen,
38+
navigateToForgotPasswordScreen = navigateToForgotPasswordScreen,
3739
)
3840
}
3941
}

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/login/LoginScreen.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import org.mifos.mobile.core.ui.utils.EventsEffect
7474
@Composable
7575
internal fun LoginScreen(
7676
navigateToRegisterScreen: () -> Unit,
77+
navigateToForgotPasswordScreen: () -> Unit,
7778
navigateToPasscodeScreen: () -> Unit,
7879
modifier: Modifier = Modifier,
7980
viewModel: LoginViewModel = koinViewModel(),
@@ -87,7 +88,9 @@ internal fun LoginScreen(
8788
when (event) {
8889
is LoginEvent.NavigateToSignup -> navigateToRegisterScreen.invoke()
8990

90-
is LoginEvent.NavigateToPasscodeScreen -> navigateToPasscodeScreen.invoke()
91+
is LoginEvent.NavigateToPasscode -> navigateToPasscodeScreen.invoke()
92+
93+
is LoginEvent.NavigateToForgotPassword -> navigateToForgotPasswordScreen.invoke()
9194

9295
is LoginEvent.ShowToast -> {
9396
scope.launch {
@@ -288,6 +291,7 @@ fun InputBox(
288291
modifier = Modifier
289292
.align(Alignment.End)
290293
.clickable(true) {
294+
onAction(LoginAction.NavigateToForgotPassword)
291295
},
292296
text = stringResource(Res.string.feature_sign_in_forgot_password),
293297
style = MifosTypography.labelMedium,

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/login/LoginViewModel.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,13 @@ class LoginViewModel(
7575
updateState { it.copy(isPasswordVisible = !it.isPasswordVisible) }
7676
}
7777

78-
is LoginAction.LoginClicked -> {
79-
loginUser(state.username, state.password)
80-
}
78+
is LoginAction.LoginClicked -> loginUser(state.username, state.password)
8179

82-
is LoginAction.Internal.ReceiveLoginResult -> {
83-
handleLoginResult(action)
84-
}
80+
is LoginAction.Internal.ReceiveLoginResult -> handleLoginResult(action)
8581

86-
is LoginAction.SignupClicked -> {
87-
sendEvent(LoginEvent.NavigateToSignup)
88-
}
82+
is LoginAction.SignupClicked -> sendEvent(LoginEvent.NavigateToSignup)
83+
84+
is LoginAction.NavigateToForgotPassword -> sendEvent(LoginEvent.NavigateToForgotPassword)
8985

9086
is LoginAction.ErrorDialogDismiss -> {
9187
updateState { it.copy(dialogState = null) }
@@ -126,7 +122,7 @@ class LoginViewModel(
126122
viewModelScope.launch {
127123
userPreferencesRepositoryImpl.updateUser(userData)
128124
}
129-
sendEvent(LoginEvent.NavigateToPasscodeScreen)
125+
sendEvent(LoginEvent.NavigateToPasscode)
130126
}
131127
}
132128
}
@@ -177,7 +173,8 @@ data class LoginState(
177173

178174
sealed interface LoginEvent {
179175
data object NavigateToSignup : LoginEvent
180-
data object NavigateToPasscodeScreen : LoginEvent
176+
data object NavigateToPasscode : LoginEvent
177+
data object NavigateToForgotPassword : LoginEvent
181178
data class ShowToast(val message: String) : LoginEvent
182179
}
183180

@@ -188,6 +185,7 @@ sealed interface LoginAction {
188185
data object ErrorDialogDismiss : LoginAction
189186
data object LoginClicked : LoginAction
190187
data object SignupClicked : LoginAction
188+
data object NavigateToForgotPassword : LoginAction
191189

192190
sealed class Internal : LoginAction {
193191
data class ReceiveLoginResult(

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/navigation/AuthenticationNavGraph.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import org.mifos.mobile.feature.auth.login.loginDestination
2323
import org.mifos.mobile.feature.auth.login.navigateToLoginScreen
2424
import org.mifos.mobile.feature.auth.otpAuthentication.navigateToOtpAuthScreen
2525
import org.mifos.mobile.feature.auth.otpAuthentication.otpAuthenticationDestination
26+
import org.mifos.mobile.feature.auth.recoverPassword.navigateToRecoverPasswordScreen
27+
import org.mifos.mobile.feature.auth.recoverPassword.recoverPasswordDestination
2628
import org.mifos.mobile.feature.auth.registration.navigateToRegisterScreen
2729
import org.mifos.mobile.feature.auth.registration.registrationDestination
2830
import org.mifos.mobile.feature.auth.status.navigateToStatusScreen
@@ -49,6 +51,7 @@ fun NavGraphBuilder.authenticationNavGraph(
4951
// navigateToRegisterScreen = navController::navigateToRegisterScreen,
5052
navigateToRegisterScreen = navController::navigateToOtpAuthScreen,
5153
navigateToPasscodeScreen = navigateToPasscodeScreen,
54+
navigateToForgotPasswordScreen = navController::navigateToRecoverPasswordScreen,
5255
)
5356

5457
registrationDestination(
@@ -70,5 +73,10 @@ fun NavGraphBuilder.authenticationNavGraph(
7073
navController.navigate(it)
7174
},
7275
)
76+
77+
recoverPasswordDestination(
78+
navigateToLoginScreen = navController::navigateToLoginScreen,
79+
navigateToOtpAuthenticationScreen = navController::navigateToOtpAuthScreen,
80+
)
7381
}
7482
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
@file:Suppress("MatchingDeclarationName")
11+
12+
package org.mifos.mobile.feature.auth.recoverPassword
13+
14+
import androidx.navigation.NavController
15+
import androidx.navigation.NavGraphBuilder
16+
import androidx.navigation.NavOptions
17+
import kotlinx.serialization.Serializable
18+
import org.mifos.mobile.core.ui.composableWithSlideTransitions
19+
20+
@Serializable
21+
data object RecoverPasswordRoute
22+
23+
fun NavController.navigateToRecoverPasswordScreen(navOptions: NavOptions? = null) {
24+
this.navigate(RecoverPasswordRoute, navOptions)
25+
}
26+
27+
fun NavGraphBuilder.recoverPasswordDestination(
28+
navigateToOtpAuthenticationScreen: () -> Unit,
29+
navigateToLoginScreen: () -> Unit,
30+
) {
31+
composableWithSlideTransitions<RecoverPasswordRoute> {
32+
RecoverPasswordScreen(
33+
navigateToOtpAuthenticationScreen = navigateToOtpAuthenticationScreen,
34+
navigateToLoginScreen = navigateToLoginScreen,
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)