import axios from "axios"; import { t } from "i18next"; import { useSession } from "next-auth/react"; import { useEffect, useState } from "react"; import { Payment } from "@/types"; import { getCurrencySymbol, getDateString } from "@/utils"; const PaymentHistoryTable = () => { const [list, setList] = useState([]); const { data: session } = useSession(); useEffect(() => { const refreshPaymentList = async (userId: string) => { let list: Payment[] = []; try { const { data } = await axios.get("/api/payment", { headers: { Authorization: `Bearer ${userId}` }, }); list = data; } catch (error) { // do nth } setList(list); }; if (session?.user.id) { refreshPaymentList(session.user.id); } }, [session]); if (list.length === 0) { return <>; } return (
{list.map((payment) => ( ))}
{t("common.date")} {t("common.description")} {t("common.amount")}
{getDateString(payment.createdAt)} {payment.description} {getCurrencySymbol(payment.currency.toLocaleUpperCase())} {payment.amount / 100} {t("setting.subscription.view-receipt")}
); }; export default PaymentHistoryTable;