diff --git a/src/components/History/index.jsx b/src/components/History/index.jsx index 369cb7f..0fd3d53 100644 --- a/src/components/History/index.jsx +++ b/src/components/History/index.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, {useState, useEffect} from "react"; import HistoryAnalyticsCard from "../Cards/HistoryAnalyticsCard"; import SellHistoryMarketVisitorAnalytic from "../Home/SellHistoryMarketVisitorAnalytic"; import Layout from "../Partials/Layout"; @@ -6,7 +6,59 @@ import HistoryTable from "./HistoryTable"; import MarketHistorySection from "./MarketHistorySection"; import TopHxBox from "./TopHxBox"; +import usersService from "../../services/UsersService"; +import PurchasesTable from "../MyWallet/WalletComponent/PurchasesTable"; +import RecentActivityTable from "../MyWallet/WalletComponent/RecentActivityTable"; +import LoadingSpinner from "../Spinners/LoadingSpinner"; + export default function History() { + + const apiCall = new usersService() + + let [paymentHistory, setPaymentHistory] = useState({ // FOR PAYMENT HISTORY + loading: true, + data: [], + error: false + }) + + let [purchaseHistory, setPurchaseHistory] = useState({ // FOR PURCHASE HISTORY + loading: true, + data: [], + error: false + }) + + //FUNCTION TO GET PAYMENT HISTORY + const getPaymentHistory = ()=>{ + apiCall.getPaymentHx().then((res)=>{ + if(res.data.internal_return < 0){ // success but no data + setPaymentHistory(prev => ({...prev, loading: false})) + return + } + setPaymentHistory(prev => ({...prev, loading: false, data: res.data.result_list})) + }).catch((error)=>{ + setPaymentHistory(prev => ({...prev, loading: false, error: true})) + }) + } + + //FUNCTION TO GET PURCHASE HISTORY + const getPurchaseHistory = ()=>{ + apiCall.getPurchaseHx().then((res)=>{ + if(res.data.internal_return < 0){ // success but no data + setPurchaseHistory(prev => ({...prev, loading: false})) + return + } + // console.log('purchase',res.data) + setPurchaseHistory(prev => ({...prev, loading: false, data: res.data.result_list})) + }).catch((error)=>{ + setPurchaseHistory(prev => ({...prev, loading: false, error: true})) + }) + } + + useEffect(()=>{ + getPaymentHistory() + getPurchaseHistory() + }, []) + return ( <> @@ -148,7 +200,35 @@ export default function History() { {/**/} - + {/* */} +
+ {/* PURCHASE SECTION */} +
+
+

Purchases

+ {purchaseHistory.loading ? + + : + + } +
+
+ {/* END OF PURCHASE SECTION */} + + {/* RECENT ACTIVITY SECTION */} +
+
+

Recent Activity

+

Activity Report

+ {paymentHistory.loading ? + + : + + } +
+
+ {/* END OF RECENT ACTIVITY SECTION */} +
diff --git a/src/components/MyWallet/AddFund.jsx b/src/components/MyWallet/AddFund.jsx index b0875a9..0f3271f 100644 --- a/src/components/MyWallet/AddFund.jsx +++ b/src/components/MyWallet/AddFund.jsx @@ -71,7 +71,7 @@ function AddFund({payment}) {
-
+

Recent Activity

Activity Report

{payment.loading ? diff --git a/src/components/MyWallet/Balance.jsx b/src/components/MyWallet/Balance.jsx index 8270b2f..cb55f92 100644 --- a/src/components/MyWallet/Balance.jsx +++ b/src/components/MyWallet/Balance.jsx @@ -5,7 +5,7 @@ import PurchasesTable from './WalletComponent/PurchasesTable' import CouponTable from './WalletComponent/CouponTable' import LoadingSpinner from '../Spinners/LoadingSpinner' -function Balance({wallet, payment, coupon, purchase}) { +function Balance({wallet, coupon}) { return (
@@ -65,36 +65,6 @@ function Balance({wallet, payment, coupon, purchase}) { {/* END OF WALLET SECTION */} - {/* RECENT ACTIVITY SECTION */} -
-
-

Recent Activity

-

Activity Report

- {payment.loading ? - - : - - } -
-
- {/* END OF RECENT ACTIVITY SECTION */} -
- - -
- {/* PURCHASE SECTION */} -
-
-

Purchases

- {purchase.loading ? - - : - - } -
-
- {/* END OF PURCHASE SECTION */} - {/* COUPON SECTION */}
@@ -107,8 +77,7 @@ function Balance({wallet, payment, coupon, purchase}) {
{/* END OF COUPON SECTION */} -
- +
) } diff --git a/src/components/MyWallet/Wallet.jsx b/src/components/MyWallet/Wallet.jsx index 9b9cc16..7237fd9 100644 --- a/src/components/MyWallet/Wallet.jsx +++ b/src/components/MyWallet/Wallet.jsx @@ -115,7 +115,7 @@ const WalletRoutes = () => { } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/src/components/MyWallet/WalletComponent/ReferralTable.jsx b/src/components/MyWallet/WalletComponent/ReferralTable.jsx new file mode 100644 index 0000000..02418c6 --- /dev/null +++ b/src/components/MyWallet/WalletComponent/ReferralTable.jsx @@ -0,0 +1,60 @@ +import React, {useState} from 'react' + +import PaginatedList from '../../Pagination/PaginatedList'; +import {handlePagingFunc} from '../../Pagination/HandlePagination'; + +function ReferralTable({history}) { + + const [currentPage, setCurrentPage] = useState(0); + const indexOfFirstItem = Number(currentPage); + const indexOfLastItem = Number(indexOfFirstItem)+Number(process.env.REACT_APP_ITEM_PER_PAGE); + const currentReferral = history?.data?.slice(indexOfFirstItem, indexOfLastItem); + + const handlePagination = (e) => { + handlePagingFunc(e,setCurrentPage) + } + + return ( + <> + + + + + + + + + + {history.data.length ? + currentReferral.map((item, index) => ( + + + + + + )) + : + ( + history.error ? + + + + : + ( + + + + ) + ) + } + +
Added/NameEmailStatus
{item.added_date} / {item.firstname} {item.lastname}{item.email}{item.status}
Opps! couldn't get referral history. Try reloading the page
No Item Found on referral List
+ + {/* PAGINATION BUTTON */} + = history?.data?.length ? true : false} data={history?.data} start={indexOfFirstItem} stop={indexOfLastItem} /> + {/* END OF PAGINATION BUTTON */} + + ) +} + +export default ReferralTable \ No newline at end of file diff --git a/src/components/Referral/ReferralDisplay.jsx b/src/components/Referral/ReferralDisplay.jsx index 620b5e1..8489016 100644 --- a/src/components/Referral/ReferralDisplay.jsx +++ b/src/components/Referral/ReferralDisplay.jsx @@ -7,6 +7,7 @@ import LoadingSpinner from '../Spinners/LoadingSpinner'; import {Formik, Form} from 'formik' import * as Yup from 'yup' +import ReferralTable from '../MyWallet/WalletComponent/ReferralTable'; const validationSchema = Yup.object().shape({ email: Yup.string() @@ -169,39 +170,7 @@ function ReferralDisplay() { ) : ( - - - - - - - - - - {referralList.data.length ? - referralList.data.map((item, index) => ( - - - - - - )) - : - ( - referralList.error ? - - - - : - ( - - - - ) - ) - } - -
Added/NameEmailStatus
{item.added_date} / {item.firstname} {item.lastname}{item.email}{item.status}
Opps! couldn't get referral history. Try reloading the page
No Item Found on referral List
+ ) }