Skip to content

Commit

Permalink
feat: added custom validate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomuso committed Sep 1, 2022
1 parent 3060996 commit 8994ec4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/ldap-auth/src/components/LoginPage/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type LoginFormProps = {
error?: Error;
helperTextUsername?: string;
helperTextPassword?: string;
validateUsername?: (usr: string) => boolean;
validatePassword?: (pass: string) => boolean;
};

const useStyles = makeStyles((theme) => ({
Expand All @@ -35,16 +37,23 @@ export const LoginForm = ({
error,
helperTextUsername,
helperTextPassword,
validatePassword,
validateUsername,
}: LoginFormProps) => {
const validatePasswd =
validatePassword || passwordSchema.validate.bind(passwordSchema);
const validateUsern =
validateUsername || usernameSchema.validate.bind(usernameSchema);

const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [uError, setUError] = useState(Boolean(error));
const [pError, setPError] = useState(Boolean(error));
const classes = useStyles();

function onClick() {
const isUsernameValid = usernameSchema.validate(username) as boolean;
const isPasswordValid = passwordSchema.validate(password) as boolean;
const isUsernameValid = validateUsern(username) as boolean;
const isPasswordValid = validatePasswd(password) as boolean;
setUError(!isUsernameValid);
setPError(!isPasswordValid);

Expand Down
2 changes: 2 additions & 0 deletions packages/ldap-auth/src/components/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type LdapSignInPageProps = SignInPageProps & {
options?: {
helperTextPassword?: string;
helperTextUsername?: string;
validateUsername?: (usr: string) => boolean;
validatePassword?: (pass: string) => boolean;
}
};

Expand Down

0 comments on commit 8994ec4

Please sign in to comment.