Compare commits

...

4 Commits

9 changed files with 49 additions and 62 deletions
+2 -1
View File
@@ -26,7 +26,8 @@ const CouponPopup = ({ popUpHandler, data }) => {
setStatusMsg({ error: "An error occurred" }); setStatusMsg({ error: "An error occurred" });
else setStatusMsg({ success: res.data?.status_text }); else setStatusMsg({ success: res.data?.status_text });
dispatch(tableReload({ type: "COUPONTABLE" })); // dispatch(tableReload({ type: "COUPONTABLE" }));
dispatch(tableReload({ type: "WALLETTABLE" }));
setTimeout(() => { setTimeout(() => {
popUpHandler(); popUpHandler();
setLoader(false); setLoader(false);
+2 -2
View File
@@ -7,7 +7,7 @@ import { useSelector } from "react-redux";
export default function MyCoupons() { export default function MyCoupons() {
const apiCall = useMemo(() => new usersService(), []); const apiCall = useMemo(() => new usersService(), []);
const {couponTable} = useSelector(state => state.tableReload) const {couponTable, walletTable} = useSelector(state => state.tableReload)
let [couponHistory, setCouponHistory] = useState({ let [couponHistory, setCouponHistory] = useState({
// FOR COUPON HISTORY // FOR COUPON HISTORY
loading: true, loading: true,
@@ -38,7 +38,7 @@ export default function MyCoupons() {
useEffect(() => { useEffect(() => {
getCouponHistory(); getCouponHistory();
}, [couponTable]); }, [couponTable, walletTable]);
return ( return (
<> <>
+4 -29
View File
@@ -5,34 +5,17 @@ import Layout from "../Partials/Layout";
import LoadingSpinner from "../Spinners/LoadingSpinner"; import LoadingSpinner from "../Spinners/LoadingSpinner";
const WalletBox = lazy(() => import("./WalletBox")); const WalletBox = lazy(() => import("./WalletBox"));
const WalletRoutes = () => { const WalletRoutes = () => {
const apiCall = new usersService(); const apiCall = new usersService();
const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE
const { walletTable } = useSelector((state) => state.tableReload); const { walletTable } = useSelector((state) => state.tableReload);
const [walletList, setWalletList] = useState({
loading: true,
data: [],
reload: false,
});
const [paymentHistory, setPaymentHistory] = useState({ const [paymentHistory, setPaymentHistory] = useState({
loading: true, loading: true,
data: [], data: [],
}); });
const getWalletList = () => {
apiCall
.getUserWallets()
.then((res) => {
if (res.data.internal_return < 0) {
setWalletList({ loading: false, data: [] });
} else {
setWalletList({ loading: false, data: res.data?.result_list });
}
})
.catch(() => {
setWalletList({ loading: false, data: [] });
});
};
const getPaymentHistory = () => { const getPaymentHistory = () => {
apiCall apiCall
.getPaymentHx() .getPaymentHx()
@@ -49,21 +32,13 @@ const WalletRoutes = () => {
}; };
useEffect(() => { useEffect(() => {
// const fetchData = async () => {
// await Promise.all([getWalletList(), getPaymentHistory()]);
// };
// if (walletList.loading) {
// fetchData();
// }
getWalletList();
getPaymentHistory(); getPaymentHistory();
}, [walletTable]); }, [walletTable]);
return ( return (
<Layout> <Layout>
<Suspense fallback={<LoadingSpinner size="16" color="sky-blue" />}> <Suspense fallback={<LoadingSpinner size="16" color="sky-blue" />}>
<WalletBox wallet={walletList} payment={paymentHistory} /> <WalletBox wallet={walletDetails} payment={paymentHistory} />
</Suspense> </Suspense>
</Layout> </Layout>
); );
+1 -1
View File
@@ -13,7 +13,7 @@ export default function WalletBox({ wallet, payment }) {
</div> </div>
) : wallet.data.length ? ( ) : wallet.data.length ? (
wallet.data.map((item, index) => ( wallet.data.map((item, index) => (
<div className="lg:w-full h-full mb-10 lg:mb-0"> <div key={item.wallet_uid} className="lg:w-full h-full mb-10 lg:mb-0">
<WalletItemCard walletItem={item} payment={payment} /> <WalletItemCard walletItem={item} payment={payment} />
</div> </div>
)) ))
+2 -2
View File
@@ -41,8 +41,8 @@ export default function WalletHeader(props) {
<div className="content px-7 pb-7"> <div className="content px-7 pb-7">
<ul> <ul>
{props.myWalletList && {props.myWalletList &&
props.myWalletList?.result_list?.length > 0 && props.myWalletList?.length > 0 &&
props.myWalletList.result_list.map((value, index) => props.myWalletList.map((value, index) =>
{ {
let image = value.code ? `${value.code.toLocaleLowerCase()}.svg` : 'default.png' let image = value.code ? `${value.code.toLocaleLowerCase()}.svg` : 'default.png'
return( return(
+3 -16
View File
@@ -15,7 +15,7 @@ import WalletHeader from "../MyWallet/WalletHeader";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import Flag from "../../assets/images/united-states.svg"; import Flag from "../../assets/images/united-states.svg";
import siteLogo from "../../assets/images/wrenchboard-logo-text.png"; import siteLogo from "../../assets/images/wrenchboard-logo-text.png";
import { viewWalletDetails } from "../../store/walletDetails"; // import { updateWalletDetails } from "../../store/walletDetails";
import TimeDifference from "../Helpers/TimeDifference"; import TimeDifference from "../Helpers/TimeDifference";
const DEFAULT_PROFILE_IMAGE = require("../../assets/images/profile.jpg"); const DEFAULT_PROFILE_IMAGE = require("../../assets/images/profile.jpg");
@@ -34,20 +34,7 @@ export default function Header({ logoutModalHandler, sidebarHandler }) {
const navigate = useNavigate(); const navigate = useNavigate();
const { notifications } = useSelector((state) => state?.notifications); // NOTIFICATION STORE const { notifications } = useSelector((state) => state?.notifications); // NOTIFICATION STORE
const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE
const getMyWalletList = async () => {
try {
const res = await api.getUserWallets(null);
console.log("wallet - > ", res.data);
dispatch(viewWalletDetails({ ...res.data }));
setMyWalletList(res.data);
} catch (error) {
console.log("Error getting mode");
}
};
useEffect(() => {
getMyWalletList();
}, [walletTable]);
const handlerBalance = () => { const handlerBalance = () => {
setbalanceValue.toggle(); setbalanceValue.toggle();
@@ -242,7 +229,7 @@ export default function Header({ logoutModalHandler, sidebarHandler }) {
{/*<div className="lg:hidden block"></div>*/} {/*<div className="lg:hidden block"></div>*/}
<WalletHeader <WalletHeader
myWalletList={myWalletList} myWalletList={walletDetails.data}
handlerBalance={handlerBalance} handlerBalance={handlerBalance}
balanceDropdown={balanceDropdown} balanceDropdown={balanceDropdown}
addMoneyHandler={addMoneyHandler} addMoneyHandler={addMoneyHandler}
+12 -7
View File
@@ -158,13 +158,18 @@ export default function Resources(props) {
return ( return (
<ul className="lg:flex lg:space-x-14 space-x-8"> <ul className="lg:flex lg:space-x-14 space-x-8">
{tabCategories?.length > 0 && {tabCategories?.length > 0 &&
tabCategories?.map((tabValue, idx) => ( tabCategories?.map((tabValue, idx) => {
<TabItem if(tabValue.enabled){
key={tabValue.id} return (
tabValue={tabValue} <TabItem
isActive={tab === tabValue.name || (idx === 0 && tab === "")} key={tabValue.id}
/> tabValue={tabValue}
))} isActive={tab === tabValue.name || (idx === 0 && tab === "")}
/>
)
}
}
)}
</ul> </ul>
); );
}; };
+17 -1
View File
@@ -10,6 +10,7 @@ import { updateUserDetails } from "../store/UserDetails";
import { updateJobs } from "../store/jobLists"; import { updateJobs } from "../store/jobLists";
import { updateNotifications } from "../store/notifications"; import { updateNotifications } from "../store/notifications";
import { updateUserJobList } from "../store/userJobList"; import { updateUserJobList } from "../store/userJobList";
import { updateWalletDetails } from "../store/walletDetails";
const AuthRoute = ({ redirectPath = "/login", children }) => { const AuthRoute = ({ redirectPath = "/login", children }) => {
const apiCall = useMemo(() => new usersService(), []); const apiCall = useMemo(() => new usersService(), []);
@@ -19,7 +20,7 @@ const AuthRoute = ({ redirectPath = "/login", children }) => {
const [loadProfileDetails, setLoadProfileDetails] = useState([]); const [loadProfileDetails, setLoadProfileDetails] = useState([]);
const navigate = useNavigate(); const navigate = useNavigate();
const { jobListTable } = useSelector((state) => state.tableReload); const { jobListTable, walletTable } = useSelector((state) => state.tableReload);
const { const {
userDetails: { username, uid, session }, userDetails: { username, uid, session },
@@ -177,6 +178,21 @@ const AuthRoute = ({ redirectPath = "/login", children }) => {
getMyJobList(); getMyJobList();
}, [jobListTable]); }, [jobListTable]);
useEffect(() => {
const getMyWalletList = async () => {
dispatch(updateWalletDetails({ loading: true, data:[] }));
try {
const res = await apiCall.getUserWallets();
console.log("wallet - >", res.data);
dispatch(updateWalletDetails({ loading: false, data:res.data?.result_list }));
} catch (error) {
dispatch(updateWalletDetails({ loading: false, data:[] }));
console.log("Error getting mode");
}
};
getMyWalletList();
}, [walletTable]);
useEffect(() => { useEffect(() => {
// Getting market data // Getting market data
const getMarketActiveJobList = async () => { const getMarketActiveJobList = async () => {
+6 -3
View File
@@ -1,18 +1,21 @@
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
const initialState = { const initialState = {
walletDetails: {}, walletDetails: {
loading: true,
data: []
},
}; };
export const walletSlice = createSlice({ export const walletSlice = createSlice({
name: "walletDetails", name: "walletDetails",
initialState, initialState,
reducers: { reducers: {
viewWalletDetails: (state, action) => { updateWalletDetails: (state, action) => {
state.walletDetails = { ...action.payload }; state.walletDetails = { ...action.payload };
}, },
}, },
}); });
export const { viewWalletDetails } = walletSlice.actions; export const { updateWalletDetails } = walletSlice.actions;
export default walletSlice.reducer; export default walletSlice.reducer;