diff --git a/src/components/History/RewardsTable.jsx b/src/components/History/RewardsTable.jsx new file mode 100644 index 0000000..edc1b8b --- /dev/null +++ b/src/components/History/RewardsTable.jsx @@ -0,0 +1,114 @@ +import React, {useEffect, useState} from 'react' +import Image from '../../assets/images/taskbanners/default.jpg' + +import usersService from '../../services/UsersService'; +import { handlePagingFunc } from '../../components/Pagination/HandlePagination'; +import PaginatedList from '../../components/Pagination/PaginatedList'; + +import LoadingSpinner from '../Spinners/LoadingSpinner'; + +import { AmountTo2DP } from '../Helpers/PriceFormatter'; + +function RewardsTable() { + + const apiCall = new usersService() + + let [familyRewardHistory, setFamilyRewardHistory] = useState({ // FOR PURCHASE HISTORY + loading: true, + data: [], + error: false + }) + + const [currentPage, setCurrentPage] = useState(0); + const indexOfFirstItem = Number(currentPage); + const indexOfLastItem = Number(indexOfFirstItem)+Number(process.env.REACT_APP_ITEM_PER_PAGE); + const currentReward = familyRewardHistory?.data?.slice(indexOfFirstItem, indexOfLastItem); + + const handlePagination = (e) => { + handlePagingFunc(e,setCurrentPage) + } + + + //FUNCTION TO GET FAMILY REWARD HISTORY + const getFamilyRewardHistory = ()=>{ + apiCall.getFamilyRewardHx().then((res)=>{ + if(res.data.internal_return < 0){ // success but no data + setFamilyRewardHistory(prev => ({...prev, loading: false})) + return + } + setFamilyRewardHistory(prev => ({...prev, loading: false, data: res.data.result_list})) + }).catch((error)=>{ + setFamilyRewardHistory(prev => ({...prev, loading: false, error: true})) + }) + } + + useEffect(()=>{ + getFamilyRewardHistory() + }, []) + + return ( +
+ {familyRewardHistory.loading ? + + : + + + + + + + + + + {familyRewardHistory.data.length ? + ( + + {currentReward.map((item, index) => { + let date = new Date(item.added).toLocaleDateString() + return ( + + + + + + + ) + } + )} + + ) + : + familyRewardHistory.error ? + ( + + + + + + ) + : + + + + + + } +
DescriptionAmountDateConfirmation
+
+ Reward Logo +
+

Reward to {item.rec_firstname} {item.rec_lastname_}

+

{item.description}

+
+
+
{AmountTo2DP(item.amount*0.01)} {item.currency}{date}{item.confirmation}
Opps! an error occurred. Please try again!
No Rewards History Found!
+ } + + {/* PAGINATION BUTTON */} + = familyRewardHistory?.data?.length ? true : false} data={familyRewardHistory?.data} start={indexOfFirstItem} stop={indexOfLastItem} /> + {/* END OF PAGINATION BUTTON */} +
+ ) +} + +export default RewardsTable \ No newline at end of file diff --git a/src/components/History/index.jsx b/src/components/History/index.jsx index cb6a4a8..9bdc62d 100644 --- a/src/components/History/index.jsx +++ b/src/components/History/index.jsx @@ -10,6 +10,7 @@ import usersService from "../../services/UsersService"; import PurchasesTable from "../MyWallet/WalletComponent/PurchasesTable"; import RecentActivityTable from "../MyWallet/WalletComponent/RecentActivityTable"; import LoadingSpinner from "../Spinners/LoadingSpinner"; +import RewardsTable from "./RewardsTable"; export default function History() { @@ -58,6 +59,9 @@ export default function History() { useEffect(()=>{ getPaymentHistory() + }, []) + + useEffect(()=>{ getPurchaseHistory() }, []) @@ -236,6 +240,15 @@ export default function History() { > Recent Activity + {/* END OF switch button */}
@@ -265,6 +278,16 @@ export default function History() {
} {/* END OF RECENT ACTIVITY SECTION */} + + {/* REWARD SECTION */} + {tab == 'reward' && +
+

Rewards

+ {/*

Activity Report

*/} + +
+ } + {/* END OF REWARD SECTION */} {/**/} diff --git a/src/services/UsersService.js b/src/services/UsersService.js index daa9e38..bb38a78 100644 --- a/src/services/UsersService.js +++ b/src/services/UsersService.js @@ -496,6 +496,19 @@ class usersService { return this.postAuxEnd("/purchasehx", postData); } + // API FUNCTION TO GET FAMILY REWARD HISTORY + getFamilyRewardHx() { + var postData = { + uid: localStorage.getItem("uid"), + member_id: localStorage.getItem("member_id"), + sessionid: localStorage.getItem("session_token"), + offset: 1, + limit: 20, + action: 22011, + }; + return this.postAuxEnd("/familyrewardhx", postData); + } + // API FUNCTION TO GET PAYMENT HISTORY getPaymentHx() { var postData = {