1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Add from '@material-ui/icons/Add';
import { Tooltip, Fab } from '@material-ui/core';
import AddContactForm from './AddContactForm';
import FloatingPanel from '../Panel/FloatingPanel';
import styles from './contact-jss';
class AddContact extends React.Component {
constructor(props) {
super(props);
this.state = {
img: '',
files: []
};
this.onDrop = this.onDrop.bind(this);
}
onDrop(filesVal) {
const { files } = this.state;
const filesLimit = 1;
let oldFiles = files;
oldFiles = oldFiles.concat(filesVal);
if (oldFiles.length > filesLimit) {
console.log('Cannot upload more than ' + filesLimit + ' items.');
} else {
this.setState({ img: filesVal[0] });
}
}
sendValues = (values) => {
const { submit } = this.props;
const { img } = this.state;
const { avatarInit } = this.props;
const avatar = img === null ? avatarInit : img;
setTimeout(() => {
submit(values, avatar);
this.setState({ img: null });
}, 500);
}
render() {
const {
classes,
openForm,
closeForm,
avatarInit,
addContact
} = this.props;
const { img } = this.state;
const branch = '';
return (
<div>
<Tooltip title="Add New Contact">
<Fab color="secondary" onClick={() => addContact()} className={classes.addBtn}>
<Add />
</Fab>
</Tooltip>
<FloatingPanel openForm={openForm} branch={branch} closeForm={closeForm}>
<AddContactForm
onSubmit={this.sendValues}
onDrop={this.onDrop}
imgAvatar={img === null ? avatarInit : img}
/>
</FloatingPanel>
</div>
);
}
}
AddContact.propTypes = {
classes: PropTypes.object.isRequired,
submit: PropTypes.func.isRequired,
addContact: PropTypes.func.isRequired,
openForm: PropTypes.bool.isRequired,
avatarInit: PropTypes.string.isRequired,
closeForm: PropTypes.func.isRequired,
};
export default withStyles(styles)(AddContact);
|