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

91 lines (90 loc) • 4.43 kB
JavaScript
import { jsx as n } from "../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js";
/* empty css */
import { useMemo as m, 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 C } from "../../../utils/value/constants.js";
const X = {
transaction: "getTransaction",
payout: "getPayout",
dispute: "getDisputeDetail"
}, s = (t) => !("data" in t);
function dt(t) {
var f;
const k = m(() => s(t) ? null : t.data, [t]), o = m(() => s(t) ? t.id : null, [t]), y = W().endpoints[X[t.type]], { hideTitle: w, title: S } = V(t), { data: e, error: r, isFetching: v } = O(
m(
() => ({
fetchOptions: { enabled: !!o && !!y },
queryFn: async () => {
let c = null;
switch (t.type) {
case "transaction":
c = { path: { transactionId: o } };
break;
case "payout":
c = { query: { balanceAccountId: o, createdAt: t.date } };
break;
default:
break;
}
return y(C, { ...c });
}
}),
[o, y, t]
)
), _ = t.type === "payout" ? t.id : e == null ? void 0 : e.balanceAccountId, F = t.type === "payout" ? t == null ? void 0 : t.balanceAccountDescription : t == null ? void 0 : t.balanceAccount, { balanceAccounts: i } = Y(_, !F), D = m(() => {
if (r)
return q(r, "weCouldNotLoadYourTransactions", t.onContactSupport);
}, [r, t.onContactSupport]), u = k ?? e, [T, P] = x(), E = L(async () => {
var c, d, b, g, A;
if (e && (s(t) && t.type === "transaction" || t.type === "payout")) {
const l = await ((b = (d = (c = t.dataCustomization) == null ? void 0 : c.details) == null ? void 0 : d.onDataRetrieve) == null ? void 0 : b.call(d, e));
P(
(A = (g = t.dataCustomization) == null ? void 0 : g.details) == null ? void 0 : A.fields.reduce((I, a) => j.has(a.key) || J.includes(a.key) || (a == null ? void 0 : a.visibility) === "hidden" ? I : { ...I, ...l != null && l[a.key] ? { [a.key]: l[a.key] } : {} }, {})
);
}
}, [e, t]), h = s(t) && t.type === "transaction" || t.type === "payout" ? t.dataCustomization : void 0;
return N(() => {
E();
}, [E]), /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details", children: [
!w && /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details--title", children: /* @__PURE__ */ n(M, { variant: R.TITLE, medium: !0, children: S }) }),
r && D && /* @__PURE__ */ n("div", { className: "adyen-pe-overview-details--error-container", children: /* @__PURE__ */ n(z, { withImage: !0, ...D }) }),
t.type === "transaction" && /* @__PURE__ */ n(
U,
{
transaction: u ? {
...u || C,
balanceAccount: (t == null ? void 0 : t.balanceAccount) || (i == null ? void 0 : i[0])
} : void 0,
error: !!(r && D),
isFetching: v,
extraFields: T,
dataCustomization: h
}
),
t.type === "payout" && u && /* @__PURE__ */ n(
B,
{
balanceAccountId: o,
payout: u,
balanceAccountDescription: (t == null ? void 0 : t.balanceAccountDescription) || ((f = i == null ? void 0 : i[0]) == null ? void 0 : f.description),
isFetching: v,
extraFields: T,
dataCustomization: h
}
)
] });
}
export {
dt as default
};