Skip to content

Commit

Permalink
wizard: add Administrator checkbox to users step (HMS-4903)
Browse files Browse the repository at this point in the history
this commit add Administrator checkbox to users step
  • Loading branch information
mgold1234 committed Jan 6, 2025
1 parent fbf9936 commit b224c1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

import { FormGroup } from '@patternfly/react-core';
import { FormGroup, Checkbox } from '@patternfly/react-core';

import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
import {
selectUserAdministrator,
selectUserNameByIndex,
selectUserPasswordByIndex,
setUserNameByIndex,
setUserPasswordByIndex,
setUserAdministratorByIndex,
} from '../../../../../store/wizardSlice';
import { HookValidatedInput } from '../../../ValidatedTextInput';
const UserInfo = () => {
Expand All @@ -17,6 +19,8 @@ const UserInfo = () => {
const userName = useAppSelector(userNameSelector);
const userPasswordSelector = selectUserPasswordByIndex(index);
const userPassword = useAppSelector(userPasswordSelector);
const userIsAdministratorSelector = selectUserAdministrator(index);
const userAdministrator = useAppSelector(userIsAdministratorSelector);

const handleNameChange = (
_e: React.FormEvent<HTMLInputElement>,
Expand All @@ -32,6 +36,15 @@ const UserInfo = () => {
dispatch(setUserPasswordByIndex({ index: index, password: value }));
};

const handleCheckboxChange = (
_event: React.FormEvent<HTMLInputElement>,
value: boolean
) => {
dispatch(
setUserAdministratorByIndex({ index: index, isAdministrator: value })
);
};

const stepValidation = {
errors: {},
disabledNext: false,
Expand Down Expand Up @@ -59,6 +72,16 @@ const UserInfo = () => {
fieldName="userPassword"
/>
</FormGroup>
<FormGroup>
<Checkbox
label="Administrator"
isChecked={userAdministrator}
onChange={(_e, value) => handleCheckboxChange(_e, value)}
aria-label="Administrator"
id="user Administrator"
name="user Administrator"
/>
</FormGroup>
</>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/Components/CreateImageWizard/utilities/requestMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ const getUsers = (state: RootState): User[] | undefined => {
if (user.password !== '') {
result.password = user.password;
}
if (user.groups !== undefined) {
result.groups = user.groups;
}
return result as User;
});
};
Expand Down
1 change: 1 addition & 0 deletions src/store/wizardSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,5 +906,6 @@ export const {
addUser,
setUserNameByIndex,
setUserPasswordByIndex,
setUserAdministratorByIndex,
} = wizardSlice.actions;
export default wizardSlice.reducer;

0 comments on commit b224c1a

Please sign in to comment.