| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import brandImg from '../../assets/PF-IconLogo.svg'; |
| 3 |
import { |
| 4 |
LoginFooterItem, |
| 5 |
LoginForm, |
| 6 |
LoginMainFooterBandItem, |
| 7 |
LoginMainFooterLinksItem, |
| 8 |
LoginPage, |
| 9 |
ListItem, |
| 10 |
ListVariant, |
| 11 |
Button |
| 12 |
} from '@patternfly/react-core'; |
| 13 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 14 |
import GoogleIcon from '@patternfly/react-icons/dist/esm/icons/google-icon'; |
| 15 |
import GithubIcon from '@patternfly/react-icons/dist/esm/icons/github-icon'; |
| 16 |
import DropboxIcon from '@patternfly/react-icons/dist/esm/icons/dropbox-icon'; |
| 17 |
import FacebookSquareIcon from '@patternfly/react-icons/dist/esm/icons/facebook-square-icon'; |
| 18 |
import GitlabIcon from '@patternfly/react-icons/dist/esm/icons/gitlab-icon'; |
| 19 |
|
| 20 |
export const SimpleLoginPage: React.FunctionComponent = () => { |
| 21 |
const [showHelperText, setShowHelperText] = useState(false); |
| 22 |
const [username, setUsername] = useState(''); |
| 23 |
const [isValidUsername, setIsValidUsername] = useState(true); |
| 24 |
const [password, setPassword] = useState(''); |
| 25 |
const [isValidPassword, setIsValidPassword] = useState(true); |
| 26 |
const [isRememberMeChecked, setIsRememberMeChecked] = useState(false); |
| 27 |
|
| 28 |
const handleUsernameChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => { |
| 29 |
setUsername(value); |
| 30 |
}; |
| 31 |
|
| 32 |
const handlePasswordChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => { |
| 33 |
setPassword(value); |
| 34 |
}; |
| 35 |
|
| 36 |
const onRememberMeClick = () => { |
| 37 |
setIsRememberMeChecked(!isRememberMeChecked); |
| 38 |
}; |
| 39 |
|
| 40 |
const onLoginButtonClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { |
| 41 |
event.preventDefault(); |
| 42 |
setIsValidUsername(!!username); |
| 43 |
setIsValidPassword(!!password); |
| 44 |
setShowHelperText(!username || !password); |
| 45 |
}; |
| 46 |
|
| 47 |
const socialMediaLoginContent = ( |
| 48 |
<Fragment> |
| 49 |
<LoginMainFooterLinksItem> |
| 50 |
<Button variant="plain" aria-label="Login with Google" icon={<GoogleIcon />} /> |
| 51 |
</LoginMainFooterLinksItem> |
| 52 |
<LoginMainFooterLinksItem> |
| 53 |
<Button variant="plain" aria-label="Login with Github" icon={<GithubIcon />} /> |
| 54 |
</LoginMainFooterLinksItem> |
| 55 |
<LoginMainFooterLinksItem> |
| 56 |
<Button variant="plain" aria-label="Login with Dropbox" icon={<DropboxIcon />} /> |
| 57 |
</LoginMainFooterLinksItem> |
| 58 |
<LoginMainFooterLinksItem> |
| 59 |
<Button variant="plain" aria-label="Login with Facebook" icon={<FacebookSquareIcon />} /> |
| 60 |
</LoginMainFooterLinksItem> |
| 61 |
<LoginMainFooterLinksItem> |
| 62 |
<Button variant="plain" aria-label="Login with Gitlab" icon={<GitlabIcon />} /> |
| 63 |
</LoginMainFooterLinksItem> |
| 64 |
</Fragment> |
| 65 |
); |
| 66 |
|
| 67 |
const signUpForAccountMessage = ( |
| 68 |
<LoginMainFooterBandItem> |
| 69 |
Need an account? <a href="https://www.patternfly.org/">Sign up.</a> |
| 70 |
</LoginMainFooterBandItem> |
| 71 |
); |
| 72 |
|
| 73 |
const forgotCredentials = ( |
| 74 |
<LoginMainFooterBandItem> |
| 75 |
<a href="https://www.patternfly.org/">Forgot username or password?</a> |
| 76 |
</LoginMainFooterBandItem> |
| 77 |
); |
| 78 |
|
| 79 |
const listItem = ( |
| 80 |
<Fragment> |
| 81 |
<ListItem> |
| 82 |
<LoginFooterItem href="https://www.patternfly.org/">Terms of Use </LoginFooterItem> |
| 83 |
</ListItem> |
| 84 |
<ListItem> |
| 85 |
<LoginFooterItem href="https://www.patternfly.org/">Help</LoginFooterItem> |
| 86 |
</ListItem> |
| 87 |
<ListItem> |
| 88 |
<LoginFooterItem href="https://www.patternfly.org/">Privacy Policy</LoginFooterItem> |
| 89 |
</ListItem> |
| 90 |
</Fragment> |
| 91 |
); |
| 92 |
|
| 93 |
const loginForm = ( |
| 94 |
<LoginForm |
| 95 |
showHelperText={showHelperText} |
| 96 |
helperText="Invalid login credentials." |
| 97 |
helperTextIcon={<RhUiErrorFillIcon />} |
| 98 |
usernameLabel="Username" |
| 99 |
usernameValue={username} |
| 100 |
onChangeUsername={handleUsernameChange} |
| 101 |
isValidUsername={isValidUsername} |
| 102 |
passwordLabel="Password" |
| 103 |
passwordValue={password} |
| 104 |
onChangePassword={handlePasswordChange} |
| 105 |
isValidPassword={isValidPassword} |
| 106 |
rememberMeLabel="Keep me logged in for 30 days." |
| 107 |
isRememberMeChecked={isRememberMeChecked} |
| 108 |
onChangeRememberMe={onRememberMeClick} |
| 109 |
onLoginButtonClick={onLoginButtonClick} |
| 110 |
loginButtonLabel="Log in" |
| 111 |
/> |
| 112 |
); |
| 113 |
|
| 114 |
return ( |
| 115 |
<LoginPage |
| 116 |
footerListVariants={ListVariant.inline} |
| 117 |
brandImgProps={{ src: brandImg, alt: 'PatternFly logo' }} |
| 118 |
backgroundImgSrc="/assets/images/pf-background.svg" |
| 119 |
footerListItems={listItem} |
| 120 |
textContent="This is placeholder text only. Use this area to place any information or introductory message about your application that may be relevant to users." |
| 121 |
loginTitle="Log in to your account" |
| 122 |
loginSubtitle="Enter your single sign-on LDAP credentials." |
| 123 |
socialMediaLoginContent={socialMediaLoginContent} |
| 124 |
socialMediaLoginAriaLabel="Log in with social media" |
| 125 |
signUpForAccountMessage={signUpForAccountMessage} |
| 126 |
forgotCredentials={forgotCredentials} |
| 127 |
> |
| 128 |
{loginForm} |
| 129 |
</LoginPage> |
| 130 |
); |
| 131 |
}; |