Skip to content

Commit 9958df5

Browse files
leandroBorgesFerreiraLeandro Ferreira
andauthored
Showing users that only Admins can add users (#518)
Co-authored-by: Leandro Ferreira <[email protected]>
1 parent e4f4525 commit 9958df5

1 file changed

Lines changed: 100 additions & 81 deletions

File tree

  • application/features/account/src/commonMain/kotlin/io/writeopia/account/ui

application/features/account/src/commonMain/kotlin/io/writeopia/account/ui/SettingsDialog.kt

Lines changed: 100 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ private fun TeamsSection(
845845
is ResultData.Complete -> {
846846
val workspaces = (workspaces as ResultData.Complete<List<Workspace>>).data
847847

848-
849848
LazyRow(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
850849
items(workspaces) { workspace ->
851850
CommonButton(text = workspace.name) {
@@ -859,86 +858,7 @@ private fun TeamsSection(
859858
val selected = selectedWorkspaceState.collectAsState().value
860859

861860
if (selected != null) {
862-
BasicText(
863-
text = "Add users to team: ${selected.name}",
864-
style = MaterialTheme
865-
.typography
866-
.titleSmall
867-
.copy(color = MaterialTheme.colorScheme.onBackground)
868-
)
869-
870-
var userEmail by remember {
871-
mutableStateOf("")
872-
}
873-
874-
Spacer(modifier = Modifier.height(6.dp))
875-
876-
Row(verticalAlignment = Alignment.CenterVertically) {
877-
OutlinedTextField(
878-
value = userEmail,
879-
onValueChange = { userEmail = it },
880-
shape = MaterialTheme.shapes.large,
881-
singleLine = true,
882-
placeholder = {
883-
BasicText(
884-
"User email",
885-
style = MaterialTheme
886-
.typography
887-
.titleSmall
888-
.copy(color = WriteopiaTheme.colorScheme.textLighter)
889-
)
890-
},
891-
textStyle = MaterialTheme
892-
.typography
893-
.titleSmall
894-
.copy(color = MaterialTheme.colorScheme.onBackground)
895-
)
896-
897-
Spacer(modifier = Modifier.width(8.dp))
898-
899-
CommonButton(text = "Add") {
900-
addUserToTeam(userEmail)
901-
}
902-
}
903-
904-
Spacer(modifier = Modifier.height(8.dp))
905-
906-
val usersResult = usersInSelectedWorkspace.collectAsState().value
907-
908-
if (usersResult is ResultData.Complete) {
909-
val users = usersResult.data
910-
911-
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
912-
if (users.isNotEmpty()) {
913-
users.forEach { userName ->
914-
BasicText(
915-
text = userName,
916-
style = MaterialTheme
917-
.typography
918-
.bodySmall
919-
.copy(MaterialTheme.colorScheme.onBackground)
920-
)
921-
}
922-
} else {
923-
BasicText(
924-
text = "No users in this team",
925-
style = MaterialTheme
926-
.typography
927-
.bodySmall
928-
.copy(MaterialTheme.colorScheme.onBackground)
929-
)
930-
}
931-
}
932-
} else if (usersResult is ResultData.Error) {
933-
BasicText(
934-
text = "Error loading users", style = MaterialTheme
935-
.typography
936-
.bodySmall
937-
.copy(MaterialTheme.colorScheme.onBackground)
938-
)
939-
} else {
940-
CircularProgressIndicator()
941-
}
861+
AddUserToWorkspace(selected, usersInSelectedWorkspace, addUserToTeam)
942862
}
943863
}
944864

@@ -962,6 +882,105 @@ private fun TeamsSection(
962882
}
963883
}
964884

885+
@Composable
886+
private fun AddUserToWorkspace(
887+
selected: Workspace,
888+
usersInSelectedWorkspace: StateFlow<ResultData<List<String>>>,
889+
addUserToTeam: (String) -> Unit
890+
) {
891+
if (selected.role == "ADMIN") {
892+
BasicText(
893+
text = "Add users to team: ${selected.name}",
894+
style = MaterialTheme
895+
.typography
896+
.titleSmall
897+
.copy(color = MaterialTheme.colorScheme.onBackground)
898+
)
899+
900+
var userEmail by remember {
901+
mutableStateOf("")
902+
}
903+
904+
Spacer(modifier = Modifier.height(6.dp))
905+
906+
Row(verticalAlignment = Alignment.CenterVertically) {
907+
OutlinedTextField(
908+
value = userEmail,
909+
onValueChange = { userEmail = it },
910+
shape = MaterialTheme.shapes.large,
911+
singleLine = true,
912+
placeholder = {
913+
BasicText(
914+
"User email",
915+
style = MaterialTheme
916+
.typography
917+
.titleSmall
918+
.copy(color = WriteopiaTheme.colorScheme.textLighter)
919+
)
920+
},
921+
textStyle = MaterialTheme
922+
.typography
923+
.titleSmall
924+
.copy(color = MaterialTheme.colorScheme.onBackground)
925+
)
926+
927+
Spacer(modifier = Modifier.width(8.dp))
928+
929+
CommonButton(text = "Add") {
930+
addUserToTeam(userEmail)
931+
}
932+
}
933+
934+
Spacer(modifier = Modifier.height(8.dp))
935+
936+
val usersResult = usersInSelectedWorkspace.collectAsState().value
937+
938+
if (usersResult is ResultData.Complete) {
939+
val users = usersResult.data
940+
941+
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
942+
if (users.isNotEmpty()) {
943+
users.forEach { userName ->
944+
BasicText(
945+
text = userName,
946+
style = MaterialTheme
947+
.typography
948+
.bodySmall
949+
.copy(MaterialTheme.colorScheme.onBackground)
950+
)
951+
}
952+
} else {
953+
BasicText(
954+
text = "No users in this team",
955+
style = MaterialTheme
956+
.typography
957+
.bodySmall
958+
.copy(MaterialTheme.colorScheme.onBackground)
959+
)
960+
}
961+
}
962+
} else if (usersResult is ResultData.Error) {
963+
BasicText(
964+
text = "Error loading users",
965+
style = MaterialTheme
966+
.typography
967+
.bodySmall
968+
.copy(MaterialTheme.colorScheme.onBackground)
969+
)
970+
} else {
971+
CircularProgressIndicator()
972+
}
973+
} else {
974+
BasicText(
975+
text = "Only admins can add users",
976+
style = MaterialTheme
977+
.typography
978+
.bodySmall
979+
.copy(MaterialTheme.colorScheme.onBackground)
980+
)
981+
}
982+
}
983+
965984
@Composable
966985
private fun ColorThemeOptions(
967986
selectedThemePosition: StateFlow<Int>,

0 commit comments

Comments
 (0)