diff --git a/src/components/AddJob/AddJob.jsx b/src/components/AddJob/AddJob.jsx index bbd0094..290d22c 100644 --- a/src/components/AddJob/AddJob.jsx +++ b/src/components/AddJob/AddJob.jsx @@ -1,6 +1,5 @@ import { validationSchema as VS, - getWalletDetail, useDispatch, useSelector, usersService, @@ -20,21 +19,14 @@ const validationSchema = VS; function AddJob({ popUpHandler, categories }) { const ApiCall = new usersService(); const { walletDetails } = useSelector((state) => state.walletDetails); - const { userDetails } = useSelector((state) => state.userDetails); let dispatch = useDispatch(); - const getWalletDetails = getWalletDetail( - userDetails.country, - walletDetails - ); - const walletAmount = getWalletDetails; // GETTING USER BALANCE BASED ON COUNTRY SELECTED - const initialValues = { ...IV, country: walletAmount?.description }; const [requestStatus, setRequestStatus] = useState(initialReqState); // Holds state when submit button is pressed const handleAddJob = async (values, helpers) => { const reqData = { - country: walletAmount?.country, + country: values?.country, price: Number(values.price) * 100, title: values?.title, description: values?.description, @@ -80,18 +72,10 @@ function AddJob({ popUpHandler, categories }) { } }; - // Check if the user is using iOS - const isIOS = /MacIntel|MacPPC/.test(navigator.platform) && !window.MSStream; - - // Check if the user is using Windows - const isWindows = /Windows/.test(navigator.userAgent); - - // console.log(isIOS, isWindows, navigator); - return (
@@ -103,24 +87,50 @@ function AddJob({ popUpHandler, categories }) { {/* inputs starts here */}
- + Currency + {props.errors.country && props.touched.country && ( + + {props.errors.country} + + )} + +
{/* Price */} @@ -187,7 +197,7 @@ function AddJob({ popUpHandler, categories }) {
- - + + {props.errors.category && + props.touched.category && + "please select a category"} + +
diff --git a/src/components/jobPopout/EditJobPopout.jsx b/src/components/jobPopout/EditJobPopout.jsx index a06d995..104251a 100644 --- a/src/components/jobPopout/EditJobPopout.jsx +++ b/src/components/jobPopout/EditJobPopout.jsx @@ -54,12 +54,17 @@ const EditJobPopOut = ({ const { userDetails } = useSelector((state) => state.userDetails); const { walletDetails } = useSelector((state) => state.walletDetails); - - const uploadedImage = `${userDetails.session_image_server}${localStorage.getItem('session_token')}/job/${details?.job_uid}` + const uploadedImage = `${ + userDetails.session_image_server + }${localStorage.getItem("session_token")}/job/${details?.job_uid}`; - const [taskImage, setTaskImage] = useState(uploadedImage) + const [taskImage, setTaskImage] = useState(uploadedImage); - let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''}) // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS + let [uploadStatus, setUploadStatus] = useState({ + loading: false, + status: false, + message: "", + }); // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS let [requestStatus, setRequestStatus] = useState({ loading: false, @@ -115,70 +120,99 @@ const EditJobPopOut = ({ ); 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 + 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(()=>{ + 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) + 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(()=>{ + 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) + 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 + let reqData = { + // PAYLOAD FOR API CALL job_uid: details?.job_uid, - file_name: uploadedFile?.name.slice(0,19), + file_name: uploadedFile?.name.slice(0, 19), 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); - setTimeout(() => { - dispatch(tableReload({ type: "JOBTABLE" })); - navigate("/myjobs", { replace: true }); - onClose(); - }, 1000); - }).catch(error=>{ - setUploadStatus({loading: false, status: false, message: 'Network error, try again'}) - }).finally(()=>{ - setTimeout(()=>{ - setUploadStatus({loading: false, status: false, message: ''}) - },5000) - }) + 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); + setTimeout(() => { + dispatch(tableReload({ type: "JOBTABLE" })); + navigate("/myjobs", { replace: true }); + onClose(); + }, 1000); + }) + .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]); } }; - // Check if the user is using iOS - const isIOS = /MacIntel|MacPPC/.test(navigator.platform) && !window.MSStream; + // Check if the user is using iOS + const isIOS = /MacIntel|MacPPC/.test(navigator.platform) && !window.MSStream; - // Check if the user is using Windows - const isWindows = /Windows/.test(navigator.userAgent); + // Check if the user is using Windows + const isWindows = /Windows/.test(navigator.userAgent); return ( @@ -321,82 +355,77 @@ const EditJobPopOut = ({
- - -
+ + {props.errors.category && + props.touched.category && + "please select a category"} + + +
{/* FOR TASK IMAGE */}
- - {taskImage ? -
- uploaded task - setTaskImage('')} className="p-2 absolute text-sm top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white/80 hover:bg-white hover:shadow-md transition-all duration-500 cursor-pointer text-slate-800">Remove Image -
- : - + )}
{/* END OF TASK IMAGE */}
-
+
+ {/* DISPLAYS TASK IMAGE UPLOADING STATUS */} +
+ {uploadStatus.message && !uploadStatus.loading && ( +

+ {uploadStatus.message} +

+ )} + {uploadStatus.loading && ( +

{uploadStatus.message}

+ )} +
@@ -471,7 +512,9 @@ 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} + disabled={ + requestStatus.loading || uploadStatus.loading + } > Save