import React, { Fragment } from "react";
import MkdSDK from "@/utils/MkdSDK";
import PaginationBar from "./PaginationBar";
import PaginationHeader from "./PaginationHeader";
import { Menu, Transition } from "@headlessui/react";
import Icon from "./Icons";
import { useNavigate } from "react-router-dom";
import { secondsToHour } from "@/utils/utils";
import moment from "moment";
import { ID_PREFIX } from "@/utils/constants";
const Payment = ({ id, table }) => {
const navigate = useNavigate();
const [query, setQuery] = React.useState("");
const [data, setCurrentTableData] = React.useState([]);
const [pageSize, setPageSize] = React.useState(10);
const [pageCount, setPageCount] = React.useState(0);
const [dataTotal, setDataTotal] = React.useState(0);
const [currentPage, setPage] = React.useState(0);
const [canPreviousPage, setCanPreviousPage] = React.useState(false);
const [canNextPage, setCanNextPage] = React.useState(false);
const payoutMapping = [
{ key: "0", value: "Pending" },
{ key: "1", value: "Initiated" },
{ key: "2", value: "Paid" },
{ key: "3", value: "Cancelled" }
];
function updatePageSize(limit) {
(async function () {
setPageSize(limit);
await getData(0, limit);
})();
}
function previousPage() {
(async function () {
await getData(currentPage - 1 > 0 ? currentPage - 1 : 0, pageSize);
})();
}
function nextPage() {
(async function () {
await getData(currentPage + 1 <= pageCount ? currentPage + 1 : 0, pageSize);
})();
}
async function getData(pageNum, limitNum) {
try {
let sdk = new MkdSDK();
const result = await sdk.callRawAPI(
"/v2/api/custom/ergo/payout/PAGINATE",
{
where: [table ? `${table === "host" ? `ergo_user.id = ${id}` : "1"}` : 1],
page: pageNum,
limit: limitNum
},
"POST"
);
const { list, total, limit, num_pages, page } = result;
setCurrentTableData(list);
setPageSize(limit);
setPageCount(num_pages);
setPage(page);
setDataTotal(total);
setCanPreviousPage(page > 1);
setCanNextPage(page + 1 <= num_pages);
} catch (error) {
console.log("ERROR", error);
tokenExpireError(dispatch, error.message);
}
}
React.useEffect(() => {
(async function () {
await getData(1, pageSize);
})();
}, []);
return (
<>
Host
{data.host_last_name}, {data.host_first_name}{" "}
Customer
{data.customer_last_name}, {data.customer_first_name}{" "}
Booking Date
{data.create_at}
Order Number
{data.id}
Total
${data?.total?.toFixed(2)}
Tax
${data?.tax?.toFixed(2)}
Commission
${data?.commission?.toFixed(2)}
Payout Date
{data?.initiated_at ? moment(data.initiated_at).add(7, "days").format("MM/DD/YY") : ""}
{payoutMapping.find((status) => status.key == data.status)?.value}