Family Picture
This commit is contained in:
@@ -7,7 +7,7 @@ import React, {
|
|||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useReactToPrint } from "react-to-print";
|
import { useReactToPrint } from "react-to-print";
|
||||||
import profile from "../../assets/images/profile-info-profile.png";
|
import profile from "../../assets/images/icons/family.svg";
|
||||||
import localImgLoad from "../../lib/localImgLoad";
|
import localImgLoad from "../../lib/localImgLoad";
|
||||||
import usersService from "../../services/UsersService";
|
import usersService from "../../services/UsersService";
|
||||||
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
||||||
@@ -82,14 +82,29 @@ export default function FamilyManageTabs({
|
|||||||
profileImgInput.current.click();
|
profileImgInput.current.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to handle changes in the profile image input
|
/**
|
||||||
|
* Handles the change event of the profile image input field.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
const profileImgChangeHandler = (e) => {
|
const profileImgChangeHandler = (e) => {
|
||||||
if (e.target.value !== "") {
|
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();
|
const imgReader = new FileReader();
|
||||||
imgReader.onload = (event) => {
|
imgReader.onload = () => {
|
||||||
setProfileImg(event.target.result);
|
const imageDataUrl = imgReader.result;
|
||||||
|
|
||||||
|
// Set the profile image
|
||||||
|
setProfileImg(imageDataUrl);
|
||||||
};
|
};
|
||||||
imgReader.readAsDataURL(e.target.files[0]);
|
imgReader.readAsDataURL(file);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,31 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import localImgLoad from "../../../lib/localImgLoad";
|
import localImgLoad from "../../../lib/localImgLoad";
|
||||||
|
|
||||||
|
|
||||||
export default function ProfileInfo({
|
export default function ProfileInfo({
|
||||||
profileImg,
|
profileImg,
|
||||||
profileImgInput,
|
profileImgInput,
|
||||||
profileImgChangHandler,
|
profileImgChangeHandler,
|
||||||
browseProfileImg,
|
browseProfileImg,
|
||||||
accountDetails,
|
accountDetails,
|
||||||
}) {
|
}) {
|
||||||
|
console.log(accountDetails.banner)
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center gap-4">
|
<div className="flex flex-col items-center gap-4">
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<div className="w-full relative">
|
<div className="w-full relative">
|
||||||
<img
|
<img
|
||||||
src={localImgLoad(`images/icons/${accountDetails.banner}`)}
|
src={
|
||||||
alt=""
|
profileImg
|
||||||
|
? profileImg
|
||||||
|
: localImgLoad(`images/icons/${accountDetails.banner}`)
|
||||||
|
}
|
||||||
|
alt="profile"
|
||||||
className="sm:w-[180px] sm:h-[180px] w-[120px] h-[120px] rounded-full overflow-hidden object-cover"
|
className="sm:w-[180px] sm:h-[180px] w-[120px] h-[120px] rounded-full overflow-hidden object-cover"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
ref={profileImgInput}
|
ref={profileImgInput}
|
||||||
onChange={(e) => profileImgChangHandler(e)}
|
accept="image/*"
|
||||||
|
onChange={profileImgChangeHandler}
|
||||||
type="file"
|
type="file"
|
||||||
className="hidden"
|
className="hidden"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user