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

main
Last change on this file since befb988 was befb988, checked in by 223021 <daniel.ilievski.2@…>, 3 months ago

Added an edit profile page for both job seekers and recruiters, where they can upload profile pictures/company logos and edit their profile data. Added profile page specifically for recruiters. Refactored existing code.

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