@adyen/adyen-platform-experience-web
Version:

84 lines (83 loc) • 4.25 kB
JavaScript
import { jsx as n } from "../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js";
/* empty css */
import { useMemo as y, useState as x, useCallback as L, useEffect as N } from "../../../external/preact/hooks/dist/hooks.module.js";
import { useFetch as O } from "../../../hooks/useFetch.js";
import { PayoutData as B } from "../../external/PayoutDetails/components/PayoutData.js";
import Y from "../../../hooks/useBalanceAccounts.js";
import { getErrorMessage as q } from "../../utils/getErrorMessage.js";
import { ErrorMessageDisplay as z } from "../ErrorMessageDisplay/ErrorMessageDisplay.js";
import M from "../Typography/Typography.js";
import { TypographyVariant as R } from "../Typography/types.js";
import { useDataOverviewDetailsTitle as V } from "./useDataOverviewDetailsTitle.js";
import { TX_DETAILS_RESERVED_FIELDS_SET as j } from "../../external/TransactionDetails/components/constants.js";
import { PAYOUT_TABLE_FIELDS as J } from "../../external/PayoutsOverview/components/PayoutsTable/PayoutsTable.js";
import { TransactionData as U } from "../../external/TransactionDetails/components/TransactionData/TransactionData.js";
import { useConfigContext as W } from "../../../core/ConfigContext/context.js";
import { EMPTY_OBJECT as b } from "../../../utils/value/constants.js";
const X = {
transaction: "getTransaction",
payout: "getPayout"
}, l = (t) => !("data" in t);
function dt(t) {
var f;
const S = y(() => l(t) ? null : t.data, [t]), c = y(() => l(t) ? t.id : null, [t]), s = W().endpoints[X[t.type]], { hideTitle: _, title: w } = V(t), { data: e, error: o, isFetching: D } = O(
y(
() => ({
fetchOptions: { enabled: !!c && !!s },
queryFn: async () => {
const u = t.type === "transaction" ? {
path: { transactionId: c }
} : {
query: { balanceAccountId: c, createdAt: t.date }
};
return s(b, { ...u });
}
}),
[c, s, t]
)
), F = t.type === "payout" ? t.id : e == null ? void 0 : e.balanceAccountId, P = t.type === "payout" ? t == null ? void 0 : t.balanceAccountDescription : t == null ? void 0 : t.balanceAccount, { balanceAccounts: i } = Y(F, !P), v = y(() => {
if (o)
return q(o, "weCouldNotLoadYourTransactions", t.onContactSupport);
}, [o, t.onContactSupport]), r = S ?? e, [T, k] = x(), E = L(async () => {
var u, d, A, I, g;
if (e && (l(t) && t.type === "transaction" || t.type === "payout")) {
const m = await ((A = (d = (u = t.dataCustomization) == null ? void 0 : u.details) == null ? void 0 : d.onDataRetrieve) == null ? void 0 : A.call(d, e));
k(
(g = (I = t.dataCustomization) == null ? void 0 : I.details) == null ? void 0 : g.fields.reduce((C, a) => j.has(a.key) || J.includes(a.key) || (a == null ? void 0 : a.visibility) === "hidden" ? C : { ...C, ...m != null && m[a.key] ? { [a.key]: m[a.key] } : {} }, {})
);
}
}, [e, t]), h = l(t) && t.type === "transaction" || t.type === "payout" ? t.dataCustomization : void 0;
return N(() => {
E();
}, [E]), /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details", children: [
!_ && /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details--title", children: /* @__PURE__ */ n(M, { variant: R.TITLE, medium: !0, children: w }) }),
o && v && /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details--error-container", children: /* @__PURE__ */ n(z, { withImage: !0, ...v }) }),
t.type === "transaction" && /* @__PURE__ */ n(
U,
{
transaction: r ? {
...r || b,
balanceAccount: (t == null ? void 0 : t.balanceAccount) || (i == null ? void 0 : i[0])
} : void 0,
error: !!(o && v),
isFetching: D,
extraFields: T,
dataCustomization: h
}
),
t.type === "payout" && r && /* @__PURE__ */ n(
B,
{
balanceAccountId: c,
payout: r,
balanceAccountDescription: (t == null ? void 0 : t.balanceAccountDescription) || ((f = i == null ? void 0 : i[0]) == null ? void 0 : f.description),
isFetching: D,
extraFields: T,
dataCustomization: h
}
)
] });
}
export {
dt as default
};