|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
import { Field, Form, Formik } from "formik";
|
|
|
|
|
import React, { useCallback, useMemo, useState } from "react";
|
|
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
|
import * as Yup from "yup";
|
|
|
|
|
import usersService from "../../services/UsersService";
|
|
|
|
@@ -51,18 +51,12 @@ const EditJobPopOut = ({
|
|
|
|
|
categories,
|
|
|
|
|
}) => {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const { userDetails } = useSelector((state) => state.userDetails);
|
|
|
|
|
|
|
|
|
|
const uploadedImage = localStorage.getItem('session_token') ? `${userDetails.session_image_server}${localStorage.getItem('session_token')}/jobs/${details?.job_uid}` : ''
|
|
|
|
|
const [taskImage, setTaskImage] = useState(uploadedImage)
|
|
|
|
|
|
|
|
|
|
const [taskImage, setTaskImage] = useState('')
|
|
|
|
|
|
|
|
|
|
const changeTaskImage = (e) => {
|
|
|
|
|
if (e.target.value !== "") {
|
|
|
|
|
const imgReader = new FileReader();
|
|
|
|
|
imgReader.onload = (event) => {
|
|
|
|
|
setTaskImage(event.target.result);
|
|
|
|
|
};
|
|
|
|
|
imgReader.readAsDataURL(e.target.files[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''}) // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS
|
|
|
|
|
|
|
|
|
|
let [requestStatus, setRequestStatus] = useState({
|
|
|
|
|
loading: false,
|
|
|
|
@@ -117,6 +111,61 @@ const EditJobPopOut = ({
|
|
|
|
|
[jobApi, navigate, onClose, details]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const taskImgChangeHandler = (e) => {
|
|
|
|
|
setUploadStatus({loading: false, status: false, message:''})
|
|
|
|
|
let acceptedFormat = ["jpeg", "jpg", "png", "bmp", "gif"] // ARRAY OF SUPPORTED FORMATS
|
|
|
|
|
let uploadedFile = e.target.files[0] //UPLOADED FILE
|
|
|
|
|
|
|
|
|
|
const fileFormat = uploadedFile?.type?.split("/")[1]?.toLowerCase();
|
|
|
|
|
if(!acceptedFormat.includes(fileFormat)){ //CHECKING FOR CORRECT UPLOAD FORMAT
|
|
|
|
|
const msg = `Please select ${acceptedFormat.slice(0, -1).join(', ')} or ${acceptedFormat.slice(-1)}`;
|
|
|
|
|
setUploadStatus({loading: false, status: false, message:msg})
|
|
|
|
|
return setTimeout(()=>{
|
|
|
|
|
// profileImgInput.current.value = '' // clear the input
|
|
|
|
|
setUploadStatus({loading: false, status: false, message:''})
|
|
|
|
|
},5000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(uploadedFile.size > 5*1048576){ // CHECKING FOR CORRECT FILE SIZE
|
|
|
|
|
setUploadStatus({loading: false, status: false, message:'File must not exceed 5MB'})
|
|
|
|
|
return setTimeout(()=>{
|
|
|
|
|
// profileImgInput.current.value = '' // clear the input
|
|
|
|
|
setUploadStatus({loading: false, status: false, message:''})
|
|
|
|
|
},5000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.target.value !== "") {
|
|
|
|
|
const imgReader = new FileReader();
|
|
|
|
|
imgReader.onload = (event) => {
|
|
|
|
|
let base64Img = imgReader.result.split(",")[1];
|
|
|
|
|
let reqData = { // PAYLOAD FOR API CALL
|
|
|
|
|
job_uid: details?.job_uid,
|
|
|
|
|
file_name: uploadedFile?.name,
|
|
|
|
|
file_size: uploadedFile?.size,
|
|
|
|
|
file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(),
|
|
|
|
|
file_data: base64Img,
|
|
|
|
|
msg_type: 'FILE',
|
|
|
|
|
action: 11303
|
|
|
|
|
}
|
|
|
|
|
setUploadStatus({loading: true, status: false, message:'Loading...'})
|
|
|
|
|
jobApi.sendFiles(reqData).then(res=>{
|
|
|
|
|
if(res.status != 200 || res.data.internal_return < 0){
|
|
|
|
|
return setUploadStatus({loading: false, status: false, message: 'Something went wrong, try again'})
|
|
|
|
|
}
|
|
|
|
|
setUploadStatus({loading: false, status: true, message: 'Uploaded successfully'})
|
|
|
|
|
setTaskImage(event.target.result);
|
|
|
|
|
}).catch(error=>{
|
|
|
|
|
setUploadStatus({loading: false, status: false, message: 'Network error, try again'})
|
|
|
|
|
}).finally(()=>{
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
setUploadStatus({loading: false, status: false, message: ''})
|
|
|
|
|
},5000)
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
imgReader.readAsDataURL(e.target.files[0]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ModalCom action={onClose} situation={situation} className="edit-popup">
|
|
|
|
|
<div className="logout-modal-wrapper lg:w-[600px] h-full lg:h-auto bg-white dark:bg-dark-white lg:rounded-2xl">
|
|
|
|
@@ -299,7 +348,7 @@ const EditJobPopOut = ({
|
|
|
|
|
className="hidden"
|
|
|
|
|
type="file"
|
|
|
|
|
accept="image/*"
|
|
|
|
|
onChange={changeTaskImage}
|
|
|
|
|
onChange={taskImgChangeHandler}
|
|
|
|
|
/>
|
|
|
|
|
{taskImage ?
|
|
|
|
|
<div className="w-full absolute -top-5">
|
|
|
|
@@ -377,6 +426,12 @@ const EditJobPopOut = ({
|
|
|
|
|
))}
|
|
|
|
|
{/* End of error or success display */}
|
|
|
|
|
|
|
|
|
|
{/* DISPLAYS TASK IMAGE UPLOADING STATUS */}
|
|
|
|
|
<div className="w-full">
|
|
|
|
|
{uploadStatus.message && !uploadStatus.loading && <p className={`text-center ${uploadStatus.status ? 'text-green-500':'text-red-500'}`}>{uploadStatus.message}</p>}
|
|
|
|
|
{uploadStatus.loading && <p className="text-center">{uploadStatus.message}</p>}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="w-full border-t border-light-purple dark:border-[#5356fb29] flex justify-end items-center">
|
|
|
|
|
<div className="flex items-center space-x-4 mr-2 mt-2">
|
|
|
|
|
{requestStatus.loading ? (
|
|
|
|
@@ -386,6 +441,7 @@ const EditJobPopOut = ({
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-[120px] h-[40px] flex justify-center items-center btn-gradient text-base rounded-full text-white"
|
|
|
|
|
// className='w-20 h-11 flex justify-center items-center btn-gradient text-base rounded-full text-white'
|
|
|
|
|
disabled={requestStatus.loading || uploadStatus.loading}
|
|
|
|
|
>
|
|
|
|
|
Save
|
|
|
|
|
</button>
|
|
|
|
|