Skip to content

Commit

Permalink
feat: edit dialog, weird spacing & opens late
Browse files Browse the repository at this point in the history
  • Loading branch information
Mai-LinhC committed Jun 2, 2024
1 parent 0246484 commit 62e47ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -35,6 +36,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.github.se.assocify.model.entities.RoleType
import com.github.se.assocify.navigation.NavigationActions
import com.github.se.assocify.ui.composables.BackButton

Expand Down Expand Up @@ -97,8 +99,41 @@ fun ProfileMembersScreen(
ElevatedCard {
Column(
modifier = Modifier.padding(16.dp).testTag("editMemberDialog"),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)) {}
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
"Change ${state.updatingMember?.user?.name}'s role ?",
style = MaterialTheme.typography.titleMedium)

Spacer(modifier = Modifier.height(16.dp))

RoleType.entries.forEach { role ->
ListItem(
headlineContent = { Text(role.name.uppercase()) },
trailingContent = {
RadioButton(
modifier = Modifier.testTag("role-${role.name}"),
selected = state.newRole == role,
onClick = { profileMembersViewModel.updateRole(role) })
},
modifier = Modifier.testTag("roleitem-${role.name}"))
}

Spacer(modifier = Modifier.height(16.dp))

Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
OutlinedButton(
onClick = { profileMembersViewModel.onEditMemberDialogDismiss() },
modifier = Modifier.wrapContentSize().testTag("cancelButton"),
) {
Text(text = "Cancel", textAlign = TextAlign.Center)
}
OutlinedButton(
onClick = { profileMembersViewModel.confirmEditMember() },
modifier = Modifier.wrapContentSize().testTag("confirmButton")) {
Text(text = "Confirm", textAlign = TextAlign.Center)
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ProfileMembersViewModel(navActions: NavigationActions, associationAPI: Ass
}

fun onEditMember(member: AssociationMember) {
_uiState.value = _uiState.value.copy(updatingMember = member, showEditMemberDialog = true)
_uiState.value =
_uiState.value.copy(
updatingMember = member, showEditMemberDialog = true, newRole = member.role.type)
}

fun onDeleteMember(member: AssociationMember) {
Expand All @@ -39,6 +41,7 @@ class ProfileMembersViewModel(navActions: NavigationActions, associationAPI: Ass
}

fun confirmDeleteMember() {
// TODO delete the member
_uiState.value = _uiState.value.copy(showDeleteMemberDialog = false, updatingMember = null)
}

Expand All @@ -47,7 +50,7 @@ class ProfileMembersViewModel(navActions: NavigationActions, associationAPI: Ass
}

fun confirmEditMember() {
// update the member role in DB
// TODO update the member role
_uiState.value =
_uiState.value.copy(showEditMemberDialog = false, updatingMember = null, newRole = null)
}
Expand Down

0 comments on commit 62e47ff

Please sign in to comment.