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