Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace user's nickname with name and last name #295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import io.newm.feature.login.screen.password.Password
@Composable
fun ProfileForm(
email: String,
nicknameState: TextFieldState,
canUserEditName: Boolean,
firstName: TextFieldState,
lastName: TextFieldState,
currentPasswordState: TextFieldState,
newPasswordState: TextFieldState,
confirmNewPasswordState: TextFieldState,
Expand All @@ -45,13 +47,37 @@ fun ProfileForm(
modifier = Modifier
.padding(top = 12.dp, start = 12.dp, end = 12.dp)
) {
Email(
label = R.string.profile_form_nickname,
emailState = nicknameState,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
if (canUserEditName) {
Email(
label = R.string.profile_form_first_name,
emailState = firstName,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
)
)
)
Email(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a ticket to create an actual input component for non email fields. For now we will keep this 😓

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 @@ -13,16 +13,18 @@ import io.newm.core.ui.text.formNameStyle

@Composable
fun ProfileHeader(
nickname: String,
firstName: String,
lastName: String,
email: String
) {
// TODO: Replace nickname with user's name
val fullName = if(firstName.isNotEmpty() || lastName.isNotEmpty()) "$firstName $lastName" else ""

Text(
modifier = Modifier
.padding(top = 16.dp, start = 16.dp, end = 16.dp)
.fillMaxWidth()
.wrapContentWidth(Alignment.CenterHorizontally),
text = nickname.ifEmpty { "Welcome to NEWM" },
text = fullName.ifEmpty { "Welcome to NEWM" },
style = formNameStyle
)
Text(
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 @@ -51,14 +52,20 @@ class ProfileEditPresenter(
ProfileEditUiState.Content.Profile(
pictureUrl = user.pictureUrl.orEmpty(),
bannerUrl = user.bannerUrl.orEmpty(),
nickname = user.nickname.orEmpty(),
firstName = user.firstName.orEmpty(),
lastName = user.lastName.orEmpty(),
canUserEditName = user.canEditName(),
email = user.email.orEmpty(),
)
}
}

val nicknameState = remember(profile?.nickname) {
TextFieldState(profile?.nickname.orEmpty())
val firstNameState = remember(profile?.firstName) {
TextFieldState(profile?.firstName.orEmpty())
}

val lastNameState = remember(profile?.lastName) {
TextFieldState(profile?.lastName.orEmpty())
}

val currentPasswordState = remember {
Expand All @@ -79,13 +86,15 @@ class ProfileEditPresenter(

val isFormDirty =
remember(
nicknameState.isFocusedDirty,
firstNameState.isFocusedDirty,
lastNameState.isFocusedDirty,
currentPasswordState.isFocusedDirty,
newPasswordState.isFocusedDirty,
confirmPasswordState.isFocusedDirty
) {
listOf(
nicknameState,
firstNameState,
lastNameState,
currentPasswordState,
newPasswordState,
confirmPasswordState
Expand All @@ -101,7 +110,9 @@ class ProfileEditPresenter(
profile = profile,
errorMessage = errorMessage,
submitButtonEnabled = isFormDirty,
nicknameState = nicknameState,
firstName = firstNameState,
lastName = lastNameState,
canUserEditName = profile.canUserEditName,
currentPasswordState = currentPasswordState,
newPasswordState = newPasswordState,
confirmPasswordState = confirmPasswordState,
Expand All @@ -114,7 +125,8 @@ class ProfileEditPresenter(
currentPasswordState,
newPasswordState,
confirmPasswordState,
nicknameState
firstNameState,
lastNameState
)

errorMessage = error
Expand All @@ -127,7 +139,8 @@ class ProfileEditPresenter(
newPassword = newPasswordState.text.takeIf { it.isNotEmpty() },
currentPassword = currentPasswordState.text.takeIf { it.isNotEmpty() },
confirmPassword = confirmPasswordState.text.takeIf { it.isNotEmpty() },
nickname = nicknameState.text,
firstName = firstNameState.text,
lastName = lastNameState.text,
createdAt = "",
id = ""
)
Expand Down Expand Up @@ -167,7 +180,8 @@ class ProfileEditPresenter(
currentPasswordState: TextFieldState,
newPasswordState: TextFieldState,
confirmPasswordState: TextFieldState,
nicknameState: TextFieldState
firstNameState: TextFieldState,
lastNameState: TextFieldState
): String? {
if (newPasswordState.text.isNotEmpty() && isPasswordValid(newPasswordState.text).not()) {
return passwordValidationError(newPasswordState.text)
Expand All @@ -185,8 +199,12 @@ class ProfileEditPresenter(
return "Please enter your current password"
}

if (nicknameState.text.isEmpty()) {
return "Please enter a nickname"
if (firstNameState.text.isEmpty()) {
return "Please enter your name"
}

if (lastNameState.text.isEmpty()) {
return "Please enter your last name"
}

return null
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 @@ -99,20 +100,16 @@ private fun ProfileEditUiContent(
onNavigationClick = { onEvent(OnBack) }
)
ProfileHeader(
nickname = profile.nickname,
firstName = profile.firstName,
lastName = profile.lastName,
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,
nicknameState = state.nicknameState,
firstName = state.firstName,
lastName = state.lastName,
canUserEditName = profile.canUserEditName,
currentPasswordState = state.currentPasswordState,
newPasswordState = state.newPasswordState,
confirmNewPasswordState = state.confirmPasswordState,
Expand Down Expand Up @@ -165,7 +162,9 @@ private fun ProfileScreenPreview() {
profile = mockUsers.first().toProfile(),
submitButtonEnabled = true,
showConnectWallet = true,
nicknameState = TextFieldState(),
canUserEditName = true,
firstName = TextFieldState(),
lastName = TextFieldState(),
currentPasswordState = TextFieldState(),
newPasswordState = TextFieldState(),
confirmPasswordState = TextFieldState(),
Expand All @@ -179,7 +178,9 @@ private fun ProfileScreenPreview() {
private fun User.toProfile(): Content.Profile {
return Content.Profile(
email = email.orEmpty(),
nickname = nickname.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 @@ -8,7 +8,9 @@ sealed class ProfileEditUiState : CircuitUiState {
data object Loading : ProfileEditUiState()
data class Content(
val profile: Profile,
val nicknameState: TextFieldState,
val firstName: TextFieldState,
val lastName: TextFieldState,
val canUserEditName: Boolean,
val currentPasswordState: TextFieldState,
val newPasswordState: TextFieldState,
val confirmPasswordState: TextFieldState,
Expand All @@ -18,7 +20,9 @@ sealed class ProfileEditUiState : CircuitUiState {
val eventSink: (ProfileEditUiEvent) -> Unit
) : ProfileEditUiState() {
data class Profile(
val nickname: String,
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 @@ -155,7 +155,8 @@ private fun ProfileUiContent(
onOverflowTapped = { scope.launch { sheetState.show() } },
)
ProfileHeader(
nickname = user.nickname.orEmpty(),
firstName = user.firstName.orEmpty(),
lastName = user.lastName.orEmpty(),
email = user.email.orEmpty(),
)
Spacer(Modifier.height(40.dp))
Expand Down
3 changes: 2 additions & 1 deletion android/core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<string name="profile_edit_button_label">Edit Profile</string>
<string name="profile_faq">FAQ</string>
<string name="profile_form_email">EMAIL ADDRESS</string>
<string name="profile_form_nickname">NICKNAME</string>
<string name="profile_form_first_name">FIRST NAME</string>
<string name="profile_form_last_name">LAST NAME</string>
<string name="profile_form_password_confirm_password">CONFIRM NEW PASSWORD</string>
<string name="profile_form_password_current_password">CURRENT PASSWORD</string>
<string name="profile_form_password_new_password">NEW PASSWORD</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
Copy link
Contributor

@wlara wlara Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some users may have set only one of first name or last name. In the server we use this to support all possibilities when building fullName:

"${firstName.orEmpty().trim()} ${lastName.orEmpty().trim()}".trim()

}

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