import React, { useEffect, useState } from "react"; import axios from "axios"; import { Link, useNavigate, useParams } from "react-router-dom"; import { Button, Pagination } from "@mui/material"; import { isAutheticated } from "src/auth"; const AffiliateHistory = () => { const id = useParams().id; const token = isAutheticated(); //Navigation const navigate = useNavigate(); const [apiData, setApiData] = useState([]); const [name, setName] = useState(""); const [loading, setLoading] = useState(true); //Date format change function const dateFormat = (inputDate) => { const months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; const parts = inputDate.split("-"); const rearrangedDate = `${parts[2]}-${months[parseInt(parts[1]) - 1]}-${ parts[0] }`; // console.log(rearrangedDate); // Output: 11-Mar-2024 return rearrangedDate; }; //Extract time from mongodb const extractTime = (dateTimeString) => { const date = new Date(dateTimeString); const hours = date.getUTCHours().toString().padStart(2, "0"); const minutes = date.getUTCMinutes().toString().padStart(2, "0"); const seconds = date.getUTCSeconds().toString().padStart(2, "0"); const time = `${hours}:${minutes}:${seconds}`; // console.log(time); return time; }; //Func to get all Affiliate data const fetchHistoryData = () => { axios .get(`/api/v1/affiliate/history/${id}`, { headers: { Authorization: `Bearer ${token}`, }, }) .then((response) => { // console.log(response.data.message.affiliate_pay_history); setApiData(response.data.message.affiliate_pay_history); setName(response.data.message.name); setLoading(false); }) .catch((error) => { setLoading(false); const message = error?.response?.data?.message || "Something went wrong!"; console.log(message); }); }; //Call api onLoad of page useEffect(() => { fetchHistoryData(); }, []); //pagination related const [itemPerPage, setItemPerPage] = useState(10); //pagination const [page, setPage] = useState(1); //pagination const getPageCount = () => { return Math.max(1, Math.ceil(apiData.length / itemPerPage)); }; return (
{/* Coupon header start */}

Payment History :{name}

{/* Coupon header End */} {/* Coupon main body Start*/}
{/* Table Start */}
{!loading && apiData.length === 0 && ( )} {loading ? ( ) : ( apiData && apiData .slice( (`${page}` - 1) * itemPerPage, `${page}` * itemPerPage ) .map((item, i) => ( )) )}
Transection ID Amount Date Time
No Data Available
Loading...
{item.transecId} ₹{item.amount} {dateFormat(item.date)} {item.time}
{/* Table End */} {/* Pagination div Start*/}
setPage(value)} />
{/* Pagination div End*/} {/* Coupon main body End */}
); }; export default AffiliateHistory;