family profile image upload API added

This commit is contained in:
victorAnumudu
2023-11-06 12:42:10 +01:00
parent 7020e6d4dc
commit 4f0d432176
3 changed files with 21 additions and 21 deletions
+7 -12
View File
@@ -33,7 +33,7 @@ export default function FamilyManageTabs({
loading: false,
data: null,
};
console.log('accountDetails',accountDetails)
// State for family details, tasks, waitlist, and pending
const [details, setDetails] = useState({
familyDetails: { ...initialDetailState },
@@ -69,7 +69,7 @@ export default function FamilyManageTabs({
let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''}) // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS
// State for profile image
const [profileImg, setProfileImg] = useState(profile);
const [profileImg, setProfileImg] = useState(accountDetails.image ? accountDetails.image : profile);
// Ref for profile image input
const profileImgInput = useRef(null);
@@ -118,15 +118,9 @@ export default function FamilyManageTabs({
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]}, `
}
}
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
@@ -146,12 +140,13 @@ export default function FamilyManageTabs({
const imgReader = new FileReader();
imgReader.onload = (event) => {
let reqData = { // PAYLOAD FOR API CALL
family_uid: accountDetails?.family_uid,
file_name: uploadedFile?.name,
file_size: uploadedFile?.size,
file_type: uploadedFile?.type?.split("/")[0]?.toLowerCase(),
file_data: event?.target?.result,
msg_type: 'FILE',
action: 11300
action: 111305
}
setUploadStatus({loading: true, status: false, message:'Loading...'})
apiCall.sendFiles(reqData).then(res=>{