source: client_app/src/components/filter/search.js@ 580ba1a

Last change on this file since 580ba1a was 580ba1a, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

register and edit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1import React, { useEffect, useState } from 'react';
2import { Button, Checkbox, Container, Form } from "semantic-ui-react";
3import { Redirect } from 'react-router-dom';
4import Jobs from "../item_components/job_component";
5import JobSearch from "../../repository/search_repo";
6import Internships from "../item_components/internship_component";
7
8const Search = (props) => {
9 const [formData, updateData] = useState({
10 text: "",
11 type: "0",
12 items: [],
13 searchedType: "0"
14 })
15
16 const handleCheck = (e, {value}) => {
17 updateData({
18 ...formData,
19 [e.target.name]: value
20 })
21 }
22
23 useEffect(() => {
24 updateData({
25 ...formData,
26 text: "",
27 type: "0"
28 })
29 }, [formData.items]);
30
31 const onFormSubmit = (e) =>{
32 e.preventDefault();
33 updateData({
34 ...formData,
35 searchedType: formData.type
36 })
37
38 if(formData.type==="0"){
39 JobSearch.job(formData.text).then(res => {
40 updateData({
41 items: res.data
42 });
43 })
44 }else if(formData.type==="1"){
45 JobSearch.internship(formData.text).then(res => {
46 updateData({
47 items: res.data
48 });
49 })
50 }else{
51 JobSearch.project(formData.text).then(res => {
52 updateData({
53 items: res.data
54 });
55 })
56 }
57 }
58
59 if(props.loggedIn){
60 return(
61 <Container>
62 <Form onSubmit={onFormSubmit}>
63 <Form.Input id="text" name="text" type="text" value={formData.text} fluid label='Enter keyword:' placeholder='Keyword...' onChange={handleCheck} />
64 <Form.Field
65 control={Checkbox}
66 radio
67 label='Job'
68 id="0"
69 name="type"
70 value="0"
71 checked={formData.type === "0"}
72 onChange={handleCheck}
73 />
74 <Form.Field
75 control={Checkbox}
76 radio
77 label='Internship'
78 id="1"
79 name="type"
80 value="1"
81 checked={formData.type === "1"}
82 onChange={handleCheck}
83 />
84 <Form.Field
85 control={Checkbox}
86 radio
87 label='Project'
88 id="2"
89 name="type"
90 value="2"
91 checked={formData.type === "2"}
92 onChange={handleCheck}
93 />
94 <Form.Field control={Button}>Search</Form.Field>
95 </Form>
96
97 {formData.items.map(item => {
98 return (item.skillsTrained && <Internships
99 title={item.title}
100 description={item.description}
101 accountName={item.accountName}
102 accountEmail={item.accountEmail}
103 skills={item.skillsTrained}
104 />) || (<Jobs
105 title={item.title}
106 description={item.description}
107 accountName={item.accountName}
108 accountEmail={item.accountEmail}
109 skills={item.skillsRequired}
110 />)
111 })}
112 </Container>
113 );
114 }
115
116 return(
117 <Redirect to={"/profile"}/>
118 );
119
120}
121
122export default Search;
Note: See TracBrowser for help on using the repository browser.