fixed update user rights button
This commit is contained in:
parent
9cc7462ad2
commit
c617fff315
@ -23,7 +23,7 @@ data class UserDTO (
|
||||
@SerialName("roles")
|
||||
val roles: List<AuthorityDTO>,
|
||||
@SerialName("acsblocked")
|
||||
val isACSBlocked: Boolean
|
||||
var isACSBlocked: Boolean
|
||||
// @SerialName("lastVisit")
|
||||
// val lastVisit: String,
|
||||
) : java.io.Serializable
|
@ -15,6 +15,7 @@ import com.displaynone.acss.components.acs.models.visit.VisitAdapter
|
||||
import com.displaynone.acss.components.auth.models.user.UserServiceST
|
||||
import com.displaynone.acss.components.auth.models.user.repository.dto.UserDTO
|
||||
import com.displaynone.acss.databinding.FragmentProfileBinding
|
||||
import com.displaynone.acss.ui.init.InitFragmentViewModel
|
||||
import com.displaynone.acss.ui.profile.ProfileViewModel.Action
|
||||
import com.displaynone.acss.ui.scan.QrScanDestination
|
||||
import com.displaynone.acss.util.collectWithLifecycle
|
||||
@ -92,19 +93,25 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
|
||||
binding.position.text = userDTO.position
|
||||
setAvatar(userDTO.photo)
|
||||
}
|
||||
private fun updateRights(isACSBlocked: Boolean){
|
||||
binding.changeRights.text = if(isACSBlocked) "Разблокировать пользователя" else "Заблокировать пользователя"
|
||||
}
|
||||
|
||||
private fun showData(userDTO: UserDTO) {
|
||||
binding.fio.text = userDTO.name
|
||||
binding.position.text = userDTO.position
|
||||
binding.changeRights.text = if(userDTO.isACSBlocked) "Разблокировать пользователя" else "Заблокировать пользователя"
|
||||
updateRights(userDTO.isACSBlocked)
|
||||
viewModel.setLogin(login1 = userDTO.login)
|
||||
binding.changeRights.setOnClickListener {
|
||||
viewModel.changeRights(userDTO.login, !userDTO.isACSBlocked)
|
||||
}
|
||||
viewModel.state.collectWithLifecycle(this){ state ->
|
||||
if (state is ProfileViewModel.State.Change){
|
||||
updateRights(state.item)
|
||||
userDTO.isACSBlocked = state.item
|
||||
}
|
||||
}
|
||||
Log.d("ProfileFragment", userDTO.login)
|
||||
|
||||
// binding.lastEntry.text = userDTO.lastVisit
|
||||
|
||||
setAvatar(userDTO.photo)
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ProfileViewModel(): ViewModel() {
|
||||
Log.d("Pvm", data.login)
|
||||
},
|
||||
onFailure = { error ->
|
||||
error.message?.let { error(it) }
|
||||
error.message?.let { error(it) } //FIXME()
|
||||
Log.e("ProfileViewModel", error.message.toString())
|
||||
}
|
||||
)
|
||||
@ -72,7 +72,7 @@ class ProfileViewModel(): ViewModel() {
|
||||
UserServiceST.getInstance().changeRights(login, isACSBlocked).fold(
|
||||
onSuccess = {
|
||||
Log.d("ProfileViewModel", "changed rights")
|
||||
// _state.emit(State.Change(isACSBlocked))
|
||||
_state.emit(State.Change(isACSBlocked))
|
||||
},
|
||||
onFailure = { error ->
|
||||
Log.d("ProfileViewModel", "failed to change rights ${error.message}")
|
||||
@ -98,7 +98,7 @@ class ProfileViewModel(): ViewModel() {
|
||||
) : State
|
||||
data class Change(
|
||||
val item: Boolean
|
||||
)
|
||||
) : State
|
||||
}
|
||||
sealed interface Action {
|
||||
data object GoToAuth: Action
|
||||
|
Loading…
x
Reference in New Issue
Block a user