diff --git a/src/components/History/RewardsTable.jsx b/src/components/History/RewardsTable.jsx index 7a65412..edc1b8b 100644 --- a/src/components/History/RewardsTable.jsx +++ b/src/components/History/RewardsTable.jsx @@ -1,34 +1,66 @@ -import React, {useState} from 'react' +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({reward}) { +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 = reward?.data?.slice(indexOfFirstItem, indexOfLastItem); + 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 ? + + : - + - {reward.data.length ? + {familyRewardHistory.data.length ? ( {currentReward.map((item, index) => { @@ -37,10 +69,10 @@ function RewardsTable({reward}) { @@ -54,7 +86,7 @@ function RewardsTable({reward}) { ) : - reward.error ? + familyRewardHistory.error ? ( @@ -70,9 +102,10 @@ function RewardsTable({reward}) { }
TitleDescription Amount Date Confirmation
- Reward Logo + Reward Logo
-

Title Goes Here

-

Title Goes Here

+

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

+

{item.description}

+ } {/* PAGINATION BUTTON */} - = reward?.data?.length ? true : false} data={reward?.data} start={indexOfFirstItem} stop={indexOfLastItem} /> + = familyRewardHistory?.data?.length ? true : false} data={familyRewardHistory?.data} start={indexOfFirstItem} stop={indexOfLastItem} /> {/* END OF PAGINATION BUTTON */}
) diff --git a/src/components/History/index.jsx b/src/components/History/index.jsx index cb7aaf6..9d8726f 100644 --- a/src/components/History/index.jsx +++ b/src/components/History/index.jsx @@ -30,12 +30,6 @@ export default function History() { error: false }) - let [familyRewardHistory, setFamilyRewardHistory] = useState({ // FOR PURCHASE HISTORY - loading: true, - data: [], - error: false - }) - //FUNCTION TO GET PAYMENT HISTORY const getPaymentHistory = ()=>{ apiCall.getPaymentHx().then((res)=>{ @@ -63,19 +57,6 @@ export default function History() { }) } - //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(()=>{ getPaymentHistory() }, []) @@ -84,10 +65,6 @@ export default function History() { getPurchaseHistory() }, []) - useEffect(()=>{ - getFamilyRewardHistory() - }, []) - return ( <> @@ -307,11 +284,11 @@ export default function History() {

Rewards

{/*

Activity Report

*/} - {paymentHistory.loading ? + {/* {paymentHistory.loading ? - : - - } + : */} + {/* } */} +
} {/* END OF REWARD SECTION */}