From 930559c96bb87366699d385a5fdd529b2b7e0089 Mon Sep 17 00:00:00 2001 From: Ebube Date: Mon, 9 Oct 2023 13:32:07 +0100 Subject: [PATCH] Family Picture --- src/components/FamilyAcc/FamilyManageTabs.jsx | 27 ++++++++++++++----- src/components/FamilyAcc/Tabs/ProfileInfo.jsx | 15 +++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/components/FamilyAcc/FamilyManageTabs.jsx b/src/components/FamilyAcc/FamilyManageTabs.jsx index 64dc4a5..22df090 100644 --- a/src/components/FamilyAcc/FamilyManageTabs.jsx +++ b/src/components/FamilyAcc/FamilyManageTabs.jsx @@ -7,7 +7,7 @@ import React, { useState, } from "react"; 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 usersService from "../../services/UsersService"; import LoadingSpinner from "../Spinners/LoadingSpinner"; @@ -82,14 +82,29 @@ export default function FamilyManageTabs({ 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) => { - 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(); - imgReader.onload = (event) => { - setProfileImg(event.target.result); + imgReader.onload = () => { + const imageDataUrl = imgReader.result; + + // Set the profile image + setProfileImg(imageDataUrl); }; - imgReader.readAsDataURL(e.target.files[0]); + imgReader.readAsDataURL(file); } }; diff --git a/src/components/FamilyAcc/Tabs/ProfileInfo.jsx b/src/components/FamilyAcc/Tabs/ProfileInfo.jsx index e998103..39dded0 100644 --- a/src/components/FamilyAcc/Tabs/ProfileInfo.jsx +++ b/src/components/FamilyAcc/Tabs/ProfileInfo.jsx @@ -1,26 +1,31 @@ import React from "react"; import localImgLoad from "../../../lib/localImgLoad"; - export default function ProfileInfo({ profileImg, profileImgInput, - profileImgChangHandler, + profileImgChangeHandler, browseProfileImg, accountDetails, }) { + console.log(accountDetails.banner) return (
profileImgChangHandler(e)} + accept="image/*" + onChange={profileImgChangeHandler} type="file" className="hidden" />