vonpay-medusa 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +904 -904
- package/.medusa/server/src/admin/index.mjs +906 -906
- package/package.json +1 -1
- package/storefront/src/server.ts +0 -4
|
@@ -626,975 +626,975 @@ const UpdateBanner = () => {
|
|
|
626
626
|
] }) });
|
|
627
627
|
};
|
|
628
628
|
adminSdk.defineWidgetConfig({ zone: "order.list.before" });
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
off: "One-click offers are off. Turn them on with the upsells option in medusa-config; the offers below are kept.",
|
|
635
|
-
fromConfig: "Your offers come from medusa-config right now (upsells.variantIds). Import them to manage them here. Once an offer exists here, this list is used instead.",
|
|
636
|
-
configEmpty: "No offers yet. Add the first one below.",
|
|
637
|
-
adminEmpty: "No offers are shown to shoppers. Add one below.",
|
|
638
|
-
importButton: "Import from medusa-config",
|
|
639
|
-
add: "Add offer",
|
|
640
|
-
name: "Name (only you see it)",
|
|
641
|
-
variant: "Product variant id (variant_…)",
|
|
642
|
-
shown: "Shown",
|
|
643
|
-
up: "Move up",
|
|
644
|
-
down: "Move down",
|
|
645
|
-
remove: "Remove",
|
|
646
|
-
removeConfirm: "Remove this offer? A shopper already paying for it is not affected.",
|
|
647
|
-
missingVariant: "This product variant no longer exists — it is not offered.",
|
|
648
|
-
loadFailed: "The offers could not be loaded. Reload the page to try again.",
|
|
649
|
-
lag: "A change shows on your store at once; with more than one server it can take up to 30 seconds everywhere.",
|
|
650
|
-
rules: "Who sees it",
|
|
651
|
-
downsell: "If they say No thanks",
|
|
652
|
-
downsellNone: "Nothing",
|
|
653
|
-
downsellIntro: 'Show one other product after a shopper says No thanks to this offer — usually a smaller or cheaper option. It counts toward the three offers per order, and the same "Who sees it" applies.',
|
|
654
|
-
downsellVariant: "Downsell product variant id (variant_…)",
|
|
655
|
-
downsellRemove: "Remove downsell",
|
|
656
|
-
downsellMissing: "This product variant no longer exists — it is not offered.",
|
|
657
|
-
wording: "Wording",
|
|
658
|
-
wordingDefault: "Standard",
|
|
659
|
-
wordingPitchOnly: "Pitch only",
|
|
660
|
-
wordingUnreadable: "The saved wording can't be read, so shoppers see the standard wording. Save it again.",
|
|
661
|
-
wordingIntro: "What shoppers read on this offer. Leave a field empty to use the standard wording. The payment line, the buttons and every result message stay the same.",
|
|
662
|
-
headline: "Headline",
|
|
663
|
-
headlineHint: 'Replaces the heading. Standard: "Add this to your order?"',
|
|
664
|
-
pitch: "Pitch",
|
|
665
|
-
pitchHint: "Replaces the product's description under its name. A phone shows about two lines.",
|
|
666
|
-
wordingDownsellNote: `A downsell keeps the standard wording: "How about this instead?" and its product's description.`,
|
|
667
|
-
wordingReset: "Use the standard wording",
|
|
668
|
-
rulesEveryone: "Everyone",
|
|
669
|
-
rulesUnreadable: "Its rules can't be read, so it is not shown. Set them again.",
|
|
670
|
-
rulesIntro: "Show this offer only when ALL the conditions you set match. Leave a condition empty to ignore it.",
|
|
671
|
-
customers: "Customers",
|
|
672
|
-
customersAll: "Everyone",
|
|
673
|
-
customersGuests: "Guests only",
|
|
674
|
-
customersSignedIn: "Signed-in customers only",
|
|
675
|
-
products: "The shopper bought one of these products at checkout",
|
|
676
|
-
collections: "The shopper bought a product from one of these collections at checkout",
|
|
677
|
-
groups: "The signed-in customer is in one of these groups",
|
|
678
|
-
paid: "The amount paid at checkout (tax and shipping included)",
|
|
679
|
-
paidNote: "An order in a currency not listed here does not see this offer.",
|
|
680
|
-
paidAtLeast: "At least",
|
|
681
|
-
paidAtMost: "At most",
|
|
682
|
-
search: "Search by name",
|
|
683
|
-
addCurrency: "Add currency",
|
|
684
|
-
removeCurrency: "Remove currency",
|
|
685
|
-
rulesUnreadableNotice: "The saved rules for this offer can't be read, so the offer is not shown. Saving replaces them with what you set here.",
|
|
686
|
-
replaceRules: "Replace the rules",
|
|
687
|
-
save: "Save",
|
|
688
|
-
cancel: "Cancel",
|
|
689
|
-
saveFailed: "That change was not saved."
|
|
690
|
-
};
|
|
691
|
-
function errorSentence(err, fallback = OFFERS_COPY.saveFailed) {
|
|
692
|
-
const m = err?.message;
|
|
693
|
-
if (typeof m !== "string") return fallback;
|
|
694
|
-
const i = m.indexOf(": ");
|
|
695
|
-
return m.startsWith("vonpay_") && i > 0 ? m.slice(i + 2) : fallback;
|
|
696
|
-
}
|
|
697
|
-
function productLabel(o) {
|
|
698
|
-
if (o.product_title === null) return o.variant_id;
|
|
699
|
-
return [o.product_title, o.variant_title].filter((x) => x && x !== "Default variant").join(" — ");
|
|
700
|
-
}
|
|
701
|
-
function wordingSummary(copy) {
|
|
702
|
-
if (copy === "unreadable") return OFFERS_COPY.wordingUnreadable;
|
|
703
|
-
if (!copy) return OFFERS_COPY.wordingDefault;
|
|
704
|
-
return copy.headline ?? OFFERS_COPY.wordingPitchOnly;
|
|
705
|
-
}
|
|
706
|
-
function rulesSummary(rules) {
|
|
707
|
-
if (rules === "unreadable") return OFFERS_COPY.rulesUnreadable;
|
|
708
|
-
if (!rules) return OFFERS_COPY.rulesEveryone;
|
|
709
|
-
const parts = [];
|
|
710
|
-
if (rules.customers === "guests") parts.push("Guests");
|
|
711
|
-
if (rules.customers === "signed_in") parts.push("Signed-in");
|
|
712
|
-
if (rules.groups) parts.push(`${rules.groups.length} group${rules.groups.length === 1 ? "" : "s"}`);
|
|
713
|
-
if (rules.products) parts.push(`${rules.products.length} product${rules.products.length === 1 ? "" : "s"}`);
|
|
714
|
-
if (rules.collections) parts.push(`${rules.collections.length} collection${rules.collections.length === 1 ? "" : "s"}`);
|
|
715
|
-
for (const [c, n] of Object.entries(rules.min_paid ?? {})) parts.push(`paid ≥ ${n} ${c.toUpperCase()}`);
|
|
716
|
-
for (const [c, n] of Object.entries(rules.max_paid ?? {})) parts.push(`paid ≤ ${n} ${c.toUpperCase()}`);
|
|
717
|
-
return parts.length ? parts.join(" · ") : OFFERS_COPY.rulesEveryone;
|
|
629
|
+
function useSetupCheck() {
|
|
630
|
+
return reactQuery.useMutation({
|
|
631
|
+
mutationFn: () => sdk.client.fetch("/admin/vonpay/setup-check", { method: "POST", body: {} }),
|
|
632
|
+
retry: false
|
|
633
|
+
});
|
|
718
634
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
if (refused === null) onOpenChange(false);
|
|
727
|
-
else setProblem(refused);
|
|
728
|
-
};
|
|
729
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
730
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
731
|
-
OFFERS_COPY.downsell,
|
|
732
|
-
": ",
|
|
733
|
-
offer.name
|
|
734
|
-
] }) }),
|
|
735
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-4", children: [
|
|
736
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.downsellIntro }),
|
|
635
|
+
const LABEL = { pass: "OK", warn: "Check", fail: "Fix", not_checked: "Not checked" };
|
|
636
|
+
const COLOR = { pass: "green", warn: "orange", fail: "red", not_checked: "grey" };
|
|
637
|
+
const SetupCheckPanel = () => {
|
|
638
|
+
const check = useSetupCheck();
|
|
639
|
+
const items = check.data?.items ?? [];
|
|
640
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
641
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4 px-6 py-4", children: [
|
|
737
642
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
738
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
739
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
643
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Vonpay setup" }),
|
|
644
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Checks your Vonpay key, your notification endpoint and the Medusa setup Vonpay needs. With test keys it also sends one test notification (it never creates a payment); that usually takes under 30 seconds." })
|
|
740
645
|
] }),
|
|
741
|
-
|
|
646
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", isLoading: check.isPending, onClick: () => check.mutate(), children: "Check Vonpay setup" })
|
|
742
647
|
] }),
|
|
743
|
-
/* @__PURE__ */ jsxRuntime.
|
|
744
|
-
|
|
745
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
746
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
648
|
+
check.isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "The check could not run. Try again, or run npx vonpay-medusa-check on the server." }) }),
|
|
649
|
+
check.data && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3 px-6 py-4", children: [
|
|
650
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: !check.data.ok ? "error" : check.data.complete ? "success" : "warning", children: !check.data.ok ? "Something needs fixing — see the items marked Fix." : check.data.complete ? "No problems found." : `No failures, but ${check.data.unverified} ${check.data.unverified === 1 ? "check" : "checks"} could not run — see the items marked Not checked.` }),
|
|
651
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex flex-col gap-y-3", "aria-label": "Setup check results", children: items.map((i, n) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex flex-col gap-y-1 sm:flex-row sm:items-start sm:gap-x-3", children: [
|
|
652
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: COLOR[i.status], className: "w-fit shrink-0", children: LABEL[i.status] }),
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
654
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: i.detail }),
|
|
655
|
+
i.fix && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: i.fix })
|
|
656
|
+
] })
|
|
657
|
+
] }, `${i.id}:${i.provider ?? ""}:${n}`)) })
|
|
747
658
|
] })
|
|
748
|
-
] })
|
|
749
|
-
}
|
|
750
|
-
const SOURCES = {
|
|
751
|
-
products: { path: "/admin/products", key: "products", label: "title" },
|
|
752
|
-
collections: { path: "/admin/collections", key: "collections", label: "title" },
|
|
753
|
-
groups: { path: "/admin/customer-groups", key: "customer_groups", label: "name" }
|
|
659
|
+
] });
|
|
754
660
|
};
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
661
|
+
const relative = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
|
|
662
|
+
const UNITS = [
|
|
663
|
+
["day", 864e5],
|
|
664
|
+
["hour", 36e5],
|
|
665
|
+
["minute", 6e4]
|
|
666
|
+
];
|
|
667
|
+
function since(iso) {
|
|
668
|
+
if (!iso) return "Unknown";
|
|
669
|
+
const diff = Date.parse(iso) - Date.now();
|
|
670
|
+
for (const [unit, ms] of UNITS) {
|
|
671
|
+
if (Math.abs(diff) >= ms) return relative.format((diff - diff % ms) / ms, unit);
|
|
672
|
+
}
|
|
673
|
+
return "just now";
|
|
760
674
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { placeholder: OFFERS_COPY.search, value: q, maxLength: 100, "aria-label": `${label}: ${OFFERS_COPY.search}`, onChange: (e) => setQ(e.target.value) }),
|
|
773
|
-
(q.trim().length >= 2 ? found.data ?? [] : []).filter((n) => !ids.includes(n.id)).map((n) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { size: "small", variant: "transparent", type: "button", onClick: () => onChange([...ids, n.id]), children: [
|
|
774
|
-
"+ ",
|
|
775
|
-
n.label
|
|
776
|
-
] }, n.id))
|
|
777
|
-
] });
|
|
675
|
+
const STATUS_COLOR = {
|
|
676
|
+
open: "orange",
|
|
677
|
+
nothing_left: "orange",
|
|
678
|
+
refund_pending: "blue",
|
|
679
|
+
refund_unknown: "red",
|
|
680
|
+
refund_sending: "red",
|
|
681
|
+
resolved: "green"
|
|
682
|
+
};
|
|
683
|
+
const UNKNOWN_STATUS_LABEL = "Status unknown — check in Vonpay";
|
|
684
|
+
function isKnownStatus(status) {
|
|
685
|
+
return Object.prototype.hasOwnProperty.call(STATUS_LABEL, status);
|
|
778
686
|
}
|
|
779
|
-
function
|
|
780
|
-
|
|
781
|
-
return cs.map((c) => ({ currency: c, min: rules?.min_paid?.[c] ?? "", max: rules?.max_paid?.[c] ?? "" }));
|
|
687
|
+
function statusLabel(status) {
|
|
688
|
+
return isKnownStatus(status) ? STATUS_LABEL[status] : UNKNOWN_STATUS_LABEL;
|
|
782
689
|
}
|
|
783
|
-
function
|
|
784
|
-
|
|
785
|
-
if (t === "") return void 0;
|
|
786
|
-
return /^\d{1,10}(\.\d{1,6})?$/.test(t) ? t : null;
|
|
690
|
+
function statusColor(status) {
|
|
691
|
+
return isKnownStatus(status) && STATUS_COLOR[status] || "grey";
|
|
787
692
|
}
|
|
788
|
-
function
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (f.collections.length) out.collections = f.collections;
|
|
793
|
-
if (f.groups.length) out.groups = f.groups;
|
|
794
|
-
for (const r of f.paid) {
|
|
795
|
-
const c = r.currency.trim().toLowerCase();
|
|
796
|
-
if (!c && !r.min.trim() && !r.max.trim()) continue;
|
|
797
|
-
if (!/^[a-z]{3}$/.test(c)) return "Use a 3-letter currency code, like EUR.";
|
|
798
|
-
const min = amountText(r.min);
|
|
799
|
-
const max = amountText(r.max);
|
|
800
|
-
if (min === null || max === null) return `Enter a plain amount for ${c.toUpperCase()}, like 49.95.`;
|
|
801
|
-
if (min === void 0 && max === void 0) return `Enter the least or the most for ${c.toUpperCase()}, or remove its row.`;
|
|
802
|
-
if (out.min_paid?.[c] !== void 0 || out.max_paid?.[c] !== void 0) return `${c.toUpperCase()} is listed twice.`;
|
|
803
|
-
if (min !== void 0) out.min_paid = { ...out.min_paid, [c]: min };
|
|
804
|
-
if (max !== void 0) out.max_paid = { ...out.max_paid, [c]: max };
|
|
805
|
-
}
|
|
806
|
-
if (out.customers === "guests" && out.groups) return "Groups apply to signed-in customers only.";
|
|
807
|
-
return Object.keys(out).length ? out : null;
|
|
693
|
+
function routeRefusal(err) {
|
|
694
|
+
const status = err?.status;
|
|
695
|
+
const message = err?.message;
|
|
696
|
+
return typeof status === "number" && status >= 400 && status < 500 && typeof message === "string" && message !== "" ? message : null;
|
|
808
697
|
}
|
|
809
|
-
function
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const [groups, setGroups] = react.useState(start?.groups ?? []);
|
|
816
|
-
const [paid, setPaid] = react.useState(rowsOf(start));
|
|
817
|
-
const [problem, setProblem] = react.useState(null);
|
|
818
|
-
const save = async () => {
|
|
819
|
-
const r = rulesFromForm({ customers, products, collections, groups, paid });
|
|
820
|
-
if (typeof r === "string") return setProblem(r);
|
|
821
|
-
setProblem(null);
|
|
822
|
-
const refused = await onSave(r);
|
|
823
|
-
if (refused === null) onOpenChange(false);
|
|
824
|
-
else setProblem(refused);
|
|
698
|
+
function postFailure(err) {
|
|
699
|
+
const refusal = routeRefusal(err);
|
|
700
|
+
if (refusal) return { variant: "error", text: refusal };
|
|
701
|
+
return {
|
|
702
|
+
variant: "warning",
|
|
703
|
+
text: "The result is unknown. Reload the list before refunding another way — pressing Refund again is safe: it reuses the same key, so Vonpay can't refund twice."
|
|
825
704
|
};
|
|
826
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
827
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
828
|
-
OFFERS_COPY.rules,
|
|
829
|
-
": ",
|
|
830
|
-
offer.name
|
|
831
|
-
] }) }),
|
|
832
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
833
|
-
unreadable && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-rules-unreadable", children: OFFERS_COPY.rulesUnreadableNotice }),
|
|
834
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.rulesIntro }),
|
|
835
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
836
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: OFFERS_COPY.customers }),
|
|
837
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: customers, onValueChange: (v) => setCustomers(v), children: [
|
|
838
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { "aria-label": OFFERS_COPY.customers, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
839
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
840
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "all", children: OFFERS_COPY.customersAll }),
|
|
841
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "guests", children: OFFERS_COPY.customersGuests }),
|
|
842
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "signed_in", children: OFFERS_COPY.customersSignedIn })
|
|
843
|
-
] })
|
|
844
|
-
] })
|
|
845
|
-
] }),
|
|
846
|
-
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "products", label: OFFERS_COPY.products, ids: products, onChange: setProducts }),
|
|
847
|
-
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "collections", label: OFFERS_COPY.collections, ids: collections, onChange: setCollections }),
|
|
848
|
-
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "groups", label: OFFERS_COPY.groups, ids: groups, onChange: setGroups }),
|
|
849
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", "data-testid": "vonpay-rule-paid", children: [
|
|
850
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: OFFERS_COPY.paid }),
|
|
851
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.paidNote }),
|
|
852
|
-
paid.map((r, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_auto] items-center gap-2", children: [
|
|
853
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": "Currency", placeholder: "EUR", value: r.currency, maxLength: 3, onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, currency: e.target.value } : x)) }),
|
|
854
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": `${OFFERS_COPY.paidAtLeast} (${r.currency || "currency"})`, placeholder: OFFERS_COPY.paidAtLeast, value: r.min, maxLength: 17, inputMode: "decimal", onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, min: e.target.value } : x)) }),
|
|
855
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": `${OFFERS_COPY.paidAtMost} (${r.currency || "currency"})`, placeholder: OFFERS_COPY.paidAtMost, value: r.max, maxLength: 17, inputMode: "decimal", onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, max: e.target.value } : x)) }),
|
|
856
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "aria-label": `${OFFERS_COPY.removeCurrency} ${r.currency.toUpperCase()}`.trim(), onClick: () => setPaid(paid.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMarkMini, {}) })
|
|
857
|
-
] }, i)),
|
|
858
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", onClick: () => setPaid([...paid, { currency: "", min: "", max: "" }]), children: OFFERS_COPY.addCurrency }) })
|
|
859
|
-
] }),
|
|
860
|
-
problem && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-rules-problem", children: problem })
|
|
861
|
-
] }),
|
|
862
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
863
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => onOpenChange(false), children: OFFERS_COPY.cancel }),
|
|
864
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: busy, onClick: () => void save(), children: unreadable ? OFFERS_COPY.replaceRules : OFFERS_COPY.save })
|
|
865
|
-
] })
|
|
866
|
-
] }) });
|
|
867
|
-
}
|
|
868
|
-
function OfferWordingDrawer({ offer, open, onOpenChange, onSave, busy }) {
|
|
869
|
-
const start = offer.copy === "unreadable" ? null : offer.copy;
|
|
870
|
-
const [headline, setHeadline] = react.useState(start?.headline ?? "");
|
|
871
|
-
const [pitch, setPitch] = react.useState(start?.pitch ?? "");
|
|
872
|
-
const [problem, setProblem] = react.useState(null);
|
|
873
|
-
const save = async (copy) => {
|
|
874
|
-
setProblem(null);
|
|
875
|
-
const refused = await onSave(copy);
|
|
876
|
-
if (refused === null) onOpenChange(false);
|
|
877
|
-
else setProblem(refused);
|
|
878
|
-
};
|
|
879
|
-
const typed = () => {
|
|
880
|
-
const h = headline.trim();
|
|
881
|
-
const p = pitch.trim();
|
|
882
|
-
return h || p ? { ...h ? { headline: h } : {}, ...p ? { pitch: p } : {} } : null;
|
|
883
|
-
};
|
|
884
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
885
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
886
|
-
OFFERS_COPY.wording,
|
|
887
|
-
": ",
|
|
888
|
-
offer.name
|
|
889
|
-
] }) }),
|
|
890
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-4", children: [
|
|
891
|
-
offer.copy === "unreadable" && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-wording-unreadable", children: OFFERS_COPY.wordingUnreadable }),
|
|
892
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.wordingIntro }),
|
|
893
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
894
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-wording-headline", children: OFFERS_COPY.headline }),
|
|
895
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "vonpay-wording-headline", value: headline, maxLength: HEADLINE_MAX, onChange: (e) => setHeadline(e.target.value) }),
|
|
896
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.headlineHint })
|
|
897
|
-
] }),
|
|
898
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
899
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-wording-pitch", children: OFFERS_COPY.pitch }),
|
|
900
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { id: "vonpay-wording-pitch", value: pitch, maxLength: PITCH_MAX, rows: 4, onChange: (e) => setPitch(e.target.value) }),
|
|
901
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
902
|
-
OFFERS_COPY.pitchHint,
|
|
903
|
-
" (",
|
|
904
|
-
pitch.length,
|
|
905
|
-
"/",
|
|
906
|
-
PITCH_MAX,
|
|
907
|
-
")"
|
|
908
|
-
] })
|
|
909
|
-
] }),
|
|
910
|
-
offer.downsell_variant_id && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.wordingDownsellNote }),
|
|
911
|
-
problem && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-wording-problem", children: problem })
|
|
912
|
-
] }),
|
|
913
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
914
|
-
offer.copy !== null && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", disabled: busy, onClick: () => void save(null), children: OFFERS_COPY.wordingReset }),
|
|
915
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => onOpenChange(false), children: OFFERS_COPY.cancel }),
|
|
916
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: busy, onClick: () => void save(typed()), children: OFFERS_COPY.save })
|
|
917
|
-
] })
|
|
918
|
-
] }) });
|
|
919
|
-
}
|
|
920
|
-
const KEY = "vonpay-offers";
|
|
921
|
-
function useOffers() {
|
|
922
|
-
return reactQuery.useQuery({ queryKey: [KEY], queryFn: () => sdk.client.fetch("/admin/vonpay/offers") });
|
|
923
|
-
}
|
|
924
|
-
function useWrite(send) {
|
|
925
|
-
const qc = reactQuery.useQueryClient();
|
|
926
|
-
return reactQuery.useMutation({ mutationFn: send, retry: false, onSettled: () => qc.invalidateQueries({ queryKey: [KEY] }) });
|
|
927
705
|
}
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
});
|
|
933
|
-
const
|
|
934
|
-
const
|
|
935
|
-
const
|
|
936
|
-
const
|
|
937
|
-
const
|
|
938
|
-
const
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
setError(null);
|
|
953
|
-
try {
|
|
954
|
-
await work();
|
|
955
|
-
return true;
|
|
956
|
-
} catch (err) {
|
|
957
|
-
setError(errorSentence(err));
|
|
958
|
-
return false;
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
const onAdd = async (e) => {
|
|
962
|
-
e.preventDefault();
|
|
963
|
-
if (await run(() => create.mutateAsync({ name: name.trim(), variant_id: variantId.trim() }))) {
|
|
964
|
-
setName("");
|
|
965
|
-
setVariantId("");
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
const move = (offers, i, by) => {
|
|
969
|
-
const ids = offers.map((o) => o.id);
|
|
970
|
-
[ids[i], ids[i + by]] = [ids[i + by], ids[i]];
|
|
971
|
-
void run(() => reorder.mutateAsync({ ids }));
|
|
972
|
-
};
|
|
973
|
-
const onRemove = async (o) => {
|
|
974
|
-
if (await prompt({ title: OFFERS_COPY.remove, description: OFFERS_COPY.removeConfirm, confirmText: OFFERS_COPY.remove, cancelText: "Cancel" })) void run(() => remove.mutateAsync({ id: o.id }));
|
|
706
|
+
const Mono = ({ value, label }) => value ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
707
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "txt-compact-small font-mono truncate max-w-[180px]", title: value, children: value }),
|
|
708
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Copy, { content: value, variant: "mini", "aria-label": `Copy ${label}`, onClick: (e) => e.stopPropagation() })
|
|
709
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Unreadable" });
|
|
710
|
+
const ReasonBadge = ({ reason }) => /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { className: "whitespace-nowrap", color: reason === "unrecognised" ? "grey" : "orange", children: reasonCopy(reason).label });
|
|
711
|
+
const RowStatus = ({ status }) => /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { className: "whitespace-nowrap", color: statusColor(status), children: statusLabel(status) });
|
|
712
|
+
const RefundAction = ({ row, onResult }) => {
|
|
713
|
+
const [open, setOpen] = react.useState(false);
|
|
714
|
+
const preview = useRefundPreview(row, open);
|
|
715
|
+
const refund = useRefundHold();
|
|
716
|
+
const p = preview.data;
|
|
717
|
+
const description = preview.isLoading ? "Checking the payment with Vonpay…" : preview.isError ? (
|
|
718
|
+
routeRefusal(preview.error) ?? "Couldn't check the payment with Vonpay. Nothing was refunded."
|
|
719
|
+
) : p && p.refundable ? refundConfirmText(p) : outcomeCopy({ outcome: "refused", code: p?.code ?? null, recorded: true }).text;
|
|
720
|
+
const confirm = () => {
|
|
721
|
+
if (!p || !p.refundable) return;
|
|
722
|
+
refund.mutate(
|
|
723
|
+
{ row, amount_minor: p.amount_minor, currency: p.currency },
|
|
724
|
+
{
|
|
725
|
+
onSuccess: (o) => onResult(outcomeCopy(o)),
|
|
726
|
+
onError: (e) => onResult(postFailure(e)),
|
|
727
|
+
onSettled: () => setOpen(false)
|
|
728
|
+
}
|
|
729
|
+
);
|
|
975
730
|
};
|
|
976
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
977
|
-
/* @__PURE__ */ jsxRuntime.
|
|
978
|
-
|
|
979
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
OFFERS_COPY.lag
|
|
983
|
-
] })
|
|
984
|
-
] }),
|
|
985
|
-
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-8 w-full" }) }) : isError || !data ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", "data-testid": "vonpay-offers-load-error", children: errorSentence(loadError, OFFERS_COPY.loadFailed) }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
986
|
-
!data.upsells_on && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "warning", children: OFFERS_COPY.off }) }),
|
|
987
|
-
data.source === "config" && data.config.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2 px-6 py-4", "data-testid": "vonpay-offers-from-config", children: [
|
|
988
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "info", children: OFFERS_COPY.fromConfig }),
|
|
989
|
-
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc pl-6", children: data.config.map((c) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: productLabel(c) }) }, c.variant_id)) }),
|
|
990
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", disabled: busy, onClick: () => void run(() => importConfig.mutateAsync(void 0)), children: OFFERS_COPY.importButton }) })
|
|
731
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
732
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "primary", onClick: () => setOpen(true), children: "Refund in full…" }),
|
|
733
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt, { open, onOpenChange: (o) => !refund.isPending && setOpen(o), variant: "confirmation", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Content, { children: [
|
|
734
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Header, { children: [
|
|
735
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Title, { children: "Refund this payment in full?" }),
|
|
736
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Description, { children: description })
|
|
991
737
|
] }),
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.offers.map((o, i) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { "data-testid": "vonpay-offer-row", children: [
|
|
1004
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: o.name }),
|
|
1005
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: o.product_title === null ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-error", children: OFFERS_COPY.missingVariant }) : productLabel(o) }),
|
|
1006
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.rules}: ${o.name}`, disabled: busy, onClick: () => setEditing(o), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: o.rules === "unreadable" ? "text-ui-fg-error" : void 0, children: rulesSummary(o.rules) }) }) }),
|
|
1007
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.downsell}: ${o.name}`, disabled: busy, onClick: () => setDownsellFor(o), children: o.downsell_variant_id === null ? OFFERS_COPY.downsellNone : o.downsell_product_title === null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-ui-fg-error", children: OFFERS_COPY.downsellMissing }) : productLabel({ product_title: o.downsell_product_title, variant_title: o.downsell_variant_title, variant_id: o.downsell_variant_id }) }) }),
|
|
1008
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.wording}: ${o.name}`, disabled: busy, onClick: () => setWordingFor(o), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: `max-w-[16rem] truncate ${o.copy === "unreadable" ? "text-ui-fg-error" : ""}`, children: wordingSummary(o.copy) }) }) }),
|
|
1009
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Switch, { "aria-label": `${OFFERS_COPY.shown}: ${o.name}`, checked: o.enabled, disabled: busy, onCheckedChange: (on) => void run(() => update.mutateAsync({ id: o.id, enabled: on })) }) }),
|
|
1010
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-1", children: [
|
|
1011
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.up}: ${o.name}`, disabled: busy || i === 0, onClick: () => move(data.offers, i, -1), children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, {}) }),
|
|
1012
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.down}: ${o.name}`, disabled: busy || i === data.offers.length - 1, onClick: () => move(data.offers, i, 1), children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, {}) }),
|
|
1013
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.remove}: ${o.name}`, disabled: busy, onClick: () => void onRemove(o), children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}) })
|
|
1014
|
-
] }) })
|
|
1015
|
-
] }, o.id)) })
|
|
1016
|
-
] }) }),
|
|
1017
|
-
downsellFor && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1018
|
-
OfferDownsellDrawer,
|
|
1019
|
-
{
|
|
1020
|
-
offer: downsellFor,
|
|
1021
|
-
open: downsellFor !== null,
|
|
1022
|
-
busy,
|
|
1023
|
-
onOpenChange: (o) => !o && setDownsellFor(null),
|
|
1024
|
-
onSave: async (downsell) => {
|
|
1025
|
-
try {
|
|
1026
|
-
await update.mutateAsync({ id: downsellFor.id, downsell_variant_id: downsell });
|
|
1027
|
-
return null;
|
|
1028
|
-
} catch (err) {
|
|
1029
|
-
return errorSentence(err);
|
|
1030
|
-
}
|
|
738
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Footer, { children: [
|
|
739
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Cancel, { disabled: refund.isPending, children: "Cancel" }),
|
|
740
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
741
|
+
ui.Prompt.Action,
|
|
742
|
+
{
|
|
743
|
+
disabled: !p || !p.refundable || refund.isPending,
|
|
744
|
+
onClick: (e) => {
|
|
745
|
+
e.preventDefault();
|
|
746
|
+
confirm();
|
|
747
|
+
},
|
|
748
|
+
children: p && p.refundable ? refundActionLabel(p) : "Refund"
|
|
1031
749
|
}
|
|
750
|
+
)
|
|
751
|
+
] })
|
|
752
|
+
] }) })
|
|
753
|
+
] });
|
|
754
|
+
};
|
|
755
|
+
const CheckWithVonpayAction = ({ row, onResult }) => {
|
|
756
|
+
const reconcile = useReconcileHold();
|
|
757
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
758
|
+
ui.Button,
|
|
759
|
+
{
|
|
760
|
+
size: "small",
|
|
761
|
+
variant: "secondary",
|
|
762
|
+
isLoading: reconcile.isPending,
|
|
763
|
+
disabled: reconcile.isPending,
|
|
764
|
+
onClick: () => reconcile.mutate(row, {
|
|
765
|
+
onSuccess: (o) => onResult(reconcileCopy(o)),
|
|
766
|
+
onError: (e) => onResult({ variant: "error", text: routeRefusal(e) ?? "Couldn't check this payment with Vonpay. Nothing was changed." })
|
|
767
|
+
}),
|
|
768
|
+
children: CHECK_WITH_VONPAY
|
|
769
|
+
}
|
|
770
|
+
);
|
|
771
|
+
};
|
|
772
|
+
const MarkResolvedAction = ({ row, onResult }) => {
|
|
773
|
+
const [open, setOpen] = react.useState(false);
|
|
774
|
+
const [typed, setTyped] = react.useState("");
|
|
775
|
+
const mark = useMarkResolved();
|
|
776
|
+
const matches = markConfirmMatches(typed, row);
|
|
777
|
+
const inputId = `vonpay-mark-confirm-${row.vp_session_id ?? "unreadable"}`;
|
|
778
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
779
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
780
|
+
ui.Button,
|
|
781
|
+
{
|
|
782
|
+
size: "small",
|
|
783
|
+
variant: "secondary",
|
|
784
|
+
onClick: () => {
|
|
785
|
+
setTyped("");
|
|
786
|
+
setOpen(true);
|
|
1032
787
|
},
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
788
|
+
children: "Mark resolved…"
|
|
789
|
+
}
|
|
790
|
+
),
|
|
791
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt, { open, onOpenChange: (o) => !mark.isPending && setOpen(o), variant: "confirmation", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Content, { children: [
|
|
792
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Header, { children: [
|
|
793
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Title, { children: "Mark this payment resolved?" }),
|
|
794
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Description, { children: "Do this only after you've refunded it (for example from the command line) or settled it with the buyer. Nothing is sent to Vonpay. The buyer can no longer complete an order with this payment. It leaves this list and stays under Resolved, with your name on it; pressing Refund later still works." })
|
|
795
|
+
] }),
|
|
796
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2 px-6 pb-4", children: [
|
|
797
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Label, { htmlFor: inputId, size: "small", children: [
|
|
798
|
+
"Type this payment's Vonpay session id to confirm: ",
|
|
799
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono", children: row.vp_session_id })
|
|
800
|
+
] }),
|
|
801
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: inputId, size: "small", autoComplete: "off", value: typed, onChange: (e) => setTyped(e.target.value) })
|
|
802
|
+
] }),
|
|
803
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Footer, { children: [
|
|
804
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Cancel, { disabled: mark.isPending, children: "Cancel" }),
|
|
805
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
806
|
+
ui.Prompt.Action,
|
|
807
|
+
{
|
|
808
|
+
disabled: mark.isPending || !matches,
|
|
809
|
+
onClick: (e) => {
|
|
810
|
+
e.preventDefault();
|
|
811
|
+
if (!matches) return;
|
|
812
|
+
mark.mutate({ row, confirm_vp_session_id: typed }, {
|
|
813
|
+
onSuccess: (o) => onResult(resolveOutcomeCopy(o)),
|
|
814
|
+
onError: (e2) => {
|
|
815
|
+
const f = postFailure(e2);
|
|
816
|
+
onResult(f.variant === "error" ? f : { variant: "warning", text: "Couldn't confirm that it was saved. Reload the list." });
|
|
817
|
+
},
|
|
818
|
+
onSettled: () => setOpen(false)
|
|
819
|
+
});
|
|
820
|
+
},
|
|
821
|
+
children: "Mark resolved"
|
|
1049
822
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
823
|
+
)
|
|
824
|
+
] })
|
|
825
|
+
] }) })
|
|
826
|
+
] });
|
|
827
|
+
};
|
|
828
|
+
const WalletHoldAction = ({ row, kind, onResult }) => {
|
|
829
|
+
const [open, setOpen] = react.useState(false);
|
|
830
|
+
const release = useReleaseHold();
|
|
831
|
+
const complete = useCompleteHold();
|
|
832
|
+
const pending = release.isPending || complete.isPending;
|
|
833
|
+
const text = kind === "release" ? { button: "Release…", title: "Release this held payment?", body: "The hold is cancelled at Vonpay and drops off the buyer's card. Nothing was taken, so nothing is refunded. The buyer can't complete an order with this payment afterwards.", action: "Release" } : { button: "Complete the order…", title: "Create the order from this payment?", body: "Medusa completes the buyer's checkout with this held payment and creates the order; the payment is then taken with the order. Do this only if you intend to fulfil it.", action: "Complete the order" };
|
|
834
|
+
const fail = (e2) => {
|
|
835
|
+
const f = postFailure(e2);
|
|
836
|
+
onResult(f.variant === "error" ? f : { variant: "warning", text: "Couldn't confirm the outcome. Reload the list." });
|
|
837
|
+
};
|
|
838
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
839
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: kind === "release" ? "secondary" : "primary", onClick: () => setOpen(true), children: text.button }),
|
|
840
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt, { open, onOpenChange: (o) => !pending && setOpen(o), variant: "confirmation", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Content, { children: [
|
|
841
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Header, { children: [
|
|
842
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Title, { children: text.title }),
|
|
843
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Description, { children: text.body })
|
|
844
|
+
] }),
|
|
845
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Footer, { children: [
|
|
846
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Cancel, { disabled: pending, children: "Cancel" }),
|
|
847
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
848
|
+
ui.Prompt.Action,
|
|
849
|
+
{
|
|
850
|
+
disabled: pending,
|
|
851
|
+
onClick: (e) => {
|
|
852
|
+
e.preventDefault();
|
|
853
|
+
if (kind === "release") release.mutate({ row }, { onSuccess: (o) => onResult(releaseOutcomeCopy(o)), onError: fail, onSettled: () => setOpen(false) });
|
|
854
|
+
else complete.mutate({ row }, { onSuccess: (o) => onResult(completeOutcomeCopy(o)), onError: fail, onSettled: () => setOpen(false) });
|
|
855
|
+
},
|
|
856
|
+
children: text.action
|
|
1067
857
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
858
|
+
)
|
|
859
|
+
] })
|
|
860
|
+
] }) })
|
|
861
|
+
] });
|
|
862
|
+
};
|
|
863
|
+
const HoldDrawer = ({ row, onClose }) => {
|
|
864
|
+
const copy = row ? reasonCopy(row.reason) : void 0;
|
|
865
|
+
const known = row ? isKnownStatus(row.status) && !isUnrecognisedRecord(row) : false;
|
|
866
|
+
const showRefund = !!row && known && canRefund(row);
|
|
867
|
+
const showMark = !!row && known && canMarkResolved(row);
|
|
868
|
+
const showRelease = !!row && known && canRelease(row);
|
|
869
|
+
const showComplete = !!row && known && canComplete(row);
|
|
870
|
+
const showOpenOrder = !!row && known && canOpenOrder(row);
|
|
871
|
+
const steps = row ? resolutionSteps(known ? row : { ...row, reason: "unrecognised" }) : [];
|
|
872
|
+
const [result, setResult] = react.useState(null);
|
|
873
|
+
const close = () => {
|
|
874
|
+
setResult(null);
|
|
875
|
+
onClose();
|
|
876
|
+
};
|
|
877
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open: row !== null, onOpenChange: (open) => !open && close(), children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { children: [
|
|
878
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Header, { children: [
|
|
879
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Title, { children: copy?.label ?? "Held payment" }),
|
|
880
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Description, { children: copy?.what })
|
|
881
|
+
] }),
|
|
882
|
+
row && /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
883
|
+
/* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-2", children: [
|
|
884
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Status" }),
|
|
885
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(RowStatus, { status: row.status }) }),
|
|
886
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Held since" }),
|
|
887
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "txt-compact-small", children: row.held_at ? new Date(row.held_at).toLocaleString() : "Unknown" }),
|
|
888
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Where" }),
|
|
889
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "txt-compact-small", children: SOURCE_LABEL[row.source] ?? row.source }),
|
|
890
|
+
row.retry_until && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
891
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Retrying until" }),
|
|
892
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "txt-compact-small", children: new Date(row.retry_until).toLocaleString() })
|
|
893
|
+
] }),
|
|
894
|
+
fromBuyerCheckout(row) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
895
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Evidence" }),
|
|
896
|
+
/* @__PURE__ */ jsxRuntime.jsxs("dd", { className: "flex flex-col gap-y-1", children: [
|
|
897
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { className: "w-fit whitespace-nowrap", color: "grey", children: FROM_BUYER_CHECKOUT }),
|
|
898
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: FROM_BUYER_CHECKOUT_NOTE })
|
|
1081
899
|
] })
|
|
1082
900
|
] }),
|
|
1083
|
-
|
|
901
|
+
row.order_id && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
902
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Order" }),
|
|
903
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.order_id, label: "order id" }) })
|
|
904
|
+
] }),
|
|
905
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Vonpay session" }),
|
|
906
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.vp_session_id, label: "Vonpay session id" }) }),
|
|
907
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Medusa payment session" }),
|
|
908
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.medusa_payment_session_id, label: "Medusa payment session id" }) }),
|
|
909
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Payment collection" }),
|
|
910
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.payment_collection_id, label: "payment collection id" }) }),
|
|
911
|
+
row.resolution && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
912
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: row.status === "resolved" ? "Resolved" : "Last action" }),
|
|
913
|
+
/* @__PURE__ */ jsxRuntime.jsxs("dd", { className: "txt-compact-small", children: [
|
|
914
|
+
row.resolution.how ? `${RESOLVED_HOW_LABEL[row.resolution.how] ?? row.resolution.how} · ` : "",
|
|
915
|
+
new Date(row.resolution.at).toLocaleString(),
|
|
916
|
+
" · by ",
|
|
917
|
+
actorLabel(row.resolution)
|
|
918
|
+
] }),
|
|
919
|
+
row.resolution.refund_id && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
920
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Vonpay refund" }),
|
|
921
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.resolution.refund_id, label: "Vonpay refund id" }) })
|
|
922
|
+
] }),
|
|
923
|
+
row.resolution.prior && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
924
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "txt-compact-small text-ui-fg-subtle", children: "Before that" }),
|
|
925
|
+
/* @__PURE__ */ jsxRuntime.jsxs("dd", { className: "txt-compact-small", children: [
|
|
926
|
+
row.resolution.prior.how ? `${RESOLVED_HOW_LABEL[row.resolution.prior.how] ?? row.resolution.prior.how}` : statusLabel(row.resolution.prior.state),
|
|
927
|
+
` · ${new Date(row.resolution.prior.at).toLocaleString()} · by ${actorLabel(row.resolution.prior)}`
|
|
928
|
+
] })
|
|
929
|
+
] })
|
|
930
|
+
] })
|
|
931
|
+
] }),
|
|
932
|
+
result && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: result.variant, children: result.text }),
|
|
933
|
+
(showRefund || showMark || showRelease || showComplete || showOpenOrder) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2", children: [
|
|
934
|
+
showOpenOrder && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "primary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: orderPath(row.order_id), children: "Open order" }) }),
|
|
935
|
+
showComplete && /* @__PURE__ */ jsxRuntime.jsx(WalletHoldAction, { row, kind: "complete", onResult: setResult }),
|
|
936
|
+
showRelease && /* @__PURE__ */ jsxRuntime.jsx(WalletHoldAction, { row, kind: "release", onResult: setResult }),
|
|
937
|
+
showRefund && /* @__PURE__ */ jsxRuntime.jsx(RefundAction, { row, onResult: setResult }),
|
|
938
|
+
showRefund && /* @__PURE__ */ jsxRuntime.jsx(CheckWithVonpayAction, { row, onResult: setResult }),
|
|
939
|
+
showMark && /* @__PURE__ */ jsxRuntime.jsx(MarkResolvedAction, { row, onResult: setResult })
|
|
940
|
+
] }),
|
|
941
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
942
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", children: "Or do it by hand" }),
|
|
943
|
+
steps.map((step) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
944
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: step.title }),
|
|
945
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: step.body }),
|
|
946
|
+
step.command && /* @__PURE__ */ jsxRuntime.jsxs(ui.CodeBlock, { snippets: [{ label: "Terminal", language: "bash", code: step.command, hideLineNumbers: true }], children: [
|
|
947
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.CodeBlock.Header, {}),
|
|
948
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.CodeBlock.Body, {})
|
|
949
|
+
] })
|
|
950
|
+
] }, step.title)),
|
|
951
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: STILL_LISTED_NOTE })
|
|
1084
952
|
] })
|
|
1085
953
|
] })
|
|
1086
|
-
] });
|
|
1087
|
-
};
|
|
1088
|
-
const config$2 = adminSdk.defineRouteConfig({
|
|
1089
|
-
label: "One-click offers",
|
|
1090
|
-
icon: icons.Sparkles,
|
|
1091
|
-
nested: "/orders"
|
|
1092
|
-
});
|
|
1093
|
-
const EVENT_LABEL = {
|
|
1094
|
-
"subscription.created": "Signed up",
|
|
1095
|
-
"subscription.renewed": "Renewal paid",
|
|
1096
|
-
"subscription.payment_failed": "Renewal declined",
|
|
1097
|
-
"subscription.cancelled": "Cancelled",
|
|
1098
|
-
"subscription.updated": "Changed"
|
|
1099
|
-
};
|
|
1100
|
-
const eventLabel = (type) => EVENT_LABEL[type] ?? "Other";
|
|
1101
|
-
const amountLabel = (major, currency) => major && currency ? `${major} ${currency}` : "—";
|
|
1102
|
-
const NOT_ENABLED_NOTE = `Vonpay is not running this store's subscriptions. To let it, set the payment provider's subscriptions option to "vonpay", register the plugin's subscriptions module in medusa-config, run npx medusa db:migrate and restart — the setup check confirms each step.`;
|
|
1103
|
-
const ORDERS_NOT_YET_NOTE = "Renewal orders are not created from these notifications yet: this list shows what Vonpay reported, so nothing here changes an order.";
|
|
1104
|
-
const SUBSCRIPTION_PAGE_SIZE = 20;
|
|
1105
|
-
function useSubscriptionEvents(page) {
|
|
1106
|
-
return reactQuery.useQuery({
|
|
1107
|
-
queryKey: ["vonpay-subscription-events", page.limit, page.offset],
|
|
1108
|
-
queryFn: () => sdk.client.fetch("/admin/vonpay/subscriptions", { query: { limit: page.limit, offset: page.offset } }),
|
|
1109
|
-
placeholderData: reactQuery.keepPreviousData
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
const pageCountFor = (count) => {
|
|
1113
|
-
const remainder = count % SUBSCRIPTION_PAGE_SIZE;
|
|
1114
|
-
return Math.max(1, (count - remainder) / SUBSCRIPTION_PAGE_SIZE + (remainder > 0 ? 1 : 0));
|
|
954
|
+
] }) });
|
|
1115
955
|
};
|
|
1116
|
-
const
|
|
1117
|
-
const
|
|
956
|
+
const FILTER_LABEL = { open: "Needs action", resolved: "Resolved", all: "All" };
|
|
957
|
+
const HeldPaymentsPage = () => {
|
|
1118
958
|
const [pageIndex, setPageIndex] = react.useState(0);
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
959
|
+
const [filter, setFilter] = react.useState("open");
|
|
960
|
+
const [opened, setOpened] = react.useState(null);
|
|
961
|
+
const { data, isLoading, isError, refetch } = useHeldPayments({ limit: HELD_PAGE_SIZE, offset: pageIndex * HELD_PAGE_SIZE, status: filter });
|
|
962
|
+
const count = data?.count ?? 0;
|
|
963
|
+
const remainder = count % HELD_PAGE_SIZE;
|
|
964
|
+
const pageCount = Math.max(1, (count - remainder) / HELD_PAGE_SIZE + (remainder > 0 ? 1 : 0));
|
|
965
|
+
const keyOf = (row) => `${row.payment_collection_id}:${row.vp_session_id ?? "unreadable"}:${row.source}:${row.payment_id ?? ""}:${row.medusa_payment_session_id ?? ""}`;
|
|
966
|
+
const open = opened ? data?.holds.find((r) => keyOf(r) === keyOf(opened)) ?? opened : null;
|
|
967
|
+
const onRowKey = (row) => (e) => {
|
|
968
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
969
|
+
e.preventDefault();
|
|
970
|
+
setOpened(row);
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
|
|
974
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
975
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4 px-6 py-4", children: [
|
|
976
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
977
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Held payments" }),
|
|
978
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Buyers who were charged through Vonpay but whose order couldn't be completed safely, cancelled orders whose refund Vonpay hasn't confirmed, and Apple Pay / Google Pay payments not yet collected for an order. Nothing here is refunded automatically." })
|
|
979
|
+
] }),
|
|
980
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-[180px]", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
981
|
+
ui.Select,
|
|
982
|
+
{
|
|
983
|
+
size: "small",
|
|
984
|
+
value: filter,
|
|
985
|
+
onValueChange: (v) => {
|
|
986
|
+
setFilter(v);
|
|
987
|
+
setPageIndex(0);
|
|
988
|
+
},
|
|
989
|
+
children: [
|
|
990
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { "aria-label": "Show", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
991
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: ["open", "resolved", "all"].map((f) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: f, children: FILTER_LABEL[f] }, f)) })
|
|
992
|
+
]
|
|
993
|
+
}
|
|
994
|
+
) })
|
|
995
|
+
] }),
|
|
996
|
+
data && !data.scan_complete && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "warning", children: "This list may be incomplete: the store has more records than one page load can check." }) }),
|
|
997
|
+
isError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-y-3 px-6 py-6", children: [
|
|
998
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Couldn't load held payments." }),
|
|
999
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", onClick: () => refetch(), children: "Try again" })
|
|
1000
|
+
] }) : isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-3 px-6 py-6", "aria-busy": "true", "aria-label": "Loading held payments", children: [0, 1, 2].map((i) => /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-6 w-full" }, i)) }) : count === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-10", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: filter === "resolved" ? "Nothing resolved yet." : "No held payments. When a buyer is charged but the order can't be completed safely, it appears here." }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1128
1001
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
1129
1002
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1130
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1131
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1132
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1133
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1134
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1135
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1003
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Reason" }),
|
|
1004
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Status" }),
|
|
1005
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Held since" }),
|
|
1006
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Vonpay session" }),
|
|
1007
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Medusa payment session" }),
|
|
1008
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Where" })
|
|
1136
1009
|
] }) }),
|
|
1137
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1010
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.holds.map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1011
|
+
ui.Table.Row,
|
|
1012
|
+
{
|
|
1013
|
+
className: "cursor-pointer",
|
|
1014
|
+
tabIndex: 0,
|
|
1015
|
+
role: "button",
|
|
1016
|
+
"aria-label": `${reasonCopy(row.reason).label}, ${statusLabel(row.status)}, open details`,
|
|
1017
|
+
onClick: () => setOpened(row),
|
|
1018
|
+
onKeyDown: onRowKey(row),
|
|
1019
|
+
children: [
|
|
1020
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ReasonBadge, { reason: row.reason }) }),
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(RowStatus, { status: row.status }) }),
|
|
1022
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: row.held_at ? new Date(row.held_at).toLocaleString() : "Unknown", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "txt-compact-small whitespace-nowrap", children: since(row.held_at) }) }) }),
|
|
1023
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.vp_session_id, label: "Vonpay session id" }) }),
|
|
1024
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.medusa_payment_session_id, label: "Medusa payment session id" }) }),
|
|
1025
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1026
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "txt-compact-small text-ui-fg-subtle whitespace-nowrap", children: SOURCE_LABEL[row.source] }),
|
|
1027
|
+
fromBuyerCheckout(row) && /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { className: "w-fit whitespace-nowrap", color: "grey", children: FROM_BUYER_CHECKOUT })
|
|
1028
|
+
] }) })
|
|
1029
|
+
]
|
|
1030
|
+
},
|
|
1031
|
+
keyOf(row)
|
|
1032
|
+
)) })
|
|
1148
1033
|
] }) }),
|
|
1149
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1034
|
+
pageCount > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1150
1035
|
ui.Table.Pagination,
|
|
1151
1036
|
{
|
|
1152
|
-
count
|
|
1153
|
-
pageSize:
|
|
1037
|
+
count,
|
|
1038
|
+
pageSize: HELD_PAGE_SIZE,
|
|
1154
1039
|
pageIndex,
|
|
1155
|
-
pageCount
|
|
1040
|
+
pageCount,
|
|
1156
1041
|
canPreviousPage: pageIndex > 0,
|
|
1157
|
-
canNextPage:
|
|
1042
|
+
canNextPage: pageIndex + 1 < pageCount,
|
|
1158
1043
|
previousPage: () => setPageIndex((p) => Math.max(0, p - 1)),
|
|
1159
1044
|
nextPage: () => setPageIndex((p) => p + 1)
|
|
1160
1045
|
}
|
|
1161
1046
|
)
|
|
1162
|
-
] })
|
|
1163
|
-
|
|
1047
|
+
] }),
|
|
1048
|
+
/* @__PURE__ */ jsxRuntime.jsx(HoldDrawer, { row: open, onClose: () => setOpened(null) })
|
|
1049
|
+
] }),
|
|
1050
|
+
/* @__PURE__ */ jsxRuntime.jsx(SetupCheckPanel, {})
|
|
1164
1051
|
] });
|
|
1165
1052
|
};
|
|
1166
|
-
const config$
|
|
1167
|
-
label: "
|
|
1168
|
-
icon: icons.
|
|
1053
|
+
const config$2 = adminSdk.defineRouteConfig({
|
|
1054
|
+
label: "Held payments",
|
|
1055
|
+
icon: icons.ExclamationCircle,
|
|
1169
1056
|
nested: "/orders"
|
|
1170
1057
|
});
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1058
|
+
const HEADLINE_MAX = 80;
|
|
1059
|
+
const PITCH_MAX = 300;
|
|
1060
|
+
const OFFERS_COPY = {
|
|
1061
|
+
title: "One-click offers",
|
|
1062
|
+
intro: "After paying, shoppers see these offers one at a time (up to three per order), in this order. Only switched-on offers are shown.",
|
|
1063
|
+
off: "One-click offers are off. Turn them on with the upsells option in medusa-config; the offers below are kept.",
|
|
1064
|
+
fromConfig: "Your offers come from medusa-config right now (upsells.variantIds). Import them to manage them here. Once an offer exists here, this list is used instead.",
|
|
1065
|
+
configEmpty: "No offers yet. Add the first one below.",
|
|
1066
|
+
adminEmpty: "No offers are shown to shoppers. Add one below.",
|
|
1067
|
+
importButton: "Import from medusa-config",
|
|
1068
|
+
add: "Add offer",
|
|
1069
|
+
name: "Name (only you see it)",
|
|
1070
|
+
variant: "Product variant id (variant_…)",
|
|
1071
|
+
shown: "Shown",
|
|
1072
|
+
up: "Move up",
|
|
1073
|
+
down: "Move down",
|
|
1074
|
+
remove: "Remove",
|
|
1075
|
+
removeConfirm: "Remove this offer? A shopper already paying for it is not affected.",
|
|
1076
|
+
missingVariant: "This product variant no longer exists — it is not offered.",
|
|
1077
|
+
loadFailed: "The offers could not be loaded. Reload the page to try again.",
|
|
1078
|
+
lag: "A change shows on your store at once; with more than one server it can take up to 30 seconds everywhere.",
|
|
1079
|
+
rules: "Who sees it",
|
|
1080
|
+
downsell: "If they say No thanks",
|
|
1081
|
+
downsellNone: "Nothing",
|
|
1082
|
+
downsellIntro: 'Show one other product after a shopper says No thanks to this offer — usually a smaller or cheaper option. It counts toward the three offers per order, and the same "Who sees it" applies.',
|
|
1083
|
+
downsellVariant: "Downsell product variant id (variant_…)",
|
|
1084
|
+
downsellRemove: "Remove downsell",
|
|
1085
|
+
downsellMissing: "This product variant no longer exists — it is not offered.",
|
|
1086
|
+
wording: "Wording",
|
|
1087
|
+
wordingDefault: "Standard",
|
|
1088
|
+
wordingPitchOnly: "Pitch only",
|
|
1089
|
+
wordingUnreadable: "The saved wording can't be read, so shoppers see the standard wording. Save it again.",
|
|
1090
|
+
wordingIntro: "What shoppers read on this offer. Leave a field empty to use the standard wording. The payment line, the buttons and every result message stay the same.",
|
|
1091
|
+
headline: "Headline",
|
|
1092
|
+
headlineHint: 'Replaces the heading. Standard: "Add this to your order?"',
|
|
1093
|
+
pitch: "Pitch",
|
|
1094
|
+
pitchHint: "Replaces the product's description under its name. A phone shows about two lines.",
|
|
1095
|
+
wordingDownsellNote: `A downsell keeps the standard wording: "How about this instead?" and its product's description.`,
|
|
1096
|
+
wordingReset: "Use the standard wording",
|
|
1097
|
+
rulesEveryone: "Everyone",
|
|
1098
|
+
rulesUnreadable: "Its rules can't be read, so it is not shown. Set them again.",
|
|
1099
|
+
rulesIntro: "Show this offer only when ALL the conditions you set match. Leave a condition empty to ignore it.",
|
|
1100
|
+
customers: "Customers",
|
|
1101
|
+
customersAll: "Everyone",
|
|
1102
|
+
customersGuests: "Guests only",
|
|
1103
|
+
customersSignedIn: "Signed-in customers only",
|
|
1104
|
+
products: "The shopper bought one of these products at checkout",
|
|
1105
|
+
collections: "The shopper bought a product from one of these collections at checkout",
|
|
1106
|
+
groups: "The signed-in customer is in one of these groups",
|
|
1107
|
+
paid: "The amount paid at checkout (tax and shipping included)",
|
|
1108
|
+
paidNote: "An order in a currency not listed here does not see this offer.",
|
|
1109
|
+
paidAtLeast: "At least",
|
|
1110
|
+
paidAtMost: "At most",
|
|
1111
|
+
search: "Search by name",
|
|
1112
|
+
addCurrency: "Add currency",
|
|
1113
|
+
removeCurrency: "Remove currency",
|
|
1114
|
+
rulesUnreadableNotice: "The saved rules for this offer can't be read, so the offer is not shown. Saving replaces them with what you set here.",
|
|
1115
|
+
replaceRules: "Replace the rules",
|
|
1116
|
+
save: "Save",
|
|
1117
|
+
cancel: "Cancel",
|
|
1118
|
+
saveFailed: "That change was not saved."
|
|
1202
1119
|
};
|
|
1203
|
-
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
function
|
|
1210
|
-
if (
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
return
|
|
1120
|
+
function errorSentence(err, fallback = OFFERS_COPY.saveFailed) {
|
|
1121
|
+
const m = err?.message;
|
|
1122
|
+
if (typeof m !== "string") return fallback;
|
|
1123
|
+
const i = m.indexOf(": ");
|
|
1124
|
+
return m.startsWith("vonpay_") && i > 0 ? m.slice(i + 2) : fallback;
|
|
1125
|
+
}
|
|
1126
|
+
function productLabel(o) {
|
|
1127
|
+
if (o.product_title === null) return o.variant_id;
|
|
1128
|
+
return [o.product_title, o.variant_title].filter((x) => x && x !== "Default variant").join(" — ");
|
|
1129
|
+
}
|
|
1130
|
+
function wordingSummary(copy) {
|
|
1131
|
+
if (copy === "unreadable") return OFFERS_COPY.wordingUnreadable;
|
|
1132
|
+
if (!copy) return OFFERS_COPY.wordingDefault;
|
|
1133
|
+
return copy.headline ?? OFFERS_COPY.wordingPitchOnly;
|
|
1134
|
+
}
|
|
1135
|
+
function rulesSummary(rules) {
|
|
1136
|
+
if (rules === "unreadable") return OFFERS_COPY.rulesUnreadable;
|
|
1137
|
+
if (!rules) return OFFERS_COPY.rulesEveryone;
|
|
1138
|
+
const parts = [];
|
|
1139
|
+
if (rules.customers === "guests") parts.push("Guests");
|
|
1140
|
+
if (rules.customers === "signed_in") parts.push("Signed-in");
|
|
1141
|
+
if (rules.groups) parts.push(`${rules.groups.length} group${rules.groups.length === 1 ? "" : "s"}`);
|
|
1142
|
+
if (rules.products) parts.push(`${rules.products.length} product${rules.products.length === 1 ? "" : "s"}`);
|
|
1143
|
+
if (rules.collections) parts.push(`${rules.collections.length} collection${rules.collections.length === 1 ? "" : "s"}`);
|
|
1144
|
+
for (const [c, n] of Object.entries(rules.min_paid ?? {})) parts.push(`paid ≥ ${n} ${c.toUpperCase()}`);
|
|
1145
|
+
for (const [c, n] of Object.entries(rules.max_paid ?? {})) parts.push(`paid ≤ ${n} ${c.toUpperCase()}`);
|
|
1146
|
+
return parts.length ? parts.join(" · ") : OFFERS_COPY.rulesEveryone;
|
|
1147
|
+
}
|
|
1148
|
+
function OfferDownsellDrawer({ offer, open, onOpenChange, onSave, busy }) {
|
|
1149
|
+
const [variant, setVariant] = react.useState(offer.downsell_variant_id ?? "");
|
|
1150
|
+
const [problem, setProblem] = react.useState(null);
|
|
1151
|
+
const save = async (value) => {
|
|
1152
|
+
if (value !== null && !/^variant_[A-Za-z0-9]{1,64}$/.test(value)) return setProblem("Enter a product variant id, like variant_01H….");
|
|
1153
|
+
setProblem(null);
|
|
1154
|
+
const refused = await onSave(value);
|
|
1155
|
+
if (refused === null) onOpenChange(false);
|
|
1156
|
+
else setProblem(refused);
|
|
1157
|
+
};
|
|
1158
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
1159
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
1160
|
+
OFFERS_COPY.downsell,
|
|
1161
|
+
": ",
|
|
1162
|
+
offer.name
|
|
1163
|
+
] }) }),
|
|
1164
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-4", children: [
|
|
1165
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.downsellIntro }),
|
|
1166
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1167
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-downsell-variant", children: OFFERS_COPY.downsellVariant }),
|
|
1168
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "vonpay-downsell-variant", value: variant, maxLength: 72, onChange: (e) => setVariant(e.target.value) })
|
|
1169
|
+
] }),
|
|
1170
|
+
problem && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-downsell-problem", children: problem })
|
|
1171
|
+
] }),
|
|
1172
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
1173
|
+
offer.downsell_variant_id && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "danger", disabled: busy, onClick: () => void save(null), children: OFFERS_COPY.downsellRemove }),
|
|
1174
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => onOpenChange(false), children: OFFERS_COPY.cancel }),
|
|
1175
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: busy, onClick: () => void save(variant.trim()), children: OFFERS_COPY.save })
|
|
1176
|
+
] })
|
|
1177
|
+
] }) });
|
|
1216
1178
|
}
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
refund_unknown: "red",
|
|
1222
|
-
refund_sending: "red",
|
|
1223
|
-
resolved: "green"
|
|
1179
|
+
const SOURCES = {
|
|
1180
|
+
products: { path: "/admin/products", key: "products", label: "title" },
|
|
1181
|
+
collections: { path: "/admin/collections", key: "collections", label: "title" },
|
|
1182
|
+
groups: { path: "/admin/customer-groups", key: "customer_groups", label: "name" }
|
|
1224
1183
|
};
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1184
|
+
async function fetchNamed(kind, query) {
|
|
1185
|
+
const s = SOURCES[kind];
|
|
1186
|
+
const body = await sdk.client.fetch(s.path, { query: { ...query, fields: `id,${s.label}` } });
|
|
1187
|
+
const plain = (t) => t.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, "").trim();
|
|
1188
|
+
return (body[s.key] ?? []).flatMap((r) => typeof r.id === "string" ? [{ id: r.id, label: typeof r[s.label] === "string" && plain(r[s.label]) || r.id }] : []);
|
|
1228
1189
|
}
|
|
1229
|
-
function
|
|
1230
|
-
|
|
1190
|
+
function Picker({ kind, label, ids, onChange }) {
|
|
1191
|
+
const [q, setQ] = react.useState("");
|
|
1192
|
+
const names = reactQuery.useQuery({ queryKey: ["vonpay-offer-rule-names", kind, ids], queryFn: () => fetchNamed(kind, { id: ids, limit: ids.length }), enabled: ids.length > 0 });
|
|
1193
|
+
const found = reactQuery.useQuery({ queryKey: ["vonpay-offer-rule-search", kind, q], queryFn: () => fetchNamed(kind, { q, limit: 8 }), enabled: q.trim().length >= 2, placeholderData: reactQuery.keepPreviousData });
|
|
1194
|
+
const nameOf = (id) => names.data?.find((n) => n.id === id)?.label ?? id;
|
|
1195
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", "data-testid": `vonpay-rule-${kind}`, children: [
|
|
1196
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: label }),
|
|
1197
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: ids.map((id) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "bg-ui-bg-subtle flex items-center gap-x-1 rounded-md px-2 py-1", children: [
|
|
1198
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: nameOf(id) }),
|
|
1199
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "aria-label": `Remove ${nameOf(id)}`, onClick: () => onChange(ids.filter((x) => x !== id)), children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMarkMini, {}) })
|
|
1200
|
+
] }, id)) }),
|
|
1201
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { placeholder: OFFERS_COPY.search, value: q, maxLength: 100, "aria-label": `${label}: ${OFFERS_COPY.search}`, onChange: (e) => setQ(e.target.value) }),
|
|
1202
|
+
(q.trim().length >= 2 ? found.data ?? [] : []).filter((n) => !ids.includes(n.id)).map((n) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { size: "small", variant: "transparent", type: "button", onClick: () => onChange([...ids, n.id]), children: [
|
|
1203
|
+
"+ ",
|
|
1204
|
+
n.label
|
|
1205
|
+
] }, n.id))
|
|
1206
|
+
] });
|
|
1231
1207
|
}
|
|
1232
|
-
function
|
|
1233
|
-
|
|
1208
|
+
function rowsOf(rules) {
|
|
1209
|
+
const cs = [.../* @__PURE__ */ new Set([...Object.keys(rules?.min_paid ?? {}), ...Object.keys(rules?.max_paid ?? {})])];
|
|
1210
|
+
return cs.map((c) => ({ currency: c, min: rules?.min_paid?.[c] ?? "", max: rules?.max_paid?.[c] ?? "" }));
|
|
1234
1211
|
}
|
|
1235
|
-
function
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
return
|
|
1212
|
+
function amountText(text) {
|
|
1213
|
+
const t = text.trim().replace(",", ".");
|
|
1214
|
+
if (t === "") return void 0;
|
|
1215
|
+
return /^\d{1,10}(\.\d{1,6})?$/.test(t) ? t : null;
|
|
1239
1216
|
}
|
|
1240
|
-
function
|
|
1241
|
-
const
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1217
|
+
function rulesFromForm(f) {
|
|
1218
|
+
const out = {};
|
|
1219
|
+
if (f.customers !== "all") out.customers = f.customers;
|
|
1220
|
+
if (f.products.length) out.products = f.products;
|
|
1221
|
+
if (f.collections.length) out.collections = f.collections;
|
|
1222
|
+
if (f.groups.length) out.groups = f.groups;
|
|
1223
|
+
for (const r of f.paid) {
|
|
1224
|
+
const c = r.currency.trim().toLowerCase();
|
|
1225
|
+
if (!c && !r.min.trim() && !r.max.trim()) continue;
|
|
1226
|
+
if (!/^[a-z]{3}$/.test(c)) return "Use a 3-letter currency code, like EUR.";
|
|
1227
|
+
const min = amountText(r.min);
|
|
1228
|
+
const max = amountText(r.max);
|
|
1229
|
+
if (min === null || max === null) return `Enter a plain amount for ${c.toUpperCase()}, like 49.95.`;
|
|
1230
|
+
if (min === void 0 && max === void 0) return `Enter the least or the most for ${c.toUpperCase()}, or remove its row.`;
|
|
1231
|
+
if (out.min_paid?.[c] !== void 0 || out.max_paid?.[c] !== void 0) return `${c.toUpperCase()} is listed twice.`;
|
|
1232
|
+
if (min !== void 0) out.min_paid = { ...out.min_paid, [c]: min };
|
|
1233
|
+
if (max !== void 0) out.max_paid = { ...out.max_paid, [c]: max };
|
|
1234
|
+
}
|
|
1235
|
+
if (out.customers === "guests" && out.groups) return "Groups apply to signed-in customers only.";
|
|
1236
|
+
return Object.keys(out).length ? out : null;
|
|
1247
1237
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
const
|
|
1253
|
-
const
|
|
1254
|
-
const
|
|
1255
|
-
const [
|
|
1256
|
-
const
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
refund.mutate(
|
|
1265
|
-
{ row, amount_minor: p.amount_minor, currency: p.currency },
|
|
1266
|
-
{
|
|
1267
|
-
onSuccess: (o) => onResult(outcomeCopy(o)),
|
|
1268
|
-
onError: (e) => onResult(postFailure(e)),
|
|
1269
|
-
onSettled: () => setOpen(false)
|
|
1270
|
-
}
|
|
1271
|
-
);
|
|
1238
|
+
function OfferRulesDrawer({ offer, open, onOpenChange, onSave, busy }) {
|
|
1239
|
+
const unreadable = offer.rules === "unreadable";
|
|
1240
|
+
const start = offer.rules === "unreadable" ? null : offer.rules;
|
|
1241
|
+
const [customers, setCustomers] = react.useState(start?.customers ?? "all");
|
|
1242
|
+
const [products, setProducts] = react.useState(start?.products ?? []);
|
|
1243
|
+
const [collections, setCollections] = react.useState(start?.collections ?? []);
|
|
1244
|
+
const [groups, setGroups] = react.useState(start?.groups ?? []);
|
|
1245
|
+
const [paid, setPaid] = react.useState(rowsOf(start));
|
|
1246
|
+
const [problem, setProblem] = react.useState(null);
|
|
1247
|
+
const save = async () => {
|
|
1248
|
+
const r = rulesFromForm({ customers, products, collections, groups, paid });
|
|
1249
|
+
if (typeof r === "string") return setProblem(r);
|
|
1250
|
+
setProblem(null);
|
|
1251
|
+
const refused = await onSave(r);
|
|
1252
|
+
if (refused === null) onOpenChange(false);
|
|
1253
|
+
else setProblem(refused);
|
|
1272
1254
|
};
|
|
1273
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
1274
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1255
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
1256
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
1257
|
+
OFFERS_COPY.rules,
|
|
1258
|
+
": ",
|
|
1259
|
+
offer.name
|
|
1260
|
+
] }) }),
|
|
1261
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
1262
|
+
unreadable && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-rules-unreadable", children: OFFERS_COPY.rulesUnreadableNotice }),
|
|
1263
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.rulesIntro }),
|
|
1264
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
1265
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: OFFERS_COPY.customers }),
|
|
1266
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: customers, onValueChange: (v) => setCustomers(v), children: [
|
|
1267
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { "aria-label": OFFERS_COPY.customers, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
1268
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
1269
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "all", children: OFFERS_COPY.customersAll }),
|
|
1270
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "guests", children: OFFERS_COPY.customersGuests }),
|
|
1271
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "signed_in", children: OFFERS_COPY.customersSignedIn })
|
|
1272
|
+
] })
|
|
1273
|
+
] })
|
|
1279
1274
|
] }),
|
|
1280
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
)
|
|
1293
|
-
] })
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
},
|
|
1330
|
-
|
|
1331
|
-
}
|
|
1332
|
-
),
|
|
1333
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt, { open, onOpenChange: (o) => !mark.isPending && setOpen(o), variant: "confirmation", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Content, { children: [
|
|
1334
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Header, { children: [
|
|
1335
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Title, { children: "Mark this payment resolved?" }),
|
|
1336
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Description, { children: "Do this only after you've refunded it (for example from the command line) or settled it with the buyer. Nothing is sent to Vonpay. The buyer can no longer complete an order with this payment. It leaves this list and stays under Resolved, with your name on it; pressing Refund later still works." })
|
|
1275
|
+
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "products", label: OFFERS_COPY.products, ids: products, onChange: setProducts }),
|
|
1276
|
+
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "collections", label: OFFERS_COPY.collections, ids: collections, onChange: setCollections }),
|
|
1277
|
+
/* @__PURE__ */ jsxRuntime.jsx(Picker, { kind: "groups", label: OFFERS_COPY.groups, ids: groups, onChange: setGroups }),
|
|
1278
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", "data-testid": "vonpay-rule-paid", children: [
|
|
1279
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: OFFERS_COPY.paid }),
|
|
1280
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.paidNote }),
|
|
1281
|
+
paid.map((r, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_auto] items-center gap-2", children: [
|
|
1282
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": "Currency", placeholder: "EUR", value: r.currency, maxLength: 3, onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, currency: e.target.value } : x)) }),
|
|
1283
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": `${OFFERS_COPY.paidAtLeast} (${r.currency || "currency"})`, placeholder: OFFERS_COPY.paidAtLeast, value: r.min, maxLength: 17, inputMode: "decimal", onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, min: e.target.value } : x)) }),
|
|
1284
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { "aria-label": `${OFFERS_COPY.paidAtMost} (${r.currency || "currency"})`, placeholder: OFFERS_COPY.paidAtMost, value: r.max, maxLength: 17, inputMode: "decimal", onChange: (e) => setPaid(paid.map((x, j) => j === i ? { ...x, max: e.target.value } : x)) }),
|
|
1285
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "aria-label": `${OFFERS_COPY.removeCurrency} ${r.currency.toUpperCase()}`.trim(), onClick: () => setPaid(paid.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMarkMini, {}) })
|
|
1286
|
+
] }, i)),
|
|
1287
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", onClick: () => setPaid([...paid, { currency: "", min: "", max: "" }]), children: OFFERS_COPY.addCurrency }) })
|
|
1288
|
+
] }),
|
|
1289
|
+
problem && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-rules-problem", children: problem })
|
|
1290
|
+
] }),
|
|
1291
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
1292
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => onOpenChange(false), children: OFFERS_COPY.cancel }),
|
|
1293
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: busy, onClick: () => void save(), children: unreadable ? OFFERS_COPY.replaceRules : OFFERS_COPY.save })
|
|
1294
|
+
] })
|
|
1295
|
+
] }) });
|
|
1296
|
+
}
|
|
1297
|
+
function OfferWordingDrawer({ offer, open, onOpenChange, onSave, busy }) {
|
|
1298
|
+
const start = offer.copy === "unreadable" ? null : offer.copy;
|
|
1299
|
+
const [headline, setHeadline] = react.useState(start?.headline ?? "");
|
|
1300
|
+
const [pitch, setPitch] = react.useState(start?.pitch ?? "");
|
|
1301
|
+
const [problem, setProblem] = react.useState(null);
|
|
1302
|
+
const save = async (copy) => {
|
|
1303
|
+
setProblem(null);
|
|
1304
|
+
const refused = await onSave(copy);
|
|
1305
|
+
if (refused === null) onOpenChange(false);
|
|
1306
|
+
else setProblem(refused);
|
|
1307
|
+
};
|
|
1308
|
+
const typed = () => {
|
|
1309
|
+
const h = headline.trim();
|
|
1310
|
+
const p = pitch.trim();
|
|
1311
|
+
return h || p ? { ...h ? { headline: h } : {}, ...p ? { pitch: p } : {} } : null;
|
|
1312
|
+
};
|
|
1313
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { "aria-describedby": void 0, children: [
|
|
1314
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Title, { children: [
|
|
1315
|
+
OFFERS_COPY.wording,
|
|
1316
|
+
": ",
|
|
1317
|
+
offer.name
|
|
1318
|
+
] }) }),
|
|
1319
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Body, { className: "flex flex-col gap-y-4", children: [
|
|
1320
|
+
offer.copy === "unreadable" && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-wording-unreadable", children: OFFERS_COPY.wordingUnreadable }),
|
|
1321
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.wordingIntro }),
|
|
1322
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1323
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-wording-headline", children: OFFERS_COPY.headline }),
|
|
1324
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "vonpay-wording-headline", value: headline, maxLength: HEADLINE_MAX, onChange: (e) => setHeadline(e.target.value) }),
|
|
1325
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.headlineHint })
|
|
1337
1326
|
] }),
|
|
1338
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-
|
|
1339
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1327
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-wording-pitch", children: OFFERS_COPY.pitch }),
|
|
1329
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { id: "vonpay-wording-pitch", value: pitch, maxLength: PITCH_MAX, rows: 4, onChange: (e) => setPitch(e.target.value) }),
|
|
1330
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
1331
|
+
OFFERS_COPY.pitchHint,
|
|
1332
|
+
" (",
|
|
1333
|
+
pitch.length,
|
|
1334
|
+
"/",
|
|
1335
|
+
PITCH_MAX,
|
|
1336
|
+
")"
|
|
1337
|
+
] })
|
|
1344
1338
|
] }),
|
|
1345
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
};
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
const
|
|
1373
|
-
const
|
|
1374
|
-
const
|
|
1375
|
-
const
|
|
1376
|
-
const
|
|
1377
|
-
|
|
1378
|
-
|
|
1339
|
+
offer.downsell_variant_id && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: OFFERS_COPY.wordingDownsellNote }),
|
|
1340
|
+
problem && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", "data-testid": "vonpay-wording-problem", children: problem })
|
|
1341
|
+
] }),
|
|
1342
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
1343
|
+
offer.copy !== null && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", disabled: busy, onClick: () => void save(null), children: OFFERS_COPY.wordingReset }),
|
|
1344
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => onOpenChange(false), children: OFFERS_COPY.cancel }),
|
|
1345
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: busy, onClick: () => void save(typed()), children: OFFERS_COPY.save })
|
|
1346
|
+
] })
|
|
1347
|
+
] }) });
|
|
1348
|
+
}
|
|
1349
|
+
const KEY = "vonpay-offers";
|
|
1350
|
+
function useOffers() {
|
|
1351
|
+
return reactQuery.useQuery({ queryKey: [KEY], queryFn: () => sdk.client.fetch("/admin/vonpay/offers") });
|
|
1352
|
+
}
|
|
1353
|
+
function useWrite(send) {
|
|
1354
|
+
const qc = reactQuery.useQueryClient();
|
|
1355
|
+
return reactQuery.useMutation({ mutationFn: send, retry: false, onSettled: () => qc.invalidateQueries({ queryKey: [KEY] }) });
|
|
1356
|
+
}
|
|
1357
|
+
const useCreateOffer = () => useWrite((v) => sdk.client.fetch("/admin/vonpay/offers", { method: "POST", body: v }));
|
|
1358
|
+
const useUpdateOffer = () => useWrite((v) => {
|
|
1359
|
+
const { id, ...body } = v;
|
|
1360
|
+
return sdk.client.fetch(`/admin/vonpay/offers/${encodeURIComponent(id)}`, { method: "POST", body });
|
|
1361
|
+
});
|
|
1362
|
+
const useDeleteOffer = () => useWrite((v) => sdk.client.fetch(`/admin/vonpay/offers/${encodeURIComponent(v.id)}`, { method: "DELETE" }));
|
|
1363
|
+
const useReorderOffers = () => useWrite((v) => sdk.client.fetch("/admin/vonpay/offers/reorder", { method: "POST", body: v }));
|
|
1364
|
+
const useImportOffers = () => useWrite(() => sdk.client.fetch("/admin/vonpay/offers/import", { method: "POST", body: {} }));
|
|
1365
|
+
const VonpayOffersPage = () => {
|
|
1366
|
+
const { data, isLoading, isError, error: loadError } = useOffers();
|
|
1367
|
+
const create = useCreateOffer();
|
|
1368
|
+
const update = useUpdateOffer();
|
|
1369
|
+
const remove = useDeleteOffer();
|
|
1370
|
+
const reorder = useReorderOffers();
|
|
1371
|
+
const importConfig = useImportOffers();
|
|
1372
|
+
const prompt = ui.usePrompt();
|
|
1373
|
+
const [name, setName] = react.useState("");
|
|
1374
|
+
const [variantId, setVariantId] = react.useState("");
|
|
1375
|
+
const [error, setError] = react.useState(null);
|
|
1376
|
+
const [editing, setEditing] = react.useState(null);
|
|
1377
|
+
const [downsellFor, setDownsellFor] = react.useState(null);
|
|
1378
|
+
const [wordingFor, setWordingFor] = react.useState(null);
|
|
1379
|
+
const busy = create.isPending || update.isPending || remove.isPending || reorder.isPending || importConfig.isPending;
|
|
1380
|
+
const run = async (work) => {
|
|
1381
|
+
setError(null);
|
|
1382
|
+
try {
|
|
1383
|
+
await work();
|
|
1384
|
+
return true;
|
|
1385
|
+
} catch (err) {
|
|
1386
|
+
setError(errorSentence(err));
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1379
1389
|
};
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
] }),
|
|
1387
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Prompt.Footer, { children: [
|
|
1388
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Prompt.Cancel, { disabled: pending, children: "Cancel" }),
|
|
1389
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1390
|
-
ui.Prompt.Action,
|
|
1391
|
-
{
|
|
1392
|
-
disabled: pending,
|
|
1393
|
-
onClick: (e) => {
|
|
1394
|
-
e.preventDefault();
|
|
1395
|
-
if (kind === "release") release.mutate({ row }, { onSuccess: (o) => onResult(releaseOutcomeCopy(o)), onError: fail, onSettled: () => setOpen(false) });
|
|
1396
|
-
else complete.mutate({ row }, { onSuccess: (o) => onResult(completeOutcomeCopy(o)), onError: fail, onSettled: () => setOpen(false) });
|
|
1397
|
-
},
|
|
1398
|
-
children: text.action
|
|
1399
|
-
}
|
|
1400
|
-
)
|
|
1401
|
-
] })
|
|
1402
|
-
] }) })
|
|
1403
|
-
] });
|
|
1404
|
-
};
|
|
1405
|
-
const HoldDrawer = ({ row, onClose }) => {
|
|
1406
|
-
const copy = row ? reasonCopy(row.reason) : void 0;
|
|
1407
|
-
const known = row ? isKnownStatus(row.status) && !isUnrecognisedRecord(row) : false;
|
|
1408
|
-
const showRefund = !!row && known && canRefund(row);
|
|
1409
|
-
const showMark = !!row && known && canMarkResolved(row);
|
|
1410
|
-
const showRelease = !!row && known && canRelease(row);
|
|
1411
|
-
const showComplete = !!row && known && canComplete(row);
|
|
1412
|
-
const showOpenOrder = !!row && known && canOpenOrder(row);
|
|
1413
|
-
const steps = row ? resolutionSteps(known ? row : { ...row, reason: "unrecognised" }) : [];
|
|
1414
|
-
const [result, setResult] = react.useState(null);
|
|
1415
|
-
const close = () => {
|
|
1416
|
-
setResult(null);
|
|
1417
|
-
onClose();
|
|
1390
|
+
const onAdd = async (e) => {
|
|
1391
|
+
e.preventDefault();
|
|
1392
|
+
if (await run(() => create.mutateAsync({ name: name.trim(), variant_id: variantId.trim() }))) {
|
|
1393
|
+
setName("");
|
|
1394
|
+
setVariantId("");
|
|
1395
|
+
}
|
|
1418
1396
|
};
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1397
|
+
const move = (offers, i, by) => {
|
|
1398
|
+
const ids = offers.map((o) => o.id);
|
|
1399
|
+
[ids[i], ids[i + by]] = [ids[i + by], ids[i]];
|
|
1400
|
+
void run(() => reorder.mutateAsync({ ids }));
|
|
1401
|
+
};
|
|
1402
|
+
const onRemove = async (o) => {
|
|
1403
|
+
if (await prompt({ title: OFFERS_COPY.remove, description: OFFERS_COPY.removeConfirm, confirmText: OFFERS_COPY.remove, cancelText: "Cancel" })) void run(() => remove.mutateAsync({ id: o.id }));
|
|
1404
|
+
};
|
|
1405
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
1406
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4", children: [
|
|
1407
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: OFFERS_COPY.title }),
|
|
1408
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
1409
|
+
OFFERS_COPY.intro,
|
|
1410
|
+
" ",
|
|
1411
|
+
OFFERS_COPY.lag
|
|
1412
|
+
] })
|
|
1423
1413
|
] }),
|
|
1424
|
-
|
|
1425
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1426
|
-
|
|
1427
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1428
|
-
/* @__PURE__ */ jsxRuntime.jsx("
|
|
1429
|
-
/* @__PURE__ */ jsxRuntime.jsx("
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1438
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1445
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1414
|
+
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-8 w-full" }) }) : isError || !data ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", "data-testid": "vonpay-offers-load-error", children: errorSentence(loadError, OFFERS_COPY.loadFailed) }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1415
|
+
!data.upsells_on && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "warning", children: OFFERS_COPY.off }) }),
|
|
1416
|
+
data.source === "config" && data.config.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2 px-6 py-4", "data-testid": "vonpay-offers-from-config", children: [
|
|
1417
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "info", children: OFFERS_COPY.fromConfig }),
|
|
1418
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc pl-6", children: data.config.map((c) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: productLabel(c) }) }, c.variant_id)) }),
|
|
1419
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", disabled: busy, onClick: () => void run(() => importConfig.mutateAsync(void 0)), children: OFFERS_COPY.importButton }) })
|
|
1420
|
+
] }),
|
|
1421
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", "data-testid": "vonpay-offers-error", children: error }) }),
|
|
1422
|
+
data.offers.length === 0 ? (data.source === "admin" || data.config.length === 0) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: data.source === "admin" ? OFFERS_COPY.adminEmpty : OFFERS_COPY.configEmpty }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
1423
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1424
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Offer" }),
|
|
1425
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Product" }),
|
|
1426
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: OFFERS_COPY.rules }),
|
|
1427
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: OFFERS_COPY.downsell }),
|
|
1428
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: OFFERS_COPY.wording }),
|
|
1429
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: OFFERS_COPY.shown }),
|
|
1430
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, {})
|
|
1431
|
+
] }) }),
|
|
1432
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.offers.map((o, i) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { "data-testid": "vonpay-offer-row", children: [
|
|
1433
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: o.name }),
|
|
1434
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: o.product_title === null ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-error", children: OFFERS_COPY.missingVariant }) : productLabel(o) }),
|
|
1435
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.rules}: ${o.name}`, disabled: busy, onClick: () => setEditing(o), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: o.rules === "unreadable" ? "text-ui-fg-error" : void 0, children: rulesSummary(o.rules) }) }) }),
|
|
1436
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.downsell}: ${o.name}`, disabled: busy, onClick: () => setDownsellFor(o), children: o.downsell_variant_id === null ? OFFERS_COPY.downsellNone : o.downsell_product_title === null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-ui-fg-error", children: OFFERS_COPY.downsellMissing }) : productLabel({ product_title: o.downsell_product_title, variant_title: o.downsell_variant_title, variant_id: o.downsell_variant_id }) }) }),
|
|
1437
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.wording}: ${o.name}`, disabled: busy, onClick: () => setWordingFor(o), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: `max-w-[16rem] truncate ${o.copy === "unreadable" ? "text-ui-fg-error" : ""}`, children: wordingSummary(o.copy) }) }) }),
|
|
1438
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Switch, { "aria-label": `${OFFERS_COPY.shown}: ${o.name}`, checked: o.enabled, disabled: busy, onCheckedChange: (on) => void run(() => update.mutateAsync({ id: o.id, enabled: on })) }) }),
|
|
1439
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-1", children: [
|
|
1440
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.up}: ${o.name}`, disabled: busy || i === 0, onClick: () => move(data.offers, i, -1), children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, {}) }),
|
|
1441
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.down}: ${o.name}`, disabled: busy || i === data.offers.length - 1, onClick: () => move(data.offers, i, 1), children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, {}) }),
|
|
1442
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", "aria-label": `${OFFERS_COPY.remove}: ${o.name}`, disabled: busy, onClick: () => void onRemove(o), children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}) })
|
|
1443
|
+
] }) })
|
|
1444
|
+
] }, o.id)) })
|
|
1445
|
+
] }) }),
|
|
1446
|
+
downsellFor && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1447
|
+
OfferDownsellDrawer,
|
|
1448
|
+
{
|
|
1449
|
+
offer: downsellFor,
|
|
1450
|
+
open: downsellFor !== null,
|
|
1451
|
+
busy,
|
|
1452
|
+
onOpenChange: (o) => !o && setDownsellFor(null),
|
|
1453
|
+
onSave: async (downsell) => {
|
|
1454
|
+
try {
|
|
1455
|
+
await update.mutateAsync({ id: downsellFor.id, downsell_variant_id: downsell });
|
|
1456
|
+
return null;
|
|
1457
|
+
} catch (err) {
|
|
1458
|
+
return errorSentence(err);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
},
|
|
1462
|
+
downsellFor.id
|
|
1463
|
+
),
|
|
1464
|
+
wordingFor && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1465
|
+
OfferWordingDrawer,
|
|
1466
|
+
{
|
|
1467
|
+
offer: wordingFor,
|
|
1468
|
+
open: wordingFor !== null,
|
|
1469
|
+
busy,
|
|
1470
|
+
onOpenChange: (o) => !o && setWordingFor(null),
|
|
1471
|
+
onSave: async (copy) => {
|
|
1472
|
+
try {
|
|
1473
|
+
await update.mutateAsync({ id: wordingFor.id, copy });
|
|
1474
|
+
return null;
|
|
1475
|
+
} catch (err) {
|
|
1476
|
+
return errorSentence(err);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
},
|
|
1480
|
+
wordingFor.id
|
|
1481
|
+
),
|
|
1482
|
+
editing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1483
|
+
OfferRulesDrawer,
|
|
1484
|
+
{
|
|
1485
|
+
offer: editing,
|
|
1486
|
+
open: editing !== null,
|
|
1487
|
+
busy,
|
|
1488
|
+
onOpenChange: (o) => !o && setEditing(null),
|
|
1489
|
+
onSave: async (rules) => {
|
|
1490
|
+
try {
|
|
1491
|
+
await update.mutateAsync({ id: editing.id, rules });
|
|
1492
|
+
return null;
|
|
1493
|
+
} catch (err) {
|
|
1494
|
+
return errorSentence(err);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
editing.id
|
|
1499
|
+
),
|
|
1500
|
+
/* @__PURE__ */ jsxRuntime.jsxs("form", { className: "flex flex-col gap-y-3 px-6 py-4", onSubmit: (e) => void onAdd(e), children: [
|
|
1501
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: OFFERS_COPY.add }),
|
|
1502
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-3 md:grid-cols-2", children: [
|
|
1503
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1504
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-offer-name", children: OFFERS_COPY.name }),
|
|
1505
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "vonpay-offer-name", value: name, maxLength: 80, onChange: (e) => setName(e.target.value) })
|
|
1464
1506
|
] }),
|
|
1465
|
-
|
|
1466
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1467
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1468
|
-
row.resolution.prior.how ? `${RESOLVED_HOW_LABEL[row.resolution.prior.how] ?? row.resolution.prior.how}` : statusLabel(row.resolution.prior.state),
|
|
1469
|
-
` · ${new Date(row.resolution.prior.at).toLocaleString()} · by ${actorLabel(row.resolution.prior)}`
|
|
1470
|
-
] })
|
|
1471
|
-
] })
|
|
1472
|
-
] })
|
|
1473
|
-
] }),
|
|
1474
|
-
result && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: result.variant, children: result.text }),
|
|
1475
|
-
(showRefund || showMark || showRelease || showComplete || showOpenOrder) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2", children: [
|
|
1476
|
-
showOpenOrder && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "primary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: orderPath(row.order_id), children: "Open order" }) }),
|
|
1477
|
-
showComplete && /* @__PURE__ */ jsxRuntime.jsx(WalletHoldAction, { row, kind: "complete", onResult: setResult }),
|
|
1478
|
-
showRelease && /* @__PURE__ */ jsxRuntime.jsx(WalletHoldAction, { row, kind: "release", onResult: setResult }),
|
|
1479
|
-
showRefund && /* @__PURE__ */ jsxRuntime.jsx(RefundAction, { row, onResult: setResult }),
|
|
1480
|
-
showRefund && /* @__PURE__ */ jsxRuntime.jsx(CheckWithVonpayAction, { row, onResult: setResult }),
|
|
1481
|
-
showMark && /* @__PURE__ */ jsxRuntime.jsx(MarkResolvedAction, { row, onResult: setResult })
|
|
1482
|
-
] }),
|
|
1483
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
1484
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", children: "Or do it by hand" }),
|
|
1485
|
-
steps.map((step) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
1486
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: step.title }),
|
|
1487
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: step.body }),
|
|
1488
|
-
step.command && /* @__PURE__ */ jsxRuntime.jsxs(ui.CodeBlock, { snippets: [{ label: "Terminal", language: "bash", code: step.command, hideLineNumbers: true }], children: [
|
|
1489
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.CodeBlock.Header, {}),
|
|
1490
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.CodeBlock.Body, {})
|
|
1507
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1508
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vonpay-offer-variant", children: OFFERS_COPY.variant }),
|
|
1509
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { id: "vonpay-offer-variant", value: variantId, onChange: (e) => setVariantId(e.target.value) })
|
|
1491
1510
|
] })
|
|
1492
|
-
] }
|
|
1493
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
1511
|
+
] }),
|
|
1512
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", disabled: busy || !name.trim() || !variantId.trim(), children: OFFERS_COPY.add }) })
|
|
1494
1513
|
] })
|
|
1495
1514
|
] })
|
|
1496
|
-
] })
|
|
1515
|
+
] });
|
|
1497
1516
|
};
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1517
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
1518
|
+
label: "One-click offers",
|
|
1519
|
+
icon: icons.Sparkles,
|
|
1520
|
+
nested: "/orders"
|
|
1521
|
+
});
|
|
1522
|
+
const EVENT_LABEL = {
|
|
1523
|
+
"subscription.created": "Signed up",
|
|
1524
|
+
"subscription.renewed": "Renewal paid",
|
|
1525
|
+
"subscription.payment_failed": "Renewal declined",
|
|
1526
|
+
"subscription.cancelled": "Cancelled",
|
|
1527
|
+
"subscription.updated": "Changed"
|
|
1528
|
+
};
|
|
1529
|
+
const eventLabel = (type) => EVENT_LABEL[type] ?? "Other";
|
|
1530
|
+
const amountLabel = (major, currency) => major && currency ? `${major} ${currency}` : "—";
|
|
1531
|
+
const NOT_ENABLED_NOTE = `Vonpay is not running this store's subscriptions. To let it, set the payment provider's subscriptions option to "vonpay", register the plugin's subscriptions module in medusa-config, run npx medusa db:migrate and restart — the setup check confirms each step.`;
|
|
1532
|
+
const ORDERS_NOT_YET_NOTE = "Renewal orders are not created from these notifications yet: this list shows what Vonpay reported, so nothing here changes an order.";
|
|
1533
|
+
const SUBSCRIPTION_PAGE_SIZE = 20;
|
|
1534
|
+
function useSubscriptionEvents(page) {
|
|
1535
|
+
return reactQuery.useQuery({
|
|
1536
|
+
queryKey: ["vonpay-subscription-events", page.limit, page.offset],
|
|
1537
|
+
queryFn: () => sdk.client.fetch("/admin/vonpay/subscriptions", { query: { limit: page.limit, offset: page.offset } }),
|
|
1538
|
+
placeholderData: reactQuery.keepPreviousData
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
const pageCountFor = (count) => {
|
|
1542
|
+
const remainder = count % SUBSCRIPTION_PAGE_SIZE;
|
|
1543
|
+
return Math.max(1, (count - remainder) / SUBSCRIPTION_PAGE_SIZE + (remainder > 0 ? 1 : 0));
|
|
1544
|
+
};
|
|
1545
|
+
const when = (iso) => iso ? new Date(iso).toLocaleString() : "—";
|
|
1546
|
+
const VonpaySubscriptionsPage = () => {
|
|
1500
1547
|
const [pageIndex, setPageIndex] = react.useState(0);
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
1511
|
-
e.preventDefault();
|
|
1512
|
-
setOpened(row);
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
|
|
1516
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
1517
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4 px-6 py-4", children: [
|
|
1518
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1519
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Held payments" }),
|
|
1520
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Buyers who were charged through Vonpay but whose order couldn't be completed safely, cancelled orders whose refund Vonpay hasn't confirmed, and Apple Pay / Google Pay payments not yet collected for an order. Nothing here is refunded automatically." })
|
|
1521
|
-
] }),
|
|
1522
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-[180px]", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1523
|
-
ui.Select,
|
|
1524
|
-
{
|
|
1525
|
-
size: "small",
|
|
1526
|
-
value: filter,
|
|
1527
|
-
onValueChange: (v) => {
|
|
1528
|
-
setFilter(v);
|
|
1529
|
-
setPageIndex(0);
|
|
1530
|
-
},
|
|
1531
|
-
children: [
|
|
1532
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { "aria-label": "Show", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
1533
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: ["open", "resolved", "all"].map((f) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: f, children: FILTER_LABEL[f] }, f)) })
|
|
1534
|
-
]
|
|
1535
|
-
}
|
|
1536
|
-
) })
|
|
1537
|
-
] }),
|
|
1538
|
-
data && !data.scan_complete && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "warning", children: "This list may be incomplete: the store has more records than one page load can check." }) }),
|
|
1539
|
-
isError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-y-3 px-6 py-6", children: [
|
|
1540
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Couldn't load held payments." }),
|
|
1541
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", onClick: () => refetch(), children: "Try again" })
|
|
1542
|
-
] }) : isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-3 px-6 py-6", "aria-busy": "true", "aria-label": "Loading held payments", children: [0, 1, 2].map((i) => /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-6 w-full" }, i)) }) : count === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-10", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: filter === "resolved" ? "Nothing resolved yet." : "No held payments. When a buyer is charged but the order can't be completed safely, it appears here." }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1548
|
+
const { data, isLoading, isError } = useSubscriptionEvents({ limit: SUBSCRIPTION_PAGE_SIZE, offset: pageIndex * SUBSCRIPTION_PAGE_SIZE });
|
|
1549
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
1550
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4", children: [
|
|
1551
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Vonpay subscriptions" }),
|
|
1552
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Notifications from Vonpay's subscription billing, newest first." })
|
|
1553
|
+
] }),
|
|
1554
|
+
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-8 w-full" }) }) : isError ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "The list could not be loaded. Reload the page to try again." }) }) : !data?.enabled ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "info", children: NOT_ENABLED_NOTE }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1555
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: ORDERS_NOT_YET_NOTE }) }),
|
|
1556
|
+
data.events.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "No subscription notifications yet." }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1543
1557
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
1544
1558
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1545
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1546
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1547
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1548
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1549
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1550
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "
|
|
1559
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "What happened" }),
|
|
1560
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Subscription" }),
|
|
1561
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Period" }),
|
|
1562
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Amount" }),
|
|
1563
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Next bill" }),
|
|
1564
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Received" })
|
|
1551
1565
|
] }) }),
|
|
1552
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.
|
|
1553
|
-
ui.Table.
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(RowStatus, { status: row.status }) }),
|
|
1564
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: row.held_at ? new Date(row.held_at).toLocaleString() : "Unknown", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "txt-compact-small whitespace-nowrap", children: since(row.held_at) }) }) }),
|
|
1565
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.vp_session_id, label: "Vonpay session id" }) }),
|
|
1566
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(Mono, { value: row.medusa_payment_session_id, label: "Medusa payment session id" }) }),
|
|
1567
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1568
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "txt-compact-small text-ui-fg-subtle whitespace-nowrap", children: SOURCE_LABEL[row.source] }),
|
|
1569
|
-
fromBuyerCheckout(row) && /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { className: "w-fit whitespace-nowrap", color: "grey", children: FROM_BUYER_CHECKOUT })
|
|
1570
|
-
] }) })
|
|
1571
|
-
]
|
|
1572
|
-
},
|
|
1573
|
-
keyOf(row)
|
|
1574
|
-
)) })
|
|
1566
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: data.events.map((e) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1567
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Cell, { children: [
|
|
1568
|
+
eventLabel(e.type),
|
|
1569
|
+
e.mode === "test" ? " (test)" : ""
|
|
1570
|
+
] }),
|
|
1571
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { className: "font-mono text-xs", children: e.subscription_id }),
|
|
1572
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: e.billing_cycle ?? "—" }),
|
|
1573
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: amountLabel(e.amount_major, e.currency) }),
|
|
1574
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: when(e.next_bill_at) }),
|
|
1575
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: when(e.received_at) })
|
|
1576
|
+
] }, e.id)) })
|
|
1575
1577
|
] }) }),
|
|
1576
|
-
|
|
1578
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1577
1579
|
ui.Table.Pagination,
|
|
1578
1580
|
{
|
|
1579
|
-
count,
|
|
1580
|
-
pageSize:
|
|
1581
|
+
count: data.count,
|
|
1582
|
+
pageSize: SUBSCRIPTION_PAGE_SIZE,
|
|
1581
1583
|
pageIndex,
|
|
1582
|
-
pageCount,
|
|
1584
|
+
pageCount: pageCountFor(data.count),
|
|
1583
1585
|
canPreviousPage: pageIndex > 0,
|
|
1584
|
-
canNextPage: pageIndex + 1 <
|
|
1586
|
+
canNextPage: (pageIndex + 1) * SUBSCRIPTION_PAGE_SIZE < data.count,
|
|
1585
1587
|
previousPage: () => setPageIndex((p) => Math.max(0, p - 1)),
|
|
1586
1588
|
nextPage: () => setPageIndex((p) => p + 1)
|
|
1587
1589
|
}
|
|
1588
1590
|
)
|
|
1589
|
-
] })
|
|
1590
|
-
|
|
1591
|
-
] }),
|
|
1592
|
-
/* @__PURE__ */ jsxRuntime.jsx(SetupCheckPanel, {})
|
|
1591
|
+
] })
|
|
1592
|
+
] })
|
|
1593
1593
|
] });
|
|
1594
1594
|
};
|
|
1595
1595
|
const config = adminSdk.defineRouteConfig({
|
|
1596
|
-
label: "
|
|
1597
|
-
icon: icons.
|
|
1596
|
+
label: "Vonpay subscriptions",
|
|
1597
|
+
icon: icons.ArrowPath,
|
|
1598
1598
|
nested: "/orders"
|
|
1599
1599
|
});
|
|
1600
1600
|
const i18nTranslations0 = {};
|
|
@@ -1618,18 +1618,18 @@ const widgetModule = { widgets: [
|
|
|
1618
1618
|
const routeModule = {
|
|
1619
1619
|
routes: [
|
|
1620
1620
|
{
|
|
1621
|
-
Component:
|
|
1622
|
-
path: "/vonpay-
|
|
1621
|
+
Component: HeldPaymentsPage,
|
|
1622
|
+
path: "/vonpay-holds",
|
|
1623
1623
|
handle: { label: config$2.label, translationNs: config$2.translationNs }
|
|
1624
1624
|
},
|
|
1625
1625
|
{
|
|
1626
|
-
Component:
|
|
1627
|
-
path: "/vonpay-
|
|
1626
|
+
Component: VonpayOffersPage,
|
|
1627
|
+
path: "/vonpay-offers",
|
|
1628
1628
|
handle: { label: config$1.label, translationNs: config$1.translationNs }
|
|
1629
1629
|
},
|
|
1630
1630
|
{
|
|
1631
|
-
Component:
|
|
1632
|
-
path: "/vonpay-
|
|
1631
|
+
Component: VonpaySubscriptionsPage,
|
|
1632
|
+
path: "/vonpay-subscriptions",
|
|
1633
1633
|
handle: { label: config.label, translationNs: config.translationNs }
|
|
1634
1634
|
}
|
|
1635
1635
|
]
|
|
@@ -1637,24 +1637,24 @@ const routeModule = {
|
|
|
1637
1637
|
const menuItemModule = {
|
|
1638
1638
|
menuItems: [
|
|
1639
1639
|
{
|
|
1640
|
-
label: config.label,
|
|
1641
|
-
icon: config.icon,
|
|
1640
|
+
label: config$2.label,
|
|
1641
|
+
icon: config$2.icon,
|
|
1642
1642
|
path: "/vonpay-holds",
|
|
1643
1643
|
nested: "/orders",
|
|
1644
1644
|
rank: void 0,
|
|
1645
1645
|
translationNs: void 0
|
|
1646
1646
|
},
|
|
1647
1647
|
{
|
|
1648
|
-
label: config$
|
|
1649
|
-
icon: config$
|
|
1648
|
+
label: config$1.label,
|
|
1649
|
+
icon: config$1.icon,
|
|
1650
1650
|
path: "/vonpay-offers",
|
|
1651
1651
|
nested: "/orders",
|
|
1652
1652
|
rank: void 0,
|
|
1653
1653
|
translationNs: void 0
|
|
1654
1654
|
},
|
|
1655
1655
|
{
|
|
1656
|
-
label: config
|
|
1657
|
-
icon: config
|
|
1656
|
+
label: config.label,
|
|
1657
|
+
icon: config.icon,
|
|
1658
1658
|
path: "/vonpay-subscriptions",
|
|
1659
1659
|
nested: "/orders",
|
|
1660
1660
|
rank: void 0,
|