diff --git a/src/components/Settings/Tabs/PersonalInfoTab.jsx b/src/components/Settings/Tabs/PersonalInfoTab.jsx
index 5b1d4c9..021751c 100644
--- a/src/components/Settings/Tabs/PersonalInfoTab.jsx
+++ b/src/components/Settings/Tabs/PersonalInfoTab.jsx
@@ -51,6 +51,7 @@ export default function PersonalInfoTab({
coverImgInput,
browseCoverImg,
coverImgChangHandler,
+ uploadStatus
}) {
let { userDetails } = useSelector((state) => state.userDetails);
@@ -361,7 +362,7 @@ export default function PersonalInfoTab({
{/* inputs ends here */}
- {process.env.REACT_APP_SHOW_UPLOAD_PROFILE_PICTURE != 0 &&
+ {/* {process.env.REACT_APP_SHOW_UPLOAD_PROFILE_PICTURE != 0 && */}
@@ -417,9 +418,11 @@ export default function PersonalInfoTab({
+ {uploadStatus.message && !uploadStatus.loading && {uploadStatus.message}
}
+ {uploadStatus.loading && {uploadStatus.message}
}
- }
+ {/* } */}
diff --git a/src/components/Settings/index.jsx b/src/components/Settings/index.jsx
index bffcdf5..161d216 100644
--- a/src/components/Settings/index.jsx
+++ b/src/components/Settings/index.jsx
@@ -24,6 +24,7 @@ import {
import RecipientAccountTab from "./Tabs/RecipientAccountTab";
export default function Settings({ faq }) {
+ const apiCall = new usersService();
const { userDetails } = useSelector((state) => state?.userDetails);
const [profileImg, setProfileImg] = useState(
userDetails?.profile_pic_url ? userDetails.profile_pic_url : profile
@@ -36,12 +37,68 @@ export default function Settings({ faq }) {
const browseProfileImg = () => {
profileImgInput.current.click();
};
-
+let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''})
const profileImgChangHandler = (e) => {
+ // if (e.target.value !== "") {
+ // const imgReader = new FileReader();
+ // imgReader.onload = (event) => {
+ // setProfileImg(event.target.result);
+ // };
+ // imgReader.readAsDataURL(e.target.files[0]);
+ // }
+ let acceptedFormat = ["jpeg", "jpg", "png", "bmp", "gif"] // ARRAY OF SUPPORTED FORMATS
+ let uploadedFile = e.target.files[0] //UPLOADED FILE
+
+ if(!acceptedFormat.includes(uploadedFile?.type?.split("/")[1]?.toLowerCase())){ //CHECKING FOR CORRECT UPLOAD FORMAT
+ let msg = 'Please select '
+ for(let i=0; i<=acceptedFormat.length-1; i++){
+ if(i == acceptedFormat.length-1){
+ msg+=`or ${acceptedFormat[i]}`
+ }else{
+ msg+=`${acceptedFormat[i]}, `
+ }
+ }
+ setUploadStatus({loading: false, status: false, message:msg})
+ return setTimeout(()=>{
+ profileImgInput.current.value = '' // clear the input
+ setUploadStatus({loading: false, status: false, message:''})
+ },3000)
+ }
+
+ 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:''})
+ },3000)
+ }
+
if (e.target.value !== "") {
const imgReader = new FileReader();
imgReader.onload = (event) => {
- setProfileImg(event.target.result);
+ let reqData = { // PAYLOAD FOR API CALL
+ file_name: uploadedFile?.name,
+ file_size: uploadedFile?.size,
+ file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(),
+ file_data: event?.target?.result,
+ msg_type: 'FILE',
+ action: 'WRENCHBOARD_PICTURE_PROFILE',
+ // action: 11307
+ }
+ setUploadStatus({loading: true, status: false, message:'Loading...'})
+ apiCall.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'})
+ setProfileImg(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]);
}
@@ -61,7 +118,6 @@ export default function Settings({ faq }) {
}
};
- const apiCall = useMemo(() => new usersService(), []);
// Tabs Handling
const tabs = [
{
@@ -113,7 +169,7 @@ export default function Settings({ faq }) {
iconName: "page-right",
},
{
- id: 8,
+ id: 9,
name: "terms",
title: "Terms and Conditions",
iconName: "page-right",
@@ -217,6 +273,7 @@ export default function Settings({ faq }) {
coverImgChangHandler={coverImgChangHandler}
browseCoverImg={browseCoverImg}
coverImgInput={coverImgInput}
+ uploadStatus={uploadStatus}
/>
)}