diff --git a/src/components/MyWallet/FamilyWalletBox.jsx b/src/components/MyWallet/FamilyWalletBox.jsx index 7cfb960..be0749a 100644 --- a/src/components/MyWallet/FamilyWalletBox.jsx +++ b/src/components/MyWallet/FamilyWalletBox.jsx @@ -2,7 +2,7 @@ import { useSelector } from "react-redux"; import LoadingSpinner from "../Spinners/LoadingSpinner"; import WalletItemCard from "./WalletItemCard"; import WalletItemCardFamily from "./WalletItemCardFamily"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { PriceFormatter } from "../Helpers/PriceFormatter"; import SearchCom from "../Helpers/SearchCom"; import { localImgLoad } from "../../lib"; @@ -13,17 +13,17 @@ import FamilyWalletRedeemOptions from "./FamilyWalletRedeemOptions"; * Renders a list of wallet items or a loading spinner depending on the state of the `wallet` object. */ export default function FamilyWalletBox({ wallet, payment }) { - const { loading, data } = wallet; + // const { loading, data } = wallet; - const { userDetails } = useSelector((state) => state.userDetails); - const accountType = userDetails?.account_type === "FAMILY"; + // const { userDetails } = useSelector((state) => state.userDetails); + // const accountType = userDetails?.account_type === "FAMILY"; - const [selectedWallet, setSelectedWallet] = useState(data[0]) + const [selectedWallet, setSelectedWallet] = useState('') - const [activeWalletBtn, setActiveWalletBtn] = useState(data[0].code) + const [activeWalletBtn, setActiveWalletBtn] = useState('') const handleChangeWallet = ({target:{name}}) => { // FUNCTION TO SWITCH WALLET IF USER HAS MORE THAN TWO WALLETS - const currentWalletSelected = data?.filter((item) => item.code == name); + const currentWalletSelected = wallet?.data?.filter((item) => item.code == name); setSelectedWallet(currentWalletSelected[0]) setActiveWalletBtn(name) // console.log(name, currentWalletSelected) @@ -33,63 +33,70 @@ export default function FamilyWalletBox({ wallet, payment }) { ? `${selectedWallet?.code.toLowerCase()}.svg` : "default.png"; + useEffect(()=>{ + setSelectedWallet(wallet.data[0]) + setActiveWalletBtn(wallet?.data[0]?.code) + },[wallet]) return (
-
-
- {loading ? -
- -
- - : data.length > 0 ? -
-
-
- {data.length > 1 && data.map(item =>( - - ))} -
-
- {/* image */} -
- currency-icon -
-

Current Balance

-

- {PriceFormatter(selectedWallet?.amount/100, selectedWallet?.code, undefined, "text-[2rem]")} -

-
-
-
-

Recent Activities

-
+
+
+
+
+ {wallet?.loading ? +
+
- : -
-

No Wallet Record Found

+ : wallet?.data.length > 0 ? + <> + {wallet?.data?.length > 1 && +
+ {wallet?.data?.map(item =>( + + ))} +
+ } +
+ {/* image */} +
+ currency-icon +
+

Current Balance

+

+ {PriceFormatter(selectedWallet?.amount/100, selectedWallet?.code, undefined, "text-[2rem]")} +

+
+ + : +
+

No Wallet Record Found

+
+ }
- } +
+

Recent Activities

+
+
+
+
+
-
-
-
); diff --git a/src/components/MyWallet/FamilyWallet.jsx b/src/components/MyWallet/FamilyWalletCon.jsx similarity index 63% rename from src/components/MyWallet/FamilyWallet.jsx rename to src/components/MyWallet/FamilyWalletCon.jsx index fde783d..b8f16d2 100644 --- a/src/components/MyWallet/FamilyWallet.jsx +++ b/src/components/MyWallet/FamilyWalletCon.jsx @@ -6,9 +6,9 @@ import LoadingSpinner from "../Spinners/LoadingSpinner"; import CustomBreadcrumb from "../Breadcrumb/CustomBreadcrumb"; const FamilyWalletBox = lazy(() => import("./FamilyWalletBox")); -const FamilyWallet = () => { +const FamilyWalletCon = () => { const apiCall = new usersService(); - const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE + // const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE const { walletTable } = useSelector((state) => state.tableReload); const [paymentHistory, setPaymentHistory] = useState({ @@ -16,6 +16,20 @@ const FamilyWallet = () => { data: [], }); + const [familyWalletBal, setFamilyWalletBal] = useState({ + loading: true, + data: [] + }); + + const getFamilyWalletBal = () => { + setFamilyWalletBal({loading:true, data: []}) + apiCall.getFamilyWallet({family_uid: localStorage.getItem("uid")}).then(res => { + setFamilyWalletBal({loading:false, data: res?.data?.result_list}) + }).catch(error => { + setFamilyWalletBal({loading:false, data: []}) + }) + }; + const getPaymentHistory = () => { apiCall .getPaymentHx() @@ -24,6 +38,7 @@ const FamilyWallet = () => { setPaymentHistory({ loading: false, data: [] }); } else { setPaymentHistory({ loading: false, data: res.data?.result_list }); + // console.log('Hist', res.data?.result_list) } }) .catch(() => { @@ -33,6 +48,7 @@ const FamilyWallet = () => { useEffect(() => { getPaymentHistory(); + getFamilyWalletBal() }, [walletTable]); return ( @@ -48,9 +64,13 @@ const FamilyWallet = () => { } />
- }> + + +
+ }> @@ -58,4 +78,4 @@ const FamilyWallet = () => { ); }; -export default FamilyWallet; +export default FamilyWalletCon; diff --git a/src/components/MyWallet/FamilyWalletRedeemOptions.jsx b/src/components/MyWallet/FamilyWalletRedeemOptions.jsx index 5d5972c..ec2e45f 100644 --- a/src/components/MyWallet/FamilyWalletRedeemOptions.jsx +++ b/src/components/MyWallet/FamilyWalletRedeemOptions.jsx @@ -45,7 +45,7 @@ export default function FamilyWalletRedeemOptions() {
- : Object.keys(familyWalletRedeemOptList?.data)?.length > 0 ? + : familyWalletRedeemOptList?.data && Object.keys(familyWalletRedeemOptList?.data)?.length > 0 ? Object.keys(filteredRedeemData?.data)?.length ?
{ Object.keys(filteredRedeemData?.data)?.map((item)=>{ diff --git a/src/middleware/AuthRoute.jsx b/src/middleware/AuthRoute.jsx index 7d7536c..8d5a93c 100644 --- a/src/middleware/AuthRoute.jsx +++ b/src/middleware/AuthRoute.jsx @@ -193,6 +193,9 @@ const AuthRoute = ({ redirectPath = "/login", children }) => { }, [jobListTable, isLogin.status]); useEffect(() => { + if((!loggedIn && !isLogin.status) || account_type == 'FAMILY'){ // DO NOT CALL THIS, IF USER ACCOUNT TYPE IS FAMILY + return + } const getMyWalletList = async () => { dispatch(updateWalletDetails({ loading: true, data: [] })); try { @@ -207,7 +210,7 @@ const AuthRoute = ({ redirectPath = "/login", children }) => { } }; getMyWalletList(); - }, [walletTable]); + }, [walletTable, isLogin.status]); useEffect(() => { if((!loggedIn && !isLogin.status) || account_type == 'FAMILY'){ // DO NOT CALL THIS, IF USER ACCOUNT TYPE IS FAMILY @@ -245,6 +248,9 @@ const AuthRoute = ({ redirectPath = "/login", children }) => { //FUNCTION TO GET COMMON HEAD DATA useEffect(() => { + if((!loggedIn && !isLogin.status) || account_type == 'FAMILY'){ // DO NOT CALL THIS, IF USER ACCOUNT TYPE IS FAMILY + return + } apiCall .getRecentActivitiedData() .then((res) => { @@ -257,7 +263,7 @@ const AuthRoute = ({ redirectPath = "/login", children }) => { .catch((error) => { console.log("ERROR ", error); }); - }, []); + }, [isLogin.status]); //FUNCTION TO GET FAMILY BANNERS diff --git a/src/views/FamilyWalletPage.jsx b/src/views/FamilyWalletPage.jsx index 9a52cb9..5572e63 100644 --- a/src/views/FamilyWalletPage.jsx +++ b/src/views/FamilyWalletPage.jsx @@ -1,5 +1,5 @@ -import FamilyWallet from "../components/MyWallet/FamilyWallet"; +import FamilyWalletCon from "../components/MyWallet/FamilyWalletCon"; export default function FamilyWalletPage() { - return ; + return ; }