import React, { Suspense, forwardRef, useCallback, useEffect, useMemo, useRef, useState, } from "react"; import QRCode from "react-qr-code"; import { useReactToPrint } from "react-to-print"; import usersService from "../../../services/UsersService"; import LoadingSpinner from "../../Spinners/LoadingSpinner"; import profile from "../../../assets/images/profile-info-profile.png"; import FamilyTasks from "./FamilyTasks"; export default function FamilyManageTabs({ className, accountDetails, listReload, loader, }) { const [details, setDetails] = useState({ familyDetails: { loading: false, data: null, }, familyTasks: { loading: false, data: null, }, }); const [errMsg, setErrMsg] = useState(""); // List of tabs const tabs = [ { id: 1, name: "Tasks", }, { id: 2, name: "Account", }, { id: 3, name: "Profile", }, ]; const [tab, setTab] = useState(tabs[0].name); const tabHandler = (value) => { setTab(value); }; // For profile uploads const [profileImg, setProfileImg] = useState(profile); // profile img const profileImgInput = useRef(null); const browseProfileImg = () => { profileImgInput.current.click(); }; const profileImgChangHandler = (e) => { if (e.target.value !== "") { const imgReader = new FileReader(); imgReader.onload = (event) => { setProfileImg(event.target.result); }; imgReader.readAsDataURL(e.target.files[0]); } }; // Api call const apiCall = useMemo(() => new usersService(), []); // function for manage family const manageFamily = useCallback(async () => { try { setDetails({ familyDetails: { loading: true }, familyTasks: { loading: true }, }); let { family_uid } = accountDetails; let reqData = { family_uid }; // the family response const familyRes = await apiCall.ManageFamily(reqData); const familyData = familyRes.data; // the tasks response const tasksRes = await apiCall.ManageTasks(reqData); const tasksData = tasksRes.data; // checking the internal return if (familyData?.internal_return < 0 || tasksData?.internal_return < 0) return; setDetails({ familyDetails: { loading: false, data: familyData }, familyTasks: { loading: false, data: tasksData }, }); } catch (error) { setDetails({ familyDetails: { loading: false }, familyTasks: { loading: false }, }); setErrMsg("An error occurred"); throw new Error(error); } }, [apiCall, accountDetails]); useEffect(() => { manageFamily(); }, [tab, manageFamily]); const accountRef = useRef(); // to handle printing const useHandlePrint = useReactToPrint({ content: () => accountRef.current, }); return (
Scan the code from mobile app