@medusajs/draft-order 2.22.6 → 2.22.7-preview-20261113084204
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 +1855 -1855
- package/.medusa/server/src/admin/index.mjs +1856 -1856
- package/package.json +18 -18
|
@@ -6385,1482 +6385,864 @@ const schema$3 = zod.z.object({
|
|
|
6385
6385
|
const handle$7 = {
|
|
6386
6386
|
permissions: EDIT_DRAFT_ORDER_PERMISSIONS
|
|
6387
6387
|
};
|
|
6388
|
-
const
|
|
6389
|
-
({
|
|
6390
|
-
|
|
6391
|
-
onChange,
|
|
6392
|
-
size = "base",
|
|
6393
|
-
min = 0,
|
|
6394
|
-
max = 100,
|
|
6395
|
-
step = 1,
|
|
6396
|
-
className,
|
|
6397
|
-
disabled,
|
|
6398
|
-
...props
|
|
6399
|
-
}, ref) => {
|
|
6400
|
-
const handleChange = (event) => {
|
|
6401
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
6402
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
6403
|
-
onChange(newValue);
|
|
6404
|
-
}
|
|
6405
|
-
};
|
|
6406
|
-
const handleIncrement = () => {
|
|
6407
|
-
const newValue = value + step;
|
|
6408
|
-
if (max === void 0 || newValue <= max) {
|
|
6409
|
-
onChange(newValue);
|
|
6410
|
-
}
|
|
6411
|
-
};
|
|
6412
|
-
const handleDecrement = () => {
|
|
6413
|
-
const newValue = value - step;
|
|
6414
|
-
if (min === void 0 || newValue >= min) {
|
|
6415
|
-
onChange(newValue);
|
|
6416
|
-
}
|
|
6417
|
-
};
|
|
6388
|
+
const InlineTip = React.forwardRef(
|
|
6389
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
6390
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
6418
6391
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6419
6392
|
"div",
|
|
6420
6393
|
{
|
|
6394
|
+
ref,
|
|
6421
6395
|
className: ui.clx(
|
|
6422
|
-
"
|
|
6423
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
6424
|
-
{
|
|
6425
|
-
"h-7": size === "small",
|
|
6426
|
-
"h-8": size === "base"
|
|
6427
|
-
},
|
|
6396
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
6428
6397
|
className
|
|
6429
6398
|
),
|
|
6399
|
+
...props,
|
|
6430
6400
|
children: [
|
|
6431
6401
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6432
|
-
"
|
|
6433
|
-
{
|
|
6434
|
-
ref,
|
|
6435
|
-
type: "number",
|
|
6436
|
-
value,
|
|
6437
|
-
onChange: handleChange,
|
|
6438
|
-
min,
|
|
6439
|
-
max,
|
|
6440
|
-
step,
|
|
6441
|
-
className: ui.clx(
|
|
6442
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
6443
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
6444
|
-
"placeholder:text-ui-fg-muted"
|
|
6445
|
-
),
|
|
6446
|
-
...props
|
|
6447
|
-
}
|
|
6448
|
-
),
|
|
6449
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6450
|
-
"button",
|
|
6402
|
+
"div",
|
|
6451
6403
|
{
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
"
|
|
6455
|
-
|
|
6456
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
6457
|
-
{
|
|
6458
|
-
"size-7": size === "small",
|
|
6459
|
-
"size-8": size === "base"
|
|
6460
|
-
}
|
|
6461
|
-
),
|
|
6462
|
-
type: "button",
|
|
6463
|
-
onClick: handleDecrement,
|
|
6464
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
6465
|
-
children: [
|
|
6466
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
|
|
6467
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
6468
|
-
]
|
|
6404
|
+
role: "presentation",
|
|
6405
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
6406
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
6407
|
+
})
|
|
6469
6408
|
}
|
|
6470
6409
|
),
|
|
6471
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6472
|
-
"
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
{
|
|
6480
|
-
"size-7": size === "small",
|
|
6481
|
-
"size-8": size === "base"
|
|
6482
|
-
}
|
|
6483
|
-
),
|
|
6484
|
-
type: "button",
|
|
6485
|
-
onClick: handleIncrement,
|
|
6486
|
-
disabled: max !== void 0 && value >= max || disabled,
|
|
6487
|
-
children: [
|
|
6488
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
|
|
6489
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
6490
|
-
]
|
|
6491
|
-
}
|
|
6492
|
-
)
|
|
6410
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
6411
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
6412
|
+
labelValue,
|
|
6413
|
+
":"
|
|
6414
|
+
] }),
|
|
6415
|
+
" ",
|
|
6416
|
+
children
|
|
6417
|
+
] })
|
|
6493
6418
|
]
|
|
6494
6419
|
}
|
|
6495
6420
|
);
|
|
6496
6421
|
}
|
|
6497
6422
|
);
|
|
6498
|
-
|
|
6499
|
-
const
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
6509
|
-
...options
|
|
6510
|
-
});
|
|
6511
|
-
return { ...data, ...rest };
|
|
6512
|
-
};
|
|
6513
|
-
const useCancelOrderEdit = ({ preview }) => {
|
|
6514
|
-
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview?.id);
|
|
6515
|
-
const onCancel = React.useCallback(async () => {
|
|
6516
|
-
if (!preview) {
|
|
6517
|
-
return true;
|
|
6518
|
-
}
|
|
6519
|
-
let res = false;
|
|
6520
|
-
await cancelOrderEdit(void 0, {
|
|
6521
|
-
onError: (e) => {
|
|
6522
|
-
ui.toast.error(e.message);
|
|
6523
|
-
},
|
|
6524
|
-
onSuccess: () => {
|
|
6525
|
-
res = true;
|
|
6526
|
-
}
|
|
6527
|
-
});
|
|
6528
|
-
return res;
|
|
6529
|
-
}, [preview, cancelOrderEdit]);
|
|
6530
|
-
return { onCancel };
|
|
6531
|
-
};
|
|
6532
|
-
let IS_REQUEST_RUNNING = false;
|
|
6533
|
-
const useInitiateOrderEdit = ({
|
|
6534
|
-
preview
|
|
6535
|
-
}) => {
|
|
6536
|
-
const navigate = reactRouterDom.useNavigate();
|
|
6537
|
-
const { mutateAsync } = useDraftOrderBeginEdit(preview?.id);
|
|
6538
|
-
React.useEffect(() => {
|
|
6539
|
-
async function run() {
|
|
6540
|
-
if (IS_REQUEST_RUNNING || !preview) {
|
|
6541
|
-
return;
|
|
6542
|
-
}
|
|
6543
|
-
if (preview.order_change) {
|
|
6544
|
-
return;
|
|
6545
|
-
}
|
|
6546
|
-
IS_REQUEST_RUNNING = true;
|
|
6547
|
-
await mutateAsync(void 0, {
|
|
6548
|
-
onError: (e) => {
|
|
6549
|
-
ui.toast.error(e.message);
|
|
6550
|
-
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
6551
|
-
return;
|
|
6552
|
-
}
|
|
6553
|
-
});
|
|
6554
|
-
IS_REQUEST_RUNNING = false;
|
|
6555
|
-
}
|
|
6556
|
-
run();
|
|
6557
|
-
}, [preview, navigate, mutateAsync]);
|
|
6558
|
-
};
|
|
6559
|
-
function convertNumber(value) {
|
|
6560
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
6561
|
-
}
|
|
6562
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
6563
|
-
const Items = () => {
|
|
6423
|
+
InlineTip.displayName = "InlineTip";
|
|
6424
|
+
const MetadataFieldSchema = zod.z.object({
|
|
6425
|
+
key: zod.z.string(),
|
|
6426
|
+
disabled: zod.z.boolean().optional(),
|
|
6427
|
+
value: zod.z.any()
|
|
6428
|
+
});
|
|
6429
|
+
const MetadataSchema = zod.z.object({
|
|
6430
|
+
metadata: zod.z.array(MetadataFieldSchema)
|
|
6431
|
+
});
|
|
6432
|
+
const Metadata = () => {
|
|
6564
6433
|
const { id } = reactRouterDom.useParams();
|
|
6565
|
-
const {
|
|
6566
|
-
|
|
6567
|
-
isPending: isPreviewPending,
|
|
6568
|
-
isError: isPreviewError,
|
|
6569
|
-
error: previewError
|
|
6570
|
-
} = useOrderPreview(id, void 0, {
|
|
6571
|
-
placeholderData: reactQuery.keepPreviousData
|
|
6434
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
6435
|
+
fields: "metadata"
|
|
6572
6436
|
});
|
|
6573
|
-
useInitiateOrderEdit({ preview });
|
|
6574
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
6575
|
-
id,
|
|
6576
|
-
{
|
|
6577
|
-
fields: "currency_code"
|
|
6578
|
-
},
|
|
6579
|
-
{
|
|
6580
|
-
enabled: !!id
|
|
6581
|
-
}
|
|
6582
|
-
);
|
|
6583
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
6584
6437
|
if (isError) {
|
|
6585
6438
|
throw error;
|
|
6586
6439
|
}
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6594
|
-
] })
|
|
6440
|
+
const isReady = !isPending && !!order;
|
|
6441
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
6442
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
6443
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
6444
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
6445
|
+
] }),
|
|
6446
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
6447
|
+
] });
|
|
6595
6448
|
};
|
|
6596
|
-
const
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
null
|
|
6600
|
-
);
|
|
6449
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
6450
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
6451
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
6601
6452
|
const { handleSuccess } = useRouteModal();
|
|
6602
|
-
const
|
|
6603
|
-
const {
|
|
6604
|
-
const canReadVariants = hasPermission("product_variant:read");
|
|
6605
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
6606
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
6607
|
-
const itemCount = preview.items?.reduce((acc, item) => acc + item.quantity, 0) || 0;
|
|
6608
|
-
const matches = React.useMemo(() => {
|
|
6609
|
-
return matchSorter.matchSorter(preview.items, query2, {
|
|
6610
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
6611
|
-
});
|
|
6612
|
-
}, [preview.items, query2]);
|
|
6613
|
-
const onSubmit = async () => {
|
|
6614
|
-
setIsSubmitting(true);
|
|
6615
|
-
let requestSucceeded = false;
|
|
6616
|
-
await requestOrderEdit(void 0, {
|
|
6617
|
-
onError: (e) => {
|
|
6618
|
-
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
6619
|
-
},
|
|
6620
|
-
onSuccess: () => {
|
|
6621
|
-
requestSucceeded = true;
|
|
6622
|
-
}
|
|
6623
|
-
});
|
|
6624
|
-
if (!requestSucceeded) {
|
|
6625
|
-
setIsSubmitting(false);
|
|
6626
|
-
return;
|
|
6627
|
-
}
|
|
6628
|
-
await confirmOrderEdit(void 0, {
|
|
6629
|
-
onError: (e) => {
|
|
6630
|
-
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
6631
|
-
},
|
|
6632
|
-
onSuccess: () => {
|
|
6633
|
-
handleSuccess();
|
|
6634
|
-
},
|
|
6635
|
-
onSettled: () => {
|
|
6636
|
-
setIsSubmitting(false);
|
|
6637
|
-
}
|
|
6638
|
-
});
|
|
6639
|
-
};
|
|
6640
|
-
const onKeyDown = React.useCallback(
|
|
6641
|
-
(e) => {
|
|
6642
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
6643
|
-
if (modalContent || isSubmitting) {
|
|
6644
|
-
return;
|
|
6645
|
-
}
|
|
6646
|
-
onSubmit();
|
|
6647
|
-
}
|
|
6648
|
-
},
|
|
6649
|
-
[modalContent, isSubmitting, onSubmit]
|
|
6650
|
-
);
|
|
6651
|
-
React.useEffect(() => {
|
|
6652
|
-
document.addEventListener("keydown", onKeyDown);
|
|
6653
|
-
return () => {
|
|
6654
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
6655
|
-
};
|
|
6656
|
-
}, [onKeyDown]);
|
|
6657
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
6658
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
6659
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6660
|
-
StackedFocusModal,
|
|
6661
|
-
{
|
|
6662
|
-
id: STACKED_MODAL_ID,
|
|
6663
|
-
onOpenChangeCallback: (open) => {
|
|
6664
|
-
if (!open) {
|
|
6665
|
-
setModalContent(null);
|
|
6666
|
-
}
|
|
6667
|
-
},
|
|
6668
|
-
children: [
|
|
6669
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
6670
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
6671
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
|
|
6672
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
|
|
6673
|
-
] }),
|
|
6674
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
6675
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
6676
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
6677
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
6678
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
6679
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
6680
|
-
] }),
|
|
6681
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6682
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6683
|
-
ui.Input,
|
|
6684
|
-
{
|
|
6685
|
-
type: "search",
|
|
6686
|
-
placeholder: "Search items",
|
|
6687
|
-
value: searchValue,
|
|
6688
|
-
onChange: (e) => onSearchValueChange(e.target.value)
|
|
6689
|
-
}
|
|
6690
|
-
) }),
|
|
6691
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
6692
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
|
|
6693
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
6694
|
-
canReadVariants && /* @__PURE__ */ jsxRuntime.jsx(
|
|
6695
|
-
StackedModalTrigger$1,
|
|
6696
|
-
{
|
|
6697
|
-
type: "add-items",
|
|
6698
|
-
setModalContent
|
|
6699
|
-
}
|
|
6700
|
-
),
|
|
6701
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6702
|
-
StackedModalTrigger$1,
|
|
6703
|
-
{
|
|
6704
|
-
type: "add-custom-item",
|
|
6705
|
-
setModalContent
|
|
6706
|
-
}
|
|
6707
|
-
)
|
|
6708
|
-
] })
|
|
6709
|
-
] })
|
|
6710
|
-
] })
|
|
6711
|
-
] }),
|
|
6712
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
6713
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
6714
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
6715
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
6716
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
6717
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", {})
|
|
6718
|
-
] }) }),
|
|
6719
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
6720
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
6721
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
6722
|
-
] }) : matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6723
|
-
Item,
|
|
6724
|
-
{
|
|
6725
|
-
item,
|
|
6726
|
-
preview,
|
|
6727
|
-
currencyCode
|
|
6728
|
-
},
|
|
6729
|
-
item.id
|
|
6730
|
-
)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
6731
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
6732
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
6733
|
-
'No items found for "',
|
|
6734
|
-
query2,
|
|
6735
|
-
'".'
|
|
6736
|
-
] })
|
|
6737
|
-
] }) })
|
|
6738
|
-
] })
|
|
6739
|
-
] }),
|
|
6740
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
6741
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
6742
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
6743
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6744
|
-
ui.Text,
|
|
6745
|
-
{
|
|
6746
|
-
size: "small",
|
|
6747
|
-
leading: "compact",
|
|
6748
|
-
className: "text-ui-fg-subtle",
|
|
6749
|
-
children: [
|
|
6750
|
-
itemCount,
|
|
6751
|
-
" ",
|
|
6752
|
-
itemCount === 1 ? "item" : "items"
|
|
6753
|
-
]
|
|
6754
|
-
}
|
|
6755
|
-
) }),
|
|
6756
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
6757
|
-
] })
|
|
6758
|
-
] }) }),
|
|
6759
|
-
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
6760
|
-
CustomItemForm,
|
|
6761
|
-
{
|
|
6762
|
-
orderId: preview.id,
|
|
6763
|
-
currencyCode
|
|
6764
|
-
}
|
|
6765
|
-
) : null)
|
|
6766
|
-
]
|
|
6767
|
-
}
|
|
6768
|
-
) }),
|
|
6769
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
6770
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
6771
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6772
|
-
ui.Button,
|
|
6773
|
-
{
|
|
6774
|
-
size: "small",
|
|
6775
|
-
type: "button",
|
|
6776
|
-
onClick: onSubmit,
|
|
6777
|
-
isLoading: isSubmitting,
|
|
6778
|
-
children: "Save"
|
|
6779
|
-
}
|
|
6780
|
-
)
|
|
6781
|
-
] }) })
|
|
6782
|
-
] });
|
|
6783
|
-
};
|
|
6784
|
-
const Item = ({ item, preview, currencyCode }) => {
|
|
6785
|
-
if (item.variant_id) {
|
|
6786
|
-
return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
|
|
6787
|
-
}
|
|
6788
|
-
return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
|
|
6789
|
-
};
|
|
6790
|
-
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
6791
|
-
const [editing, setEditing] = React.useState(false);
|
|
6453
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
6454
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
6792
6455
|
const form = reactHookForm.useForm({
|
|
6793
6456
|
defaultValues: {
|
|
6794
|
-
|
|
6795
|
-
unit_price: item.unit_price
|
|
6457
|
+
metadata: getDefaultValues(metadata)
|
|
6796
6458
|
},
|
|
6797
|
-
resolver: zod$1.zodResolver(
|
|
6459
|
+
resolver: zod$1.zodResolver(MetadataSchema)
|
|
6798
6460
|
});
|
|
6799
|
-
const
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
6803
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
6804
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
6805
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem || isRemovingActionItem;
|
|
6806
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
6807
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
6808
|
-
setEditing(false);
|
|
6809
|
-
return;
|
|
6810
|
-
}
|
|
6811
|
-
if (!actionId) {
|
|
6812
|
-
await updateOriginalItem(
|
|
6813
|
-
{
|
|
6814
|
-
item_id: item.id,
|
|
6815
|
-
quantity: data.quantity,
|
|
6816
|
-
unit_price: convertNumber(data.unit_price)
|
|
6817
|
-
},
|
|
6818
|
-
{
|
|
6819
|
-
onSuccess: () => {
|
|
6820
|
-
setEditing(false);
|
|
6821
|
-
},
|
|
6822
|
-
onError: (e) => {
|
|
6823
|
-
ui.toast.error(e.message);
|
|
6824
|
-
}
|
|
6825
|
-
}
|
|
6826
|
-
);
|
|
6827
|
-
return;
|
|
6828
|
-
}
|
|
6829
|
-
if (data.quantity === 0) {
|
|
6830
|
-
await removeActionItem(actionId, {
|
|
6831
|
-
onSuccess: () => {
|
|
6832
|
-
setEditing(false);
|
|
6833
|
-
},
|
|
6834
|
-
onError: (e) => {
|
|
6835
|
-
ui.toast.error(e.message);
|
|
6836
|
-
}
|
|
6837
|
-
});
|
|
6838
|
-
return;
|
|
6839
|
-
}
|
|
6840
|
-
await updateActionItem(
|
|
6461
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
6462
|
+
const parsedData = parseValues(data);
|
|
6463
|
+
await mutateAsync(
|
|
6841
6464
|
{
|
|
6842
|
-
|
|
6843
|
-
quantity: data.quantity,
|
|
6844
|
-
unit_price: convertNumber(data.unit_price)
|
|
6465
|
+
metadata: parsedData
|
|
6845
6466
|
},
|
|
6846
6467
|
{
|
|
6847
6468
|
onSuccess: () => {
|
|
6848
|
-
|
|
6469
|
+
ui.toast.success("Metadata updated");
|
|
6470
|
+
handleSuccess();
|
|
6849
6471
|
},
|
|
6850
|
-
onError: (
|
|
6851
|
-
ui.toast.error(
|
|
6472
|
+
onError: (error) => {
|
|
6473
|
+
ui.toast.error(error.message);
|
|
6852
6474
|
}
|
|
6853
6475
|
}
|
|
6854
6476
|
);
|
|
6855
6477
|
});
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
Thumbnail,
|
|
6860
|
-
{
|
|
6861
|
-
thumbnail: item.thumbnail,
|
|
6862
|
-
alt: item.product_title ?? void 0
|
|
6863
|
-
}
|
|
6864
|
-
),
|
|
6865
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
6866
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
6867
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
6868
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6869
|
-
ui.Text,
|
|
6870
|
-
{
|
|
6871
|
-
size: "small",
|
|
6872
|
-
leading: "compact",
|
|
6873
|
-
className: "text-ui-fg-subtle",
|
|
6874
|
-
children: [
|
|
6875
|
-
"(",
|
|
6876
|
-
item.variant_title,
|
|
6877
|
-
")"
|
|
6878
|
-
]
|
|
6879
|
-
}
|
|
6880
|
-
)
|
|
6881
|
-
] }),
|
|
6882
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6883
|
-
ui.Text,
|
|
6884
|
-
{
|
|
6885
|
-
size: "small",
|
|
6886
|
-
leading: "compact",
|
|
6887
|
-
className: "text-ui-fg-subtle",
|
|
6888
|
-
children: item.variant_sku
|
|
6889
|
-
}
|
|
6890
|
-
)
|
|
6891
|
-
] })
|
|
6892
|
-
] }),
|
|
6893
|
-
editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6894
|
-
Form$2.Field,
|
|
6895
|
-
{
|
|
6896
|
-
control: form.control,
|
|
6897
|
-
name: "quantity",
|
|
6898
|
-
render: ({ field }) => {
|
|
6899
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
|
|
6900
|
-
}
|
|
6901
|
-
}
|
|
6902
|
-
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
6903
|
-
editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6904
|
-
Form$2.Field,
|
|
6905
|
-
{
|
|
6906
|
-
control: form.control,
|
|
6907
|
-
name: "unit_price",
|
|
6908
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
6909
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6910
|
-
ui.CurrencyInput,
|
|
6911
|
-
{
|
|
6912
|
-
...field,
|
|
6913
|
-
symbol: getNativeSymbol(currencyCode),
|
|
6914
|
-
code: currencyCode,
|
|
6915
|
-
onValueChange: (_value, _name, values) => onChange(values?.value)
|
|
6916
|
-
}
|
|
6917
|
-
) }) });
|
|
6918
|
-
}
|
|
6919
|
-
}
|
|
6920
|
-
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
6921
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6922
|
-
ui.IconButton,
|
|
6923
|
-
{
|
|
6924
|
-
type: "button",
|
|
6925
|
-
size: "small",
|
|
6926
|
-
onClick: editing ? onSubmit : () => {
|
|
6927
|
-
setEditing(true);
|
|
6928
|
-
},
|
|
6929
|
-
disabled: isPending,
|
|
6930
|
-
children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
|
|
6931
|
-
}
|
|
6932
|
-
)
|
|
6933
|
-
] }) }) });
|
|
6934
|
-
};
|
|
6935
|
-
const variantItemSchema = zod.z.object({
|
|
6936
|
-
quantity: zod.z.number(),
|
|
6937
|
-
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
6938
|
-
});
|
|
6939
|
-
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
6940
|
-
const [editing, setEditing] = React.useState(false);
|
|
6941
|
-
const { quantity, unit_price, title } = item;
|
|
6942
|
-
const form = reactHookForm.useForm({
|
|
6943
|
-
defaultValues: {
|
|
6944
|
-
title,
|
|
6945
|
-
quantity,
|
|
6946
|
-
unit_price
|
|
6947
|
-
},
|
|
6948
|
-
resolver: zod$1.zodResolver(customItemSchema)
|
|
6478
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
6479
|
+
control: form.control,
|
|
6480
|
+
name: "metadata"
|
|
6949
6481
|
});
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
const actionId = React.useMemo(() => {
|
|
6958
|
-
return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
|
|
6959
|
-
}, [item]);
|
|
6960
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
6961
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
6962
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
6963
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
6964
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
6965
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
6966
|
-
setEditing(false);
|
|
6967
|
-
return;
|
|
6968
|
-
}
|
|
6969
|
-
if (!actionId) {
|
|
6970
|
-
await updateOriginalItem(
|
|
6971
|
-
{
|
|
6972
|
-
item_id: item.id,
|
|
6973
|
-
quantity: data.quantity,
|
|
6974
|
-
unit_price: convertNumber(data.unit_price)
|
|
6975
|
-
},
|
|
6976
|
-
{
|
|
6977
|
-
onSuccess: () => {
|
|
6978
|
-
setEditing(false);
|
|
6979
|
-
},
|
|
6980
|
-
onError: (e) => {
|
|
6981
|
-
ui.toast.error(e.message);
|
|
6982
|
-
}
|
|
6983
|
-
}
|
|
6984
|
-
);
|
|
6985
|
-
return;
|
|
6986
|
-
}
|
|
6987
|
-
if (data.quantity === 0) {
|
|
6988
|
-
await removeActionItem(actionId, {
|
|
6989
|
-
onSuccess: () => {
|
|
6990
|
-
setEditing(false);
|
|
6991
|
-
},
|
|
6992
|
-
onError: (e) => {
|
|
6993
|
-
ui.toast.error(e.message);
|
|
6994
|
-
}
|
|
6482
|
+
function deleteRow(index) {
|
|
6483
|
+
remove(index);
|
|
6484
|
+
if (fields.length === 1) {
|
|
6485
|
+
insert(0, {
|
|
6486
|
+
key: "",
|
|
6487
|
+
value: "",
|
|
6488
|
+
disabled: false
|
|
6995
6489
|
});
|
|
6996
|
-
return;
|
|
6997
6490
|
}
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
onError: (e) => {
|
|
7009
|
-
ui.toast.error(e.message);
|
|
7010
|
-
}
|
|
7011
|
-
}
|
|
7012
|
-
);
|
|
7013
|
-
});
|
|
7014
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
7015
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
7016
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7017
|
-
Thumbnail,
|
|
7018
|
-
{
|
|
7019
|
-
thumbnail: item.thumbnail,
|
|
7020
|
-
alt: item.title ?? void 0
|
|
7021
|
-
}
|
|
7022
|
-
),
|
|
7023
|
-
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
7024
|
-
Form$2.Field,
|
|
7025
|
-
{
|
|
7026
|
-
control: form.control,
|
|
7027
|
-
name: "title",
|
|
7028
|
-
render: ({ field }) => {
|
|
7029
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
|
|
7030
|
-
}
|
|
7031
|
-
}
|
|
7032
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
|
|
7033
|
-
] }),
|
|
7034
|
-
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
7035
|
-
Form$2.Field,
|
|
7036
|
-
{
|
|
7037
|
-
control: form.control,
|
|
7038
|
-
name: "quantity",
|
|
7039
|
-
render: ({ field }) => {
|
|
7040
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
|
|
7041
|
-
}
|
|
7042
|
-
}
|
|
7043
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
7044
|
-
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
7045
|
-
Form$2.Field,
|
|
7046
|
-
{
|
|
7047
|
-
control: form.control,
|
|
7048
|
-
name: "unit_price",
|
|
7049
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
7050
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7051
|
-
ui.CurrencyInput,
|
|
7052
|
-
{
|
|
7053
|
-
...field,
|
|
7054
|
-
symbol: getNativeSymbol(currencyCode),
|
|
7055
|
-
code: currencyCode,
|
|
7056
|
-
onValueChange: (_value, _name, values) => onChange(values?.value)
|
|
7057
|
-
}
|
|
7058
|
-
) }) });
|
|
7059
|
-
}
|
|
7060
|
-
}
|
|
7061
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
7062
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7063
|
-
ui.IconButton,
|
|
7064
|
-
{
|
|
7065
|
-
type: "button",
|
|
7066
|
-
size: "small",
|
|
7067
|
-
onClick: editing ? onSubmit : () => {
|
|
7068
|
-
setEditing(true);
|
|
7069
|
-
},
|
|
7070
|
-
disabled: isPending,
|
|
7071
|
-
children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
|
|
7072
|
-
}
|
|
7073
|
-
)
|
|
7074
|
-
] }) }) });
|
|
7075
|
-
};
|
|
7076
|
-
const StackedModalTrigger$1 = ({
|
|
7077
|
-
type,
|
|
7078
|
-
setModalContent
|
|
7079
|
-
}) => {
|
|
7080
|
-
const { setIsOpen } = useStackedModal();
|
|
7081
|
-
const onClick = React.useCallback(() => {
|
|
7082
|
-
setModalContent(type);
|
|
7083
|
-
setIsOpen(STACKED_MODAL_ID, true);
|
|
7084
|
-
}, [setModalContent, setIsOpen, type]);
|
|
7085
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
7086
|
-
};
|
|
7087
|
-
const VARIANT_PREFIX = "items";
|
|
7088
|
-
const LIMIT = 50;
|
|
7089
|
-
const ExistingItemsForm = ({ orderId, items }) => {
|
|
7090
|
-
const { setIsOpen } = useStackedModal();
|
|
7091
|
-
const [rowSelection, setRowSelection] = React.useState(
|
|
7092
|
-
items.reduce((acc, item) => {
|
|
7093
|
-
acc[item.variant_id] = true;
|
|
7094
|
-
return acc;
|
|
7095
|
-
}, {})
|
|
7096
|
-
);
|
|
7097
|
-
React.useEffect(() => {
|
|
7098
|
-
setRowSelection(
|
|
7099
|
-
items.reduce((acc, item) => {
|
|
7100
|
-
if (item.variant_id) {
|
|
7101
|
-
acc[item.variant_id] = true;
|
|
7102
|
-
}
|
|
7103
|
-
return acc;
|
|
7104
|
-
}, {})
|
|
7105
|
-
);
|
|
7106
|
-
}, [items]);
|
|
7107
|
-
const { q, order, offset } = useQueryParams(
|
|
7108
|
-
["q", "order", "offset"],
|
|
7109
|
-
VARIANT_PREFIX
|
|
7110
|
-
);
|
|
7111
|
-
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
7112
|
-
{
|
|
7113
|
-
q,
|
|
7114
|
-
order,
|
|
7115
|
-
offset: offset ? parseInt(offset) : void 0,
|
|
7116
|
-
limit: LIMIT,
|
|
7117
|
-
fields: "*inventory_items.inventory.location_levels,+inventory_quantity,+manage_inventory"
|
|
7118
|
-
},
|
|
6491
|
+
}
|
|
6492
|
+
function insertRow(index, position) {
|
|
6493
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
6494
|
+
key: "",
|
|
6495
|
+
value: "",
|
|
6496
|
+
disabled: false
|
|
6497
|
+
});
|
|
6498
|
+
}
|
|
6499
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6500
|
+
KeyboundForm,
|
|
7119
6501
|
{
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
);
|
|
7123
|
-
const columns = useColumns();
|
|
7124
|
-
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
7125
|
-
const onSubmit = async () => {
|
|
7126
|
-
const ids = Object.keys(rowSelection).filter(
|
|
7127
|
-
(id) => !items.find((i) => i.variant_id === id)
|
|
7128
|
-
);
|
|
7129
|
-
await mutateAsync(
|
|
7130
|
-
{
|
|
7131
|
-
items: ids.map((id) => ({
|
|
7132
|
-
variant_id: id,
|
|
7133
|
-
quantity: 1
|
|
7134
|
-
}))
|
|
7135
|
-
},
|
|
7136
|
-
{
|
|
7137
|
-
onSuccess: () => {
|
|
7138
|
-
setRowSelection({});
|
|
7139
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
7140
|
-
},
|
|
7141
|
-
onError: (e) => {
|
|
7142
|
-
ui.toast.error(e.message);
|
|
7143
|
-
}
|
|
7144
|
-
}
|
|
7145
|
-
);
|
|
7146
|
-
};
|
|
7147
|
-
if (isError) {
|
|
7148
|
-
throw error;
|
|
7149
|
-
}
|
|
7150
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7151
|
-
StackedFocusModal.Content,
|
|
7152
|
-
{
|
|
7153
|
-
onOpenAutoFocus: (e) => {
|
|
7154
|
-
e.preventDefault();
|
|
7155
|
-
const searchInput = document.querySelector(
|
|
7156
|
-
"[data-modal-id='modal-search-input']"
|
|
7157
|
-
);
|
|
7158
|
-
if (searchInput) {
|
|
7159
|
-
searchInput.focus();
|
|
7160
|
-
}
|
|
7161
|
-
},
|
|
6502
|
+
onSubmit: handleSubmit,
|
|
6503
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
7162
6504
|
children: [
|
|
7163
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7164
|
-
/* @__PURE__ */ jsxRuntime.
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
rowCount: count,
|
|
7175
|
-
prefix: VARIANT_PREFIX,
|
|
7176
|
-
layout: "fill",
|
|
7177
|
-
rowSelection: {
|
|
7178
|
-
state: rowSelection,
|
|
7179
|
-
onRowSelectionChange: setRowSelection,
|
|
7180
|
-
enableRowSelection: (row) => {
|
|
7181
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
6505
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
6506
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
6507
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
6508
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
6509
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
6510
|
+
] }),
|
|
6511
|
+
fields.map((field, index) => {
|
|
6512
|
+
const isDisabled = field.disabled || false;
|
|
6513
|
+
let placeholder = "-";
|
|
6514
|
+
if (typeof field.value === "object") {
|
|
6515
|
+
placeholder = "{ ... }";
|
|
7182
6516
|
}
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
6517
|
+
if (Array.isArray(field.value)) {
|
|
6518
|
+
placeholder = "[ ... ]";
|
|
6519
|
+
}
|
|
6520
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6521
|
+
ConditionalTooltip,
|
|
6522
|
+
{
|
|
6523
|
+
showTooltip: isDisabled,
|
|
6524
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
6525
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
6526
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6527
|
+
"div",
|
|
6528
|
+
{
|
|
6529
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
6530
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
6531
|
+
}),
|
|
6532
|
+
children: [
|
|
6533
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6534
|
+
Form$2.Field,
|
|
6535
|
+
{
|
|
6536
|
+
control: form.control,
|
|
6537
|
+
name: `metadata.${index}.key`,
|
|
6538
|
+
render: ({ field: field2 }) => {
|
|
6539
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6540
|
+
GridInput,
|
|
6541
|
+
{
|
|
6542
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
6543
|
+
...field2,
|
|
6544
|
+
disabled: isDisabled,
|
|
6545
|
+
placeholder: "Key"
|
|
6546
|
+
}
|
|
6547
|
+
) }) });
|
|
6548
|
+
}
|
|
6549
|
+
}
|
|
6550
|
+
),
|
|
6551
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6552
|
+
Form$2.Field,
|
|
6553
|
+
{
|
|
6554
|
+
control: form.control,
|
|
6555
|
+
name: `metadata.${index}.value`,
|
|
6556
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
6557
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6558
|
+
GridInput,
|
|
6559
|
+
{
|
|
6560
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
6561
|
+
...field2,
|
|
6562
|
+
value: isDisabled ? placeholder : value,
|
|
6563
|
+
disabled: isDisabled,
|
|
6564
|
+
placeholder: "Value"
|
|
6565
|
+
}
|
|
6566
|
+
) }) });
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
6569
|
+
)
|
|
6570
|
+
]
|
|
6571
|
+
}
|
|
6572
|
+
),
|
|
6573
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
6574
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6575
|
+
ui.DropdownMenu.Trigger,
|
|
6576
|
+
{
|
|
6577
|
+
className: ui.clx(
|
|
6578
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
6579
|
+
{
|
|
6580
|
+
hidden: isDisabled
|
|
6581
|
+
}
|
|
6582
|
+
),
|
|
6583
|
+
disabled: isDisabled,
|
|
6584
|
+
asChild: true,
|
|
6585
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
6586
|
+
}
|
|
6587
|
+
),
|
|
6588
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
6589
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6590
|
+
ui.DropdownMenu.Item,
|
|
6591
|
+
{
|
|
6592
|
+
className: "gap-x-2",
|
|
6593
|
+
onClick: () => insertRow(index, "above"),
|
|
6594
|
+
children: [
|
|
6595
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
6596
|
+
"Insert row above"
|
|
6597
|
+
]
|
|
6598
|
+
}
|
|
6599
|
+
),
|
|
6600
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6601
|
+
ui.DropdownMenu.Item,
|
|
6602
|
+
{
|
|
6603
|
+
className: "gap-x-2",
|
|
6604
|
+
onClick: () => insertRow(index, "below"),
|
|
6605
|
+
children: [
|
|
6606
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
6607
|
+
"Insert row below"
|
|
6608
|
+
]
|
|
6609
|
+
}
|
|
6610
|
+
),
|
|
6611
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
6612
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6613
|
+
ui.DropdownMenu.Item,
|
|
6614
|
+
{
|
|
6615
|
+
className: "gap-x-2",
|
|
6616
|
+
onClick: () => deleteRow(index),
|
|
6617
|
+
children: [
|
|
6618
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
6619
|
+
"Delete row"
|
|
6620
|
+
]
|
|
6621
|
+
}
|
|
6622
|
+
)
|
|
6623
|
+
] })
|
|
6624
|
+
] })
|
|
6625
|
+
] })
|
|
6626
|
+
},
|
|
6627
|
+
field.id
|
|
6628
|
+
);
|
|
6629
|
+
})
|
|
6630
|
+
] }),
|
|
6631
|
+
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
6632
|
+
] }),
|
|
6633
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
6634
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
6635
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7190
6636
|
] }) })
|
|
7191
6637
|
]
|
|
7192
6638
|
}
|
|
7193
|
-
);
|
|
6639
|
+
) });
|
|
7194
6640
|
};
|
|
7195
|
-
const
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
return
|
|
6641
|
+
const GridInput = React.forwardRef(({ className, ...props }, ref) => {
|
|
6642
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6643
|
+
"input",
|
|
6644
|
+
{
|
|
6645
|
+
ref,
|
|
6646
|
+
...props,
|
|
6647
|
+
autoComplete: "off",
|
|
6648
|
+
className: ui.clx(
|
|
6649
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
6650
|
+
className
|
|
6651
|
+
)
|
|
6652
|
+
}
|
|
6653
|
+
);
|
|
6654
|
+
});
|
|
6655
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
6656
|
+
const PlaceholderInner = () => {
|
|
6657
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
6658
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
6659
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
6660
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
6661
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
6662
|
+
] }) })
|
|
6663
|
+
] });
|
|
7212
6664
|
};
|
|
7213
|
-
const
|
|
7214
|
-
|
|
6665
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
6666
|
+
function getDefaultValues(metadata) {
|
|
6667
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
7215
6668
|
return [
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7222
|
-
Thumbnail,
|
|
7223
|
-
{
|
|
7224
|
-
thumbnail: row.original.product?.thumbnail,
|
|
7225
|
-
alt: row.original.product?.title
|
|
7226
|
-
}
|
|
7227
|
-
),
|
|
7228
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: row.original.product?.title })
|
|
7229
|
-
] });
|
|
7230
|
-
},
|
|
7231
|
-
enableSorting: true
|
|
7232
|
-
}),
|
|
7233
|
-
columnHelper.accessor("title", {
|
|
7234
|
-
header: "Variant",
|
|
7235
|
-
enableSorting: true
|
|
7236
|
-
}),
|
|
7237
|
-
columnHelper.accessor("sku", {
|
|
7238
|
-
header: "SKU",
|
|
7239
|
-
cell: ({ getValue }) => {
|
|
7240
|
-
return getValue() ?? "-";
|
|
7241
|
-
},
|
|
7242
|
-
enableSorting: true
|
|
7243
|
-
}),
|
|
7244
|
-
columnHelper.accessor("updated_at", {
|
|
7245
|
-
header: "Updated",
|
|
7246
|
-
cell: ({ getValue }) => {
|
|
7247
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7248
|
-
ui.Tooltip,
|
|
7249
|
-
{
|
|
7250
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
7251
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
7252
|
-
}
|
|
7253
|
-
);
|
|
7254
|
-
},
|
|
7255
|
-
enableSorting: true,
|
|
7256
|
-
sortAscLabel: "Oldest first",
|
|
7257
|
-
sortDescLabel: "Newest first"
|
|
7258
|
-
}),
|
|
7259
|
-
columnHelper.accessor("created_at", {
|
|
7260
|
-
header: "Created",
|
|
7261
|
-
cell: ({ getValue }) => {
|
|
7262
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7263
|
-
ui.Tooltip,
|
|
7264
|
-
{
|
|
7265
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
7266
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
7267
|
-
}
|
|
7268
|
-
);
|
|
7269
|
-
},
|
|
7270
|
-
enableSorting: true,
|
|
7271
|
-
sortAscLabel: "Oldest first",
|
|
7272
|
-
sortDescLabel: "Newest first"
|
|
7273
|
-
}),
|
|
7274
|
-
columnHelper.display({
|
|
7275
|
-
id: "inventory",
|
|
7276
|
-
header: "Stock",
|
|
7277
|
-
cell: ({ row }) => {
|
|
7278
|
-
const { text, hasInventoryKit, quantity, notManaged } = getVariantInventory(row.original);
|
|
7279
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: text, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full w-full items-center gap-2 overflow-hidden", children: [
|
|
7280
|
-
hasInventoryKit && /* @__PURE__ */ jsxRuntime.jsx(icons.Component, {}),
|
|
7281
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7282
|
-
"span",
|
|
7283
|
-
{
|
|
7284
|
-
className: ui.clx("truncate", {
|
|
7285
|
-
"text-ui-fg-error": !quantity && !notManaged
|
|
7286
|
-
}),
|
|
7287
|
-
children: text
|
|
7288
|
-
}
|
|
7289
|
-
)
|
|
7290
|
-
] }) });
|
|
7291
|
-
}
|
|
7292
|
-
})
|
|
6669
|
+
{
|
|
6670
|
+
key: "",
|
|
6671
|
+
value: "",
|
|
6672
|
+
disabled: false
|
|
6673
|
+
}
|
|
7293
6674
|
];
|
|
7294
|
-
}
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
6675
|
+
}
|
|
6676
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
6677
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
6678
|
+
return {
|
|
6679
|
+
key,
|
|
6680
|
+
value,
|
|
6681
|
+
disabled: true
|
|
6682
|
+
};
|
|
6683
|
+
}
|
|
6684
|
+
let stringValue = value;
|
|
6685
|
+
if (typeof value !== "string") {
|
|
6686
|
+
stringValue = JSON.stringify(value);
|
|
6687
|
+
}
|
|
6688
|
+
return {
|
|
6689
|
+
key,
|
|
6690
|
+
value: stringValue,
|
|
6691
|
+
original_key: key
|
|
6692
|
+
};
|
|
7306
6693
|
});
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
6694
|
+
}
|
|
6695
|
+
function parseValues(values) {
|
|
6696
|
+
const metadata = values.metadata;
|
|
6697
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
6698
|
+
if (isEmpty) {
|
|
6699
|
+
return null;
|
|
6700
|
+
}
|
|
6701
|
+
const update = {};
|
|
6702
|
+
metadata.forEach((field) => {
|
|
6703
|
+
let key = field.key;
|
|
6704
|
+
let value = field.value;
|
|
6705
|
+
const disabled = field.disabled;
|
|
6706
|
+
if (!key || !value) {
|
|
6707
|
+
return;
|
|
6708
|
+
}
|
|
6709
|
+
if (disabled) {
|
|
6710
|
+
update[key] = value;
|
|
6711
|
+
return;
|
|
6712
|
+
}
|
|
6713
|
+
key = key.trim();
|
|
6714
|
+
value = value.trim();
|
|
6715
|
+
if (value === "true") {
|
|
6716
|
+
update[key] = true;
|
|
6717
|
+
} else if (value === "false") {
|
|
6718
|
+
update[key] = false;
|
|
6719
|
+
} else {
|
|
6720
|
+
const parsedNumber = parseFloat(value);
|
|
6721
|
+
if (!isNaN(parsedNumber)) {
|
|
6722
|
+
update[key] = parsedNumber;
|
|
6723
|
+
} else {
|
|
6724
|
+
update[key] = value;
|
|
7325
6725
|
}
|
|
7326
|
-
|
|
6726
|
+
}
|
|
7327
6727
|
});
|
|
7328
|
-
return
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
{
|
|
7339
|
-
control: form.control,
|
|
7340
|
-
name: "title",
|
|
7341
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
7342
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7343
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
|
|
7344
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
7345
|
-
] }),
|
|
7346
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7347
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
7348
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7349
|
-
] })
|
|
7350
|
-
] }) })
|
|
7351
|
-
}
|
|
7352
|
-
),
|
|
7353
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
7354
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7355
|
-
Form$2.Field,
|
|
7356
|
-
{
|
|
7357
|
-
control: form.control,
|
|
7358
|
-
name: "unit_price",
|
|
7359
|
-
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
7360
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7361
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
|
|
7362
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
7363
|
-
] }),
|
|
7364
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7365
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7366
|
-
ui.CurrencyInput,
|
|
7367
|
-
{
|
|
7368
|
-
symbol: getNativeSymbol(currencyCode),
|
|
7369
|
-
code: currencyCode,
|
|
7370
|
-
onValueChange: (_value, _name, values) => onChange(values?.value),
|
|
7371
|
-
...field
|
|
7372
|
-
}
|
|
7373
|
-
) }),
|
|
7374
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7375
|
-
] })
|
|
7376
|
-
] }) })
|
|
7377
|
-
}
|
|
7378
|
-
),
|
|
7379
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
7380
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7381
|
-
Form$2.Field,
|
|
7382
|
-
{
|
|
7383
|
-
control: form.control,
|
|
7384
|
-
name: "quantity",
|
|
7385
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
7386
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7387
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
|
|
7388
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
7389
|
-
] }),
|
|
7390
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
|
|
7391
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
7392
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7393
|
-
] })
|
|
7394
|
-
] }) })
|
|
7395
|
-
}
|
|
7396
|
-
)
|
|
7397
|
-
] }) }) }),
|
|
7398
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7399
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
7400
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
7401
|
-
] }) })
|
|
7402
|
-
] }) }) });
|
|
7403
|
-
};
|
|
7404
|
-
const customItemSchema = zod.z.object({
|
|
7405
|
-
title: zod.z.string().min(1),
|
|
7406
|
-
quantity: zod.z.number(),
|
|
7407
|
-
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
7408
|
-
});
|
|
6728
|
+
return update;
|
|
6729
|
+
}
|
|
6730
|
+
function getHasUneditableRows(metadata) {
|
|
6731
|
+
if (!metadata) {
|
|
6732
|
+
return false;
|
|
6733
|
+
}
|
|
6734
|
+
return Object.values(metadata).some(
|
|
6735
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
6736
|
+
);
|
|
6737
|
+
}
|
|
7409
6738
|
const handle$6 = {
|
|
7410
6739
|
permissions: EDIT_DRAFT_ORDER_PERMISSIONS
|
|
7411
6740
|
};
|
|
7412
|
-
const
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
6741
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
6742
|
+
const promotionsQueryKeys = {
|
|
6743
|
+
list: (query2) => [
|
|
6744
|
+
PROMOTION_QUERY_KEY,
|
|
6745
|
+
query2 ? query2 : void 0
|
|
6746
|
+
],
|
|
6747
|
+
detail: (id, query2) => [
|
|
6748
|
+
PROMOTION_QUERY_KEY,
|
|
6749
|
+
id,
|
|
6750
|
+
query2 ? query2 : void 0
|
|
6751
|
+
]
|
|
6752
|
+
};
|
|
6753
|
+
const usePromotions = (query2, options) => {
|
|
6754
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
6755
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
6756
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
6757
|
+
...options
|
|
6758
|
+
});
|
|
6759
|
+
return { ...data, ...rest };
|
|
6760
|
+
};
|
|
6761
|
+
const useCancelOrderEdit = ({ preview }) => {
|
|
6762
|
+
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview?.id);
|
|
6763
|
+
const onCancel = React.useCallback(async () => {
|
|
6764
|
+
if (!preview) {
|
|
6765
|
+
return true;
|
|
6766
|
+
}
|
|
6767
|
+
let res = false;
|
|
6768
|
+
await cancelOrderEdit(void 0, {
|
|
6769
|
+
onError: (e) => {
|
|
6770
|
+
ui.toast.error(e.message);
|
|
6771
|
+
},
|
|
6772
|
+
onSuccess: () => {
|
|
6773
|
+
res = true;
|
|
7443
6774
|
}
|
|
7444
|
-
);
|
|
7445
|
-
|
|
7446
|
-
);
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
})
|
|
7453
|
-
const
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
6775
|
+
});
|
|
6776
|
+
return res;
|
|
6777
|
+
}, [preview, cancelOrderEdit]);
|
|
6778
|
+
return { onCancel };
|
|
6779
|
+
};
|
|
6780
|
+
let IS_REQUEST_RUNNING = false;
|
|
6781
|
+
const useInitiateOrderEdit = ({
|
|
6782
|
+
preview
|
|
6783
|
+
}) => {
|
|
6784
|
+
const navigate = reactRouterDom.useNavigate();
|
|
6785
|
+
const { mutateAsync } = useDraftOrderBeginEdit(preview?.id);
|
|
6786
|
+
React.useEffect(() => {
|
|
6787
|
+
async function run() {
|
|
6788
|
+
if (IS_REQUEST_RUNNING || !preview) {
|
|
6789
|
+
return;
|
|
6790
|
+
}
|
|
6791
|
+
if (preview.order_change) {
|
|
6792
|
+
return;
|
|
6793
|
+
}
|
|
6794
|
+
IS_REQUEST_RUNNING = true;
|
|
6795
|
+
await mutateAsync(void 0, {
|
|
6796
|
+
onError: (e) => {
|
|
6797
|
+
ui.toast.error(e.message);
|
|
6798
|
+
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
6799
|
+
return;
|
|
6800
|
+
}
|
|
6801
|
+
});
|
|
6802
|
+
IS_REQUEST_RUNNING = false;
|
|
6803
|
+
}
|
|
6804
|
+
run();
|
|
6805
|
+
}, [preview, navigate, mutateAsync]);
|
|
6806
|
+
};
|
|
6807
|
+
const Promotions = () => {
|
|
7457
6808
|
const { id } = reactRouterDom.useParams();
|
|
7458
|
-
const {
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
6809
|
+
const {
|
|
6810
|
+
order: preview,
|
|
6811
|
+
isError: isPreviewError,
|
|
6812
|
+
error: previewError
|
|
6813
|
+
} = useOrderPreview(id, void 0);
|
|
6814
|
+
useInitiateOrderEdit({ preview });
|
|
6815
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
6816
|
+
if (isPreviewError) {
|
|
6817
|
+
throw previewError;
|
|
7463
6818
|
}
|
|
7464
|
-
const isReady =
|
|
7465
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7466
|
-
/* @__PURE__ */ jsxRuntime.
|
|
7467
|
-
|
|
7468
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
7469
|
-
] }),
|
|
7470
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
6819
|
+
const isReady = !!preview;
|
|
6820
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
6821
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
6822
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
7471
6823
|
] });
|
|
7472
6824
|
};
|
|
7473
|
-
const
|
|
7474
|
-
const
|
|
7475
|
-
const
|
|
6825
|
+
const PromotionForm = ({ preview }) => {
|
|
6826
|
+
const { items, shipping_methods } = preview;
|
|
6827
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
6828
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
7476
6829
|
const { handleSuccess } = useRouteModal();
|
|
7477
|
-
const
|
|
7478
|
-
const
|
|
7479
|
-
const
|
|
7480
|
-
|
|
7481
|
-
|
|
6830
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
6831
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
6832
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
6833
|
+
{
|
|
6834
|
+
id: promoIds
|
|
7482
6835
|
},
|
|
7483
|
-
|
|
6836
|
+
{
|
|
6837
|
+
enabled: !!promoIds.length
|
|
6838
|
+
}
|
|
6839
|
+
);
|
|
6840
|
+
const comboboxData = useComboboxData({
|
|
6841
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
6842
|
+
queryFn: async (params) => {
|
|
6843
|
+
return await sdk.admin.promotion.list({
|
|
6844
|
+
...params,
|
|
6845
|
+
id: {
|
|
6846
|
+
$nin: promoIds
|
|
6847
|
+
}
|
|
6848
|
+
});
|
|
6849
|
+
},
|
|
6850
|
+
getOptions: (data) => {
|
|
6851
|
+
return data.promotions.map((promotion) => ({
|
|
6852
|
+
label: promotion.code,
|
|
6853
|
+
value: promotion.code
|
|
6854
|
+
}));
|
|
6855
|
+
}
|
|
7484
6856
|
});
|
|
7485
|
-
const
|
|
7486
|
-
|
|
7487
|
-
|
|
6857
|
+
const add = async (value) => {
|
|
6858
|
+
if (!value) {
|
|
6859
|
+
return;
|
|
6860
|
+
}
|
|
6861
|
+
addPromotions(
|
|
7488
6862
|
{
|
|
7489
|
-
|
|
6863
|
+
promo_codes: [value]
|
|
7490
6864
|
},
|
|
7491
6865
|
{
|
|
7492
|
-
|
|
7493
|
-
ui.toast.
|
|
7494
|
-
|
|
6866
|
+
onError: (e) => {
|
|
6867
|
+
ui.toast.error(e.message);
|
|
6868
|
+
comboboxData.onSearchValueChange("");
|
|
6869
|
+
setComboboxValue("");
|
|
7495
6870
|
},
|
|
7496
|
-
|
|
7497
|
-
|
|
6871
|
+
onSuccess: () => {
|
|
6872
|
+
comboboxData.onSearchValueChange("");
|
|
6873
|
+
setComboboxValue("");
|
|
7498
6874
|
}
|
|
7499
6875
|
}
|
|
7500
6876
|
);
|
|
7501
|
-
}
|
|
7502
|
-
const {
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
}
|
|
6877
|
+
};
|
|
6878
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
6879
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
6880
|
+
const onSubmit = async () => {
|
|
6881
|
+
setIsSubmitting(true);
|
|
6882
|
+
let requestSucceeded = false;
|
|
6883
|
+
await requestOrderEdit(void 0, {
|
|
6884
|
+
onError: (e) => {
|
|
6885
|
+
ui.toast.error(e.message);
|
|
6886
|
+
},
|
|
6887
|
+
onSuccess: () => {
|
|
6888
|
+
requestSucceeded = true;
|
|
6889
|
+
}
|
|
6890
|
+
});
|
|
6891
|
+
if (!requestSucceeded) {
|
|
6892
|
+
setIsSubmitting(false);
|
|
6893
|
+
return;
|
|
7514
6894
|
}
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
6895
|
+
await confirmOrderEdit(void 0, {
|
|
6896
|
+
onError: (e) => {
|
|
6897
|
+
ui.toast.error(e.message);
|
|
6898
|
+
},
|
|
6899
|
+
onSuccess: () => {
|
|
6900
|
+
handleSuccess();
|
|
6901
|
+
},
|
|
6902
|
+
onSettled: () => {
|
|
6903
|
+
setIsSubmitting(false);
|
|
6904
|
+
}
|
|
7521
6905
|
});
|
|
6906
|
+
};
|
|
6907
|
+
if (isError) {
|
|
6908
|
+
throw error;
|
|
7522
6909
|
}
|
|
7523
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
7530
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
7531
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
7532
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
7533
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
7534
|
-
] }),
|
|
7535
|
-
fields.map((field, index) => {
|
|
7536
|
-
const isDisabled = field.disabled || false;
|
|
7537
|
-
let placeholder = "-";
|
|
7538
|
-
if (typeof field.value === "object") {
|
|
7539
|
-
placeholder = "{ ... }";
|
|
7540
|
-
}
|
|
7541
|
-
if (Array.isArray(field.value)) {
|
|
7542
|
-
placeholder = "[ ... ]";
|
|
7543
|
-
}
|
|
7544
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7545
|
-
ConditionalTooltip,
|
|
7546
|
-
{
|
|
7547
|
-
showTooltip: isDisabled,
|
|
7548
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
7549
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
7550
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7551
|
-
"div",
|
|
7552
|
-
{
|
|
7553
|
-
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
7554
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
7555
|
-
}),
|
|
7556
|
-
children: [
|
|
7557
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7558
|
-
Form$2.Field,
|
|
7559
|
-
{
|
|
7560
|
-
control: form.control,
|
|
7561
|
-
name: `metadata.${index}.key`,
|
|
7562
|
-
render: ({ field: field2 }) => {
|
|
7563
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7564
|
-
GridInput,
|
|
7565
|
-
{
|
|
7566
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
7567
|
-
...field2,
|
|
7568
|
-
disabled: isDisabled,
|
|
7569
|
-
placeholder: "Key"
|
|
7570
|
-
}
|
|
7571
|
-
) }) });
|
|
7572
|
-
}
|
|
7573
|
-
}
|
|
7574
|
-
),
|
|
7575
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7576
|
-
Form$2.Field,
|
|
7577
|
-
{
|
|
7578
|
-
control: form.control,
|
|
7579
|
-
name: `metadata.${index}.value`,
|
|
7580
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
7581
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7582
|
-
GridInput,
|
|
7583
|
-
{
|
|
7584
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
7585
|
-
...field2,
|
|
7586
|
-
value: isDisabled ? placeholder : value,
|
|
7587
|
-
disabled: isDisabled,
|
|
7588
|
-
placeholder: "Value"
|
|
7589
|
-
}
|
|
7590
|
-
) }) });
|
|
7591
|
-
}
|
|
7592
|
-
}
|
|
7593
|
-
)
|
|
7594
|
-
]
|
|
7595
|
-
}
|
|
7596
|
-
),
|
|
7597
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
7598
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7599
|
-
ui.DropdownMenu.Trigger,
|
|
7600
|
-
{
|
|
7601
|
-
className: ui.clx(
|
|
7602
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
7603
|
-
{
|
|
7604
|
-
hidden: isDisabled
|
|
7605
|
-
}
|
|
7606
|
-
),
|
|
7607
|
-
disabled: isDisabled,
|
|
7608
|
-
asChild: true,
|
|
7609
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
|
|
7610
|
-
}
|
|
7611
|
-
),
|
|
7612
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
7613
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7614
|
-
ui.DropdownMenu.Item,
|
|
7615
|
-
{
|
|
7616
|
-
className: "gap-x-2",
|
|
7617
|
-
onClick: () => insertRow(index, "above"),
|
|
7618
|
-
children: [
|
|
7619
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
7620
|
-
"Insert row above"
|
|
7621
|
-
]
|
|
7622
|
-
}
|
|
7623
|
-
),
|
|
7624
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7625
|
-
ui.DropdownMenu.Item,
|
|
7626
|
-
{
|
|
7627
|
-
className: "gap-x-2",
|
|
7628
|
-
onClick: () => insertRow(index, "below"),
|
|
7629
|
-
children: [
|
|
7630
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
7631
|
-
"Insert row below"
|
|
7632
|
-
]
|
|
7633
|
-
}
|
|
7634
|
-
),
|
|
7635
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
7636
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7637
|
-
ui.DropdownMenu.Item,
|
|
7638
|
-
{
|
|
7639
|
-
className: "gap-x-2",
|
|
7640
|
-
onClick: () => deleteRow(index),
|
|
7641
|
-
children: [
|
|
7642
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
7643
|
-
"Delete row"
|
|
7644
|
-
]
|
|
7645
|
-
}
|
|
7646
|
-
)
|
|
7647
|
-
] })
|
|
7648
|
-
] })
|
|
7649
|
-
] })
|
|
7650
|
-
},
|
|
7651
|
-
field.id
|
|
7652
|
-
);
|
|
7653
|
-
})
|
|
7654
|
-
] }),
|
|
7655
|
-
hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
6910
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
6911
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
6912
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
6913
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
6914
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
6915
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
7656
6916
|
] }),
|
|
7657
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
6917
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6918
|
+
Combobox,
|
|
6919
|
+
{
|
|
6920
|
+
id: "promotion-combobox",
|
|
6921
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
6922
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
6923
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
6924
|
+
options: comboboxData.options,
|
|
6925
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
6926
|
+
searchValue: comboboxData.searchValue,
|
|
6927
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
6928
|
+
onChange: add,
|
|
6929
|
+
value: comboboxValue
|
|
6930
|
+
}
|
|
6931
|
+
)
|
|
6932
|
+
] }),
|
|
6933
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
6934
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6935
|
+
PromotionItem,
|
|
6936
|
+
{
|
|
6937
|
+
promotion,
|
|
6938
|
+
orderId: preview.id,
|
|
6939
|
+
isLoading: isPending
|
|
6940
|
+
},
|
|
6941
|
+
promotion.id
|
|
6942
|
+
)) })
|
|
6943
|
+
] }) }),
|
|
6944
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6945
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6946
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6947
|
+
ui.Button,
|
|
6948
|
+
{
|
|
6949
|
+
size: "small",
|
|
6950
|
+
type: "submit",
|
|
6951
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
6952
|
+
children: "Save"
|
|
6953
|
+
}
|
|
7675
6954
|
)
|
|
7676
|
-
}
|
|
7677
|
-
);
|
|
7678
|
-
});
|
|
7679
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
7680
|
-
const PlaceholderInner = () => {
|
|
7681
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
7682
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
7683
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7684
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
7685
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
7686
6955
|
] }) })
|
|
7687
6956
|
] });
|
|
7688
6957
|
};
|
|
7689
|
-
const
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
6958
|
+
const PromotionItem = ({
|
|
6959
|
+
promotion,
|
|
6960
|
+
orderId,
|
|
6961
|
+
isLoading
|
|
6962
|
+
}) => {
|
|
6963
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
6964
|
+
const onRemove = async () => {
|
|
6965
|
+
removePromotions(
|
|
7693
6966
|
{
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
6967
|
+
promo_codes: [promotion.code]
|
|
6968
|
+
},
|
|
6969
|
+
{
|
|
6970
|
+
onError: (e) => {
|
|
6971
|
+
ui.toast.error(e.message);
|
|
6972
|
+
}
|
|
7697
6973
|
}
|
|
7698
|
-
|
|
6974
|
+
);
|
|
6975
|
+
};
|
|
6976
|
+
const displayValue = getDisplayValue(promotion);
|
|
6977
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6978
|
+
"div",
|
|
6979
|
+
{
|
|
6980
|
+
className: ui.clx(
|
|
6981
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
6982
|
+
{
|
|
6983
|
+
"animate-pulse": isLoading
|
|
6984
|
+
}
|
|
6985
|
+
),
|
|
6986
|
+
children: [
|
|
6987
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
6988
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
6989
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
6990
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
6991
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
6992
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
6993
|
+
] }),
|
|
6994
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
6995
|
+
] })
|
|
6996
|
+
] }),
|
|
6997
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6998
|
+
ui.IconButton,
|
|
6999
|
+
{
|
|
7000
|
+
size: "small",
|
|
7001
|
+
type: "button",
|
|
7002
|
+
variant: "transparent",
|
|
7003
|
+
onClick: onRemove,
|
|
7004
|
+
isLoading: isPending || isLoading,
|
|
7005
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
7006
|
+
}
|
|
7007
|
+
)
|
|
7008
|
+
]
|
|
7009
|
+
},
|
|
7010
|
+
promotion.id
|
|
7011
|
+
);
|
|
7012
|
+
};
|
|
7013
|
+
function getDisplayValue(promotion) {
|
|
7014
|
+
const value = promotion.application_method?.value;
|
|
7015
|
+
if (!value) {
|
|
7016
|
+
return null;
|
|
7699
7017
|
}
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
value,
|
|
7705
|
-
disabled: true
|
|
7706
|
-
};
|
|
7018
|
+
if (promotion.application_method?.type === "fixed") {
|
|
7019
|
+
const currency = promotion.application_method?.currency_code;
|
|
7020
|
+
if (!currency) {
|
|
7021
|
+
return null;
|
|
7707
7022
|
}
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
key,
|
|
7714
|
-
value: stringValue,
|
|
7715
|
-
original_key: key
|
|
7716
|
-
};
|
|
7717
|
-
});
|
|
7023
|
+
return getLocaleAmount(value, currency);
|
|
7024
|
+
} else if (promotion.application_method?.type === "percentage") {
|
|
7025
|
+
return formatPercentage(value);
|
|
7026
|
+
}
|
|
7027
|
+
return null;
|
|
7718
7028
|
}
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
|
|
7723
|
-
|
|
7029
|
+
const formatter = new Intl.NumberFormat([], {
|
|
7030
|
+
style: "percent",
|
|
7031
|
+
minimumFractionDigits: 2
|
|
7032
|
+
});
|
|
7033
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
7034
|
+
let val = value || 0;
|
|
7035
|
+
if (!isPercentageValue) {
|
|
7036
|
+
val = val / 100;
|
|
7724
7037
|
}
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
if (
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7038
|
+
return formatter.format(val);
|
|
7039
|
+
};
|
|
7040
|
+
function getPromotionIds(items, shippingMethods) {
|
|
7041
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
7042
|
+
for (const item of items) {
|
|
7043
|
+
if (item.adjustments) {
|
|
7044
|
+
for (const adjustment of item.adjustments) {
|
|
7045
|
+
if (adjustment.promotion_id) {
|
|
7046
|
+
promotionIds.add(adjustment.promotion_id);
|
|
7047
|
+
}
|
|
7048
|
+
}
|
|
7736
7049
|
}
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
if (
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
const parsedNumber = parseFloat(value);
|
|
7745
|
-
if (!isNaN(parsedNumber)) {
|
|
7746
|
-
update[key] = parsedNumber;
|
|
7747
|
-
} else {
|
|
7748
|
-
update[key] = value;
|
|
7050
|
+
}
|
|
7051
|
+
for (const shippingMethod of shippingMethods) {
|
|
7052
|
+
if (shippingMethod.adjustments) {
|
|
7053
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
7054
|
+
if (adjustment.promotion_id) {
|
|
7055
|
+
promotionIds.add(adjustment.promotion_id);
|
|
7056
|
+
}
|
|
7749
7057
|
}
|
|
7750
7058
|
}
|
|
7751
|
-
});
|
|
7752
|
-
return update;
|
|
7753
|
-
}
|
|
7754
|
-
function getHasUneditableRows(metadata) {
|
|
7755
|
-
if (!metadata) {
|
|
7756
|
-
return false;
|
|
7757
7059
|
}
|
|
7758
|
-
return
|
|
7759
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7760
|
-
);
|
|
7060
|
+
return Array.from(promotionIds);
|
|
7761
7061
|
}
|
|
7762
7062
|
const handle$5 = {
|
|
7763
|
-
permissions:
|
|
7063
|
+
permissions: EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
|
|
7764
7064
|
};
|
|
7765
|
-
const
|
|
7766
|
-
const
|
|
7767
|
-
|
|
7768
|
-
PROMOTION_QUERY_KEY,
|
|
7769
|
-
query2 ? query2 : void 0
|
|
7770
|
-
],
|
|
7771
|
-
detail: (id, query2) => [
|
|
7772
|
-
PROMOTION_QUERY_KEY,
|
|
7065
|
+
const SalesChannel = () => {
|
|
7066
|
+
const { id } = reactRouterDom.useParams();
|
|
7067
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7773
7068
|
id,
|
|
7774
|
-
|
|
7775
|
-
|
|
7069
|
+
{
|
|
7070
|
+
fields: "+sales_channel_id"
|
|
7071
|
+
},
|
|
7072
|
+
{
|
|
7073
|
+
enabled: !!id
|
|
7074
|
+
}
|
|
7075
|
+
);
|
|
7076
|
+
if (isError) {
|
|
7077
|
+
throw error;
|
|
7078
|
+
}
|
|
7079
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
7080
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
7081
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
7082
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
7083
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7084
|
+
] }),
|
|
7085
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
7086
|
+
] });
|
|
7776
7087
|
};
|
|
7777
|
-
const
|
|
7778
|
-
const
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7088
|
+
const SalesChannelForm = ({ order }) => {
|
|
7089
|
+
const form = reactHookForm.useForm({
|
|
7090
|
+
defaultValues: {
|
|
7091
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
7092
|
+
},
|
|
7093
|
+
resolver: zod$1.zodResolver(schema$2)
|
|
7782
7094
|
});
|
|
7783
|
-
|
|
7095
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7096
|
+
const { handleSuccess } = useRouteModal();
|
|
7097
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
7098
|
+
await mutateAsync(
|
|
7099
|
+
{
|
|
7100
|
+
sales_channel_id: data.sales_channel_id
|
|
7101
|
+
},
|
|
7102
|
+
{
|
|
7103
|
+
onSuccess: () => {
|
|
7104
|
+
ui.toast.success("Sales channel updated");
|
|
7105
|
+
handleSuccess();
|
|
7106
|
+
},
|
|
7107
|
+
onError: (error) => {
|
|
7108
|
+
ui.toast.error(error.message);
|
|
7109
|
+
}
|
|
7110
|
+
}
|
|
7111
|
+
);
|
|
7112
|
+
});
|
|
7113
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7114
|
+
KeyboundForm,
|
|
7115
|
+
{
|
|
7116
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
7117
|
+
onSubmit,
|
|
7118
|
+
children: [
|
|
7119
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
7120
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7121
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7122
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7123
|
+
] }) })
|
|
7124
|
+
]
|
|
7125
|
+
}
|
|
7126
|
+
) });
|
|
7784
7127
|
};
|
|
7785
|
-
const
|
|
7128
|
+
const SalesChannelField = ({ control, order }) => {
|
|
7129
|
+
const salesChannels = useComboboxData({
|
|
7130
|
+
queryFn: async (params) => {
|
|
7131
|
+
return await sdk.admin.salesChannel.list(params);
|
|
7132
|
+
},
|
|
7133
|
+
queryKey: ["sales-channels"],
|
|
7134
|
+
getOptions: (data) => {
|
|
7135
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
7136
|
+
label: salesChannel.name,
|
|
7137
|
+
value: salesChannel.id
|
|
7138
|
+
}));
|
|
7139
|
+
},
|
|
7140
|
+
defaultValue: order.sales_channel_id || void 0
|
|
7141
|
+
});
|
|
7142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7143
|
+
Form$2.Field,
|
|
7144
|
+
{
|
|
7145
|
+
control,
|
|
7146
|
+
name: "sales_channel_id",
|
|
7147
|
+
render: ({ field }) => {
|
|
7148
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
7149
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7150
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7151
|
+
Combobox,
|
|
7152
|
+
{
|
|
7153
|
+
options: salesChannels.options,
|
|
7154
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
7155
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7156
|
+
searchValue: salesChannels.searchValue,
|
|
7157
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7158
|
+
placeholder: "Select sales channel",
|
|
7159
|
+
...field
|
|
7160
|
+
}
|
|
7161
|
+
) }),
|
|
7162
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
7163
|
+
] });
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
);
|
|
7167
|
+
};
|
|
7168
|
+
const schema$2 = zod.z.object({
|
|
7169
|
+
sales_channel_id: zod.z.string().min(1)
|
|
7170
|
+
});
|
|
7171
|
+
const handle$4 = {
|
|
7172
|
+
permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
|
|
7173
|
+
};
|
|
7174
|
+
function convertNumber(value) {
|
|
7175
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
7176
|
+
}
|
|
7177
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7178
|
+
const Shipping = () => {
|
|
7786
7179
|
const { id } = reactRouterDom.useParams();
|
|
7180
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
7181
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
7182
|
+
});
|
|
7787
7183
|
const {
|
|
7788
7184
|
order: preview,
|
|
7185
|
+
isPending: isPreviewPending,
|
|
7789
7186
|
isError: isPreviewError,
|
|
7790
7187
|
error: previewError
|
|
7791
|
-
} = useOrderPreview(id
|
|
7188
|
+
} = useOrderPreview(id);
|
|
7792
7189
|
useInitiateOrderEdit({ preview });
|
|
7793
7190
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
7191
|
+
if (isError) {
|
|
7192
|
+
throw error;
|
|
7193
|
+
}
|
|
7794
7194
|
if (isPreviewError) {
|
|
7795
7195
|
throw previewError;
|
|
7796
7196
|
}
|
|
7797
|
-
const
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7197
|
+
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
7198
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
7199
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
7200
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
7201
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
7202
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
7203
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
7204
|
+
] }) }) }),
|
|
7205
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
7206
|
+
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7207
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
7208
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
7209
|
+
] }) });
|
|
7802
7210
|
};
|
|
7803
|
-
const
|
|
7804
|
-
const {
|
|
7211
|
+
const ShippingForm = ({ preview, order }) => {
|
|
7212
|
+
const { setIsOpen } = useStackedModal();
|
|
7805
7213
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
7806
|
-
const [
|
|
7807
|
-
const
|
|
7808
|
-
const {
|
|
7809
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
7810
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
7214
|
+
const [data, setData] = React.useState(null);
|
|
7215
|
+
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
7216
|
+
const { shipping_options } = useShippingOptions(
|
|
7811
7217
|
{
|
|
7812
|
-
id:
|
|
7218
|
+
id: appliedShippingOptionIds,
|
|
7219
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
7813
7220
|
},
|
|
7814
7221
|
{
|
|
7815
|
-
enabled:
|
|
7222
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
7816
7223
|
}
|
|
7817
7224
|
);
|
|
7818
|
-
const
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
return data.promotions.map((promotion) => ({
|
|
7830
|
-
label: promotion.code,
|
|
7831
|
-
value: promotion.code
|
|
7832
|
-
}));
|
|
7833
|
-
}
|
|
7834
|
-
});
|
|
7835
|
-
const add = async (value) => {
|
|
7836
|
-
if (!value) {
|
|
7837
|
-
return;
|
|
7838
|
-
}
|
|
7839
|
-
addPromotions(
|
|
7840
|
-
{
|
|
7841
|
-
promo_codes: [value]
|
|
7842
|
-
},
|
|
7843
|
-
{
|
|
7844
|
-
onError: (e) => {
|
|
7845
|
-
ui.toast.error(e.message);
|
|
7846
|
-
comboboxData.onSearchValueChange("");
|
|
7847
|
-
setComboboxValue("");
|
|
7848
|
-
},
|
|
7849
|
-
onSuccess: () => {
|
|
7850
|
-
comboboxData.onSearchValueChange("");
|
|
7851
|
-
setComboboxValue("");
|
|
7852
|
-
}
|
|
7853
|
-
}
|
|
7854
|
-
);
|
|
7855
|
-
};
|
|
7225
|
+
const uniqueShippingProfiles = React.useMemo(() => {
|
|
7226
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
7227
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
7228
|
+
profiles.set(profile.id, profile);
|
|
7229
|
+
});
|
|
7230
|
+
shipping_options?.forEach((option) => {
|
|
7231
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
7232
|
+
});
|
|
7233
|
+
return Array.from(profiles.values());
|
|
7234
|
+
}, [order.items, shipping_options]);
|
|
7235
|
+
const { handleSuccess } = useRouteModal();
|
|
7856
7236
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
7857
|
-
const { mutateAsync: requestOrderEdit } =
|
|
7237
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
7238
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
7239
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
7858
7240
|
const onSubmit = async () => {
|
|
7859
7241
|
setIsSubmitting(true);
|
|
7860
7242
|
let requestSucceeded = false;
|
|
7861
7243
|
await requestOrderEdit(void 0, {
|
|
7862
7244
|
onError: (e) => {
|
|
7863
|
-
ui.toast.error(e.message);
|
|
7245
|
+
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
7864
7246
|
},
|
|
7865
7247
|
onSuccess: () => {
|
|
7866
7248
|
requestSucceeded = true;
|
|
@@ -7872,7 +7254,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
7872
7254
|
}
|
|
7873
7255
|
await confirmOrderEdit(void 0, {
|
|
7874
7256
|
onError: (e) => {
|
|
7875
|
-
ui.toast.error(e.message);
|
|
7257
|
+
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
7876
7258
|
},
|
|
7877
7259
|
onSuccess: () => {
|
|
7878
7260
|
handleSuccess();
|
|
@@ -7882,373 +7264,16 @@ const PromotionForm = ({ preview }) => {
|
|
|
7882
7264
|
}
|
|
7883
7265
|
});
|
|
7884
7266
|
};
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
7891
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
7892
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
7893
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
7894
|
-
] }),
|
|
7895
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7896
|
-
Combobox,
|
|
7897
|
-
{
|
|
7898
|
-
id: "promotion-combobox",
|
|
7899
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
7900
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
7901
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
7902
|
-
options: comboboxData.options,
|
|
7903
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
7904
|
-
searchValue: comboboxData.searchValue,
|
|
7905
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
7906
|
-
onChange: add,
|
|
7907
|
-
value: comboboxValue
|
|
7908
|
-
}
|
|
7909
|
-
)
|
|
7910
|
-
] }),
|
|
7911
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
7912
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
7913
|
-
PromotionItem,
|
|
7914
|
-
{
|
|
7915
|
-
promotion,
|
|
7916
|
-
orderId: preview.id,
|
|
7917
|
-
isLoading: isPending
|
|
7918
|
-
},
|
|
7919
|
-
promotion.id
|
|
7920
|
-
)) })
|
|
7921
|
-
] }) }),
|
|
7922
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7923
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7924
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7925
|
-
ui.Button,
|
|
7926
|
-
{
|
|
7927
|
-
size: "small",
|
|
7928
|
-
type: "submit",
|
|
7929
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
7930
|
-
children: "Save"
|
|
7931
|
-
}
|
|
7932
|
-
)
|
|
7933
|
-
] }) })
|
|
7934
|
-
] });
|
|
7935
|
-
};
|
|
7936
|
-
const PromotionItem = ({
|
|
7937
|
-
promotion,
|
|
7938
|
-
orderId,
|
|
7939
|
-
isLoading
|
|
7940
|
-
}) => {
|
|
7941
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
7942
|
-
const onRemove = async () => {
|
|
7943
|
-
removePromotions(
|
|
7944
|
-
{
|
|
7945
|
-
promo_codes: [promotion.code]
|
|
7946
|
-
},
|
|
7947
|
-
{
|
|
7948
|
-
onError: (e) => {
|
|
7949
|
-
ui.toast.error(e.message);
|
|
7950
|
-
}
|
|
7951
|
-
}
|
|
7952
|
-
);
|
|
7953
|
-
};
|
|
7954
|
-
const displayValue = getDisplayValue(promotion);
|
|
7955
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7956
|
-
"div",
|
|
7957
|
-
{
|
|
7958
|
-
className: ui.clx(
|
|
7959
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
7960
|
-
{
|
|
7961
|
-
"animate-pulse": isLoading
|
|
7962
|
-
}
|
|
7963
|
-
),
|
|
7964
|
-
children: [
|
|
7965
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
7966
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
7967
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
7968
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
7969
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
7970
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
7971
|
-
] }),
|
|
7972
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
7973
|
-
] })
|
|
7974
|
-
] }),
|
|
7975
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7976
|
-
ui.IconButton,
|
|
7977
|
-
{
|
|
7978
|
-
size: "small",
|
|
7979
|
-
type: "button",
|
|
7980
|
-
variant: "transparent",
|
|
7981
|
-
onClick: onRemove,
|
|
7982
|
-
isLoading: isPending || isLoading,
|
|
7983
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
7984
|
-
}
|
|
7985
|
-
)
|
|
7986
|
-
]
|
|
7987
|
-
},
|
|
7988
|
-
promotion.id
|
|
7989
|
-
);
|
|
7990
|
-
};
|
|
7991
|
-
function getDisplayValue(promotion) {
|
|
7992
|
-
const value = promotion.application_method?.value;
|
|
7993
|
-
if (!value) {
|
|
7994
|
-
return null;
|
|
7995
|
-
}
|
|
7996
|
-
if (promotion.application_method?.type === "fixed") {
|
|
7997
|
-
const currency = promotion.application_method?.currency_code;
|
|
7998
|
-
if (!currency) {
|
|
7999
|
-
return null;
|
|
8000
|
-
}
|
|
8001
|
-
return getLocaleAmount(value, currency);
|
|
8002
|
-
} else if (promotion.application_method?.type === "percentage") {
|
|
8003
|
-
return formatPercentage(value);
|
|
8004
|
-
}
|
|
8005
|
-
return null;
|
|
8006
|
-
}
|
|
8007
|
-
const formatter = new Intl.NumberFormat([], {
|
|
8008
|
-
style: "percent",
|
|
8009
|
-
minimumFractionDigits: 2
|
|
8010
|
-
});
|
|
8011
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
8012
|
-
let val = value || 0;
|
|
8013
|
-
if (!isPercentageValue) {
|
|
8014
|
-
val = val / 100;
|
|
8015
|
-
}
|
|
8016
|
-
return formatter.format(val);
|
|
8017
|
-
};
|
|
8018
|
-
function getPromotionIds(items, shippingMethods) {
|
|
8019
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
8020
|
-
for (const item of items) {
|
|
8021
|
-
if (item.adjustments) {
|
|
8022
|
-
for (const adjustment of item.adjustments) {
|
|
8023
|
-
if (adjustment.promotion_id) {
|
|
8024
|
-
promotionIds.add(adjustment.promotion_id);
|
|
8025
|
-
}
|
|
8026
|
-
}
|
|
8027
|
-
}
|
|
8028
|
-
}
|
|
8029
|
-
for (const shippingMethod of shippingMethods) {
|
|
8030
|
-
if (shippingMethod.adjustments) {
|
|
8031
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
8032
|
-
if (adjustment.promotion_id) {
|
|
8033
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7267
|
+
const onKeydown = React.useCallback(
|
|
7268
|
+
(e) => {
|
|
7269
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
7270
|
+
if (data || isSubmitting) {
|
|
7271
|
+
return;
|
|
8034
7272
|
}
|
|
7273
|
+
onSubmit();
|
|
8035
7274
|
}
|
|
8036
|
-
}
|
|
8037
|
-
}
|
|
8038
|
-
return Array.from(promotionIds);
|
|
8039
|
-
}
|
|
8040
|
-
const handle$4 = {
|
|
8041
|
-
permissions: EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
|
|
8042
|
-
};
|
|
8043
|
-
const SalesChannel = () => {
|
|
8044
|
-
const { id } = reactRouterDom.useParams();
|
|
8045
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
8046
|
-
id,
|
|
8047
|
-
{
|
|
8048
|
-
fields: "+sales_channel_id"
|
|
8049
7275
|
},
|
|
8050
|
-
|
|
8051
|
-
enabled: !!id
|
|
8052
|
-
}
|
|
8053
|
-
);
|
|
8054
|
-
if (isError) {
|
|
8055
|
-
throw error;
|
|
8056
|
-
}
|
|
8057
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
8058
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
8059
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
8060
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
8061
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
8062
|
-
] }),
|
|
8063
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
8064
|
-
] });
|
|
8065
|
-
};
|
|
8066
|
-
const SalesChannelForm = ({ order }) => {
|
|
8067
|
-
const form = reactHookForm.useForm({
|
|
8068
|
-
defaultValues: {
|
|
8069
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
8070
|
-
},
|
|
8071
|
-
resolver: zod$1.zodResolver(schema$2)
|
|
8072
|
-
});
|
|
8073
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8074
|
-
const { handleSuccess } = useRouteModal();
|
|
8075
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
8076
|
-
await mutateAsync(
|
|
8077
|
-
{
|
|
8078
|
-
sales_channel_id: data.sales_channel_id
|
|
8079
|
-
},
|
|
8080
|
-
{
|
|
8081
|
-
onSuccess: () => {
|
|
8082
|
-
ui.toast.success("Sales channel updated");
|
|
8083
|
-
handleSuccess();
|
|
8084
|
-
},
|
|
8085
|
-
onError: (error) => {
|
|
8086
|
-
ui.toast.error(error.message);
|
|
8087
|
-
}
|
|
8088
|
-
}
|
|
8089
|
-
);
|
|
8090
|
-
});
|
|
8091
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8092
|
-
KeyboundForm,
|
|
8093
|
-
{
|
|
8094
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
8095
|
-
onSubmit,
|
|
8096
|
-
children: [
|
|
8097
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
8098
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
8099
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
8100
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
8101
|
-
] }) })
|
|
8102
|
-
]
|
|
8103
|
-
}
|
|
8104
|
-
) });
|
|
8105
|
-
};
|
|
8106
|
-
const SalesChannelField = ({ control, order }) => {
|
|
8107
|
-
const salesChannels = useComboboxData({
|
|
8108
|
-
queryFn: async (params) => {
|
|
8109
|
-
return await sdk.admin.salesChannel.list(params);
|
|
8110
|
-
},
|
|
8111
|
-
queryKey: ["sales-channels"],
|
|
8112
|
-
getOptions: (data) => {
|
|
8113
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
8114
|
-
label: salesChannel.name,
|
|
8115
|
-
value: salesChannel.id
|
|
8116
|
-
}));
|
|
8117
|
-
},
|
|
8118
|
-
defaultValue: order.sales_channel_id || void 0
|
|
8119
|
-
});
|
|
8120
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8121
|
-
Form$2.Field,
|
|
8122
|
-
{
|
|
8123
|
-
control,
|
|
8124
|
-
name: "sales_channel_id",
|
|
8125
|
-
render: ({ field }) => {
|
|
8126
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
8127
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
8128
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8129
|
-
Combobox,
|
|
8130
|
-
{
|
|
8131
|
-
options: salesChannels.options,
|
|
8132
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
8133
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
8134
|
-
searchValue: salesChannels.searchValue,
|
|
8135
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
8136
|
-
placeholder: "Select sales channel",
|
|
8137
|
-
...field
|
|
8138
|
-
}
|
|
8139
|
-
) }),
|
|
8140
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
8141
|
-
] });
|
|
8142
|
-
}
|
|
8143
|
-
}
|
|
8144
|
-
);
|
|
8145
|
-
};
|
|
8146
|
-
const schema$2 = zod.z.object({
|
|
8147
|
-
sales_channel_id: zod.z.string().min(1)
|
|
8148
|
-
});
|
|
8149
|
-
const handle$3 = {
|
|
8150
|
-
permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
|
|
8151
|
-
};
|
|
8152
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
8153
|
-
const Shipping = () => {
|
|
8154
|
-
const { id } = reactRouterDom.useParams();
|
|
8155
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
8156
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
8157
|
-
});
|
|
8158
|
-
const {
|
|
8159
|
-
order: preview,
|
|
8160
|
-
isPending: isPreviewPending,
|
|
8161
|
-
isError: isPreviewError,
|
|
8162
|
-
error: previewError
|
|
8163
|
-
} = useOrderPreview(id);
|
|
8164
|
-
useInitiateOrderEdit({ preview });
|
|
8165
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
8166
|
-
if (isError) {
|
|
8167
|
-
throw error;
|
|
8168
|
-
}
|
|
8169
|
-
if (isPreviewError) {
|
|
8170
|
-
throw previewError;
|
|
8171
|
-
}
|
|
8172
|
-
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
8173
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
8174
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
8175
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
8176
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
8177
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
8178
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
8179
|
-
] }) }) }),
|
|
8180
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
8181
|
-
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8182
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
8183
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
8184
|
-
] }) });
|
|
8185
|
-
};
|
|
8186
|
-
const ShippingForm = ({ preview, order }) => {
|
|
8187
|
-
const { setIsOpen } = useStackedModal();
|
|
8188
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
8189
|
-
const [data, setData] = React.useState(null);
|
|
8190
|
-
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
8191
|
-
const { shipping_options } = useShippingOptions(
|
|
8192
|
-
{
|
|
8193
|
-
id: appliedShippingOptionIds,
|
|
8194
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
8195
|
-
},
|
|
8196
|
-
{
|
|
8197
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
8198
|
-
}
|
|
8199
|
-
);
|
|
8200
|
-
const uniqueShippingProfiles = React.useMemo(() => {
|
|
8201
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
8202
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
8203
|
-
profiles.set(profile.id, profile);
|
|
8204
|
-
});
|
|
8205
|
-
shipping_options?.forEach((option) => {
|
|
8206
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
8207
|
-
});
|
|
8208
|
-
return Array.from(profiles.values());
|
|
8209
|
-
}, [order.items, shipping_options]);
|
|
8210
|
-
const { handleSuccess } = useRouteModal();
|
|
8211
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
8212
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
8213
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
8214
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
8215
|
-
const onSubmit = async () => {
|
|
8216
|
-
setIsSubmitting(true);
|
|
8217
|
-
let requestSucceeded = false;
|
|
8218
|
-
await requestOrderEdit(void 0, {
|
|
8219
|
-
onError: (e) => {
|
|
8220
|
-
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
8221
|
-
},
|
|
8222
|
-
onSuccess: () => {
|
|
8223
|
-
requestSucceeded = true;
|
|
8224
|
-
}
|
|
8225
|
-
});
|
|
8226
|
-
if (!requestSucceeded) {
|
|
8227
|
-
setIsSubmitting(false);
|
|
8228
|
-
return;
|
|
8229
|
-
}
|
|
8230
|
-
await confirmOrderEdit(void 0, {
|
|
8231
|
-
onError: (e) => {
|
|
8232
|
-
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
8233
|
-
},
|
|
8234
|
-
onSuccess: () => {
|
|
8235
|
-
handleSuccess();
|
|
8236
|
-
},
|
|
8237
|
-
onSettled: () => {
|
|
8238
|
-
setIsSubmitting(false);
|
|
8239
|
-
}
|
|
8240
|
-
});
|
|
8241
|
-
};
|
|
8242
|
-
const onKeydown = React.useCallback(
|
|
8243
|
-
(e) => {
|
|
8244
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
8245
|
-
if (data || isSubmitting) {
|
|
8246
|
-
return;
|
|
8247
|
-
}
|
|
8248
|
-
onSubmit();
|
|
8249
|
-
}
|
|
8250
|
-
},
|
|
8251
|
-
[data, isSubmitting, onSubmit]
|
|
7276
|
+
[data, isSubmitting, onSubmit]
|
|
8252
7277
|
);
|
|
8253
7278
|
React.useEffect(() => {
|
|
8254
7279
|
document.addEventListener("keydown", onKeydown);
|
|
@@ -8450,7 +7475,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
8450
7475
|
]
|
|
8451
7476
|
}
|
|
8452
7477
|
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
8453
|
-
StackedModalTrigger,
|
|
7478
|
+
StackedModalTrigger$1,
|
|
8454
7479
|
{
|
|
8455
7480
|
shippingProfileId: profile.id,
|
|
8456
7481
|
shippingOption,
|
|
@@ -8560,7 +7585,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
8560
7585
|
] }) })
|
|
8561
7586
|
] });
|
|
8562
7587
|
};
|
|
8563
|
-
const StackedModalTrigger = ({
|
|
7588
|
+
const StackedModalTrigger$1 = ({
|
|
8564
7589
|
shippingProfileId,
|
|
8565
7590
|
shippingOption,
|
|
8566
7591
|
shippingMethod,
|
|
@@ -8943,7 +7968,7 @@ const CustomAmountField = ({
|
|
|
8943
7968
|
}
|
|
8944
7969
|
);
|
|
8945
7970
|
};
|
|
8946
|
-
const handle$
|
|
7971
|
+
const handle$3 = {
|
|
8947
7972
|
permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
|
|
8948
7973
|
};
|
|
8949
7974
|
const ShippingAddress = () => {
|
|
@@ -9148,7 +8173,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
9148
8173
|
) });
|
|
9149
8174
|
};
|
|
9150
8175
|
const schema$1 = addressSchema;
|
|
9151
|
-
const handle$
|
|
8176
|
+
const handle$2 = {
|
|
9152
8177
|
permissions: EDIT_DRAFT_ORDER_PERMISSIONS
|
|
9153
8178
|
};
|
|
9154
8179
|
const TransferOwnership = () => {
|
|
@@ -9497,139 +8522,1114 @@ const Illustration = () => {
|
|
|
9497
8522
|
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
9498
8523
|
fill: "#A1A1AA"
|
|
9499
8524
|
}
|
|
9500
|
-
),
|
|
8525
|
+
),
|
|
8526
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8527
|
+
"path",
|
|
8528
|
+
{
|
|
8529
|
+
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
8530
|
+
fill: "#52525B"
|
|
8531
|
+
}
|
|
8532
|
+
),
|
|
8533
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8534
|
+
"path",
|
|
8535
|
+
{
|
|
8536
|
+
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
8537
|
+
stroke: "#A1A1AA",
|
|
8538
|
+
strokeWidth: "1.5",
|
|
8539
|
+
strokeLinecap: "round",
|
|
8540
|
+
strokeLinejoin: "round"
|
|
8541
|
+
}
|
|
8542
|
+
) }),
|
|
8543
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8544
|
+
"path",
|
|
8545
|
+
{
|
|
8546
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
8547
|
+
stroke: "#A1A1AA",
|
|
8548
|
+
strokeWidth: "1.5",
|
|
8549
|
+
strokeLinecap: "round",
|
|
8550
|
+
strokeLinejoin: "round"
|
|
8551
|
+
}
|
|
8552
|
+
) }),
|
|
8553
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8554
|
+
"path",
|
|
8555
|
+
{
|
|
8556
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
8557
|
+
stroke: "#A1A1AA",
|
|
8558
|
+
strokeWidth: "1.5",
|
|
8559
|
+
strokeLinecap: "round",
|
|
8560
|
+
strokeLinejoin: "round"
|
|
8561
|
+
}
|
|
8562
|
+
) }),
|
|
8563
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8564
|
+
"path",
|
|
8565
|
+
{
|
|
8566
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
8567
|
+
stroke: "#A1A1AA",
|
|
8568
|
+
strokeWidth: "1.5",
|
|
8569
|
+
strokeLinecap: "round",
|
|
8570
|
+
strokeLinejoin: "round"
|
|
8571
|
+
}
|
|
8572
|
+
) }),
|
|
8573
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8574
|
+
"path",
|
|
8575
|
+
{
|
|
8576
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
8577
|
+
stroke: "#A1A1AA",
|
|
8578
|
+
strokeWidth: "1.5",
|
|
8579
|
+
strokeLinecap: "round",
|
|
8580
|
+
strokeLinejoin: "round"
|
|
8581
|
+
}
|
|
8582
|
+
) }),
|
|
8583
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8584
|
+
"path",
|
|
8585
|
+
{
|
|
8586
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
8587
|
+
stroke: "#A1A1AA",
|
|
8588
|
+
strokeWidth: "1.5",
|
|
8589
|
+
strokeLinecap: "round",
|
|
8590
|
+
strokeLinejoin: "round"
|
|
8591
|
+
}
|
|
8592
|
+
) }),
|
|
8593
|
+
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
8594
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8595
|
+
"rect",
|
|
8596
|
+
{
|
|
8597
|
+
width: "12",
|
|
8598
|
+
height: "12",
|
|
8599
|
+
fill: "white",
|
|
8600
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
8601
|
+
}
|
|
8602
|
+
) }),
|
|
8603
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8604
|
+
"rect",
|
|
8605
|
+
{
|
|
8606
|
+
width: "12",
|
|
8607
|
+
height: "12",
|
|
8608
|
+
fill: "white",
|
|
8609
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
8610
|
+
}
|
|
8611
|
+
) }),
|
|
8612
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8613
|
+
"rect",
|
|
8614
|
+
{
|
|
8615
|
+
width: "12",
|
|
8616
|
+
height: "12",
|
|
8617
|
+
fill: "white",
|
|
8618
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
8619
|
+
}
|
|
8620
|
+
) }),
|
|
8621
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8622
|
+
"rect",
|
|
8623
|
+
{
|
|
8624
|
+
width: "12",
|
|
8625
|
+
height: "12",
|
|
8626
|
+
fill: "white",
|
|
8627
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
8628
|
+
}
|
|
8629
|
+
) }),
|
|
8630
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8631
|
+
"rect",
|
|
8632
|
+
{
|
|
8633
|
+
width: "12",
|
|
8634
|
+
height: "12",
|
|
8635
|
+
fill: "white",
|
|
8636
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
8637
|
+
}
|
|
8638
|
+
) }),
|
|
8639
|
+
/* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8640
|
+
"rect",
|
|
8641
|
+
{
|
|
8642
|
+
width: "12",
|
|
8643
|
+
height: "12",
|
|
8644
|
+
fill: "white",
|
|
8645
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
8646
|
+
}
|
|
8647
|
+
) })
|
|
8648
|
+
] })
|
|
8649
|
+
]
|
|
8650
|
+
}
|
|
8651
|
+
);
|
|
8652
|
+
};
|
|
8653
|
+
const schema = zod.z.object({
|
|
8654
|
+
customer_id: zod.z.string().min(1)
|
|
8655
|
+
});
|
|
8656
|
+
const handle$1 = {
|
|
8657
|
+
permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
|
|
8658
|
+
};
|
|
8659
|
+
const NumberInput = React.forwardRef(
|
|
8660
|
+
({
|
|
8661
|
+
value,
|
|
8662
|
+
onChange,
|
|
8663
|
+
size = "base",
|
|
8664
|
+
min = 0,
|
|
8665
|
+
max = 100,
|
|
8666
|
+
step = 1,
|
|
8667
|
+
className,
|
|
8668
|
+
disabled,
|
|
8669
|
+
...props
|
|
8670
|
+
}, ref) => {
|
|
8671
|
+
const handleChange = (event) => {
|
|
8672
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
8673
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
8674
|
+
onChange(newValue);
|
|
8675
|
+
}
|
|
8676
|
+
};
|
|
8677
|
+
const handleIncrement = () => {
|
|
8678
|
+
const newValue = value + step;
|
|
8679
|
+
if (max === void 0 || newValue <= max) {
|
|
8680
|
+
onChange(newValue);
|
|
8681
|
+
}
|
|
8682
|
+
};
|
|
8683
|
+
const handleDecrement = () => {
|
|
8684
|
+
const newValue = value - step;
|
|
8685
|
+
if (min === void 0 || newValue >= min) {
|
|
8686
|
+
onChange(newValue);
|
|
8687
|
+
}
|
|
8688
|
+
};
|
|
8689
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8690
|
+
"div",
|
|
8691
|
+
{
|
|
8692
|
+
className: ui.clx(
|
|
8693
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
8694
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
8695
|
+
{
|
|
8696
|
+
"h-7": size === "small",
|
|
8697
|
+
"h-8": size === "base"
|
|
8698
|
+
},
|
|
8699
|
+
className
|
|
8700
|
+
),
|
|
8701
|
+
children: [
|
|
8702
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8703
|
+
"input",
|
|
8704
|
+
{
|
|
8705
|
+
ref,
|
|
8706
|
+
type: "number",
|
|
8707
|
+
value,
|
|
8708
|
+
onChange: handleChange,
|
|
8709
|
+
min,
|
|
8710
|
+
max,
|
|
8711
|
+
step,
|
|
8712
|
+
className: ui.clx(
|
|
8713
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
8714
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
8715
|
+
"placeholder:text-ui-fg-muted"
|
|
8716
|
+
),
|
|
8717
|
+
...props
|
|
8718
|
+
}
|
|
8719
|
+
),
|
|
8720
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
8721
|
+
"button",
|
|
8722
|
+
{
|
|
8723
|
+
className: ui.clx(
|
|
8724
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
8725
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
8726
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
8727
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
8728
|
+
{
|
|
8729
|
+
"size-7": size === "small",
|
|
8730
|
+
"size-8": size === "base"
|
|
8731
|
+
}
|
|
8732
|
+
),
|
|
8733
|
+
type: "button",
|
|
8734
|
+
onClick: handleDecrement,
|
|
8735
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
8736
|
+
children: [
|
|
8737
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
|
|
8738
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
8739
|
+
]
|
|
8740
|
+
}
|
|
8741
|
+
),
|
|
8742
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
8743
|
+
"button",
|
|
8744
|
+
{
|
|
8745
|
+
className: ui.clx(
|
|
8746
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
8747
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
8748
|
+
"focus:bg-ui-bg-field-hover",
|
|
8749
|
+
"hover:bg-ui-bg-field-hover",
|
|
8750
|
+
{
|
|
8751
|
+
"size-7": size === "small",
|
|
8752
|
+
"size-8": size === "base"
|
|
8753
|
+
}
|
|
8754
|
+
),
|
|
8755
|
+
type: "button",
|
|
8756
|
+
onClick: handleIncrement,
|
|
8757
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
8758
|
+
children: [
|
|
8759
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
|
|
8760
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
8761
|
+
]
|
|
8762
|
+
}
|
|
8763
|
+
)
|
|
8764
|
+
]
|
|
8765
|
+
}
|
|
8766
|
+
);
|
|
8767
|
+
}
|
|
8768
|
+
);
|
|
8769
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
8770
|
+
const productVariantsQueryKeys = {
|
|
8771
|
+
list: (query2) => [
|
|
8772
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
8773
|
+
query2 ? query2 : void 0
|
|
8774
|
+
]
|
|
8775
|
+
};
|
|
8776
|
+
const useProductVariants = (query2, options) => {
|
|
8777
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
8778
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
8779
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
8780
|
+
...options
|
|
8781
|
+
});
|
|
8782
|
+
return { ...data, ...rest };
|
|
8783
|
+
};
|
|
8784
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
8785
|
+
const Items = () => {
|
|
8786
|
+
const { id } = reactRouterDom.useParams();
|
|
8787
|
+
const {
|
|
8788
|
+
order: preview,
|
|
8789
|
+
isPending: isPreviewPending,
|
|
8790
|
+
isError: isPreviewError,
|
|
8791
|
+
error: previewError
|
|
8792
|
+
} = useOrderPreview(id, void 0, {
|
|
8793
|
+
placeholderData: reactQuery.keepPreviousData
|
|
8794
|
+
});
|
|
8795
|
+
useInitiateOrderEdit({ preview });
|
|
8796
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
8797
|
+
id,
|
|
8798
|
+
{
|
|
8799
|
+
fields: "currency_code"
|
|
8800
|
+
},
|
|
8801
|
+
{
|
|
8802
|
+
enabled: !!id
|
|
8803
|
+
}
|
|
8804
|
+
);
|
|
8805
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
8806
|
+
if (isError) {
|
|
8807
|
+
throw error;
|
|
8808
|
+
}
|
|
8809
|
+
if (isPreviewError) {
|
|
8810
|
+
throw previewError;
|
|
8811
|
+
}
|
|
8812
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
8813
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8814
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
8815
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
8816
|
+
] }) });
|
|
8817
|
+
};
|
|
8818
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
8819
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
8820
|
+
const [modalContent, setModalContent] = React.useState(
|
|
8821
|
+
null
|
|
8822
|
+
);
|
|
8823
|
+
const { handleSuccess } = useRouteModal();
|
|
8824
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
8825
|
+
const { hasPermission } = hooks.usePermissions();
|
|
8826
|
+
const canReadVariants = hasPermission("product_variant:read");
|
|
8827
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
8828
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
8829
|
+
const itemCount = preview.items?.reduce((acc, item) => acc + item.quantity, 0) || 0;
|
|
8830
|
+
const matches = React.useMemo(() => {
|
|
8831
|
+
return matchSorter.matchSorter(preview.items, query2, {
|
|
8832
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
8833
|
+
});
|
|
8834
|
+
}, [preview.items, query2]);
|
|
8835
|
+
const onSubmit = async () => {
|
|
8836
|
+
setIsSubmitting(true);
|
|
8837
|
+
let requestSucceeded = false;
|
|
8838
|
+
await requestOrderEdit(void 0, {
|
|
8839
|
+
onError: (e) => {
|
|
8840
|
+
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
8841
|
+
},
|
|
8842
|
+
onSuccess: () => {
|
|
8843
|
+
requestSucceeded = true;
|
|
8844
|
+
}
|
|
8845
|
+
});
|
|
8846
|
+
if (!requestSucceeded) {
|
|
8847
|
+
setIsSubmitting(false);
|
|
8848
|
+
return;
|
|
8849
|
+
}
|
|
8850
|
+
await confirmOrderEdit(void 0, {
|
|
8851
|
+
onError: (e) => {
|
|
8852
|
+
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
8853
|
+
},
|
|
8854
|
+
onSuccess: () => {
|
|
8855
|
+
handleSuccess();
|
|
8856
|
+
},
|
|
8857
|
+
onSettled: () => {
|
|
8858
|
+
setIsSubmitting(false);
|
|
8859
|
+
}
|
|
8860
|
+
});
|
|
8861
|
+
};
|
|
8862
|
+
const onKeyDown = React.useCallback(
|
|
8863
|
+
(e) => {
|
|
8864
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
8865
|
+
if (modalContent || isSubmitting) {
|
|
8866
|
+
return;
|
|
8867
|
+
}
|
|
8868
|
+
onSubmit();
|
|
8869
|
+
}
|
|
8870
|
+
},
|
|
8871
|
+
[modalContent, isSubmitting, onSubmit]
|
|
8872
|
+
);
|
|
8873
|
+
React.useEffect(() => {
|
|
8874
|
+
document.addEventListener("keydown", onKeyDown);
|
|
8875
|
+
return () => {
|
|
8876
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
8877
|
+
};
|
|
8878
|
+
}, [onKeyDown]);
|
|
8879
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
8880
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
8881
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8882
|
+
StackedFocusModal,
|
|
8883
|
+
{
|
|
8884
|
+
id: STACKED_MODAL_ID,
|
|
8885
|
+
onOpenChangeCallback: (open) => {
|
|
8886
|
+
if (!open) {
|
|
8887
|
+
setModalContent(null);
|
|
8888
|
+
}
|
|
8889
|
+
},
|
|
8890
|
+
children: [
|
|
8891
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
8892
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8893
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
|
|
8894
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
|
|
8895
|
+
] }),
|
|
8896
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
8897
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
8898
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
8899
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
8900
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
8901
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
8902
|
+
] }),
|
|
8903
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
8904
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8905
|
+
ui.Input,
|
|
8906
|
+
{
|
|
8907
|
+
type: "search",
|
|
8908
|
+
placeholder: "Search items",
|
|
8909
|
+
value: searchValue,
|
|
8910
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
8911
|
+
}
|
|
8912
|
+
) }),
|
|
8913
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
8914
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
|
|
8915
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
8916
|
+
canReadVariants && /* @__PURE__ */ jsxRuntime.jsx(
|
|
8917
|
+
StackedModalTrigger,
|
|
8918
|
+
{
|
|
8919
|
+
type: "add-items",
|
|
8920
|
+
setModalContent
|
|
8921
|
+
}
|
|
8922
|
+
),
|
|
8923
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8924
|
+
StackedModalTrigger,
|
|
8925
|
+
{
|
|
8926
|
+
type: "add-custom-item",
|
|
8927
|
+
setModalContent
|
|
8928
|
+
}
|
|
8929
|
+
)
|
|
8930
|
+
] })
|
|
8931
|
+
] })
|
|
8932
|
+
] })
|
|
8933
|
+
] }),
|
|
8934
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
8935
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
8936
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
8937
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
8938
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
8939
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", {})
|
|
8940
|
+
] }) }),
|
|
8941
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
8942
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
8943
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
8944
|
+
] }) : matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
8945
|
+
Item,
|
|
8946
|
+
{
|
|
8947
|
+
item,
|
|
8948
|
+
preview,
|
|
8949
|
+
currencyCode
|
|
8950
|
+
},
|
|
8951
|
+
item.id
|
|
8952
|
+
)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
8953
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
8954
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
8955
|
+
'No items found for "',
|
|
8956
|
+
query2,
|
|
8957
|
+
'".'
|
|
8958
|
+
] })
|
|
8959
|
+
] }) })
|
|
8960
|
+
] })
|
|
8961
|
+
] }),
|
|
8962
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
8963
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
8964
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
8965
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8966
|
+
ui.Text,
|
|
8967
|
+
{
|
|
8968
|
+
size: "small",
|
|
8969
|
+
leading: "compact",
|
|
8970
|
+
className: "text-ui-fg-subtle",
|
|
8971
|
+
children: [
|
|
8972
|
+
itemCount,
|
|
8973
|
+
" ",
|
|
8974
|
+
itemCount === 1 ? "item" : "items"
|
|
8975
|
+
]
|
|
8976
|
+
}
|
|
8977
|
+
) }),
|
|
8978
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
8979
|
+
] })
|
|
8980
|
+
] }) }),
|
|
8981
|
+
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
8982
|
+
CustomItemForm,
|
|
8983
|
+
{
|
|
8984
|
+
orderId: preview.id,
|
|
8985
|
+
currencyCode
|
|
8986
|
+
}
|
|
8987
|
+
) : null)
|
|
8988
|
+
]
|
|
8989
|
+
}
|
|
8990
|
+
) }),
|
|
8991
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
8992
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
8993
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8994
|
+
ui.Button,
|
|
8995
|
+
{
|
|
8996
|
+
size: "small",
|
|
8997
|
+
type: "button",
|
|
8998
|
+
onClick: onSubmit,
|
|
8999
|
+
isLoading: isSubmitting,
|
|
9000
|
+
children: "Save"
|
|
9001
|
+
}
|
|
9002
|
+
)
|
|
9003
|
+
] }) })
|
|
9004
|
+
] });
|
|
9005
|
+
};
|
|
9006
|
+
const Item = ({ item, preview, currencyCode }) => {
|
|
9007
|
+
if (item.variant_id) {
|
|
9008
|
+
return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
|
|
9009
|
+
}
|
|
9010
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
|
|
9011
|
+
};
|
|
9012
|
+
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
9013
|
+
const [editing, setEditing] = React.useState(false);
|
|
9014
|
+
const form = reactHookForm.useForm({
|
|
9015
|
+
defaultValues: {
|
|
9016
|
+
quantity: item.quantity,
|
|
9017
|
+
unit_price: item.unit_price
|
|
9018
|
+
},
|
|
9019
|
+
resolver: zod$1.zodResolver(variantItemSchema)
|
|
9020
|
+
});
|
|
9021
|
+
const actionId = React.useMemo(() => {
|
|
9022
|
+
return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
|
|
9023
|
+
}, [item]);
|
|
9024
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
9025
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
9026
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
9027
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem || isRemovingActionItem;
|
|
9028
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9029
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
9030
|
+
setEditing(false);
|
|
9031
|
+
return;
|
|
9032
|
+
}
|
|
9033
|
+
if (!actionId) {
|
|
9034
|
+
await updateOriginalItem(
|
|
9035
|
+
{
|
|
9036
|
+
item_id: item.id,
|
|
9037
|
+
quantity: data.quantity,
|
|
9038
|
+
unit_price: convertNumber(data.unit_price)
|
|
9039
|
+
},
|
|
9040
|
+
{
|
|
9041
|
+
onSuccess: () => {
|
|
9042
|
+
setEditing(false);
|
|
9043
|
+
},
|
|
9044
|
+
onError: (e) => {
|
|
9045
|
+
ui.toast.error(e.message);
|
|
9046
|
+
}
|
|
9047
|
+
}
|
|
9048
|
+
);
|
|
9049
|
+
return;
|
|
9050
|
+
}
|
|
9051
|
+
if (data.quantity === 0) {
|
|
9052
|
+
await removeActionItem(actionId, {
|
|
9053
|
+
onSuccess: () => {
|
|
9054
|
+
setEditing(false);
|
|
9055
|
+
},
|
|
9056
|
+
onError: (e) => {
|
|
9057
|
+
ui.toast.error(e.message);
|
|
9058
|
+
}
|
|
9059
|
+
});
|
|
9060
|
+
return;
|
|
9061
|
+
}
|
|
9062
|
+
await updateActionItem(
|
|
9063
|
+
{
|
|
9064
|
+
action_id: actionId,
|
|
9065
|
+
quantity: data.quantity,
|
|
9066
|
+
unit_price: convertNumber(data.unit_price)
|
|
9067
|
+
},
|
|
9068
|
+
{
|
|
9069
|
+
onSuccess: () => {
|
|
9070
|
+
setEditing(false);
|
|
9071
|
+
},
|
|
9072
|
+
onError: (e) => {
|
|
9073
|
+
ui.toast.error(e.message);
|
|
9074
|
+
}
|
|
9075
|
+
}
|
|
9076
|
+
);
|
|
9077
|
+
});
|
|
9078
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
9079
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
|
|
9080
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9081
|
+
Thumbnail,
|
|
9082
|
+
{
|
|
9083
|
+
thumbnail: item.thumbnail,
|
|
9084
|
+
alt: item.product_title ?? void 0
|
|
9085
|
+
}
|
|
9086
|
+
),
|
|
9087
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
9088
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
9089
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
9090
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
9091
|
+
ui.Text,
|
|
9092
|
+
{
|
|
9093
|
+
size: "small",
|
|
9094
|
+
leading: "compact",
|
|
9095
|
+
className: "text-ui-fg-subtle",
|
|
9096
|
+
children: [
|
|
9097
|
+
"(",
|
|
9098
|
+
item.variant_title,
|
|
9099
|
+
")"
|
|
9100
|
+
]
|
|
9101
|
+
}
|
|
9102
|
+
)
|
|
9103
|
+
] }),
|
|
9501
9104
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9502
|
-
|
|
9503
|
-
{
|
|
9504
|
-
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
9505
|
-
fill: "#52525B"
|
|
9506
|
-
}
|
|
9507
|
-
),
|
|
9508
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9509
|
-
"path",
|
|
9510
|
-
{
|
|
9511
|
-
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
9512
|
-
stroke: "#A1A1AA",
|
|
9513
|
-
strokeWidth: "1.5",
|
|
9514
|
-
strokeLinecap: "round",
|
|
9515
|
-
strokeLinejoin: "round"
|
|
9516
|
-
}
|
|
9517
|
-
) }),
|
|
9518
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9519
|
-
"path",
|
|
9520
|
-
{
|
|
9521
|
-
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
9522
|
-
stroke: "#A1A1AA",
|
|
9523
|
-
strokeWidth: "1.5",
|
|
9524
|
-
strokeLinecap: "round",
|
|
9525
|
-
strokeLinejoin: "round"
|
|
9526
|
-
}
|
|
9527
|
-
) }),
|
|
9528
|
-
/* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9529
|
-
"path",
|
|
9105
|
+
ui.Text,
|
|
9530
9106
|
{
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
strokeLinejoin: "round"
|
|
9107
|
+
size: "small",
|
|
9108
|
+
leading: "compact",
|
|
9109
|
+
className: "text-ui-fg-subtle",
|
|
9110
|
+
children: item.variant_sku
|
|
9536
9111
|
}
|
|
9537
|
-
)
|
|
9538
|
-
|
|
9539
|
-
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9112
|
+
)
|
|
9113
|
+
] })
|
|
9114
|
+
] }),
|
|
9115
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9116
|
+
Form$2.Field,
|
|
9117
|
+
{
|
|
9118
|
+
control: form.control,
|
|
9119
|
+
name: "quantity",
|
|
9120
|
+
render: ({ field }) => {
|
|
9121
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
|
|
9122
|
+
}
|
|
9123
|
+
}
|
|
9124
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
9125
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9126
|
+
Form$2.Field,
|
|
9127
|
+
{
|
|
9128
|
+
control: form.control,
|
|
9129
|
+
name: "unit_price",
|
|
9130
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
9131
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9132
|
+
ui.CurrencyInput,
|
|
9133
|
+
{
|
|
9134
|
+
...field,
|
|
9135
|
+
symbol: getNativeSymbol(currencyCode),
|
|
9136
|
+
code: currencyCode,
|
|
9137
|
+
onValueChange: (_value, _name, values) => onChange(values?.value)
|
|
9138
|
+
}
|
|
9139
|
+
) }) });
|
|
9140
|
+
}
|
|
9141
|
+
}
|
|
9142
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
9143
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9144
|
+
ui.IconButton,
|
|
9145
|
+
{
|
|
9146
|
+
type: "button",
|
|
9147
|
+
size: "small",
|
|
9148
|
+
onClick: editing ? onSubmit : () => {
|
|
9149
|
+
setEditing(true);
|
|
9150
|
+
},
|
|
9151
|
+
disabled: isPending,
|
|
9152
|
+
children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
|
|
9153
|
+
}
|
|
9154
|
+
)
|
|
9155
|
+
] }) }) });
|
|
9156
|
+
};
|
|
9157
|
+
const variantItemSchema = zod.z.object({
|
|
9158
|
+
quantity: zod.z.number(),
|
|
9159
|
+
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
9160
|
+
});
|
|
9161
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
9162
|
+
const [editing, setEditing] = React.useState(false);
|
|
9163
|
+
const { quantity, unit_price, title } = item;
|
|
9164
|
+
const form = reactHookForm.useForm({
|
|
9165
|
+
defaultValues: {
|
|
9166
|
+
title,
|
|
9167
|
+
quantity,
|
|
9168
|
+
unit_price
|
|
9169
|
+
},
|
|
9170
|
+
resolver: zod$1.zodResolver(customItemSchema)
|
|
9171
|
+
});
|
|
9172
|
+
React.useEffect(() => {
|
|
9173
|
+
form.reset({
|
|
9174
|
+
title,
|
|
9175
|
+
quantity,
|
|
9176
|
+
unit_price
|
|
9177
|
+
});
|
|
9178
|
+
}, [form, title, quantity, unit_price]);
|
|
9179
|
+
const actionId = React.useMemo(() => {
|
|
9180
|
+
return item.actions?.find((a) => a.action === "ITEM_ADD")?.id;
|
|
9181
|
+
}, [item]);
|
|
9182
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
9183
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
9184
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
9185
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
9186
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9187
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
9188
|
+
setEditing(false);
|
|
9189
|
+
return;
|
|
9190
|
+
}
|
|
9191
|
+
if (!actionId) {
|
|
9192
|
+
await updateOriginalItem(
|
|
9193
|
+
{
|
|
9194
|
+
item_id: item.id,
|
|
9195
|
+
quantity: data.quantity,
|
|
9196
|
+
unit_price: convertNumber(data.unit_price)
|
|
9197
|
+
},
|
|
9198
|
+
{
|
|
9199
|
+
onSuccess: () => {
|
|
9200
|
+
setEditing(false);
|
|
9201
|
+
},
|
|
9202
|
+
onError: (e) => {
|
|
9203
|
+
ui.toast.error(e.message);
|
|
9546
9204
|
}
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9205
|
+
}
|
|
9206
|
+
);
|
|
9207
|
+
return;
|
|
9208
|
+
}
|
|
9209
|
+
if (data.quantity === 0) {
|
|
9210
|
+
await removeActionItem(actionId, {
|
|
9211
|
+
onSuccess: () => {
|
|
9212
|
+
setEditing(false);
|
|
9213
|
+
},
|
|
9214
|
+
onError: (e) => {
|
|
9215
|
+
ui.toast.error(e.message);
|
|
9216
|
+
}
|
|
9217
|
+
});
|
|
9218
|
+
return;
|
|
9219
|
+
}
|
|
9220
|
+
await updateActionItem(
|
|
9221
|
+
{
|
|
9222
|
+
action_id: actionId,
|
|
9223
|
+
quantity: data.quantity,
|
|
9224
|
+
unit_price: convertNumber(data.unit_price)
|
|
9225
|
+
},
|
|
9226
|
+
{
|
|
9227
|
+
onSuccess: () => {
|
|
9228
|
+
setEditing(false);
|
|
9229
|
+
},
|
|
9230
|
+
onError: (e) => {
|
|
9231
|
+
ui.toast.error(e.message);
|
|
9232
|
+
}
|
|
9233
|
+
}
|
|
9234
|
+
);
|
|
9235
|
+
});
|
|
9236
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
9237
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
9238
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9239
|
+
Thumbnail,
|
|
9240
|
+
{
|
|
9241
|
+
thumbnail: item.thumbnail,
|
|
9242
|
+
alt: item.title ?? void 0
|
|
9243
|
+
}
|
|
9244
|
+
),
|
|
9245
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
9246
|
+
Form$2.Field,
|
|
9247
|
+
{
|
|
9248
|
+
control: form.control,
|
|
9249
|
+
name: "title",
|
|
9250
|
+
render: ({ field }) => {
|
|
9251
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
|
|
9556
9252
|
}
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9253
|
+
}
|
|
9254
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
|
|
9255
|
+
] }),
|
|
9256
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
9257
|
+
Form$2.Field,
|
|
9258
|
+
{
|
|
9259
|
+
control: form.control,
|
|
9260
|
+
name: "quantity",
|
|
9261
|
+
render: ({ field }) => {
|
|
9262
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
|
|
9263
|
+
}
|
|
9264
|
+
}
|
|
9265
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
9266
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
9267
|
+
Form$2.Field,
|
|
9268
|
+
{
|
|
9269
|
+
control: form.control,
|
|
9270
|
+
name: "unit_price",
|
|
9271
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
9272
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9273
|
+
ui.CurrencyInput,
|
|
9274
|
+
{
|
|
9275
|
+
...field,
|
|
9276
|
+
symbol: getNativeSymbol(currencyCode),
|
|
9277
|
+
code: currencyCode,
|
|
9278
|
+
onValueChange: (_value, _name, values) => onChange(values?.value)
|
|
9279
|
+
}
|
|
9280
|
+
) }) });
|
|
9281
|
+
}
|
|
9282
|
+
}
|
|
9283
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
9284
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9285
|
+
ui.IconButton,
|
|
9286
|
+
{
|
|
9287
|
+
type: "button",
|
|
9288
|
+
size: "small",
|
|
9289
|
+
onClick: editing ? onSubmit : () => {
|
|
9290
|
+
setEditing(true);
|
|
9291
|
+
},
|
|
9292
|
+
disabled: isPending,
|
|
9293
|
+
children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
|
|
9294
|
+
}
|
|
9295
|
+
)
|
|
9296
|
+
] }) }) });
|
|
9297
|
+
};
|
|
9298
|
+
const StackedModalTrigger = ({
|
|
9299
|
+
type,
|
|
9300
|
+
setModalContent
|
|
9301
|
+
}) => {
|
|
9302
|
+
const { setIsOpen } = useStackedModal();
|
|
9303
|
+
const onClick = React.useCallback(() => {
|
|
9304
|
+
setModalContent(type);
|
|
9305
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
9306
|
+
}, [setModalContent, setIsOpen, type]);
|
|
9307
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
9308
|
+
};
|
|
9309
|
+
const VARIANT_PREFIX = "items";
|
|
9310
|
+
const LIMIT = 50;
|
|
9311
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
9312
|
+
const { setIsOpen } = useStackedModal();
|
|
9313
|
+
const [rowSelection, setRowSelection] = React.useState(
|
|
9314
|
+
items.reduce((acc, item) => {
|
|
9315
|
+
acc[item.variant_id] = true;
|
|
9316
|
+
return acc;
|
|
9317
|
+
}, {})
|
|
9318
|
+
);
|
|
9319
|
+
React.useEffect(() => {
|
|
9320
|
+
setRowSelection(
|
|
9321
|
+
items.reduce((acc, item) => {
|
|
9322
|
+
if (item.variant_id) {
|
|
9323
|
+
acc[item.variant_id] = true;
|
|
9324
|
+
}
|
|
9325
|
+
return acc;
|
|
9326
|
+
}, {})
|
|
9327
|
+
);
|
|
9328
|
+
}, [items]);
|
|
9329
|
+
const { q, order, offset } = useQueryParams(
|
|
9330
|
+
["q", "order", "offset"],
|
|
9331
|
+
VARIANT_PREFIX
|
|
9332
|
+
);
|
|
9333
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
9334
|
+
{
|
|
9335
|
+
q,
|
|
9336
|
+
order,
|
|
9337
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
9338
|
+
limit: LIMIT,
|
|
9339
|
+
fields: "*inventory_items.inventory.location_levels,+inventory_quantity,+manage_inventory"
|
|
9340
|
+
},
|
|
9341
|
+
{
|
|
9342
|
+
placeholderData: reactQuery.keepPreviousData
|
|
9343
|
+
}
|
|
9344
|
+
);
|
|
9345
|
+
const columns = useColumns();
|
|
9346
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
9347
|
+
const onSubmit = async () => {
|
|
9348
|
+
const ids = Object.keys(rowSelection).filter(
|
|
9349
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
9350
|
+
);
|
|
9351
|
+
await mutateAsync(
|
|
9352
|
+
{
|
|
9353
|
+
items: ids.map((id) => ({
|
|
9354
|
+
variant_id: id,
|
|
9355
|
+
quantity: 1
|
|
9356
|
+
}))
|
|
9357
|
+
},
|
|
9358
|
+
{
|
|
9359
|
+
onSuccess: () => {
|
|
9360
|
+
setRowSelection({});
|
|
9361
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
9362
|
+
},
|
|
9363
|
+
onError: (e) => {
|
|
9364
|
+
ui.toast.error(e.message);
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
);
|
|
9368
|
+
};
|
|
9369
|
+
if (isError) {
|
|
9370
|
+
throw error;
|
|
9371
|
+
}
|
|
9372
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9373
|
+
StackedFocusModal.Content,
|
|
9374
|
+
{
|
|
9375
|
+
onOpenAutoFocus: (e) => {
|
|
9376
|
+
e.preventDefault();
|
|
9377
|
+
const searchInput = document.querySelector(
|
|
9378
|
+
"[data-modal-id='modal-search-input']"
|
|
9379
|
+
);
|
|
9380
|
+
if (searchInput) {
|
|
9381
|
+
searchInput.focus();
|
|
9382
|
+
}
|
|
9383
|
+
},
|
|
9384
|
+
children: [
|
|
9385
|
+
/* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
|
|
9386
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
9387
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
9388
|
+
] }),
|
|
9389
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9390
|
+
DataTable,
|
|
9560
9391
|
{
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9392
|
+
data: variants,
|
|
9393
|
+
columns,
|
|
9394
|
+
isLoading: isPending,
|
|
9395
|
+
getRowId: (row) => row.id,
|
|
9396
|
+
rowCount: count,
|
|
9397
|
+
prefix: VARIANT_PREFIX,
|
|
9398
|
+
layout: "fill",
|
|
9399
|
+
rowSelection: {
|
|
9400
|
+
state: rowSelection,
|
|
9401
|
+
onRowSelectionChange: setRowSelection,
|
|
9402
|
+
enableRowSelection: (row) => {
|
|
9403
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
9404
|
+
}
|
|
9405
|
+
},
|
|
9406
|
+
autoFocusSearch: true
|
|
9566
9407
|
}
|
|
9567
9408
|
) }),
|
|
9568
|
-
/* @__PURE__ */ jsxRuntime.jsxs("
|
|
9569
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9409
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9410
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9411
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
9412
|
+
] }) })
|
|
9413
|
+
]
|
|
9414
|
+
}
|
|
9415
|
+
);
|
|
9416
|
+
};
|
|
9417
|
+
const columnHelper = ui.createDataTableColumnHelper();
|
|
9418
|
+
const getVariantInventory = (variant) => {
|
|
9419
|
+
if (!variant.manage_inventory) {
|
|
9420
|
+
return { text: "Not managed", hasInventoryKit: false, notManaged: true };
|
|
9421
|
+
}
|
|
9422
|
+
const quantity = variant.inventory_quantity;
|
|
9423
|
+
const inventoryItems = variant.inventory_items?.map((i) => i.inventory).filter(Boolean) ?? [];
|
|
9424
|
+
const hasInventoryKit = inventoryItems.length > 1;
|
|
9425
|
+
const locations = {};
|
|
9426
|
+
inventoryItems.forEach((i) => {
|
|
9427
|
+
i.location_levels?.forEach((l) => {
|
|
9428
|
+
locations[l.id] = true;
|
|
9429
|
+
});
|
|
9430
|
+
});
|
|
9431
|
+
const locationCount = Object.keys(locations).length;
|
|
9432
|
+
const text = hasInventoryKit ? `${quantity} available` : `${quantity} available at ${locationCount} location${locationCount === 1 ? "" : "s"}`;
|
|
9433
|
+
return { text, hasInventoryKit, quantity, notManaged: false };
|
|
9434
|
+
};
|
|
9435
|
+
const useColumns = () => {
|
|
9436
|
+
return React.useMemo(() => {
|
|
9437
|
+
return [
|
|
9438
|
+
columnHelper.select(),
|
|
9439
|
+
columnHelper.accessor("product.title", {
|
|
9440
|
+
header: "Product",
|
|
9441
|
+
cell: ({ row }) => {
|
|
9442
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
9443
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9444
|
+
Thumbnail,
|
|
9445
|
+
{
|
|
9446
|
+
thumbnail: row.original.product?.thumbnail,
|
|
9447
|
+
alt: row.original.product?.title
|
|
9448
|
+
}
|
|
9449
|
+
),
|
|
9450
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: row.original.product?.title })
|
|
9451
|
+
] });
|
|
9452
|
+
},
|
|
9453
|
+
enableSorting: true
|
|
9454
|
+
}),
|
|
9455
|
+
columnHelper.accessor("title", {
|
|
9456
|
+
header: "Variant",
|
|
9457
|
+
enableSorting: true
|
|
9458
|
+
}),
|
|
9459
|
+
columnHelper.accessor("sku", {
|
|
9460
|
+
header: "SKU",
|
|
9461
|
+
cell: ({ getValue }) => {
|
|
9462
|
+
return getValue() ?? "-";
|
|
9463
|
+
},
|
|
9464
|
+
enableSorting: true
|
|
9465
|
+
}),
|
|
9466
|
+
columnHelper.accessor("updated_at", {
|
|
9467
|
+
header: "Updated",
|
|
9468
|
+
cell: ({ getValue }) => {
|
|
9469
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9470
|
+
ui.Tooltip,
|
|
9607
9471
|
{
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
fill: "white",
|
|
9611
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
9472
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
9473
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
9612
9474
|
}
|
|
9613
|
-
)
|
|
9614
|
-
|
|
9615
|
-
|
|
9475
|
+
);
|
|
9476
|
+
},
|
|
9477
|
+
enableSorting: true,
|
|
9478
|
+
sortAscLabel: "Oldest first",
|
|
9479
|
+
sortDescLabel: "Newest first"
|
|
9480
|
+
}),
|
|
9481
|
+
columnHelper.accessor("created_at", {
|
|
9482
|
+
header: "Created",
|
|
9483
|
+
cell: ({ getValue }) => {
|
|
9484
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9485
|
+
ui.Tooltip,
|
|
9616
9486
|
{
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
fill: "white",
|
|
9620
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
9487
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
9488
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
9621
9489
|
}
|
|
9622
|
-
)
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9490
|
+
);
|
|
9491
|
+
},
|
|
9492
|
+
enableSorting: true,
|
|
9493
|
+
sortAscLabel: "Oldest first",
|
|
9494
|
+
sortDescLabel: "Newest first"
|
|
9495
|
+
}),
|
|
9496
|
+
columnHelper.display({
|
|
9497
|
+
id: "inventory",
|
|
9498
|
+
header: "Stock",
|
|
9499
|
+
cell: ({ row }) => {
|
|
9500
|
+
const { text, hasInventoryKit, quantity, notManaged } = getVariantInventory(row.original);
|
|
9501
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: text, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full w-full items-center gap-2 overflow-hidden", children: [
|
|
9502
|
+
hasInventoryKit && /* @__PURE__ */ jsxRuntime.jsx(icons.Component, {}),
|
|
9503
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9504
|
+
"span",
|
|
9505
|
+
{
|
|
9506
|
+
className: ui.clx("truncate", {
|
|
9507
|
+
"text-ui-fg-error": !quantity && !notManaged
|
|
9508
|
+
}),
|
|
9509
|
+
children: text
|
|
9510
|
+
}
|
|
9511
|
+
)
|
|
9512
|
+
] }) });
|
|
9513
|
+
}
|
|
9514
|
+
})
|
|
9515
|
+
];
|
|
9516
|
+
}, []);
|
|
9627
9517
|
};
|
|
9628
|
-
const
|
|
9629
|
-
|
|
9518
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
9519
|
+
const { setIsOpen } = useStackedModal();
|
|
9520
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
9521
|
+
const form = reactHookForm.useForm({
|
|
9522
|
+
defaultValues: {
|
|
9523
|
+
title: "",
|
|
9524
|
+
quantity: 1,
|
|
9525
|
+
unit_price: ""
|
|
9526
|
+
},
|
|
9527
|
+
resolver: zod$1.zodResolver(customItemSchema)
|
|
9528
|
+
});
|
|
9529
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9530
|
+
await addItems(
|
|
9531
|
+
{
|
|
9532
|
+
items: [
|
|
9533
|
+
{
|
|
9534
|
+
title: data.title,
|
|
9535
|
+
quantity: data.quantity,
|
|
9536
|
+
unit_price: convertNumber(data.unit_price)
|
|
9537
|
+
}
|
|
9538
|
+
]
|
|
9539
|
+
},
|
|
9540
|
+
{
|
|
9541
|
+
onSuccess: () => {
|
|
9542
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
9543
|
+
},
|
|
9544
|
+
onError: (e) => {
|
|
9545
|
+
ui.toast.error(e.message);
|
|
9546
|
+
}
|
|
9547
|
+
}
|
|
9548
|
+
);
|
|
9549
|
+
});
|
|
9550
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
|
|
9551
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
|
|
9552
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
|
|
9553
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9554
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
|
|
9555
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
9556
|
+
] }),
|
|
9557
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
9558
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9559
|
+
Form$2.Field,
|
|
9560
|
+
{
|
|
9561
|
+
control: form.control,
|
|
9562
|
+
name: "title",
|
|
9563
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
9564
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9565
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
|
|
9566
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
9567
|
+
] }),
|
|
9568
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9569
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9570
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9571
|
+
] })
|
|
9572
|
+
] }) })
|
|
9573
|
+
}
|
|
9574
|
+
),
|
|
9575
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
9576
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9577
|
+
Form$2.Field,
|
|
9578
|
+
{
|
|
9579
|
+
control: form.control,
|
|
9580
|
+
name: "unit_price",
|
|
9581
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
9582
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9583
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
|
|
9584
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
9585
|
+
] }),
|
|
9586
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9587
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9588
|
+
ui.CurrencyInput,
|
|
9589
|
+
{
|
|
9590
|
+
symbol: getNativeSymbol(currencyCode),
|
|
9591
|
+
code: currencyCode,
|
|
9592
|
+
onValueChange: (_value, _name, values) => onChange(values?.value),
|
|
9593
|
+
...field
|
|
9594
|
+
}
|
|
9595
|
+
) }),
|
|
9596
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9597
|
+
] })
|
|
9598
|
+
] }) })
|
|
9599
|
+
}
|
|
9600
|
+
),
|
|
9601
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
9602
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9603
|
+
Form$2.Field,
|
|
9604
|
+
{
|
|
9605
|
+
control: form.control,
|
|
9606
|
+
name: "quantity",
|
|
9607
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
9608
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
9609
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
|
|
9610
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
9611
|
+
] }),
|
|
9612
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
|
|
9613
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
9614
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9615
|
+
] })
|
|
9616
|
+
] }) })
|
|
9617
|
+
}
|
|
9618
|
+
)
|
|
9619
|
+
] }) }) }),
|
|
9620
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9621
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9622
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
9623
|
+
] }) })
|
|
9624
|
+
] }) }) });
|
|
9625
|
+
};
|
|
9626
|
+
const customItemSchema = zod.z.object({
|
|
9627
|
+
title: zod.z.string().min(1),
|
|
9628
|
+
quantity: zod.z.number(),
|
|
9629
|
+
unit_price: zod.z.union([zod.z.number(), zod.z.string()])
|
|
9630
9630
|
});
|
|
9631
9631
|
const handle = {
|
|
9632
|
-
permissions:
|
|
9632
|
+
permissions: EDIT_DRAFT_ORDER_PERMISSIONS
|
|
9633
9633
|
};
|
|
9634
9634
|
const widgetModule = { widgets: [] };
|
|
9635
9635
|
const routeModule = {
|
|
@@ -9667,39 +9667,39 @@ const routeModule = {
|
|
|
9667
9667
|
path: "/draft-orders/:id/email",
|
|
9668
9668
|
handle: handle$7
|
|
9669
9669
|
},
|
|
9670
|
-
{
|
|
9671
|
-
Component: Items,
|
|
9672
|
-
path: "/draft-orders/:id/items",
|
|
9673
|
-
handle: handle$6
|
|
9674
|
-
},
|
|
9675
9670
|
{
|
|
9676
9671
|
Component: Metadata,
|
|
9677
9672
|
path: "/draft-orders/:id/metadata",
|
|
9678
|
-
handle: handle$
|
|
9673
|
+
handle: handle$6
|
|
9679
9674
|
},
|
|
9680
9675
|
{
|
|
9681
9676
|
Component: Promotions,
|
|
9682
9677
|
path: "/draft-orders/:id/promotions",
|
|
9683
|
-
handle: handle$
|
|
9678
|
+
handle: handle$5
|
|
9684
9679
|
},
|
|
9685
9680
|
{
|
|
9686
9681
|
Component: SalesChannel,
|
|
9687
9682
|
path: "/draft-orders/:id/sales-channel",
|
|
9688
|
-
handle: handle$
|
|
9683
|
+
handle: handle$4
|
|
9689
9684
|
},
|
|
9690
9685
|
{
|
|
9691
9686
|
Component: Shipping,
|
|
9692
9687
|
path: "/draft-orders/:id/shipping",
|
|
9693
|
-
handle: handle$
|
|
9688
|
+
handle: handle$3
|
|
9694
9689
|
},
|
|
9695
9690
|
{
|
|
9696
9691
|
Component: ShippingAddress,
|
|
9697
9692
|
path: "/draft-orders/:id/shipping-address",
|
|
9698
|
-
handle: handle$
|
|
9693
|
+
handle: handle$2
|
|
9699
9694
|
},
|
|
9700
9695
|
{
|
|
9701
9696
|
Component: TransferOwnership,
|
|
9702
9697
|
path: "/draft-orders/:id/transfer-ownership",
|
|
9698
|
+
handle: handle$1
|
|
9699
|
+
},
|
|
9700
|
+
{
|
|
9701
|
+
Component: Items,
|
|
9702
|
+
path: "/draft-orders/:id/items",
|
|
9703
9703
|
handle
|
|
9704
9704
|
}
|
|
9705
9705
|
]
|