fix #7 新增了修改密码时错误的旧密码提示

This commit is contained in:
2024-11-03 09:15:19 +08:00
parent 7ed3c51118
commit d49e037f51

View File

@@ -1,3 +1,4 @@
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -15,17 +16,21 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R
import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.data.ServiceException
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.data.api.showToast
import com.aiosman.riderpro.data.api.toErrorMessage
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
import com.aiosman.riderpro.ui.composables.ActionButton
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
import com.aiosman.riderpro.ui.composables.TextInputField
import com.google.android.gms.common.api.ApiException
import kotlinx.coroutines.launch
/**
@@ -49,6 +54,7 @@ class ChangePasswordViewModel {
*/
@Composable
fun ChangePasswordScreen() {
val context = LocalContext.current
val viewModel = remember { ChangePasswordViewModel() }
var currentPassword by remember { mutableStateOf("") }
var newPassword by remember { mutableStateOf("") }
@@ -126,17 +132,24 @@ fun ChangePasswordScreen() {
Spacer(modifier = Modifier.height(50.dp))
ActionButton(
modifier = Modifier
.width(345.dp)
.height(48.dp),
.width(345.dp),
text = "Let's Ride",
) {
if (validate()) {
scope.launch {
try {
viewModel.changePassword(currentPassword, newPassword)
navController.popBackStack()
} catch (e: ServiceException) {
when (e.errorType) {
ErrorCode.IncorrectOldPassword ->
oldPasswordError = e.errorType.toErrorMessage(context)
else ->
e.errorType.showToast(context)
}
} catch (e: Exception) {
errorMessage = e.message ?: "An error occurred"
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
}
}
}