source: jobvista-frontend/src/views/job_advertisements/AddJobAdModal.js@ 28b3398

main
Last change on this file since 28b3398 was 28b3398, checked in by 223021 <daniel.ilievski.2@…>, 2 weeks ago

Implemented job application functionality, added job advertisement filtering and replaced text areas with editors

  • Property mode set to 100644
File size: 7.0 KB
Line 
1import React, {useState} from "react";
2import "./Form.css";
3
4import { Editor } from 'primereact/editor';
5
6import 'react-responsive-modal/styles.css';
7import {Modal} from 'react-responsive-modal';
8import Select from "react-select";
9
10//Validation
11import * as yup from "yup";
12import {yupResolver} from "@hookform/resolvers/yup";
13import {Controller, useForm} from "react-hook-form";
14
15
16import {employmentStatusOptions, industryOptions, jobTypeOptions} from "../selectOptions";
17import {useDispatch, useSelector} from "react-redux";
18import {JobAdvertisementActions} from "../../redux/actions/jobAdvertisementActions";
19
20
21export const AddJobAdModal = () => {
22 const [modal, setModal] = useState(false);
23 const [text, setText] = useState("");
24 const dispatch = useDispatch();
25 const auth = useSelector(state => state.auth.currentUser)
26 const toggleModal = () => {
27 setModal(!modal);
28 };
29
30 const schema = yup.object().shape({
31 title: yup.string().required("Please enter a title"),
32 description: yup.string().required("Please enter a description"),
33 industry: yup.mixed().required("Select industry"),
34 startingSalary: yup.number().required("Please enter the starting salary"),
35 jobType: yup.mixed().required("Select job type"),
36 employmentStatus: yup.mixed().required("Select employment status"),
37 })
38
39 const {register, handleSubmit, control, formState: {errors}} = useForm({
40 resolver: yupResolver(schema),
41 });
42
43 const addJobAdvertisement = async (values) => {
44 //const description = values.description.replace(/\n/g, "\\n");
45 try {
46 dispatch(JobAdvertisementActions.addJobAdvertisement(
47 {
48 email: auth.email,
49 title: values.title,
50 description: values.description,
51 industry: values.industry.value,
52 startingSalary: values.startingSalary,
53 activeUntil: values.date,
54 jobType: values.jobType.value,
55 employmentStatus: values.employmentStatus.value,
56 }, (success, response) => {
57 if (success) {
58 console.log("Job Advertisement added")
59 toggleModal()
60 }
61 }
62 ))
63 } catch (err) {
64 console.error(err)
65 }
66 }
67 let minimumDate = new Date();
68 minimumDate.setDate(minimumDate.getDate() + 1);
69
70 return (<div className="modal-wrap">
71 <div className="col">
72 <button onClick={toggleModal} className="add-new-card">
73 <h3>+ Post Advertisement</h3>
74 </button>
75 </div>
76 {/*<button onClick={toggleModal} className="btn-open-modal">POST ADVERTISEMENT</button>*/}
77 <Modal open={modal} onClose={toggleModal} center classNames="job-advertisement-modal">
78 <div className="head-modal">
79 <h3>Post Job Advertisement</h3>
80 <i className="fa-solid fa-x btn-close-modal" onClick={toggleModal}></i>
81 </div>
82
83 <div className="modal-content">
84 <form onSubmit={handleSubmit(addJobAdvertisement)}>
85 <div className="row">
86 <div className="col-md-7">
87
88 <label className="label">Job title:</label>
89 <input type="text" {...register("title")}/>
90 <p style={{color: "red"}}>{errors.title?.message}</p>
91
92 <label className="label">Job description:</label>
93 {/*<textarea type="text" placeholder="Describe the job position and all the requirements"*/}
94 {/* className="description-textarea" {...register("description")}/>*/}
95
96
97 <Controller
98 name="description"
99 control={control}
100 render={({ field }) => (
101 <Editor
102 value={field.value}
103 onTextChange={(e) => field.onChange(e.htmlValue)}
104 style={{ height: '300px', fontSize: "16px", fontFamily: "Segoe UI" }}
105 />
106 )}
107 />
108 <p style={{color: "red"}}>{errors.description?.message}</p>
109 </div>
110
111 <div className="col-md-5">
112 <label className="label">Hourly rate:</label>
113 <input {...register("startingSalary")}/>
114 <p style={{color: "red"}}>{errors.startingSalary?.message}</p>
115
116 <label className="label">Industry:</label>
117 <Controller
118 name="industry"
119 control={control}
120 render={({field}) => (<Select
121 {...field}
122 options={industryOptions}
123 />)}
124 />
125 <p style={{color: "red"}}>{errors.industry?.message}</p>
126
127 <label className="label">Job type:</label>
128 <Controller
129 name="jobType"
130 control={control}
131 render={({field}) => (<Select
132 {...field}
133 options={jobTypeOptions}
134 />)}
135 />
136 <p style={{color: "red"}}>{errors.jobType?.message}</p>
137
138 <label className="label">Employment status</label>
139 <Controller
140 name="employmentStatus"
141 control={control}
142 render={({field}) => (<Select
143 {...field}
144 options={employmentStatusOptions}
145 />)}
146 />
147 <p style={{color: "red"}}>{errors.employmentStatus?.message}</p>
148
149 <label htmlFor="start">Active until:</label>
150 <input type="date" defaultValue={minimumDate.toLocaleDateString('en-CA')}
151 min={minimumDate.toLocaleDateString('en-CA')}
152 onChange={(event) => console.log(event.target.value)}
153 {...register("date")}/>
154
155
156 </div>
157 </div>
158
159 <div className="aligned">
160 <button className="submit-btn"> Submit</button>
161 </div>
162
163 </form>
164 </div>
165 </Modal>
166 </div>)
167}
Note: See TracBrowser for help on using the repository browser.