-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.js
78 lines (71 loc) · 2.15 KB
/
Search.js
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
import React, { useState, useContext } from 'react';
import { Form, Button, Col } from 'react-bootstrap';
import JobsContext from '../context/jobs';
const initialValues = {
description: '',
location: '',
full_time: false,
};
const Search = () => {
const { onSearch } = useContext(JobsContext);
const [state, setState] = useState(initialValues);
const { description, location, full_time } = state;
const handleInputChange = (event) => {
const { name, value } = event.target;
if (name === 'full_time') {
setState((prevState) => ({ ...state, [name]: !prevState.full_time }));
} else {
setState({ ...state, [name]: value });
}
};
const handleSearch = (event) => {
event.preventDefault();
onSearch(state);
console.log(state);
};
return (
<div className='search-section'>
<Form className='search-form' onSubmit={handleSearch}>
<Form.Row>
<Form.Group as={Col} controlId='description'>
<Form.Label srOnly>Enter search term</Form.Label>
<Form.Control
type='text'
name='description'
value={description || ''}
placeholder='Enter search term'
onChange={handleInputChange}
/>
</Form.Group>
<Form.Group as={Col} controlId='location'>
<Form.Label srOnly>Enter location</Form.Label>
<Form.Control
type='text'
name='location'
value={location || ''}
placeholder='Enter location'
onChange={handleInputChange}
/>
</Form.Group>
<Col>
<Button variant='primary' type='submit' className='btn-search'>
Search
</Button>
</Col>
</Form.Row>
<div className='filters'>
<Form.Group controlId='full_time'>
<Form.Check
type='checkbox'
name='full_time'
label='Full time only'
checked={full_time}
onChange={handleInputChange}
/>
</Form.Group>
</div>
</Form>
</div>
);
};
export default Search;