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

106 lines (105 loc) • 2.96 kB
JavaScript
import { jsx as E } from "../../../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { createContext as j } from "../../../../../external/preact/dist/preact.module.js";
import { memo as q } from "../../../../../external/preact/compat/dist/compat.module.js";
import { useState as f, useCallback as a, useEffect as A, useContext as B } from "../../../../../external/preact/hooks/dist/hooks.module.js";
const w = (c) => {
const l = new FormData();
for (const [i, o] of c.entries())
o instanceof File ? l.set(i, o, o.name) : l.set(i, o);
return l;
}, P = j(void 0), z = q(({ dispute: c, setDispute: l, children: i }) => {
const [o, d] = f("details"), [u, x] = f(null), [R, F] = f([]), [S, r] = f(null), [h, b] = f(null), D = a(() => {
r((e) => {
if (e) {
const n = [...e.keys()].filter((t) => t !== "defenseReason");
if (n.length > 0) {
const t = w(e);
return n.forEach((s) => t.delete(s)), t;
}
}
return e;
});
}, []), k = a(() => {
switch (o) {
case "defendReasonSelectionView":
d("details");
break;
case "accept":
d("details");
break;
case "uploadDefenseFilesView":
D(), d("defendReasonSelectionView");
break;
default:
d("details");
break;
}
}, [D, o]), p = a(() => {
x(null), F(null), r(null), b(null), l(void 0);
}, [l]), y = a((e, n) => {
r((t) => {
const s = t ? w(t) : new FormData();
return s.set(e, n, n.name), s;
});
}, []), C = a((e, n) => {
r((t) => {
if (t && t.has(e)) {
const s = t.get(e), m = w(t);
return m.delete(e), s instanceof File ? m.set(n, s, s.name) : m.set(n, s), m;
}
return t;
});
}, []), V = a((e) => {
r((n) => {
if (n && n.has(e)) {
const t = w(n);
return t.delete(e), t;
}
return n;
});
}, []), g = a((e) => {
b(e);
}, []);
return A(() => {
r(() => {
if (u) {
const e = new FormData();
return e.set("defenseReason", u), e;
}
return null;
});
}, [u]), /* @__PURE__ */ E(
P.Provider,
{
value: {
addFileToDefendPayload: y,
applicableDocuments: R,
clearFiles: D,
clearStates: p,
defendResponse: h,
dispute: c,
flowState: o,
goBack: k,
setApplicableDocuments: F,
setFlowState: d,
setDispute: l,
selectedDefenseReason: u,
setSelectedDefenseReason: x,
defendDisputePayload: S,
onDefendSubmit: g,
moveFieldInDefendPayload: C,
removeFieldFromDefendPayload: V
},
children: i
}
);
}), G = () => {
const c = B(P);
if (!c) throw new Error("useDisputeFlow must be used within DisputeFlowProvider");
return c;
};
export {
z as DisputeContextProvider,
P as DisputeFlowContext,
G as useDisputeFlow
};