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
RevLine 
[19398ad]1import React, {useState} from "react";
[befb988]2import "../shared_css/Modal.css";
[19398ad]3
[28b3398]4import { Editor } from 'primereact/editor';
5
[19398ad]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";
[befb988]19import {notifyJobAdPost} from "../../utils/toastUtils";
[19398ad]20
21
22export const AddJobAdModal = () => {
23 const [modal, setModal] = useState(false);
[28b3398]24 const [text, setText] = useState("");
[19398ad]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"),
[befb988]35 startingSalary: yup.string().required("Please enter the starting salary"),
[19398ad]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 {
[befb988]49 id: auth.id,
[19398ad]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) => {
[28b3398]58 if (success) {
[befb988]59 // console.log("Job Advertisement added")
[19398ad]60 toggleModal()
[befb988]61 notifyJobAdPost()
[19398ad]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">
[28b3398]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>*/}
[befb988]79 <Modal open={modal} onClose={toggleModal} center>
[28b3398]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">
[befb988]86 <form>
[28b3398]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>
[19398ad]111 </div>
112
[28b3398]113 <div className="col-md-5">
114 <label className="label">Hourly rate:</label>
[befb988]115 <input type="number" {...register("startingSalary")}/>
[28b3398]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
[19398ad]158 </div>
[28b3398]159 </div>
160
[befb988]161 <div className="modal-buttons">
162 <div className="cancel-btn" onClick={toggleModal}> Cancel</div>
163 <button className="submit-btn" onClick={handleSubmit(addJobAdvertisement)}>Submit</button>
[28b3398]164 </div>
[19398ad]165
[28b3398]166 </form>
167 </div>
168 </Modal>
169 </div>)
[19398ad]170}
Note: See TracBrowser for help on using the repository browser.