Skip to content

Commit

Permalink
remove disable Password/ sshKey
Browse files Browse the repository at this point in the history
  • Loading branch information
mgold1234 committed Nov 24, 2024
1 parent 11c7b14 commit 9b3fe35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ const UserInfo = () => {
};
const toggleConfirmPasswordVisibility = () =>
setIsConfirmPasswordVisible((prevState) => !prevState);
const isPasswordDisabled = Boolean(userSshKey);
const isSshKeyDisabled = Boolean(userPassword || confirmUserPassword);

const stepValidation = useUserValidation();
return (
<Form>
Expand All @@ -120,7 +119,6 @@ const UserInfo = () => {
placeholder="Enter password"
stepValidation={stepValidation}
fieldName="userPassword"
isDisabled={isPasswordDisabled}
togglePasswordVisibility={togglePasswordVisibility}
isPasswordVisible={isPasswordVisible}
/>
Expand Down Expand Up @@ -152,7 +150,6 @@ const UserInfo = () => {
placeholder="Enter confirm password"
stepValidation={stepValidation}
fieldName="userConfirmPassword"
isDisabled={isPasswordDisabled}
togglePasswordVisibility={toggleConfirmPasswordVisibility}
isPasswordVisible={isConfirmPasswordVisible}
/>
Expand All @@ -165,14 +162,11 @@ const UserInfo = () => {
onChange={(event, ssh_key) =>
handleFieldChange('ssh_key', ssh_key, setUserSshKey, () => {
// Additional logic for SSH key
dispatch(setUserPassword(''));
dispatch(setConfirmUserPassword(''));
})
}
placeholder="Paste your public SSH key"
stepValidation={stepValidation}
fieldName="userSshKey"
isDisabled={isSshKeyDisabled}
/>
<Button
component="a"
Expand Down
45 changes: 27 additions & 18 deletions src/Components/CreateImageWizard/utilities/useValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ export function useUserValidation(): StepValidation {
const userPassword = useAppSelector(selectUserPassword);
const userConfirmPassword = useAppSelector(selectConfirmUserPassword);
const userSshKey = useAppSelector(selectUserSshKey);
const shouldValidatePassword = !userSshKey;
const shouldValidateSshKey = !userPassword;
const userNameValid = isUserNameValid(userName);
const passwordValid = shouldValidatePassword
? isPasswordValid(userPassword || '')
: true;
const passwordValid = isPasswordValid(userPassword || '');

const passwordConfirmMatchValid = isConfirmPasswordValid(
userPassword || '',
userConfirmPassword || ''
);
const sshKeyValid = shouldValidateSshKey
? isSshKeyValid(userSshKey || '')
: true;
const sshKeyValid = isSshKeyValid(userSshKey || '');
const isPasswordAndConfirmValid = passwordValid && passwordConfirmMatchValid;
const canProceed =
userNameValid &&
((userSshKey && sshKeyValid) ||
(userPassword && isPasswordAndConfirmValid));

return {
errors: {
userName: !userNameValid
Expand All @@ -171,17 +171,26 @@ export function useUserValidation(): StepValidation {
'\n' +
' Usernames may only be up to 32 characters long.'
: '',
userPassword: !passwordValid ? 'Invalid user password' : '',
userConfirmPassword: !passwordConfirmMatchValid
? 'password and confirm password should be the same'
: '',
userSshKey: !sshKeyValid
? "Value does not match pattern: /^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521)) \\\\S+/.'"
: '',
userPassword:
userSshKey || !userPassword
? ''
: !passwordValid
? 'Invalid user password'
: '',
userConfirmPassword:
userSshKey || !userPassword
? ''
: !passwordConfirmMatchValid
? 'password and confirm password should be the same'
: '',
userSshKey:
userPassword || !userSshKey
? ''
: !sshKeyValid
? "Value does not match pattern: /^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521)) \\\\S+/.'"
: '',
},
disabledNext:
!(userNameValid && passwordValid && passwordConfirmMatchValid) ||
!(userNameValid && sshKeyValid),
disabledNext: !canProceed,
};
}

Expand Down

0 comments on commit 9b3fe35

Please sign in to comment.