family profile image upload API added
This commit is contained in:
@@ -33,7 +33,7 @@ export default function FamilyManageTabs({
|
|||||||
loading: false,
|
loading: false,
|
||||||
data: null,
|
data: null,
|
||||||
};
|
};
|
||||||
|
console.log('accountDetails',accountDetails)
|
||||||
// State for family details, tasks, waitlist, and pending
|
// State for family details, tasks, waitlist, and pending
|
||||||
const [details, setDetails] = useState({
|
const [details, setDetails] = useState({
|
||||||
familyDetails: { ...initialDetailState },
|
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
|
let [uploadStatus, setUploadStatus] = useState({loading: false, status: false, message:''}) // HOLDS STATE FOR UPLOAD PROFILE PICTURE STATUS
|
||||||
|
|
||||||
// State for profile image
|
// State for profile image
|
||||||
const [profileImg, setProfileImg] = useState(profile);
|
const [profileImg, setProfileImg] = useState(accountDetails.image ? accountDetails.image : profile);
|
||||||
|
|
||||||
// Ref for profile image input
|
// Ref for profile image input
|
||||||
const profileImgInput = useRef(null);
|
const profileImgInput = useRef(null);
|
||||||
@@ -118,15 +118,9 @@ export default function FamilyManageTabs({
|
|||||||
let acceptedFormat = ["jpeg", "jpg", "png", "bmp", "gif"] // ARRAY OF SUPPORTED FORMATS
|
let acceptedFormat = ["jpeg", "jpg", "png", "bmp", "gif"] // ARRAY OF SUPPORTED FORMATS
|
||||||
let uploadedFile = e.target.files[0] //UPLOADED FILE
|
let uploadedFile = e.target.files[0] //UPLOADED FILE
|
||||||
|
|
||||||
if(!acceptedFormat.includes(uploadedFile?.type?.split("/")[1]?.toLowerCase())){ //CHECKING FOR CORRECT UPLOAD FORMAT
|
const fileFormat = uploadedFile?.type?.split("/")[1]?.toLowerCase();
|
||||||
let msg = 'Please select '
|
if(!acceptedFormat.includes(fileFormat)){ //CHECKING FOR CORRECT UPLOAD FORMAT
|
||||||
for(let i=0; i<=acceptedFormat.length-1; i++){
|
const msg = `Please select ${acceptedFormat.slice(0, -1).join(', ')} or ${acceptedFormat.slice(-1)}`;
|
||||||
if(i == acceptedFormat.length-1){
|
|
||||||
msg+=`or ${acceptedFormat[i]}`
|
|
||||||
}else{
|
|
||||||
msg+=`${acceptedFormat[i]}, `
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setUploadStatus({loading: false, status: false, message:msg})
|
setUploadStatus({loading: false, status: false, message:msg})
|
||||||
return setTimeout(()=>{
|
return setTimeout(()=>{
|
||||||
profileImgInput.current.value = '' // clear the input
|
profileImgInput.current.value = '' // clear the input
|
||||||
@@ -146,12 +140,13 @@ export default function FamilyManageTabs({
|
|||||||
const imgReader = new FileReader();
|
const imgReader = new FileReader();
|
||||||
imgReader.onload = (event) => {
|
imgReader.onload = (event) => {
|
||||||
let reqData = { // PAYLOAD FOR API CALL
|
let reqData = { // PAYLOAD FOR API CALL
|
||||||
|
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: event?.target?.result,
|
||||||
msg_type: 'FILE',
|
msg_type: 'FILE',
|
||||||
action: 11300
|
action: 111305
|
||||||
}
|
}
|
||||||
setUploadStatus({loading: true, status: false, message:'Loading...'})
|
setUploadStatus({loading: true, status: false, message:'Loading...'})
|
||||||
apiCall.sendFiles(reqData).then(res=>{
|
apiCall.sendFiles(reqData).then(res=>{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export default function FamilyTable({
|
|||||||
familyList,
|
familyList,
|
||||||
loader,
|
loader,
|
||||||
popUpHandler,
|
popUpHandler,
|
||||||
|
imageServer
|
||||||
}) {
|
}) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [currentPage, setCurrentPage] = useState(0);
|
const [currentPage, setCurrentPage] = useState(0);
|
||||||
@@ -54,12 +55,14 @@ export default function FamilyTable({
|
|||||||
banner,
|
banner,
|
||||||
enable_traking,
|
enable_traking,
|
||||||
profile_picture,
|
profile_picture,
|
||||||
|
imageServer
|
||||||
}) => {
|
}) => {
|
||||||
// Check for valid dates
|
// Check for valid dates
|
||||||
const addedDate = added ? added.split(" ")[0] : "N/A";
|
const addedDate = added ? added.split(" ")[0] : "N/A";
|
||||||
const loginDate = last_login ? formatDateString(last_login) : "N/A";
|
const loginDate = last_login ? formatDateString(last_login) : "N/A";
|
||||||
const key = `family-${family_uid}`; // Assign a unique key
|
const key = `family-${family_uid}`; // Assign a unique key
|
||||||
|
const image = localStorage.getItem('session_token') ? `${imageServer}${localStorage.getItem('session_token')}/family/${family_uid}` : ''
|
||||||
|
|
||||||
const trackingStatus =
|
const trackingStatus =
|
||||||
enable_traking === "0"
|
enable_traking === "0"
|
||||||
? "Stopped"
|
? "Stopped"
|
||||||
@@ -76,8 +79,8 @@ export default function FamilyTable({
|
|||||||
<div className="flex space-x-2 items-center w-full">
|
<div className="flex space-x-2 items-center w-full">
|
||||||
<div className="w-[60px] h-[60px] rounded-full overflow-hidden flex justify-center items-center flex-[0.1]">
|
<div className="w-[60px] h-[60px] rounded-full overflow-hidden flex justify-center items-center flex-[0.1]">
|
||||||
<img
|
<img
|
||||||
src={profile_picture}
|
// src={profile_picture}
|
||||||
// src={profile_picture || localImgLoad(`images/icons/${banner}`)}
|
src={image || profile_picture || localImgLoad(`images/icons/${banner}`)}
|
||||||
alt={`Avatar of ${firstname} ${lastname}`}
|
alt={`Avatar of ${firstname} ${lastname}`}
|
||||||
className="w-full h-full"
|
className="w-full h-full"
|
||||||
/>
|
/>
|
||||||
@@ -133,6 +136,7 @@ export default function FamilyTable({
|
|||||||
task_count,
|
task_count,
|
||||||
family_uid,
|
family_uid,
|
||||||
banner,
|
banner,
|
||||||
|
image
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -182,7 +186,7 @@ export default function FamilyTable({
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody className="h-full">
|
<tbody className="h-full">
|
||||||
{currentFamilyList?.map((familyMember, index) => {
|
{currentFamilyList?.map((familyMember, index) => {
|
||||||
return <FamilyRow key={index} {...familyMember} />;
|
return <FamilyRow key={index} {...familyMember} imageServer={imageServer} />;
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -213,7 +217,7 @@ export default function FamilyTable({
|
|||||||
<PaginatedList
|
<PaginatedList
|
||||||
onClick={handlePagination}
|
onClick={handlePagination}
|
||||||
prev={currentPage == 0}
|
prev={currentPage == 0}
|
||||||
next={currentPage + itemsPerPage >= familyList.length}
|
next={currentPage + itemsPerPage >= familyList?.length}
|
||||||
data={familyList}
|
data={familyList}
|
||||||
start={indexOfFirstItem}
|
start={indexOfFirstItem}
|
||||||
stop={indexOfLastItem}
|
stop={indexOfLastItem}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user