import React, { Suspense, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useLocation, useOutletContext } from "react-router-dom"; import usersService from "../../../../services/UsersService"; import ModalCom from '../../../Helpers/ModalCom'; import LoadingSpinner from "../../../Spinners/LoadingSpinner"; import localImgLoad from '../../../../lib/localImgLoad' // import { tableReload } from "../../../store/TableReloads"; // import { PriceFormatter } from "../../Helpers/PriceFormatter"; const RelativePopout = ({ relativeSelected, action, situation, familyList }) => { const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE const {userDetails} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active const [relativeSettings, setRelativeSettings] = useState({loading:true, data:[]}) const [reloadSettings, setReloadSettings] = useState(false) const [relativeEditKids, setRelativeEditKids] = useState({loading:false, family_uid: ''}) const apiCall = new usersService(); let { pathname, state } = useLocation(); const dispatch = useDispatch(); const handleUncheck = (e, family_uid) => { // FUNCTION TO EDIT RELATIVE KIDS let isChecked = e.target.checked const reqData = { family_uid: family_uid, relative_uid: relativeSelected.relative_uid, add: isChecked ? '1' : '0' } // console.log('family_uid', isChecked) setRelativeEditKids({loading:true, family_uid:family_uid}) apiCall.getRelativeEditKids(reqData).then(res => { setReloadSettings(prev => !prev) // MAKE RELATIVE SETTINGS TO RELOAD IN ORDER TO SET RELATIVE EDIT KIDS LOADING TO FALSE // setRelativeEditKids({loading:false, family_uid:''}) }).catch((err)=>{ setRelativeEditKids({loading:false, family_uid:''}) console.log(err) }) } useEffect(()=>{ // FUNCTION TO GET RELATIVE KIDS SETTINGS apiCall.getRelativeSettings({relative_uid: relativeSelected.relative_uid}).then(res => { setRelativeSettings({loading:false, data:res?.data?.kids_list || []}) }).catch((err)=>{ setRelativeSettings({loading:false, data:[]}) console.log(err) }).finally(()=>{ // SET RELATIVE EDIT KIDS TO FALSE setRelativeEditKids({loading:false, family_uid:''}) }) },[reloadSettings]) return ( <>

{relativeSelected.firstname && relativeSelected.firstname} {relativeSelected.lastname && relativeSelected.lastname}

{familyList.loader || relativeSettings.loading ? : (!familyList.loader && familyList?.familyList?.result_list?.length > 0) ? familyList?.familyList?.result_list?.map(item => { const isChecked = relativeSettings?.data?.filter(value => value?.family_uid == item?.family_uid) const image = localStorage.getItem("session_token") ? `${familyList?.imageServer}${localStorage.getItem("session_token")}/family/${item?.family_uid}` : ""; return (
{relativeEditKids.loading && relativeEditKids.family_uid == item.family_uid? : 0} type="checkbox" className='w-4 h-4 border-2 border-blue-500 rounded-sm bg-white cursor-pointer' onChange={(e) => handleUncheck(e, item.family_uid)} /> }
{`Avatar`}

{`${item?.firstname} ${item?.lastname}`}

) }) :
No records found!
}
{/* dummy to be filled latter*/}
); }; export default RelativePopout;