-
-
Save LukeSmetham/2533aa90408df2ce50db38452104234b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import styled from 'styled-components'; | |
import { Field, Formik } from 'formik'; | |
import Button from 'components/Button'; | |
import Input from 'components/Input'; | |
import validationSchema from './validationSchema'; | |
const Root = styled.form` | |
margin-top: 24px; | |
flex: 1; | |
display: flex; | |
flex-direction: column; | |
align-items: flex-start; | |
justify-content: flex-start; | |
& button { | |
margin-top: 16px; | |
} | |
`; | |
class LoginForm extends Component { | |
get initialValues() { | |
return { | |
username: '', | |
}; | |
} | |
renderForm = (form) => { | |
const { conferenceAlias } = this.props; | |
return ( | |
<Root onSubmit={form.handleSubmit}> | |
<Field name='username' component={Input} placeholder='Username' /> | |
<Button label={conferenceAlias ? 'Join Call' : 'Start a Call'} type='submit' /> | |
</Root> | |
); | |
}; | |
render() { | |
const { onSubmit } = this.props; | |
return ( | |
<Formik | |
children={this.renderForm} | |
initialValues={this.initialValues} | |
onSubmit={onSubmit} | |
validationSchema={validationSchema} | |
/> | |
); | |
} | |
} | |
LoginForm.propTypes = { | |
conferenceAlias: PropTypes.string, | |
onSubmit: PropTypes.func.isRequired, | |
}; | |
export default LoginForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment