From 7a225e41463391da28698a81804917bd6c25197c Mon Sep 17 00:00:00 2001 From: regexowl Date: Mon, 24 Mar 2025 12:46:48 +0100 Subject: [PATCH] Wizard: Add group input to User step This adds a group input to the User step. The input is implemented as a `LabelInput`, when Administrator checkbox is checked, `wheel` group gets added and it's removal automatically unchecks the Administrator checkbox again. --- .../steps/Users/components/UserInfo.tsx | 27 +++++++++++++++- .../CreateImageWizard/validators.ts | 9 ++++++ src/store/wizardSlice.ts | 32 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/Components/CreateImageWizard/steps/Users/components/UserInfo.tsx b/src/Components/CreateImageWizard/steps/Users/components/UserInfo.tsx index 2e3756db..418898a8 100644 --- a/src/Components/CreateImageWizard/steps/Users/components/UserInfo.tsx +++ b/src/Components/CreateImageWizard/steps/Users/components/UserInfo.tsx @@ -15,10 +15,16 @@ import { setUserSshKeyByIndex, setUserAdministratorByIndex, removeUser, + selectUserGroupsByIndex, + addUserGroupByIndex, + removeUserGroupByIndex, } from '../../../../../store/wizardSlice'; +import LabelInput from '../../../LabelInput'; import { PasswordValidatedInput } from '../../../utilities/PasswordValidatedInput'; import { useUsersValidation } from '../../../utilities/useValidation'; import { ValidatedInputAndTextArea } from '../../../ValidatedInput'; +import { isUserGroupValid } from '../../../validators'; + const UserInfo = () => { const dispatch = useAppDispatch(); const index = 0; @@ -30,6 +36,8 @@ const UserInfo = () => { const userSshKey = useAppSelector(userSshKeySelector); const userIsAdministratorSelector = selectUserAdministrator(index); const userIsAdministrator = useAppSelector(userIsAdministratorSelector); + const userGroupsSelector = selectUserGroupsByIndex(index); + const userGroups = useAppSelector(userGroupsSelector); const handleNameChange = ( _e: React.FormEvent, @@ -111,13 +119,30 @@ const UserInfo = () => { handleCheckboxChange(_e, value)} aria-label="Administrator" id="user Administrator" name="user Administrator" /> + + + addUserGroupByIndex({ index: index, group: value }) + } + removeAction={(value) => + removeUserGroupByIndex({ index: index, group: value }) + } + stepValidation={stepValidation} + fieldName="groups" + /> +