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

main
Last change on this file was 0f0add0, checked in by 223021 <daniel.ilievski.2@…>, 4 days ago

Pre-final version

  • Property mode set to 100644
File size: 7.0 KB
Line 
1import React, {useState} from "react";
2import "../shared_css/Modal.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";
19import {notifyJobAdPost} from "../../utils/toastUtils";
20
21
22export const AddJobAdModal = () => {
23 const [modal, setModal] = useState(false);
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.string().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 try {
45 dispatch(JobAdvertisementActions.addJobAdvertisement(
46 {
47 id: auth.id,
48 title: values.title,
49 description: values.description,
50 industry: values.industry.value,
51 startingSalary: values.startingSalary,
52 activeUntil: values.date,
53 jobType: values.jobType.value,
54 employmentStatus: values.employmentStatus.value,
55 }, (success) => {
56 if (success) {
57 toggleModal()
58 notifyJobAdPost()
59 }
60 }
61 ))
62 } catch (err) {
63 console.error(err)
64 }
65 }
66 let minimumDate = new Date();
67 minimumDate.setDate(minimumDate.getDate() + 1);
68
69 return (<div className="modal-wrap">
70 <div className="col">
71 <button onClick={toggleModal} className="add-new-card">
72 <h3>+ Post Advertisement</h3>
73 </button>
74 </div>
75 {/*<button onClick={toggleModal} className="btn-open-modal">POST ADVERTISEMENT</button>*/}
76 <Modal open={modal} onClose={toggleModal} center>
77 <div className="head-modal">
78 <h3>Post Job Advertisement</h3>
79 <i className="fa-solid fa-x btn-close-modal" onClick={toggleModal}></i>
80 </div>
81
82 <div className="modal-content">
83 <form>
84 <div className="row">
85 <div className="col-md-7">
86
87 <label className="label">Job title:</label>
88 <input type="text" {...register("title")}/>
89 <p style={{color: "red"}}>{errors.title?.message}</p>
90
91 <label className="label">Job description:</label>
92 {/*<textarea type="text" placeholder="Describe the job position and all the requirements"*/}
93 {/* className="description-textarea" {...register("description")}/>*/}
94
95
96 <Controller
97 name="description"
98 control={control}
99 render={({ field }) => (
100 <Editor
101 value={field.value}
102 onTextChange={(e) => field.onChange(e.htmlValue)}
103 style={{ height: '300px', fontSize: "16px", fontFamily: "Segoe UI" }}
104 />
105 )}
106 />
107 <p style={{color: "red"}}>{errors.description?.message}</p>
108 </div>
109
110 <div className="col-md-5">
111 <label className="label">Hourly rate:</label>
112 <input type="number" {...register("startingSalary")}/>
113 <p style={{color: "red"}}>{errors.startingSalary?.message}</p>
114
115 <label className="label">Industry:</label>
116 <Controller
117 name="industry"
118 control={control}
119 render={({field}) => (<Select
120 {...field}
121 options={industryOptions}
122 />)}
123 />
124 <p style={{color: "red"}}>{errors.industry?.message}</p>
125
126 <label className="label">Job type:</label>
127 <Controller
128 name="jobType"
129 control={control}
130 render={({field}) => (<Select
131 {...field}
132 options={jobTypeOptions}
133 />)}
134 />
135 <p style={{color: "red"}}>{errors.jobType?.message}</p>
136
137 <label className="label">Employment status</label>
138 <Controller
139 name="employmentStatus"
140 control={control}
141 render={({field}) => (<Select
142 {...field}
143 options={employmentStatusOptions}
144 />)}
145 />
146 <p style={{color: "red"}}>{errors.employmentStatus?.message}</p>
147
148 <label htmlFor="start">Active until:</label>
149 <input type="date" defaultValue={minimumDate.toLocaleDateString('en-CA')}
150 min={minimumDate.toLocaleDateString('en-CA')}
151 onChange={(event) => console.log(event.target.value)}
152 {...register("date")}/>
153
154
155 </div>
156 </div>
157
158 <div className="modal-buttons">
159 <div className="cancel-btn" onClick={toggleModal}> Cancel</div>
160 <button className="submit-btn" onClick={handleSubmit(addJobAdvertisement)}>Submit</button>
161 </div>
162
163 </form>
164 </div>
165 </Modal>
166 </div>)
167}
Note: See TracBrowser for help on using the repository browser.