import { h, VNode } from "preact"; import { useEffect } from "preact/hooks"; import useSWR from "swr"; import { useTranslationContext } from "../../context/translation.js"; /** * Show one page of transactions. */ export function Transactions({ pageNumber, accountLabel, balanceValue, }: { pageNumber: number; accountLabel: string; balanceValue?: string; }): VNode { const { i18n } = useTranslationContext(); const { data, error, mutate } = useSWR( `access-api/accounts/${accountLabel}/transactions?page=${pageNumber}`, ); useEffect(() => { if (balanceValue) { mutate(); } }, [balanceValue ?? ""]); if (typeof error !== "undefined") { console.log("transactions not found error", error); switch (error.status) { case 404: { return
Transactions page {pageNumber} was not found.
; } case 401: { returnWrong credentials given.
; } default: { returnTransaction page {pageNumber} could not be retrieved.
; } } } if (!data) { console.log(`History data of ${accountLabel} not arrived`); returnTransactions page loading...
; } console.log(`History data of ${accountLabel}`, data); return ({i18n.str`Date`} | {i18n.str`Amount`} | {i18n.str`Counterpart`} | {i18n.str`Subject`} |
---|---|---|---|
{date} | {sign} {item.amount} {item.currency} | {counterpart} | {item.subject} |