Compare commits

..

12 Commits

Author SHA1 Message Date
victorAnumudu 612016784d added job image upload API 2023-11-06 16:34:41 +01:00
ameye 988aadfb7e Merge branch 'Server-path-added' of WrenchBoard/Users-Wrench into master 2023-11-06 14:28:14 +00:00
ameye 54851b5f77 Merge branch 'family-image-bug' of WrenchBoard/Users-Wrench into master 2023-11-06 14:27:50 +00:00
victorAnumudu 91f3b92138 Merge master into family-image-bug 2023-11-06 15:24:06 +01:00
victorAnumudu f48de9d65f upload bug fixed 2023-11-06 15:22:56 +01:00
Chief Bube c920c35a9c image now works 2023-11-06 06:15:12 -08:00
ameye 7bcaead120 Merge branch 'Server-path-added' of WrenchBoard/Users-Wrench into master 2023-11-06 14:04:08 +00:00
Chief Bube 828f56ed84 Added Image Path for server image 2023-11-06 05:30:30 -08:00
ameye 07118c10a8 Merge branch 'family-profile-image-upload' of WrenchBoard/Users-Wrench into master 2023-11-06 12:13:26 +00:00
victorAnumudu ca5923a7f8 Merge master into family-profile-image-upload 2023-11-06 12:43:20 +01:00
victorAnumudu 4f0d432176 family profile image upload API added 2023-11-06 12:42:10 +01:00
victorAnumudu 7020e6d4dc added family profile image upload 2023-11-06 04:10:03 +01:00
6 changed files with 158 additions and 88 deletions
+3 -22
View File
@@ -92,26 +92,6 @@ console.log('accountDetails',accountDetails)
* Checks if the selected file exceeds the maximum file size limit and displays an alert if it does. * Checks if the selected file exceeds the maximum file size limit and displays an alert if it does.
* If the file is within the size limit, it reads the file using the FileReader API and sets the profile image state with the result. * If the file is within the size limit, it reads the file using the FileReader API and sets the profile image state with the result.
*/ */
// const profileImgChangeHandler = (e) => {
// const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
// const file = e.target.files[0];
// if (file && file.size > MAX_FILE_SIZE) {
// alert("File size exceeds the limit.");
// return;
// }
// if (file) {
// const imgReader = new FileReader();
// imgReader.onload = () => {
// const imageDataUrl = imgReader.result;
// // Set the profile image
// setProfileImg(imageDataUrl);
// };
// imgReader.readAsDataURL(file);
// }
// };
const profileImgChangeHandler = (e) => { const profileImgChangeHandler = (e) => {
setUploadStatus({loading: false, status: false, message:''}) setUploadStatus({loading: false, status: false, message:''})
@@ -139,14 +119,15 @@ console.log('accountDetails',accountDetails)
if (e.target.value !== "") { if (e.target.value !== "") {
const imgReader = new FileReader(); const imgReader = new FileReader();
imgReader.onload = (event) => { imgReader.onload = (event) => {
let base64Img = imgReader.result.split(",")[1];
let reqData = { // PAYLOAD FOR API CALL let reqData = { // PAYLOAD FOR API CALL
family_uid: accountDetails?.family_uid, family_uid: accountDetails?.family_uid,
file_name: uploadedFile?.name, file_name: uploadedFile?.name,
file_size: uploadedFile?.size, file_size: uploadedFile?.size,
file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(), file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(),
file_data: event?.target?.result, file_data: base64Img,
msg_type: 'FILE', msg_type: 'FILE',
action: 111305 action: 11305
} }
setUploadStatus({loading: true, status: false, message:'Loading...'}) setUploadStatus({loading: true, status: false, message:'Loading...'})
apiCall.sendFiles(reqData).then(res=>{ apiCall.sendFiles(reqData).then(res=>{
@@ -7,6 +7,7 @@ export default function ProfileInfo({
profileImgChangeHandler, profileImgChangeHandler,
browseProfileImg, browseProfileImg,
accountDetails, accountDetails,
uploadStatus
}) { }) {
// console.log(accountDetails.banner) // console.log(accountDetails.banner)
return ( return (
@@ -52,6 +53,11 @@ export default function ProfileInfo({
</div> </div>
</div> </div>
</div> </div>
{/* DISPLAYS PROFILE 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="flex flex-col justify-center gap-3 items-center"> <div className="flex flex-col justify-center gap-3 items-center">
<h1 className="font-bold text-xl tracking-wide line-clamp-1 text-dark-gray dark:text-white capitalize"> <h1 className="font-bold text-xl tracking-wide line-clamp-1 text-dark-gray dark:text-white capitalize">
{accountDetails?.firstname} {accountDetails?.firstname}
+5 -4
View File
@@ -17,7 +17,7 @@ export default function FamilyAcc() {
// State to store the selected year and month // State to store the selected year and month
const [selectedYear, setSelectedYear] = useState(""); const [selectedYear, setSelectedYear] = useState("");
const [selectedMonth, setSelectedMonth] = useState(""); const [selectedMonth, setSelectedMonth] = useState("");
const [familyList, setFamilyList] = useState([]); const [familyList, setFamilyList] = useState({});
const [loader, setLoader] = useState(false); const [loader, setLoader] = useState(false);
const [popUp, setPopUp] = useState(false); const [popUp, setPopUp] = useState(false);
const [listReload, setListReload] = useState(false); const [listReload, setListReload] = useState(false);
@@ -115,8 +115,8 @@ export default function FamilyAcc() {
const res = await apiCall.familyListings(reqData); const res = await apiCall.familyListings(reqData);
const { data } = res; const { data } = res;
if (data?.internal_return >= 0 && data?.status === "OK") { if (data?.internal_return >= 0 && data?.status === "OK") {
const { result_list } = data; const { result_list, session_image_server } = data;
setFamilyList(result_list); setFamilyList({result_list, session_image_server});
setLoader(false); setLoader(false);
} else { } else {
return; return;
@@ -172,9 +172,10 @@ export default function FamilyAcc() {
</div> </div>
<Suspense fallback={<LoadingSpinner color="sky-blue" size="16" />}> <Suspense fallback={<LoadingSpinner color="sky-blue" size="16" />}>
<FamilyTable <FamilyTable
familyList={familyList} familyList={familyList?.result_list}
loader={loader} loader={loader}
popUpHandler={popUpHandler} popUpHandler={popUpHandler}
imageServer={familyList?.session_image_server}
/> />
</Suspense> </Suspense>
</div> </div>
@@ -137,15 +137,17 @@ export default function PersonalInfoTab({
if (e.target.value !== "") { if (e.target.value !== "") {
const imgReader = new FileReader(); const imgReader = new FileReader();
imgReader.onload = (event) => { imgReader.onload = (event) => {
let base64Img = imgReader.result.split(",")[1];
let reqData = { let reqData = {
// PAYLOAD FOR API CALL // PAYLOAD FOR API CALL
file_name: uploadedFile?.name, file_name: uploadedFile?.name,
file_size: uploadedFile?.size, file_size: uploadedFile?.size,
file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(), file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(),
file_data: event?.target?.result, file_data: base64Img,
msg_type: "FILE", msg_type: "FILE",
action: 11300, action: 11300,
}; };
setUploadStatus({ setUploadStatus({
loading: true, loading: true,
status: false, status: false,
+69 -13
View File
@@ -1,6 +1,6 @@
import { Field, Form, Formik } from "formik"; import { Field, Form, Formik } from "formik";
import React, { useCallback, useMemo, useState } from "react"; 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 { useNavigate } from "react-router-dom";
import * as Yup from "yup"; import * as Yup from "yup";
import usersService from "../../services/UsersService"; import usersService from "../../services/UsersService";
@@ -51,18 +51,12 @@ const EditJobPopOut = ({
categories, categories,
}) => { }) => {
const dispatch = useDispatch(); 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('') let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''}) // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS
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 [requestStatus, setRequestStatus] = useState({ let [requestStatus, setRequestStatus] = useState({
loading: false, loading: false,
@@ -117,6 +111,61 @@ const EditJobPopOut = ({
[jobApi, navigate, onClose, details] [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 ( return (
<ModalCom action={onClose} situation={situation} className="edit-popup"> <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"> <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" className="hidden"
type="file" type="file"
accept="image/*" accept="image/*"
onChange={changeTaskImage} onChange={taskImgChangeHandler}
/> />
{taskImage ? {taskImage ?
<div className="w-full absolute -top-5"> <div className="w-full absolute -top-5">
@@ -377,6 +426,12 @@ const EditJobPopOut = ({
))} ))}
{/* End of error or success display */} {/* 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="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"> <div className="flex items-center space-x-4 mr-2 mt-2">
{requestStatus.loading ? ( {requestStatus.loading ? (
@@ -386,6 +441,7 @@ const EditJobPopOut = ({
type="submit" type="submit"
className="w-[120px] h-[40px] flex justify-center items-center btn-gradient text-base rounded-full text-white" 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' // className='w-20 h-11 flex justify-center items-center btn-gradient text-base rounded-full text-white'
disabled={requestStatus.loading || uploadStatus.loading}
> >
Save Save
</button> </button>
+72 -48
View File
@@ -19,6 +19,16 @@ class usersService {
return this.postAuxEnd("/completesignuplink", reqData); return this.postAuxEnd("/completesignuplink", reqData);
} }
assignJobTask(reqData) {
var postData = {
uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"),
...reqData,
};
return this.postAuxEnd("/assigntask", postData);
}
// FUNCTION TO GET USER CURRENT TASK DUE TIME // FUNCTION TO GET USER CURRENT TASK DUE TIME
getHomeDate() { getHomeDate() {
var postData = { var postData = {
@@ -30,12 +40,12 @@ class usersService {
return this.postAuxEnd("/dashdata", postData); return this.postAuxEnd("/dashdata", postData);
} }
getRecentActivities(){ getRecentActivities() {
var postData = { var postData = {
uid: localStorage.getItem("uid"), uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"), member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"), sessionid: localStorage.getItem("session_token"),
action: 11202 action: 11202,
}; };
return this.postAuxEnd("/recentactivities", postData); return this.postAuxEnd("/recentactivities", postData);
} }
@@ -368,7 +378,7 @@ class usersService {
page: 0, page: 0,
offset: 0, offset: 0,
limit: 100, limit: 100,
allstatus: 0 allstatus: 0,
}; };
return this.postAuxEnd("/activetaskslist", postData); return this.postAuxEnd("/activetaskslist", postData);
} }
@@ -598,7 +608,7 @@ class usersService {
sessionid: localStorage.getItem("session_token"), sessionid: localStorage.getItem("session_token"),
page: 0, page: 0,
limit: 100, limit: 100,
...reqdata ...reqdata,
}; };
return this.postAuxEnd("/familyupdate", postData); return this.postAuxEnd("/familyupdate", postData);
} }
@@ -782,6 +792,17 @@ class usersService {
return this.postAuxEnd("/pendingjobsendtome", postData); return this.postAuxEnd("/pendingjobsendtome", postData);
} }
pendingCancelOffer(reqData) {
var postData = {
uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"),
action: 13043,
...reqData,
};
return this.postAuxEnd("/pendingjobcancel", postData);
}
// FUNCTION TO GET ACTIVE JOB MESSAGE LIST // FUNCTION TO GET ACTIVE JOB MESSAGE LIST
activeJobMesList(reqData) { activeJobMesList(reqData) {
var postData = { var postData = {
@@ -817,11 +838,11 @@ class usersService {
action: 14010, action: 14010,
...reqData, ...reqData,
}; };
const formData = new FormData(); const formData = new FormData();
for (let data in postData) { for (let data in postData) {
formData.append(data, postData[data]); formData.append(data, postData[data]);
} }
// return this.postAuxEnd("/uploads", formData);
return this.postAuxEnd("/uploads", postData); return this.postAuxEnd("/uploads", postData);
} }
@@ -1078,52 +1099,51 @@ class usersService {
return this.postAuxEnd("/blogdata", postData); return this.postAuxEnd("/blogdata", postData);
} }
// FUNCTION TO CANCEL TASK OR SEND REMINDER BY FAMILY MEMBER
suggestStatus(reqData) {
var postData = {
uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"),
action: 22026,
...reqData,
};
return this.postAuxEnd("/suggeststatus", postData);
}
// FUNCTION TO CANCEL TASK OR SEND REMINDER BY FAMILY MEMBER // FUNCTION TO GET FAMILY WALLET
suggestStatus(reqData) { getFamilyWallet(reqData) {
var postData = { var postData = {
uid: localStorage.getItem("uid"), uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"), member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"), sessionid: localStorage.getItem("session_token"),
action: 22026, action: 22012,
...reqData, ...reqData,
}; };
return this.postAuxEnd("/suggeststatus", postData); return this.postAuxEnd("/familywallet", postData);
} }
// FUNCTION TO GET FAMILY WALLET // FUNCTION TO START FAMILY TRANSFER
getFamilyWallet(reqData) { familyTransferStart(reqData) {
var postData = { var postData = {
uid: localStorage.getItem("uid"), uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"), member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"), sessionid: localStorage.getItem("session_token"),
action: 22012, ...reqData,
...reqData, };
}; return this.postAuxEnd("/familytransferstart", postData);
return this.postAuxEnd("/familywallet", postData); }
}
// FUNCTION TO START FAMILY TRANSFER
familyTransferStart(reqData) {
var postData = {
uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"),
...reqData,
};
return this.postAuxEnd("/familytransferstart", postData);
}
// FUNCTION TO PERFORM FAMILY TRANSFER // FUNCTION TO PERFORM FAMILY TRANSFER
familyTransfer(reqData) { familyTransfer(reqData) {
var postData = { var postData = {
uid: localStorage.getItem("uid"), uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"), member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"), sessionid: localStorage.getItem("session_token"),
...reqData, ...reqData,
}; };
return this.postAuxEnd("/familytransfer", postData); return this.postAuxEnd("/familytransfer", postData);
} }
/* /*
- 20:27:30.118 FLOG_MAX [757411]: REQ_STRING(username) - 20:27:30.118 FLOG_MAX [757411]: REQ_STRING(username)
@@ -1237,6 +1257,10 @@ class usersService {
console.log(response); console.log(response);
// res = response; // res = response;
console.log("~~~~~~~ Toks2 POST ~~~~~~~~"); console.log("~~~~~~~ Toks2 POST ~~~~~~~~");
if (response.data.internal_return == "-9999") {
localStorage.clear();
window.location.href = `/login?sessionExpired=true`;
}
return response; return response;
}) })
.catch((error) => { .catch((error) => {