blob: 5636be2b10047397631e3d29208b92e5605c8063 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001import React from 'react'
Adrien Béraude74741b2021-04-19 13:22:54 -04002import { InputBase, InputAdornment } from '@material-ui/core';
3import { SearchRounded } from '@material-ui/icons';
Larbi Gharibe9af9732021-03-31 15:08:01 +01004
5class NewContactForm extends React.Component {
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04006 constructor(props) {
7 super(props)
8 this.state = {value: ''}
9 this.controller = new AbortController()
10 this.handleChange = this.handleChange.bind(this)
11 this.handleSubmit = this.handleSubmit.bind(this)
12 }
13
14 componentDidMount() {
15 this.controller = new AbortController()
16 }
17
18 componentWillUnmount() {
19 this.controller.abort()
20 this.req = undefined
21 }
22
23 handleChange(event) {
24 this.setState({value: event.target.value})
25 this.props.onChange(event.target.value)
26 }
27
28 handleSubmit(event) {
29 event.preventDefault()
30 if (this.props.onSubmit)
31 this.props.onSubmit(this.state.value)
32 }
33
Larbi Gharibe9af9732021-03-31 15:08:01 +010034 render() {
35 return (
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040036 <form className="main-search" onSubmit={this.handleSubmit} noValidate autoComplete="off">
37 <InputBase
38 className="main-search-input"
39 type="search"
40 placeholder="Ajouter un contact"
41 onChange={this.handleChange}
Adrien Béraude74741b2021-04-19 13:22:54 -040042 startAdornment={<InputAdornment position="start"><SearchRounded /></InputAdornment>}
43 />
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040044 </form>
Larbi Gharibe9af9732021-03-31 15:08:01 +010045 )
46 }
47}
48
49export default NewContactForm