Skip to content

Commit

Permalink
Only user to update their name if they have not verified their profil…
Browse files Browse the repository at this point in the history
…e through KYC
  • Loading branch information
cristhianescobar committed Jul 22, 2024
1 parent 6a28fd7 commit f2479af
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.newm.feature.login.screen.password.Password
@Composable
fun ProfileForm(
email: String,
canUserEditName: Boolean,
firstName: TextFieldState,
lastName: TextFieldState,
currentPasswordState: TextFieldState,
Expand All @@ -46,20 +47,37 @@ fun ProfileForm(
modifier = Modifier
.padding(top = 12.dp, start = 12.dp, end = 12.dp)
) {
Email(
label = R.string.profile_form_first_name,
emailState = firstName,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
if (canUserEditName) {
Email(
label = R.string.profile_form_first_name,
emailState = firstName,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
)
)
)
Email(
label = R.string.profile_form_last_name,
emailState = lastName,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
Email(
label = R.string.profile_form_last_name,
emailState = lastName,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
)
)
)
} else {
TextFieldWithLabel(
labelResId = R.string.profile_form_first_name,
value = firstName.text,
onValueChange = { },
enabled = false,
textfieldBackgroundColor = Gray23,
)
TextFieldWithLabel(
labelResId = R.string.profile_form_last_name,
value = lastName.text,
onValueChange = { },
enabled = false,
textfieldBackgroundColor = Gray23,
)
}
TextFieldWithLabel(
labelResId = R.string.profile_form_email,
value = email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.newm.screens.profile.OnShowPrivacyPolicy
import io.newm.screens.profile.OnShowTermsAndConditions
import io.newm.shared.NewmAppLogger
import io.newm.shared.public.models.User
import io.newm.shared.public.models.canEditName
import io.newm.shared.public.usecases.ConnectWalletUseCase
import io.newm.shared.public.usecases.HasWalletConnectionsUseCase
import io.newm.shared.public.usecases.UserDetailsUseCase
Expand Down Expand Up @@ -53,6 +54,7 @@ class ProfileEditPresenter(
bannerUrl = user.bannerUrl.orEmpty(),
firstName = user.firstName.orEmpty(),
lastName = user.lastName.orEmpty(),
canUserEditName = user.canEditName(),
email = user.email.orEmpty(),
)
}
Expand Down Expand Up @@ -110,6 +112,7 @@ class ProfileEditPresenter(
submitButtonEnabled = isFormDirty,
firstName = firstNameState,
lastName = lastNameState,
canUserEditName = profile.canUserEditName,
currentPasswordState = currentPasswordState,
newPasswordState = newPasswordState,
confirmPasswordState = confirmPasswordState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import io.newm.screens.profile.ProfileHeader
import io.newm.screens.profile.edit.ProfileEditUiState.Content
import io.newm.screens.profile.edit.ProfileEditUiState.Loading
import io.newm.shared.public.models.User
import io.newm.shared.public.models.canEditName
import io.newm.shared.public.models.mocks.mockUsers
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -104,17 +105,11 @@ private fun ProfileEditUiContent(
email = profile.email,
)
Spacer(modifier = Modifier.height(40.dp))
if (state.showConnectWallet) {
LinkWalletScreen(
modifier = Modifier.padding(horizontal = 16.dp),
) {
onEvent(OnConnectWallet(it))
}
}
ProfileForm(
email = profile.email,
firstName = state.firstName,
lastName = state.lastName,
canUserEditName = profile.canUserEditName,
currentPasswordState = state.currentPasswordState,
newPasswordState = state.newPasswordState,
confirmNewPasswordState = state.confirmPasswordState,
Expand Down Expand Up @@ -167,6 +162,7 @@ private fun ProfileScreenPreview() {
profile = mockUsers.first().toProfile(),
submitButtonEnabled = true,
showConnectWallet = true,
canUserEditName = true,
firstName = TextFieldState(),
lastName = TextFieldState(),
currentPasswordState = TextFieldState(),
Expand All @@ -184,6 +180,7 @@ private fun User.toProfile(): Content.Profile {
email = email.orEmpty(),
firstName = firstName.orEmpty(),
lastName = lastName.orEmpty(),
canUserEditName = canEditName(),
pictureUrl = pictureUrl.orEmpty(),
bannerUrl = bannerUrl.orEmpty(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sealed class ProfileEditUiState : CircuitUiState {
val profile: Profile,
val firstName: TextFieldState,
val lastName: TextFieldState,
val canUserEditName: Boolean,
val currentPasswordState: TextFieldState,
val newPasswordState: TextFieldState,
val confirmPasswordState: TextFieldState,
Expand All @@ -21,6 +22,7 @@ sealed class ProfileEditUiState : CircuitUiState {
data class Profile(
val firstName: String,
val lastName: String,
val canUserEditName: Boolean,
val email: String,
val pictureUrl: String,
val bannerUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ data class User(
val newPassword: String? = null,
val confirmPassword: String? = null
)

fun User.fullName(): String? {
return if(!firstName.isNullOrBlank() && !lastName.isNullOrBlank()) "$firstName $lastName" else null
}

fun User.canEditName(): Boolean {
return verificationStatus == "Unverified"
}

0 comments on commit f2479af

Please sign in to comment.