UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

53 lines (52 loc) 1.41 kB
import { useMemo as n, useCallback as A } from "../../../../../../external/preact/hooks/dist/hooks.module.js"; import g from "../../../../../../core/Context/useCoreContext.js"; import { ActiveView as p } from "../../types.js"; const E = ({ refundAmount: t, refundReason: u, refundInProgress: l, refundTransaction: o, setActiveView: r, transactionId: c }) => { const { i18n: e } = g(), m = n(() => { const b = e.amount(t.value, t.currency); return { title: e.get("refundPayment", { values: { amount: b } }) }; }, [t, e]), s = n(() => ({ title: e.get("refundAction") }), [e]), f = n( () => ({ title: `${e.get("inProgress")}..`, state: "loading" }), [e] ), i = n( () => ({ path: { transactionId: c } }), [c] ), a = n( () => ({ amount: t, refundReason: u // ...(refundMode === RefundMode.PARTIAL_LINE_ITEMS && { lineItems: [] }), }), [t, u] ), d = A( // [TODO]: Fix broken/missing type inference for useMutation mutate() () => o == null ? void 0 : o( { body: a, contentType: "application/json" }, i ).then(() => { r(p.REFUND_SUCCESS); }).catch(() => { r(p.REFUND_ERROR); }), [o, i, a, r] ), y = n(() => l ? f : t.value > 0 ? m : s, [t, l, m, s, f]); return { refundAction: d, refundActionLabel: y }; }; export { E as useRefundAction };