import React from 'react'; import PropTypes from 'prop-types'; import Dropzone from 'react-dropzone'; import { withStyles } from '@material-ui/core/styles'; import Type from 'ba-styles/Typography.scss'; import PhotoCamera from '@material-ui/icons/PhotoCamera'; import { connect } from 'react-redux'; import { reduxForm, Field } from 'redux-form/immutable'; import PermContactCalendar from '@material-ui/icons/PermContactCalendar'; import Bookmark from '@material-ui/icons/Bookmark'; import LocalPhone from '@material-ui/icons/LocalPhone'; import Email from '@material-ui/icons/Email'; import Smartphone from '@material-ui/icons/Smartphone'; import LocationOn from '@material-ui/icons/LocationOn'; import Work from '@material-ui/icons/Work'; import Language from '@material-ui/icons/Language'; import css from 'ba-styles/Form.scss'; import { Button, Avatar, IconButton, Typography, Tooltip, InputAdornment } from '@material-ui/core'; import { TextFieldRedux } from '../Forms/ReduxFormMUI'; import styles from './contact-jss'; // validation functions const required = value => (value == null ? 'Required' : undefined); const email = value => ( value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value) ? 'Invalid email' : undefined ); class AddContactForm extends React.Component { saveRef = ref => { this.ref = ref; return this.ref; }; render() { const { classes, reset, pristine, submitting, handleSubmit, onDrop, imgAvatar } = this.props; let dropzoneRef; const acceptedFiles = ['image/jpeg', 'image/png', 'image/bmp']; const fileSizeLimit = 300000; const imgPreview = img => { if (typeof img !== 'string' && img !== '') { return URL.createObjectURL(imgAvatar); } return img; }; return (
Upload Avatar { dropzoneRef = node; }} > {({ getRootProps, getInputProps }) => (
)}
{ dropzoneRef.open(); }} >
) }} />
) }} />
) }} />
) }} />
) }} />
) }} />
) }} />
) }} />
); } } AddContactForm.propTypes = { classes: PropTypes.object.isRequired, handleSubmit: PropTypes.func.isRequired, reset: PropTypes.func.isRequired, onDrop: PropTypes.func.isRequired, pristine: PropTypes.bool.isRequired, submitting: PropTypes.bool.isRequired, imgAvatar: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired, }; const AddContactFormRedux = reduxForm({ form: 'immutableAddContact', enableReinitialize: true, })(AddContactForm); const AddContactInit = connect( state => ({ initialValues: state.getIn(['contact', 'formValues']) }) )(AddContactFormRedux); export default withStyles(styles)(AddContactInit);