rewards tab added
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
import React, {useState} from 'react'
|
||||||
|
import Image from '../../assets/images/taskbanners/default.jpg'
|
||||||
|
|
||||||
|
import { handlePagingFunc } from '../../components/Pagination/HandlePagination';
|
||||||
|
import PaginatedList from '../../components/Pagination/PaginatedList';
|
||||||
|
|
||||||
|
import { AmountTo2DP } from '../Helpers/PriceFormatter';
|
||||||
|
|
||||||
|
function RewardsTable({reward}) {
|
||||||
|
|
||||||
|
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 handlePagination = (e) => {
|
||||||
|
handlePagingFunc(e,setCurrentPage)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex flex-col justify-between min-h-[500px]'>
|
||||||
|
<table className="wallet-activity w-full table-auto border-collapse text-left">
|
||||||
|
<thead className='border-b-2'>
|
||||||
|
<tr className='text-slate-600'>
|
||||||
|
<th className="p-2">Title</th>
|
||||||
|
<th className="p-2">Amount</th>
|
||||||
|
<th className="p-2">Date</th>
|
||||||
|
<th className="p-2">Confirmation</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{reward.data.length ?
|
||||||
|
(
|
||||||
|
<tbody>
|
||||||
|
{currentReward.map((item, index) => {
|
||||||
|
let date = new Date(item.added).toLocaleDateString()
|
||||||
|
return (
|
||||||
|
<tr key={index} className='text-slate-500'>
|
||||||
|
<td className="p-2">
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<img src={Image} className='min-w-[60px] max-w-[60px] min-h-[60px] max-h-[60px] rounded-full' alt='Reward Logo' />
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<h1 className='text-lg font-bold'>Title Goes Here</h1>
|
||||||
|
<p className='text-sm'>Title Goes Here</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="p-2">{AmountTo2DP(item.amount*0.01)} {item.currency}</td>
|
||||||
|
<td className="p-2">{date}</td>
|
||||||
|
<td className="p-2">{item.confirmation}</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
reward.error ?
|
||||||
|
(
|
||||||
|
<tbody>
|
||||||
|
<tr className='text-slate-500'>
|
||||||
|
<td className="p-2" colSpan={4}>Opps! an error occurred. Please try again!</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
<tbody>
|
||||||
|
<tr className='text-slate-500'>
|
||||||
|
<td className="p-2" colSpan={4}>No Rewards History Found!</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{/* PAGINATION BUTTON */}
|
||||||
|
<PaginatedList onClick={handlePagination} prev={currentPage == 0 ? true : false} next={currentPage+Number(process.env.REACT_APP_ITEM_PER_PAGE) >= reward?.data?.length ? true : false} data={reward?.data} start={indexOfFirstItem} stop={indexOfLastItem} />
|
||||||
|
{/* END OF PAGINATION BUTTON */}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RewardsTable
|
||||||
@@ -10,6 +10,7 @@ import usersService from "../../services/UsersService";
|
|||||||
import PurchasesTable from "../MyWallet/WalletComponent/PurchasesTable";
|
import PurchasesTable from "../MyWallet/WalletComponent/PurchasesTable";
|
||||||
import RecentActivityTable from "../MyWallet/WalletComponent/RecentActivityTable";
|
import RecentActivityTable from "../MyWallet/WalletComponent/RecentActivityTable";
|
||||||
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
||||||
|
import RewardsTable from "./RewardsTable";
|
||||||
|
|
||||||
export default function History() {
|
export default function History() {
|
||||||
|
|
||||||
@@ -29,6 +30,12 @@ export default function History() {
|
|||||||
error: false
|
error: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let [familyRewardHistory, setFamilyRewardHistory] = useState({ // FOR PURCHASE HISTORY
|
||||||
|
loading: true,
|
||||||
|
data: [],
|
||||||
|
error: false
|
||||||
|
})
|
||||||
|
|
||||||
//FUNCTION TO GET PAYMENT HISTORY
|
//FUNCTION TO GET PAYMENT HISTORY
|
||||||
const getPaymentHistory = ()=>{
|
const getPaymentHistory = ()=>{
|
||||||
apiCall.getPaymentHx().then((res)=>{
|
apiCall.getPaymentHx().then((res)=>{
|
||||||
@@ -56,11 +63,31 @@ 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(()=>{
|
useEffect(()=>{
|
||||||
getPaymentHistory()
|
getPaymentHistory()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
getPurchaseHistory()
|
getPurchaseHistory()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
getFamilyRewardHistory()
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Layout>
|
<Layout>
|
||||||
@@ -236,6 +263,15 @@ export default function History() {
|
|||||||
>
|
>
|
||||||
Recent Activity
|
Recent Activity
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
name="reward"
|
||||||
|
onClick={(e) => setTab(e.target.name)}
|
||||||
|
className={`px-4 py-1 rounded-t-2xl ${
|
||||||
|
tab == "reward" ? "bg-[#4687ba] border-[2px] border-[#4687ba] text-white" : "bg-white text-[#000] border-t-[2px]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Rewards
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/* END OF switch button */}
|
{/* END OF switch button */}
|
||||||
<div className="history-tables w-full">
|
<div className="history-tables w-full">
|
||||||
@@ -265,6 +301,20 @@ export default function History() {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{/* END OF RECENT ACTIVITY SECTION */}
|
{/* END OF RECENT ACTIVITY SECTION */}
|
||||||
|
|
||||||
|
{/* REWARD SECTION */}
|
||||||
|
{tab == 'reward' &&
|
||||||
|
<div className="wallet w-full border-t">
|
||||||
|
<h1 className="p-2 text-xl font-bold text-dark-gray dark:text-white tracking-wide">Rewards</h1>
|
||||||
|
{/* <p className='text-base text-slate-500 dark:text-white'>Activity Report</p> */}
|
||||||
|
{paymentHistory.loading ?
|
||||||
|
<LoadingSpinner size='16' color='sky-blue' />
|
||||||
|
:
|
||||||
|
<RewardsTable reward={familyRewardHistory} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{/* END OF REWARD SECTION */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/*<HistoryTable />*/}
|
{/*<HistoryTable />*/}
|
||||||
|
|||||||
@@ -496,6 +496,19 @@ class usersService {
|
|||||||
return this.postAuxEnd("/purchasehx", postData);
|
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
|
// API FUNCTION TO GET PAYMENT HISTORY
|
||||||
getPaymentHx() {
|
getPaymentHx() {
|
||||||
var postData = {
|
var postData = {
|
||||||
|
|||||||
Reference in New Issue
Block a user