|
@@ -6,41 +6,100 @@ import FormData from 'form-data'
|
|
|
class SendingForm extends Component {
|
|
|
constructor(props) {
|
|
|
super(props)
|
|
|
- this.state = { image: 'http://zabavnik.club/wp-content/uploads/vopros_2_14000037-939x1024.jpg' }
|
|
|
|
|
|
+ this.state = { trig:false }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- onChange = e => {
|
|
|
- const { pushPhoto, photo } = this.props
|
|
|
- //this.setState({image: e.target.files[0]})
|
|
|
+ onChange = e =>{
|
|
|
+ const { pushPhoto, base64 } = this.props
|
|
|
+ this.setState({trig:true})
|
|
|
let data = new FormData();
|
|
|
- data.append('image', e.target.files[0], e.target.files[0].name);
|
|
|
+ data.append('image',e.target.files[0], e.target.files[0].name);
|
|
|
+ pushPhoto(data)
|
|
|
+ var file = e.target.files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onloadend = function() {
|
|
|
+ base64(reader.result)
|
|
|
+ }
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ }
|
|
|
+ onChange1 = e =>{
|
|
|
+ const { pushPhoto, base641 } = this.props
|
|
|
+ this.setState({trig:true})
|
|
|
+ let data = new FormData();
|
|
|
+ data.append('image',e.target.files[0], e.target.files[0].name);
|
|
|
+ pushPhoto(data)
|
|
|
+ var file = e.target.files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onloadend = function() {
|
|
|
+ base641(reader.result)
|
|
|
+ }
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ }
|
|
|
+ onChange2 = e =>{
|
|
|
+ const { pushPhoto, base642 } = this.props
|
|
|
+ this.setState({trig:true})
|
|
|
+ let data = new FormData();
|
|
|
+ data.append('image',e.target.files[0], e.target.files[0].name);
|
|
|
+ pushPhoto(data)
|
|
|
+ var file = e.target.files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onloadend = function() {
|
|
|
+ base642(reader.result)
|
|
|
+ }
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ }
|
|
|
+ onChange3 = e =>{
|
|
|
+ const { pushPhoto, base643 } = this.props
|
|
|
+ this.setState({trig:true})
|
|
|
+ let data = new FormData();
|
|
|
+ if( e.target.files[0] == undefined ) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data.append('image',e.target.files[0], e.target.files[0].name);
|
|
|
+ pushPhoto(data)
|
|
|
+ var file = e.target.files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onloadend = function() {
|
|
|
+ base643(reader.result)
|
|
|
+ }
|
|
|
+ reader.readAsDataURL(file);
|
|
|
|
|
|
- pushPhoto(data)
|
|
|
}
|
|
|
|
|
|
submit = values => {
|
|
|
const { AddNewStaffAction, getUser, photo } = this.props
|
|
|
//const { image } = this.state
|
|
|
|
|
|
- let massive = []
|
|
|
- // massive = photo.map(el => el.data.fileName)
|
|
|
- // console.log(photo)
|
|
|
- values.img = `http://127.0.0.1:2000/static/${photo.map(el => el.data.fileName)}`
|
|
|
+
|
|
|
+ if(!this.state.trig){
|
|
|
+ values.img = "http://rs.img.com.ua/crop?v2=1&w=600&h=0&url=%2F%2Fbm.img.com.ua%2Fberlin%2Fstorage%2Forig%2Fd224d3bd9bfe8bcb6b561da523d87364.jpg";
|
|
|
+ values.state = 0
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ values.img = `http://127.0.0.1:2000/static/${photo.map(el => el.data.fileName)}`;
|
|
|
+ values.state = 1
|
|
|
+ }
|
|
|
+ //values.img = `http://127.0.0.1:2000/static/${photo.map(el => el.data.fileName)}`
|
|
|
+
|
|
|
values.staff = "Машина"
|
|
|
- values.state = 1
|
|
|
+
|
|
|
values.userId = getUser.id
|
|
|
console.log(values)
|
|
|
AddNewStaffAction(values)
|
|
|
- }
|
|
|
|
|
|
- render() {
|
|
|
-
|
|
|
- const { handleSubmit, pristine, reset, submitting, allCategory, photo } = this.props
|
|
|
- console.log(photo)
|
|
|
-
|
|
|
-
|
|
|
- return (
|
|
|
+ };
|
|
|
+ render(){
|
|
|
+
|
|
|
+ const { handleSubmit, pristine, reset, submitting, allCategory, photo, base64Photo, addOrnot, base64Photo1, base64Photo2, base64Photo3, addOrnot1, addOrnot2, addOrnot3 } = this.props
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return (
|
|
|
+
|
|
|
|
|
|
<div className="formdiv">
|
|
|
<form onSubmit={handleSubmit(this.submit)} className="form">
|
|
@@ -79,29 +138,31 @@ class SendingForm extends Component {
|
|
|
{allCategory.map(el => <option value={el.id}> {el.title}</option>)}
|
|
|
</Field>
|
|
|
|
|
|
- <div className="file">
|
|
|
- <label className='upload-zone'>
|
|
|
- <i> </i>
|
|
|
- <input type='file' className='files' onChange={this.onChange} />
|
|
|
-
|
|
|
- </label>
|
|
|
- <label className='upload-zone zone2'>
|
|
|
- <i> </i>
|
|
|
- <input type='file' className='files' onChange={this.onChange} />
|
|
|
-
|
|
|
- </label>
|
|
|
- <label className='upload-zone zone3'>
|
|
|
- <i> </i>
|
|
|
- <input type='file' className='files' onChange={this.onChange} />
|
|
|
-
|
|
|
- </label>
|
|
|
- <label className='upload-zone zone4'>
|
|
|
- <i> </i>
|
|
|
- <input type='file' className='files' onChange={this.onChange} />
|
|
|
-
|
|
|
- </label>
|
|
|
- </div>
|
|
|
|
|
|
+ <div className="file">
|
|
|
+ <label className='upload-zone zone1'>
|
|
|
+ {addOrnot ? <img src={base64Photo} style={{"width": "80px", "height": "80px"}}></img> : <i> </i>}
|
|
|
+ <input type='file' className='files' onChange={this.onChange}/>
|
|
|
+
|
|
|
+ </label>
|
|
|
+ <label className='upload-zone zone2'>
|
|
|
+ {addOrnot1 ? <img src={base64Photo1} style={{"width": "80px", "height": "80px"}}></img> : <i> </i>}
|
|
|
+ <input type='file' className='files' onChange={this.onChange1}/>
|
|
|
+
|
|
|
+ </label>
|
|
|
+ <label className='upload-zone zone3'>
|
|
|
+ {addOrnot2 ? <img src={base64Photo2} style={{"width": "80px", "height": "80px"}}></img> : <i> </i>}
|
|
|
+ <input type='file' className='files' onChange={this.onChange2}/>
|
|
|
+
|
|
|
+ </label>
|
|
|
+ <label className='upload-zone zone4'>
|
|
|
+ {addOrnot3 ? <img src={base64Photo3} style={{"width": "80px", "height": "80px"}}></img> : <i> </i>}
|
|
|
+ <input type='file' className='files' onChange={this.onChange3}/>
|
|
|
+
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
<div className="buttonConteiner">
|
|
|
<button type="submit" disabled={pristine || submitting} className="button" >
|
|
|
Submit
|
|
@@ -122,4 +183,11 @@ class SendingForm extends Component {
|
|
|
|
|
|
export default reduxForm({
|
|
|
form: 'SendingForm'
|
|
|
-})(SendingForm)
|
|
|
+})(SendingForm)
|
|
|
+// const mapStateToProps = (state, props) => ({
|
|
|
+// form: props.formId
|
|
|
+// });
|
|
|
+
|
|
|
+// const component = reduxForm({ enableReinitialize: true })(SendingForm);
|
|
|
+
|
|
|
+// export default connect(mapStateToProps)(component);
|