@medusajs/draft-order 0.0.13 → 2.10.0-snapshot-20250825072447

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.
@@ -9760,6 +9760,74 @@ const CustomItemsForm = () => {
9760
9760
  const schema$4 = objectType({
9761
9761
  email: stringType().email()
9762
9762
  });
9763
+ const Email = () => {
9764
+ const { id } = reactRouterDom.useParams();
9765
+ const { order, isPending, isError, error } = useOrder(id, {
9766
+ fields: "+email"
9767
+ });
9768
+ if (isError) {
9769
+ throw error;
9770
+ }
9771
+ const isReady = !isPending && !!order;
9772
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9773
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9774
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9775
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9776
+ ] }),
9777
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9778
+ ] });
9779
+ };
9780
+ const EmailForm = ({ order }) => {
9781
+ const form = reactHookForm.useForm({
9782
+ defaultValues: {
9783
+ email: order.email ?? ""
9784
+ },
9785
+ resolver: zod.zodResolver(schema$3)
9786
+ });
9787
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9788
+ const { handleSuccess } = useRouteModal();
9789
+ const onSubmit = form.handleSubmit(async (data) => {
9790
+ await mutateAsync(
9791
+ { email: data.email },
9792
+ {
9793
+ onSuccess: () => {
9794
+ handleSuccess();
9795
+ },
9796
+ onError: (error) => {
9797
+ ui.toast.error(error.message);
9798
+ }
9799
+ }
9800
+ );
9801
+ });
9802
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9803
+ KeyboundForm,
9804
+ {
9805
+ className: "flex flex-1 flex-col overflow-hidden",
9806
+ onSubmit,
9807
+ children: [
9808
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9809
+ Form$2.Field,
9810
+ {
9811
+ control: form.control,
9812
+ name: "email",
9813
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9814
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9815
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9816
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9817
+ ] })
9818
+ }
9819
+ ) }),
9820
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9821
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9822
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9823
+ ] }) })
9824
+ ]
9825
+ }
9826
+ ) });
9827
+ };
9828
+ const schema$3 = objectType({
9829
+ email: stringType().email()
9830
+ });
9763
9831
  const InlineTip = React.forwardRef(
9764
9832
  ({ variant = "tip", label, className, children, ...props }, ref) => {
9765
9833
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -10461,7 +10529,7 @@ const SalesChannelForm = ({ order }) => {
10461
10529
  defaultValues: {
10462
10530
  sales_channel_id: order.sales_channel_id || ""
10463
10531
  },
10464
- resolver: zod.zodResolver(schema$3)
10532
+ resolver: zod.zodResolver(schema$2)
10465
10533
  });
10466
10534
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10467
10535
  const { handleSuccess } = useRouteModal();
@@ -10536,7 +10604,7 @@ const SalesChannelField = ({ control, order }) => {
10536
10604
  }
10537
10605
  );
10538
10606
  };
10539
- const schema$3 = objectType({
10607
+ const schema$2 = objectType({
10540
10608
  sales_channel_id: stringType().min(1)
10541
10609
  });
10542
10610
  function convertNumber(value) {
@@ -11381,7 +11449,7 @@ const ShippingAddressForm = ({ order }) => {
11381
11449
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11382
11450
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11383
11451
  },
11384
- resolver: zod.zodResolver(schema$2)
11452
+ resolver: zod.zodResolver(schema$1)
11385
11453
  });
11386
11454
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11387
11455
  const { handleSuccess } = useRouteModal();
@@ -11551,1172 +11619,179 @@ const ShippingAddressForm = ({ order }) => {
11551
11619
  }
11552
11620
  ) });
11553
11621
  };
11554
- const schema$2 = addressSchema;
11555
- const NumberInput = React.forwardRef(
11556
- ({
11557
- value,
11558
- onChange,
11559
- size = "base",
11560
- min = 0,
11561
- max = 100,
11562
- step = 1,
11563
- className,
11564
- disabled,
11565
- ...props
11566
- }, ref) => {
11567
- const handleChange = (event) => {
11568
- const newValue = event.target.value === "" ? min : Number(event.target.value);
11569
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
11570
- onChange(newValue);
11571
- }
11572
- };
11573
- const handleIncrement = () => {
11574
- const newValue = value + step;
11575
- if (max === void 0 || newValue <= max) {
11576
- onChange(newValue);
11577
- }
11578
- };
11579
- const handleDecrement = () => {
11580
- const newValue = value - step;
11581
- if (min === void 0 || newValue >= min) {
11582
- onChange(newValue);
11583
- }
11584
- };
11585
- return /* @__PURE__ */ jsxRuntime.jsxs(
11586
- "div",
11587
- {
11588
- className: ui.clx(
11589
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
11590
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
11591
- {
11592
- "h-7": size === "small",
11593
- "h-8": size === "base"
11594
- },
11595
- className
11596
- ),
11597
- children: [
11598
- /* @__PURE__ */ jsxRuntime.jsx(
11599
- "input",
11600
- {
11601
- ref,
11602
- type: "number",
11603
- value,
11604
- onChange: handleChange,
11605
- min,
11606
- max,
11607
- step,
11608
- className: ui.clx(
11609
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
11610
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
11611
- "placeholder:text-ui-fg-muted"
11612
- ),
11613
- ...props
11614
- }
11615
- ),
11616
- /* @__PURE__ */ jsxRuntime.jsxs(
11617
- "button",
11618
- {
11619
- className: ui.clx(
11620
- "flex items-center justify-center outline-none transition-fg",
11621
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11622
- "focus:bg-ui-bg-field-component-hover",
11623
- "hover:bg-ui-bg-field-component-hover",
11624
- {
11625
- "size-7": size === "small",
11626
- "size-8": size === "base"
11627
- }
11628
- ),
11629
- type: "button",
11630
- onClick: handleDecrement,
11631
- disabled: min !== void 0 && value <= min || disabled,
11632
- children: [
11633
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
11634
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
11635
- ]
11636
- }
11637
- ),
11638
- /* @__PURE__ */ jsxRuntime.jsxs(
11639
- "button",
11640
- {
11641
- className: ui.clx(
11642
- "flex items-center justify-center outline-none transition-fg",
11643
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11644
- "focus:bg-ui-bg-field-hover",
11645
- "hover:bg-ui-bg-field-hover",
11646
- {
11647
- "size-7": size === "small",
11648
- "size-8": size === "base"
11649
- }
11650
- ),
11651
- type: "button",
11652
- onClick: handleIncrement,
11653
- disabled: max !== void 0 && value >= max || disabled,
11654
- children: [
11655
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
11656
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
11657
- ]
11658
- }
11659
- )
11660
- ]
11661
- }
11662
- );
11663
- }
11664
- );
11665
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
11666
- const productVariantsQueryKeys = {
11667
- list: (query2) => [
11668
- PRODUCT_VARIANTS_QUERY_KEY,
11669
- query2 ? query2 : void 0
11670
- ]
11671
- };
11672
- const useProductVariants = (query2, options) => {
11673
- const { data, ...rest } = reactQuery.useQuery({
11674
- queryKey: productVariantsQueryKeys.list(query2),
11675
- queryFn: async () => await sdk.admin.productVariant.list(query2),
11676
- ...options
11677
- });
11678
- return { ...data, ...rest };
11679
- };
11680
- const STACKED_MODAL_ID = "items_stacked_modal";
11681
- const Items = () => {
11622
+ const schema$1 = addressSchema;
11623
+ const TransferOwnership = () => {
11682
11624
  const { id } = reactRouterDom.useParams();
11683
- const {
11684
- order: preview,
11685
- isPending: isPreviewPending,
11686
- isError: isPreviewError,
11687
- error: previewError
11688
- } = useOrderPreview(id, void 0, {
11689
- placeholderData: reactQuery.keepPreviousData
11625
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11626
+ fields: "id,customer_id,customer.*"
11690
11627
  });
11691
- useInitiateOrderEdit({ preview });
11692
- const { draft_order, isPending, isError, error } = useDraftOrder(
11693
- id,
11694
- {
11695
- fields: "currency_code"
11696
- },
11697
- {
11698
- enabled: !!id
11699
- }
11700
- );
11701
- const { onCancel } = useCancelOrderEdit({ preview });
11702
11628
  if (isError) {
11703
11629
  throw error;
11704
11630
  }
11705
- if (isPreviewError) {
11706
- throw previewError;
11707
- }
11708
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
11709
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11710
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
11711
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11712
- ] }) });
11631
+ const isReady = !isPending && !!draft_order;
11632
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11633
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11634
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11635
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11636
+ ] }),
11637
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11638
+ ] });
11713
11639
  };
11714
- const ItemsForm = ({ preview, currencyCode }) => {
11715
- var _a;
11716
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11717
- const [modalContent, setModalContent] = React.useState(
11718
- null
11719
- );
11640
+ const TransferOwnershipForm = ({ order }) => {
11641
+ var _a, _b;
11642
+ const form = reactHookForm.useForm({
11643
+ defaultValues: {
11644
+ customer_id: order.customer_id || ""
11645
+ },
11646
+ resolver: zod.zodResolver(schema)
11647
+ });
11648
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11720
11649
  const { handleSuccess } = useRouteModal();
11721
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
11722
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11723
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11724
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
11725
- const matches = React.useMemo(() => {
11726
- return matchSorter.matchSorter(preview.items, query2, {
11727
- keys: ["product_title", "variant_title", "variant_sku", "title"]
11728
- });
11729
- }, [preview.items, query2]);
11730
- const onSubmit = async () => {
11731
- setIsSubmitting(true);
11732
- let requestSucceeded = false;
11733
- await requestOrderEdit(void 0, {
11734
- onError: (e) => {
11735
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11736
- },
11737
- onSuccess: () => {
11738
- requestSucceeded = true;
11739
- }
11740
- });
11741
- if (!requestSucceeded) {
11742
- setIsSubmitting(false);
11743
- return;
11744
- }
11745
- await confirmOrderEdit(void 0, {
11746
- onError: (e) => {
11747
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11748
- },
11749
- onSuccess: () => {
11750
- handleSuccess();
11751
- },
11752
- onSettled: () => {
11753
- setIsSubmitting(false);
11754
- }
11755
- });
11756
- };
11757
- const onKeyDown = React.useCallback(
11758
- (e) => {
11759
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11760
- if (modalContent || isSubmitting) {
11761
- return;
11762
- }
11763
- onSubmit();
11764
- }
11765
- },
11766
- [modalContent, isSubmitting, onSubmit]
11767
- );
11768
- React.useEffect(() => {
11769
- document.addEventListener("keydown", onKeyDown);
11770
- return () => {
11771
- document.removeEventListener("keydown", onKeyDown);
11772
- };
11773
- }, [onKeyDown]);
11774
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11775
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11776
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
11777
- StackedFocusModal,
11650
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11651
+ const currentCustomer = order.customer ? {
11652
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11653
+ value: order.customer.id
11654
+ } : null;
11655
+ const onSubmit = form.handleSubmit(async (data) => {
11656
+ await mutateAsync(
11657
+ { customer_id: data.customer_id },
11778
11658
  {
11779
- id: STACKED_MODAL_ID,
11780
- onOpenChangeCallback: (open) => {
11781
- if (!open) {
11782
- setModalContent(null);
11783
- }
11659
+ onSuccess: () => {
11660
+ ui.toast.success("Customer updated");
11661
+ handleSuccess();
11784
11662
  },
11785
- children: [
11786
- /* @__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: [
11787
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11788
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
11789
- /* @__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." }) })
11790
- ] }),
11791
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11792
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11793
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
11794
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11795
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
11796
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
11797
- ] }),
11798
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
11799
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
11800
- ui.Input,
11801
- {
11802
- type: "search",
11803
- placeholder: "Search items",
11804
- value: searchValue,
11805
- onChange: (e) => onSearchValueChange(e.target.value)
11806
- }
11807
- ) }),
11808
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11809
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
11810
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11811
- /* @__PURE__ */ jsxRuntime.jsx(
11812
- StackedModalTrigger,
11813
- {
11814
- type: "add-items",
11815
- setModalContent
11816
- }
11817
- ),
11818
- /* @__PURE__ */ jsxRuntime.jsx(
11819
- StackedModalTrigger,
11820
- {
11821
- type: "add-custom-item",
11822
- setModalContent
11823
- }
11824
- )
11825
- ] })
11826
- ] })
11827
- ] })
11828
- ] }),
11829
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11830
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
11831
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11832
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
11833
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
11834
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
11835
- ] }) }),
11836
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11837
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
11838
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
11839
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
11840
- Item,
11841
- {
11842
- item,
11843
- preview,
11844
- currencyCode
11845
- },
11846
- item.id
11847
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11848
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11849
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11850
- 'No items found for "',
11851
- query2,
11852
- '".'
11853
- ] })
11854
- ] }) })
11855
- ] })
11663
+ onError: (error) => {
11664
+ ui.toast.error(error.message);
11665
+ }
11666
+ }
11667
+ );
11668
+ });
11669
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11670
+ KeyboundForm,
11671
+ {
11672
+ className: "flex flex-1 flex-col overflow-hidden",
11673
+ onSubmit,
11674
+ children: [
11675
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11676
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11677
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11678
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11679
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11680
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11856
11681
  ] }),
11857
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11858
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
11859
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
11860
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
11861
- ui.Text,
11862
- {
11863
- size: "small",
11864
- leading: "compact",
11865
- className: "text-ui-fg-subtle",
11866
- children: [
11867
- itemCount,
11868
- " ",
11869
- itemCount === 1 ? "item" : "items"
11870
- ]
11871
- }
11872
- ) }),
11873
- /* @__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) }) })
11682
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11683
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11684
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11874
11685
  ] })
11875
- ] }) }),
11876
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
11877
- CustomItemForm,
11686
+ ] }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(
11688
+ CustomerField,
11878
11689
  {
11879
- orderId: preview.id,
11880
- currencyCode
11690
+ control: form.control,
11691
+ currentCustomerId: order.customer_id
11881
11692
  }
11882
- ) : null)
11883
- ]
11884
- }
11885
- ) }),
11886
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11887
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11888
- /* @__PURE__ */ jsxRuntime.jsx(
11889
- ui.Button,
11890
- {
11891
- size: "small",
11892
- type: "button",
11893
- onClick: onSubmit,
11894
- isLoading: isSubmitting,
11895
- children: "Save"
11896
- }
11897
- )
11898
- ] }) })
11899
- ] });
11900
- };
11901
- const Item = ({ item, preview, currencyCode }) => {
11902
- if (item.variant_id) {
11903
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
11904
- }
11905
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
11693
+ )
11694
+ ] }),
11695
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11696
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11697
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11698
+ ] }) })
11699
+ ]
11700
+ }
11701
+ ) });
11906
11702
  };
11907
- const VariantItem = ({ item, preview, currencyCode }) => {
11908
- const [editing, setEditing] = React.useState(false);
11909
- const form = reactHookForm.useForm({
11910
- defaultValues: {
11911
- quantity: item.quantity,
11912
- unit_price: item.unit_price
11703
+ const CustomerField = ({ control, currentCustomerId }) => {
11704
+ const customers = useComboboxData({
11705
+ queryFn: async (params) => {
11706
+ return await sdk.admin.customer.list({
11707
+ ...params,
11708
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11709
+ });
11913
11710
  },
11914
- resolver: zod.zodResolver(variantItemSchema)
11915
- });
11916
- const actionId = React.useMemo(() => {
11917
- var _a, _b;
11918
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11919
- }, [item]);
11920
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11921
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11922
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11923
- const onSubmit = form.handleSubmit(async (data) => {
11924
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
11925
- setEditing(false);
11926
- return;
11711
+ queryKey: ["customers"],
11712
+ getOptions: (data) => {
11713
+ return data.customers.map((customer) => {
11714
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11715
+ return {
11716
+ label: name ? `${name} (${customer.email})` : customer.email,
11717
+ value: customer.id
11718
+ };
11719
+ });
11927
11720
  }
11928
- if (!actionId) {
11929
- await updateOriginalItem(
11930
- {
11931
- item_id: item.id,
11932
- quantity: data.quantity,
11933
- unit_price: convertNumber(data.unit_price)
11934
- },
11935
- {
11936
- onSuccess: () => {
11937
- setEditing(false);
11938
- },
11939
- onError: (e) => {
11940
- ui.toast.error(e.message);
11941
- }
11942
- }
11943
- );
11944
- return;
11945
- }
11946
- await updateActionItem(
11947
- {
11948
- action_id: actionId,
11949
- quantity: data.quantity,
11950
- unit_price: convertNumber(data.unit_price)
11951
- },
11952
- {
11953
- onSuccess: () => {
11954
- setEditing(false);
11955
- },
11956
- onError: (e) => {
11957
- ui.toast.error(e.message);
11958
- }
11959
- }
11960
- );
11961
11721
  });
11962
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11963
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
11964
- /* @__PURE__ */ jsxRuntime.jsx(
11965
- Thumbnail,
11966
- {
11967
- thumbnail: item.thumbnail,
11968
- alt: item.product_title ?? void 0
11969
- }
11970
- ),
11971
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11973
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11974
- /* @__PURE__ */ jsxRuntime.jsxs(
11975
- ui.Text,
11976
- {
11977
- size: "small",
11978
- leading: "compact",
11979
- className: "text-ui-fg-subtle",
11980
- children: [
11981
- "(",
11982
- item.variant_title,
11983
- ")"
11984
- ]
11985
- }
11986
- )
11722
+ return /* @__PURE__ */ jsxRuntime.jsx(
11723
+ Form$2.Field,
11724
+ {
11725
+ name: "customer_id",
11726
+ control,
11727
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11728
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11729
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11730
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11987
11731
  ] }),
11988
- /* @__PURE__ */ jsxRuntime.jsx(
11989
- ui.Text,
11732
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11733
+ Combobox,
11990
11734
  {
11991
- size: "small",
11992
- leading: "compact",
11993
- className: "text-ui-fg-subtle",
11994
- children: item.variant_sku
11735
+ options: customers.options,
11736
+ fetchNextPage: customers.fetchNextPage,
11737
+ isFetchingNextPage: customers.isFetchingNextPage,
11738
+ searchValue: customers.searchValue,
11739
+ onSearchValueChange: customers.onSearchValueChange,
11740
+ placeholder: "Select customer",
11741
+ ...field
11995
11742
  }
11996
- )
11743
+ ) }),
11744
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11997
11745
  ] })
11998
- ] }),
11999
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12000
- Form$2.Field,
12001
- {
12002
- control: form.control,
12003
- name: "quantity",
12004
- render: ({ field }) => {
12005
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12006
- }
12007
- }
12008
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12009
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12010
- Form$2.Field,
12011
- {
12012
- control: form.control,
12013
- name: "unit_price",
12014
- render: ({ field: { onChange, ...field } }) => {
12015
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12016
- ui.CurrencyInput,
12017
- {
12018
- ...field,
12019
- symbol: getNativeSymbol(currencyCode),
12020
- code: currencyCode,
12021
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12022
- }
12023
- ) }) });
12024
- }
12025
- }
12026
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12027
- /* @__PURE__ */ jsxRuntime.jsx(
12028
- ui.IconButton,
12029
- {
12030
- type: "button",
12031
- size: "small",
12032
- onClick: editing ? onSubmit : () => {
12033
- setEditing(true);
12034
- },
12035
- disabled: isPending,
12036
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12037
- }
12038
- )
12039
- ] }) }) });
12040
- };
12041
- const variantItemSchema = objectType({
12042
- quantity: numberType(),
12043
- unit_price: unionType([numberType(), stringType()])
12044
- });
12045
- const CustomItem = ({ item, preview, currencyCode }) => {
12046
- const [editing, setEditing] = React.useState(false);
12047
- const { quantity, unit_price, title } = item;
12048
- const form = reactHookForm.useForm({
12049
- defaultValues: {
12050
- title,
12051
- quantity,
12052
- unit_price
12053
- },
12054
- resolver: zod.zodResolver(customItemSchema)
12055
- });
12056
- React.useEffect(() => {
12057
- form.reset({
12058
- title,
12059
- quantity,
12060
- unit_price
12061
- });
12062
- }, [form, title, quantity, unit_price]);
12063
- const actionId = React.useMemo(() => {
12064
- var _a, _b;
12065
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12066
- }, [item]);
12067
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12068
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12069
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12070
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12071
- const onSubmit = form.handleSubmit(async (data) => {
12072
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12073
- setEditing(false);
12074
- return;
12075
- }
12076
- if (!actionId) {
12077
- await updateOriginalItem(
12078
- {
12079
- item_id: item.id,
12080
- quantity: data.quantity,
12081
- unit_price: convertNumber(data.unit_price)
12082
- },
12083
- {
12084
- onSuccess: () => {
12085
- setEditing(false);
12086
- },
12087
- onError: (e) => {
12088
- ui.toast.error(e.message);
12089
- }
12090
- }
12091
- );
12092
- return;
12093
- }
12094
- if (data.quantity === 0) {
12095
- await removeActionItem(actionId, {
12096
- onSuccess: () => {
12097
- setEditing(false);
12098
- },
12099
- onError: (e) => {
12100
- ui.toast.error(e.message);
12101
- }
12102
- });
12103
- return;
12104
11746
  }
12105
- await updateActionItem(
12106
- {
12107
- action_id: actionId,
12108
- quantity: data.quantity,
12109
- unit_price: convertNumber(data.unit_price)
12110
- },
12111
- {
12112
- onSuccess: () => {
12113
- setEditing(false);
12114
- },
12115
- onError: (e) => {
12116
- ui.toast.error(e.message);
12117
- }
12118
- }
12119
- );
12120
- });
12121
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12122
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12123
- /* @__PURE__ */ jsxRuntime.jsx(
12124
- Thumbnail,
12125
- {
12126
- thumbnail: item.thumbnail,
12127
- alt: item.title ?? void 0
12128
- }
12129
- ),
12130
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12131
- Form$2.Field,
12132
- {
12133
- control: form.control,
12134
- name: "title",
12135
- render: ({ field }) => {
12136
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
11747
+ );
11748
+ };
11749
+ const Illustration = () => {
11750
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11751
+ "svg",
11752
+ {
11753
+ width: "280",
11754
+ height: "180",
11755
+ viewBox: "0 0 280 180",
11756
+ fill: "none",
11757
+ xmlns: "http://www.w3.org/2000/svg",
11758
+ children: [
11759
+ /* @__PURE__ */ jsxRuntime.jsx(
11760
+ "rect",
11761
+ {
11762
+ x: "0.00428286",
11763
+ y: "-0.742904",
11764
+ width: "33.5",
11765
+ height: "65.5",
11766
+ rx: "6.75",
11767
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11768
+ fill: "#D4D4D8",
11769
+ stroke: "#52525B",
11770
+ strokeWidth: "1.5"
12137
11771
  }
12138
- }
12139
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12140
- ] }),
12141
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12142
- Form$2.Field,
12143
- {
12144
- control: form.control,
12145
- name: "quantity",
12146
- render: ({ field }) => {
12147
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12148
- }
12149
- }
12150
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12151
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12152
- Form$2.Field,
12153
- {
12154
- control: form.control,
12155
- name: "unit_price",
12156
- render: ({ field: { onChange, ...field } }) => {
12157
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12158
- ui.CurrencyInput,
12159
- {
12160
- ...field,
12161
- symbol: getNativeSymbol(currencyCode),
12162
- code: currencyCode,
12163
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12164
- }
12165
- ) }) });
12166
- }
12167
- }
12168
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12169
- /* @__PURE__ */ jsxRuntime.jsx(
12170
- ui.IconButton,
12171
- {
12172
- type: "button",
12173
- size: "small",
12174
- onClick: editing ? onSubmit : () => {
12175
- setEditing(true);
12176
- },
12177
- disabled: isPending,
12178
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12179
- }
12180
- )
12181
- ] }) }) });
12182
- };
12183
- const StackedModalTrigger = ({
12184
- type,
12185
- setModalContent
12186
- }) => {
12187
- const { setIsOpen } = useStackedModal();
12188
- const onClick = React.useCallback(() => {
12189
- setModalContent(type);
12190
- setIsOpen(STACKED_MODAL_ID, true);
12191
- }, [setModalContent, setIsOpen, type]);
12192
- 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" }) });
12193
- };
12194
- const VARIANT_PREFIX = "items";
12195
- const LIMIT = 50;
12196
- const ExistingItemsForm = ({ orderId, items }) => {
12197
- const { setIsOpen } = useStackedModal();
12198
- const [rowSelection, setRowSelection] = React.useState(
12199
- items.reduce((acc, item) => {
12200
- acc[item.variant_id] = true;
12201
- return acc;
12202
- }, {})
12203
- );
12204
- React.useEffect(() => {
12205
- setRowSelection(
12206
- items.reduce((acc, item) => {
12207
- if (item.variant_id) {
12208
- acc[item.variant_id] = true;
12209
- }
12210
- return acc;
12211
- }, {})
12212
- );
12213
- }, [items]);
12214
- const { q, order, offset } = useQueryParams(
12215
- ["q", "order", "offset"],
12216
- VARIANT_PREFIX
12217
- );
12218
- const { variants, count, isPending, isError, error } = useProductVariants(
12219
- {
12220
- q,
12221
- order,
12222
- offset: offset ? parseInt(offset) : void 0,
12223
- limit: LIMIT
12224
- },
12225
- {
12226
- placeholderData: reactQuery.keepPreviousData
12227
- }
12228
- );
12229
- const columns = useColumns();
12230
- const { mutateAsync } = useDraftOrderAddItems(orderId);
12231
- const onSubmit = async () => {
12232
- const ids = Object.keys(rowSelection).filter(
12233
- (id) => !items.find((i) => i.variant_id === id)
12234
- );
12235
- await mutateAsync(
12236
- {
12237
- items: ids.map((id) => ({
12238
- variant_id: id,
12239
- quantity: 1
12240
- }))
12241
- },
12242
- {
12243
- onSuccess: () => {
12244
- setRowSelection({});
12245
- setIsOpen(STACKED_MODAL_ID, false);
12246
- },
12247
- onError: (e) => {
12248
- ui.toast.error(e.message);
12249
- }
12250
- }
12251
- );
12252
- };
12253
- if (isError) {
12254
- throw error;
12255
- }
12256
- return /* @__PURE__ */ jsxRuntime.jsxs(
12257
- StackedFocusModal.Content,
12258
- {
12259
- onOpenAutoFocus: (e) => {
12260
- e.preventDefault();
12261
- const searchInput = document.querySelector(
12262
- "[data-modal-id='modal-search-input']"
12263
- );
12264
- if (searchInput) {
12265
- searchInput.focus();
12266
- }
12267
- },
12268
- children: [
12269
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12270
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12271
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12272
- ] }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12274
- DataTable,
11772
+ ),
11773
+ /* @__PURE__ */ jsxRuntime.jsx(
11774
+ "rect",
12275
11775
  {
12276
- data: variants,
12277
- columns,
12278
- isLoading: isPending,
12279
- getRowId: (row) => row.id,
12280
- rowCount: count,
12281
- prefix: VARIANT_PREFIX,
12282
- layout: "fill",
12283
- rowSelection: {
12284
- state: rowSelection,
12285
- onRowSelectionChange: setRowSelection,
12286
- enableRowSelection: (row) => {
12287
- return !items.find((i) => i.variant_id === row.original.id);
12288
- }
12289
- },
12290
- autoFocusSearch: true
11776
+ x: "0.00428286",
11777
+ y: "-0.742904",
11778
+ width: "33.5",
11779
+ height: "65.5",
11780
+ rx: "6.75",
11781
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11782
+ fill: "white",
11783
+ stroke: "#52525B",
11784
+ strokeWidth: "1.5"
12291
11785
  }
12292
- ) }),
12293
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12294
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12295
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12296
- ] }) })
12297
- ]
12298
- }
12299
- );
12300
- };
12301
- const columnHelper = ui.createDataTableColumnHelper();
12302
- const useColumns = () => {
12303
- return React.useMemo(() => {
12304
- return [
12305
- columnHelper.select(),
12306
- columnHelper.accessor("product.title", {
12307
- header: "Product",
12308
- cell: ({ row }) => {
12309
- var _a, _b, _c;
12310
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
12311
- /* @__PURE__ */ jsxRuntime.jsx(
12312
- Thumbnail,
12313
- {
12314
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12315
- alt: (_b = row.original.product) == null ? void 0 : _b.title
12316
- }
12317
- ),
12318
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12319
- ] });
12320
- },
12321
- enableSorting: true
12322
- }),
12323
- columnHelper.accessor("title", {
12324
- header: "Variant",
12325
- enableSorting: true
12326
- }),
12327
- columnHelper.accessor("sku", {
12328
- header: "SKU",
12329
- cell: ({ getValue }) => {
12330
- return getValue() ?? "-";
12331
- },
12332
- enableSorting: true
12333
- }),
12334
- columnHelper.accessor("updated_at", {
12335
- header: "Updated",
12336
- cell: ({ getValue }) => {
12337
- return /* @__PURE__ */ jsxRuntime.jsx(
12338
- ui.Tooltip,
12339
- {
12340
- content: getFullDate({ date: getValue(), includeTime: true }),
12341
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12342
- }
12343
- );
12344
- },
12345
- enableSorting: true,
12346
- sortAscLabel: "Oldest first",
12347
- sortDescLabel: "Newest first"
12348
- }),
12349
- columnHelper.accessor("created_at", {
12350
- header: "Created",
12351
- cell: ({ getValue }) => {
12352
- return /* @__PURE__ */ jsxRuntime.jsx(
12353
- ui.Tooltip,
12354
- {
12355
- content: getFullDate({ date: getValue(), includeTime: true }),
12356
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12357
- }
12358
- );
12359
- },
12360
- enableSorting: true,
12361
- sortAscLabel: "Oldest first",
12362
- sortDescLabel: "Newest first"
12363
- })
12364
- ];
12365
- }, []);
12366
- };
12367
- const CustomItemForm = ({ orderId, currencyCode }) => {
12368
- const { setIsOpen } = useStackedModal();
12369
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12370
- const form = reactHookForm.useForm({
12371
- defaultValues: {
12372
- title: "",
12373
- quantity: 1,
12374
- unit_price: ""
12375
- },
12376
- resolver: zod.zodResolver(customItemSchema)
12377
- });
12378
- const onSubmit = form.handleSubmit(async (data) => {
12379
- await addItems(
12380
- {
12381
- items: [
11786
+ ),
11787
+ /* @__PURE__ */ jsxRuntime.jsx(
11788
+ "path",
12382
11789
  {
12383
- title: data.title,
12384
- quantity: data.quantity,
12385
- unit_price: convertNumber(data.unit_price)
12386
- }
12387
- ]
12388
- },
12389
- {
12390
- onSuccess: () => {
12391
- setIsOpen(STACKED_MODAL_ID, false);
12392
- },
12393
- onError: (e) => {
12394
- ui.toast.error(e.message);
12395
- }
12396
- }
12397
- );
12398
- });
12399
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12400
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12401
- /* @__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: [
12402
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12403
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12404
- /* @__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." }) })
12405
- ] }),
12406
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12407
- /* @__PURE__ */ jsxRuntime.jsx(
12408
- Form$2.Field,
12409
- {
12410
- control: form.control,
12411
- name: "title",
12412
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12413
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12415
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12416
- ] }),
12417
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12418
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12419
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12420
- ] })
12421
- ] }) })
12422
- }
12423
- ),
12424
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(
12426
- Form$2.Field,
12427
- {
12428
- control: form.control,
12429
- name: "unit_price",
12430
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12431
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12432
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12433
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12434
- ] }),
12435
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12437
- ui.CurrencyInput,
12438
- {
12439
- symbol: getNativeSymbol(currencyCode),
12440
- code: currencyCode,
12441
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12442
- ...field
12443
- }
12444
- ) }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12446
- ] })
12447
- ] }) })
12448
- }
12449
- ),
12450
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(
12452
- Form$2.Field,
12453
- {
12454
- control: form.control,
12455
- name: "quantity",
12456
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12457
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12460
- ] }),
12461
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
12462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12463
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- ] }) })
12466
- }
12467
- )
12468
- ] }) }) }),
12469
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12470
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12472
- ] }) })
12473
- ] }) }) });
12474
- };
12475
- const customItemSchema = objectType({
12476
- title: stringType().min(1),
12477
- quantity: numberType(),
12478
- unit_price: unionType([numberType(), stringType()])
12479
- });
12480
- const Email = () => {
12481
- const { id } = reactRouterDom.useParams();
12482
- const { order, isPending, isError, error } = useOrder(id, {
12483
- fields: "+email"
12484
- });
12485
- if (isError) {
12486
- throw error;
12487
- }
12488
- const isReady = !isPending && !!order;
12489
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12490
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12491
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12492
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12493
- ] }),
12494
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12495
- ] });
12496
- };
12497
- const EmailForm = ({ order }) => {
12498
- const form = reactHookForm.useForm({
12499
- defaultValues: {
12500
- email: order.email ?? ""
12501
- },
12502
- resolver: zod.zodResolver(schema$1)
12503
- });
12504
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12505
- const { handleSuccess } = useRouteModal();
12506
- const onSubmit = form.handleSubmit(async (data) => {
12507
- await mutateAsync(
12508
- { email: data.email },
12509
- {
12510
- onSuccess: () => {
12511
- handleSuccess();
12512
- },
12513
- onError: (error) => {
12514
- ui.toast.error(error.message);
12515
- }
12516
- }
12517
- );
12518
- });
12519
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12520
- KeyboundForm,
12521
- {
12522
- className: "flex flex-1 flex-col overflow-hidden",
12523
- onSubmit,
12524
- children: [
12525
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
12526
- Form$2.Field,
12527
- {
12528
- control: form.control,
12529
- name: "email",
12530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
- ] })
12535
- }
12536
- ) }),
12537
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12538
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12539
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12540
- ] }) })
12541
- ]
12542
- }
12543
- ) });
12544
- };
12545
- const schema$1 = objectType({
12546
- email: stringType().email()
12547
- });
12548
- const TransferOwnership = () => {
12549
- const { id } = reactRouterDom.useParams();
12550
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12551
- fields: "id,customer_id,customer.*"
12552
- });
12553
- if (isError) {
12554
- throw error;
12555
- }
12556
- const isReady = !isPending && !!draft_order;
12557
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12558
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12559
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12560
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12561
- ] }),
12562
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12563
- ] });
12564
- };
12565
- const TransferOwnershipForm = ({ order }) => {
12566
- var _a, _b;
12567
- const form = reactHookForm.useForm({
12568
- defaultValues: {
12569
- customer_id: order.customer_id || ""
12570
- },
12571
- resolver: zod.zodResolver(schema)
12572
- });
12573
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12574
- const { handleSuccess } = useRouteModal();
12575
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12576
- const currentCustomer = order.customer ? {
12577
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12578
- value: order.customer.id
12579
- } : null;
12580
- const onSubmit = form.handleSubmit(async (data) => {
12581
- await mutateAsync(
12582
- { customer_id: data.customer_id },
12583
- {
12584
- onSuccess: () => {
12585
- ui.toast.success("Customer updated");
12586
- handleSuccess();
12587
- },
12588
- onError: (error) => {
12589
- ui.toast.error(error.message);
12590
- }
12591
- }
12592
- );
12593
- });
12594
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12595
- KeyboundForm,
12596
- {
12597
- className: "flex flex-1 flex-col overflow-hidden",
12598
- onSubmit,
12599
- children: [
12600
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12601
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12602
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12603
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12604
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12605
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12606
- ] }),
12607
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12608
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12609
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12610
- ] })
12611
- ] }),
12612
- /* @__PURE__ */ jsxRuntime.jsx(
12613
- CustomerField,
12614
- {
12615
- control: form.control,
12616
- currentCustomerId: order.customer_id
12617
- }
12618
- )
12619
- ] }),
12620
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12621
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12622
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12623
- ] }) })
12624
- ]
12625
- }
12626
- ) });
12627
- };
12628
- const CustomerField = ({ control, currentCustomerId }) => {
12629
- const customers = useComboboxData({
12630
- queryFn: async (params) => {
12631
- return await sdk.admin.customer.list({
12632
- ...params,
12633
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12634
- });
12635
- },
12636
- queryKey: ["customers"],
12637
- getOptions: (data) => {
12638
- return data.customers.map((customer) => {
12639
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12640
- return {
12641
- label: name ? `${name} (${customer.email})` : customer.email,
12642
- value: customer.id
12643
- };
12644
- });
12645
- }
12646
- });
12647
- return /* @__PURE__ */ jsxRuntime.jsx(
12648
- Form$2.Field,
12649
- {
12650
- name: "customer_id",
12651
- control,
12652
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12653
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12654
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12655
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12656
- ] }),
12657
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12658
- Combobox,
12659
- {
12660
- options: customers.options,
12661
- fetchNextPage: customers.fetchNextPage,
12662
- isFetchingNextPage: customers.isFetchingNextPage,
12663
- searchValue: customers.searchValue,
12664
- onSearchValueChange: customers.onSearchValueChange,
12665
- placeholder: "Select customer",
12666
- ...field
12667
- }
12668
- ) }),
12669
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12670
- ] })
12671
- }
12672
- );
12673
- };
12674
- const Illustration = () => {
12675
- return /* @__PURE__ */ jsxRuntime.jsxs(
12676
- "svg",
12677
- {
12678
- width: "280",
12679
- height: "180",
12680
- viewBox: "0 0 280 180",
12681
- fill: "none",
12682
- xmlns: "http://www.w3.org/2000/svg",
12683
- children: [
12684
- /* @__PURE__ */ jsxRuntime.jsx(
12685
- "rect",
12686
- {
12687
- x: "0.00428286",
12688
- y: "-0.742904",
12689
- width: "33.5",
12690
- height: "65.5",
12691
- rx: "6.75",
12692
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12693
- fill: "#D4D4D8",
12694
- stroke: "#52525B",
12695
- strokeWidth: "1.5"
12696
- }
12697
- ),
12698
- /* @__PURE__ */ jsxRuntime.jsx(
12699
- "rect",
12700
- {
12701
- x: "0.00428286",
12702
- y: "-0.742904",
12703
- width: "33.5",
12704
- height: "65.5",
12705
- rx: "6.75",
12706
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12707
- fill: "white",
12708
- stroke: "#52525B",
12709
- strokeWidth: "1.5"
12710
- }
12711
- ),
12712
- /* @__PURE__ */ jsxRuntime.jsx(
12713
- "path",
12714
- {
12715
- d: "M180.579 107.142L179.126 107.959",
12716
- stroke: "#52525B",
12717
- strokeWidth: "1.5",
12718
- strokeLinecap: "round",
12719
- strokeLinejoin: "round"
11790
+ d: "M180.579 107.142L179.126 107.959",
11791
+ stroke: "#52525B",
11792
+ strokeWidth: "1.5",
11793
+ strokeLinecap: "round",
11794
+ strokeLinejoin: "round"
12720
11795
  }
12721
11796
  ),
12722
11797
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -12867,159 +11942,1084 @@ const Illustration = () => {
12867
11942
  /* @__PURE__ */ jsxRuntime.jsx(
12868
11943
  "path",
12869
11944
  {
12870
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12871
- fill: "#A1A1AA"
12872
- }
11945
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11946
+ fill: "#A1A1AA"
11947
+ }
11948
+ ),
11949
+ /* @__PURE__ */ jsxRuntime.jsx(
11950
+ "rect",
11951
+ {
11952
+ width: "17",
11953
+ height: "3",
11954
+ rx: "1.5",
11955
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11956
+ fill: "#A1A1AA"
11957
+ }
11958
+ ),
11959
+ /* @__PURE__ */ jsxRuntime.jsx(
11960
+ "rect",
11961
+ {
11962
+ width: "12",
11963
+ height: "3",
11964
+ rx: "1.5",
11965
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11966
+ fill: "#A1A1AA"
11967
+ }
11968
+ ),
11969
+ /* @__PURE__ */ jsxRuntime.jsx(
11970
+ "path",
11971
+ {
11972
+ 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",
11973
+ fill: "#52525B"
11974
+ }
11975
+ ),
11976
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11977
+ "path",
11978
+ {
11979
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11980
+ stroke: "#A1A1AA",
11981
+ strokeWidth: "1.5",
11982
+ strokeLinecap: "round",
11983
+ strokeLinejoin: "round"
11984
+ }
11985
+ ) }),
11986
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11987
+ "path",
11988
+ {
11989
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11990
+ stroke: "#A1A1AA",
11991
+ strokeWidth: "1.5",
11992
+ strokeLinecap: "round",
11993
+ strokeLinejoin: "round"
11994
+ }
11995
+ ) }),
11996
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11997
+ "path",
11998
+ {
11999
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12000
+ stroke: "#A1A1AA",
12001
+ strokeWidth: "1.5",
12002
+ strokeLinecap: "round",
12003
+ strokeLinejoin: "round"
12004
+ }
12005
+ ) }),
12006
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12007
+ "path",
12008
+ {
12009
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12010
+ stroke: "#A1A1AA",
12011
+ strokeWidth: "1.5",
12012
+ strokeLinecap: "round",
12013
+ strokeLinejoin: "round"
12014
+ }
12015
+ ) }),
12016
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12017
+ "path",
12018
+ {
12019
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12020
+ stroke: "#A1A1AA",
12021
+ strokeWidth: "1.5",
12022
+ strokeLinecap: "round",
12023
+ strokeLinejoin: "round"
12024
+ }
12025
+ ) }),
12026
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12027
+ "path",
12028
+ {
12029
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12030
+ stroke: "#A1A1AA",
12031
+ strokeWidth: "1.5",
12032
+ strokeLinecap: "round",
12033
+ strokeLinejoin: "round"
12034
+ }
12035
+ ) }),
12036
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12037
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12038
+ "rect",
12039
+ {
12040
+ width: "12",
12041
+ height: "12",
12042
+ fill: "white",
12043
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12044
+ }
12045
+ ) }),
12046
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12047
+ "rect",
12048
+ {
12049
+ width: "12",
12050
+ height: "12",
12051
+ fill: "white",
12052
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12053
+ }
12054
+ ) }),
12055
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12056
+ "rect",
12057
+ {
12058
+ width: "12",
12059
+ height: "12",
12060
+ fill: "white",
12061
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12062
+ }
12063
+ ) }),
12064
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12065
+ "rect",
12066
+ {
12067
+ width: "12",
12068
+ height: "12",
12069
+ fill: "white",
12070
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12071
+ }
12072
+ ) }),
12073
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12074
+ "rect",
12075
+ {
12076
+ width: "12",
12077
+ height: "12",
12078
+ fill: "white",
12079
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12080
+ }
12081
+ ) }),
12082
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12083
+ "rect",
12084
+ {
12085
+ width: "12",
12086
+ height: "12",
12087
+ fill: "white",
12088
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12089
+ }
12090
+ ) })
12091
+ ] })
12092
+ ]
12093
+ }
12094
+ );
12095
+ };
12096
+ const schema = objectType({
12097
+ customer_id: stringType().min(1)
12098
+ });
12099
+ const NumberInput = React.forwardRef(
12100
+ ({
12101
+ value,
12102
+ onChange,
12103
+ size = "base",
12104
+ min = 0,
12105
+ max = 100,
12106
+ step = 1,
12107
+ className,
12108
+ disabled,
12109
+ ...props
12110
+ }, ref) => {
12111
+ const handleChange = (event) => {
12112
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12113
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12114
+ onChange(newValue);
12115
+ }
12116
+ };
12117
+ const handleIncrement = () => {
12118
+ const newValue = value + step;
12119
+ if (max === void 0 || newValue <= max) {
12120
+ onChange(newValue);
12121
+ }
12122
+ };
12123
+ const handleDecrement = () => {
12124
+ const newValue = value - step;
12125
+ if (min === void 0 || newValue >= min) {
12126
+ onChange(newValue);
12127
+ }
12128
+ };
12129
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12130
+ "div",
12131
+ {
12132
+ className: ui.clx(
12133
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12134
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12135
+ {
12136
+ "h-7": size === "small",
12137
+ "h-8": size === "base"
12138
+ },
12139
+ className
12873
12140
  ),
12874
- /* @__PURE__ */ jsxRuntime.jsx(
12875
- "rect",
12876
- {
12877
- width: "17",
12878
- height: "3",
12879
- rx: "1.5",
12880
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12881
- fill: "#A1A1AA"
12141
+ children: [
12142
+ /* @__PURE__ */ jsxRuntime.jsx(
12143
+ "input",
12144
+ {
12145
+ ref,
12146
+ type: "number",
12147
+ value,
12148
+ onChange: handleChange,
12149
+ min,
12150
+ max,
12151
+ step,
12152
+ className: ui.clx(
12153
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12154
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12155
+ "placeholder:text-ui-fg-muted"
12156
+ ),
12157
+ ...props
12158
+ }
12159
+ ),
12160
+ /* @__PURE__ */ jsxRuntime.jsxs(
12161
+ "button",
12162
+ {
12163
+ className: ui.clx(
12164
+ "flex items-center justify-center outline-none transition-fg",
12165
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12166
+ "focus:bg-ui-bg-field-component-hover",
12167
+ "hover:bg-ui-bg-field-component-hover",
12168
+ {
12169
+ "size-7": size === "small",
12170
+ "size-8": size === "base"
12171
+ }
12172
+ ),
12173
+ type: "button",
12174
+ onClick: handleDecrement,
12175
+ disabled: min !== void 0 && value <= min || disabled,
12176
+ children: [
12177
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
12178
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12179
+ ]
12180
+ }
12181
+ ),
12182
+ /* @__PURE__ */ jsxRuntime.jsxs(
12183
+ "button",
12184
+ {
12185
+ className: ui.clx(
12186
+ "flex items-center justify-center outline-none transition-fg",
12187
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12188
+ "focus:bg-ui-bg-field-hover",
12189
+ "hover:bg-ui-bg-field-hover",
12190
+ {
12191
+ "size-7": size === "small",
12192
+ "size-8": size === "base"
12193
+ }
12194
+ ),
12195
+ type: "button",
12196
+ onClick: handleIncrement,
12197
+ disabled: max !== void 0 && value >= max || disabled,
12198
+ children: [
12199
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
12200
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12201
+ ]
12202
+ }
12203
+ )
12204
+ ]
12205
+ }
12206
+ );
12207
+ }
12208
+ );
12209
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12210
+ const productVariantsQueryKeys = {
12211
+ list: (query2) => [
12212
+ PRODUCT_VARIANTS_QUERY_KEY,
12213
+ query2 ? query2 : void 0
12214
+ ]
12215
+ };
12216
+ const useProductVariants = (query2, options) => {
12217
+ const { data, ...rest } = reactQuery.useQuery({
12218
+ queryKey: productVariantsQueryKeys.list(query2),
12219
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12220
+ ...options
12221
+ });
12222
+ return { ...data, ...rest };
12223
+ };
12224
+ const STACKED_MODAL_ID = "items_stacked_modal";
12225
+ const Items = () => {
12226
+ const { id } = reactRouterDom.useParams();
12227
+ const {
12228
+ order: preview,
12229
+ isPending: isPreviewPending,
12230
+ isError: isPreviewError,
12231
+ error: previewError
12232
+ } = useOrderPreview(id, void 0, {
12233
+ placeholderData: reactQuery.keepPreviousData
12234
+ });
12235
+ useInitiateOrderEdit({ preview });
12236
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12237
+ id,
12238
+ {
12239
+ fields: "currency_code"
12240
+ },
12241
+ {
12242
+ enabled: !!id
12243
+ }
12244
+ );
12245
+ const { onCancel } = useCancelOrderEdit({ preview });
12246
+ if (isError) {
12247
+ throw error;
12248
+ }
12249
+ if (isPreviewError) {
12250
+ throw previewError;
12251
+ }
12252
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12253
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12256
+ ] }) });
12257
+ };
12258
+ const ItemsForm = ({ preview, currencyCode }) => {
12259
+ var _a;
12260
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12261
+ const [modalContent, setModalContent] = React.useState(
12262
+ null
12263
+ );
12264
+ const { handleSuccess } = useRouteModal();
12265
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12266
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12267
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12268
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12269
+ const matches = React.useMemo(() => {
12270
+ return matchSorter.matchSorter(preview.items, query2, {
12271
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12272
+ });
12273
+ }, [preview.items, query2]);
12274
+ const onSubmit = async () => {
12275
+ setIsSubmitting(true);
12276
+ let requestSucceeded = false;
12277
+ await requestOrderEdit(void 0, {
12278
+ onError: (e) => {
12279
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12280
+ },
12281
+ onSuccess: () => {
12282
+ requestSucceeded = true;
12283
+ }
12284
+ });
12285
+ if (!requestSucceeded) {
12286
+ setIsSubmitting(false);
12287
+ return;
12288
+ }
12289
+ await confirmOrderEdit(void 0, {
12290
+ onError: (e) => {
12291
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12292
+ },
12293
+ onSuccess: () => {
12294
+ handleSuccess();
12295
+ },
12296
+ onSettled: () => {
12297
+ setIsSubmitting(false);
12298
+ }
12299
+ });
12300
+ };
12301
+ const onKeyDown = React.useCallback(
12302
+ (e) => {
12303
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12304
+ if (modalContent || isSubmitting) {
12305
+ return;
12306
+ }
12307
+ onSubmit();
12308
+ }
12309
+ },
12310
+ [modalContent, isSubmitting, onSubmit]
12311
+ );
12312
+ React.useEffect(() => {
12313
+ document.addEventListener("keydown", onKeyDown);
12314
+ return () => {
12315
+ document.removeEventListener("keydown", onKeyDown);
12316
+ };
12317
+ }, [onKeyDown]);
12318
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12319
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12320
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
12321
+ StackedFocusModal,
12322
+ {
12323
+ id: STACKED_MODAL_ID,
12324
+ onOpenChangeCallback: (open) => {
12325
+ if (!open) {
12326
+ setModalContent(null);
12882
12327
  }
12883
- ),
12884
- /* @__PURE__ */ jsxRuntime.jsx(
12885
- "rect",
12886
- {
12887
- width: "12",
12888
- height: "3",
12889
- rx: "1.5",
12890
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12891
- fill: "#A1A1AA"
12328
+ },
12329
+ children: [
12330
+ /* @__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: [
12331
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12332
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
12333
+ /* @__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." }) })
12334
+ ] }),
12335
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12336
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12337
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12338
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12339
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12340
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12341
+ ] }),
12342
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
12343
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12344
+ ui.Input,
12345
+ {
12346
+ type: "search",
12347
+ placeholder: "Search items",
12348
+ value: searchValue,
12349
+ onChange: (e) => onSearchValueChange(e.target.value)
12350
+ }
12351
+ ) }),
12352
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12353
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
12354
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12355
+ /* @__PURE__ */ jsxRuntime.jsx(
12356
+ StackedModalTrigger,
12357
+ {
12358
+ type: "add-items",
12359
+ setModalContent
12360
+ }
12361
+ ),
12362
+ /* @__PURE__ */ jsxRuntime.jsx(
12363
+ StackedModalTrigger,
12364
+ {
12365
+ type: "add-custom-item",
12366
+ setModalContent
12367
+ }
12368
+ )
12369
+ ] })
12370
+ ] })
12371
+ ] })
12372
+ ] }),
12373
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12374
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12375
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12376
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12377
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
12378
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
12379
+ ] }) }),
12380
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12381
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12382
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12383
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
12384
+ Item,
12385
+ {
12386
+ item,
12387
+ preview,
12388
+ currencyCode
12389
+ },
12390
+ item.id
12391
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12392
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12393
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12394
+ 'No items found for "',
12395
+ query2,
12396
+ '".'
12397
+ ] })
12398
+ ] }) })
12399
+ ] })
12400
+ ] }),
12401
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12402
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12403
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12404
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
12405
+ ui.Text,
12406
+ {
12407
+ size: "small",
12408
+ leading: "compact",
12409
+ className: "text-ui-fg-subtle",
12410
+ children: [
12411
+ itemCount,
12412
+ " ",
12413
+ itemCount === 1 ? "item" : "items"
12414
+ ]
12415
+ }
12416
+ ) }),
12417
+ /* @__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) }) })
12418
+ ] })
12419
+ ] }) }),
12420
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
12421
+ CustomItemForm,
12422
+ {
12423
+ orderId: preview.id,
12424
+ currencyCode
12425
+ }
12426
+ ) : null)
12427
+ ]
12428
+ }
12429
+ ) }),
12430
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12431
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12432
+ /* @__PURE__ */ jsxRuntime.jsx(
12433
+ ui.Button,
12434
+ {
12435
+ size: "small",
12436
+ type: "button",
12437
+ onClick: onSubmit,
12438
+ isLoading: isSubmitting,
12439
+ children: "Save"
12440
+ }
12441
+ )
12442
+ ] }) })
12443
+ ] });
12444
+ };
12445
+ const Item = ({ item, preview, currencyCode }) => {
12446
+ if (item.variant_id) {
12447
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
12448
+ }
12449
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
12450
+ };
12451
+ const VariantItem = ({ item, preview, currencyCode }) => {
12452
+ const [editing, setEditing] = React.useState(false);
12453
+ const form = reactHookForm.useForm({
12454
+ defaultValues: {
12455
+ quantity: item.quantity,
12456
+ unit_price: item.unit_price
12457
+ },
12458
+ resolver: zod.zodResolver(variantItemSchema)
12459
+ });
12460
+ const actionId = React.useMemo(() => {
12461
+ var _a, _b;
12462
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12463
+ }, [item]);
12464
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12465
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12466
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12467
+ const onSubmit = form.handleSubmit(async (data) => {
12468
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12469
+ setEditing(false);
12470
+ return;
12471
+ }
12472
+ if (!actionId) {
12473
+ await updateOriginalItem(
12474
+ {
12475
+ item_id: item.id,
12476
+ quantity: data.quantity,
12477
+ unit_price: convertNumber(data.unit_price)
12478
+ },
12479
+ {
12480
+ onSuccess: () => {
12481
+ setEditing(false);
12482
+ },
12483
+ onError: (e) => {
12484
+ ui.toast.error(e.message);
12892
12485
  }
12893
- ),
12486
+ }
12487
+ );
12488
+ return;
12489
+ }
12490
+ await updateActionItem(
12491
+ {
12492
+ action_id: actionId,
12493
+ quantity: data.quantity,
12494
+ unit_price: convertNumber(data.unit_price)
12495
+ },
12496
+ {
12497
+ onSuccess: () => {
12498
+ setEditing(false);
12499
+ },
12500
+ onError: (e) => {
12501
+ ui.toast.error(e.message);
12502
+ }
12503
+ }
12504
+ );
12505
+ });
12506
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12507
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12508
+ /* @__PURE__ */ jsxRuntime.jsx(
12509
+ Thumbnail,
12510
+ {
12511
+ thumbnail: item.thumbnail,
12512
+ alt: item.product_title ?? void 0
12513
+ }
12514
+ ),
12515
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12516
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12518
+ /* @__PURE__ */ jsxRuntime.jsxs(
12519
+ ui.Text,
12520
+ {
12521
+ size: "small",
12522
+ leading: "compact",
12523
+ className: "text-ui-fg-subtle",
12524
+ children: [
12525
+ "(",
12526
+ item.variant_title,
12527
+ ")"
12528
+ ]
12529
+ }
12530
+ )
12531
+ ] }),
12894
12532
  /* @__PURE__ */ jsxRuntime.jsx(
12895
- "path",
12896
- {
12897
- 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",
12898
- fill: "#52525B"
12899
- }
12900
- ),
12901
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12902
- "path",
12903
- {
12904
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12905
- stroke: "#A1A1AA",
12906
- strokeWidth: "1.5",
12907
- strokeLinecap: "round",
12908
- strokeLinejoin: "round"
12909
- }
12910
- ) }),
12911
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12912
- "path",
12913
- {
12914
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12915
- stroke: "#A1A1AA",
12916
- strokeWidth: "1.5",
12917
- strokeLinecap: "round",
12918
- strokeLinejoin: "round"
12919
- }
12920
- ) }),
12921
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12922
- "path",
12533
+ ui.Text,
12923
12534
  {
12924
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12925
- stroke: "#A1A1AA",
12926
- strokeWidth: "1.5",
12927
- strokeLinecap: "round",
12928
- strokeLinejoin: "round"
12535
+ size: "small",
12536
+ leading: "compact",
12537
+ className: "text-ui-fg-subtle",
12538
+ children: item.variant_sku
12929
12539
  }
12930
- ) }),
12931
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12932
- "path",
12933
- {
12934
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12935
- stroke: "#A1A1AA",
12936
- strokeWidth: "1.5",
12937
- strokeLinecap: "round",
12938
- strokeLinejoin: "round"
12540
+ )
12541
+ ] })
12542
+ ] }),
12543
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12544
+ Form$2.Field,
12545
+ {
12546
+ control: form.control,
12547
+ name: "quantity",
12548
+ render: ({ field }) => {
12549
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12550
+ }
12551
+ }
12552
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12553
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12554
+ Form$2.Field,
12555
+ {
12556
+ control: form.control,
12557
+ name: "unit_price",
12558
+ render: ({ field: { onChange, ...field } }) => {
12559
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12560
+ ui.CurrencyInput,
12561
+ {
12562
+ ...field,
12563
+ symbol: getNativeSymbol(currencyCode),
12564
+ code: currencyCode,
12565
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12566
+ }
12567
+ ) }) });
12568
+ }
12569
+ }
12570
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12571
+ /* @__PURE__ */ jsxRuntime.jsx(
12572
+ ui.IconButton,
12573
+ {
12574
+ type: "button",
12575
+ size: "small",
12576
+ onClick: editing ? onSubmit : () => {
12577
+ setEditing(true);
12578
+ },
12579
+ disabled: isPending,
12580
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12581
+ }
12582
+ )
12583
+ ] }) }) });
12584
+ };
12585
+ const variantItemSchema = objectType({
12586
+ quantity: numberType(),
12587
+ unit_price: unionType([numberType(), stringType()])
12588
+ });
12589
+ const CustomItem = ({ item, preview, currencyCode }) => {
12590
+ const [editing, setEditing] = React.useState(false);
12591
+ const { quantity, unit_price, title } = item;
12592
+ const form = reactHookForm.useForm({
12593
+ defaultValues: {
12594
+ title,
12595
+ quantity,
12596
+ unit_price
12597
+ },
12598
+ resolver: zod.zodResolver(customItemSchema)
12599
+ });
12600
+ React.useEffect(() => {
12601
+ form.reset({
12602
+ title,
12603
+ quantity,
12604
+ unit_price
12605
+ });
12606
+ }, [form, title, quantity, unit_price]);
12607
+ const actionId = React.useMemo(() => {
12608
+ var _a, _b;
12609
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12610
+ }, [item]);
12611
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12612
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12613
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12614
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12615
+ const onSubmit = form.handleSubmit(async (data) => {
12616
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12617
+ setEditing(false);
12618
+ return;
12619
+ }
12620
+ if (!actionId) {
12621
+ await updateOriginalItem(
12622
+ {
12623
+ item_id: item.id,
12624
+ quantity: data.quantity,
12625
+ unit_price: convertNumber(data.unit_price)
12626
+ },
12627
+ {
12628
+ onSuccess: () => {
12629
+ setEditing(false);
12630
+ },
12631
+ onError: (e) => {
12632
+ ui.toast.error(e.message);
12939
12633
  }
12940
- ) }),
12941
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12942
- "path",
12943
- {
12944
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12945
- stroke: "#A1A1AA",
12946
- strokeWidth: "1.5",
12947
- strokeLinecap: "round",
12948
- strokeLinejoin: "round"
12634
+ }
12635
+ );
12636
+ return;
12637
+ }
12638
+ if (data.quantity === 0) {
12639
+ await removeActionItem(actionId, {
12640
+ onSuccess: () => {
12641
+ setEditing(false);
12642
+ },
12643
+ onError: (e) => {
12644
+ ui.toast.error(e.message);
12645
+ }
12646
+ });
12647
+ return;
12648
+ }
12649
+ await updateActionItem(
12650
+ {
12651
+ action_id: actionId,
12652
+ quantity: data.quantity,
12653
+ unit_price: convertNumber(data.unit_price)
12654
+ },
12655
+ {
12656
+ onSuccess: () => {
12657
+ setEditing(false);
12658
+ },
12659
+ onError: (e) => {
12660
+ ui.toast.error(e.message);
12661
+ }
12662
+ }
12663
+ );
12664
+ });
12665
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12666
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12667
+ /* @__PURE__ */ jsxRuntime.jsx(
12668
+ Thumbnail,
12669
+ {
12670
+ thumbnail: item.thumbnail,
12671
+ alt: item.title ?? void 0
12672
+ }
12673
+ ),
12674
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12675
+ Form$2.Field,
12676
+ {
12677
+ control: form.control,
12678
+ name: "title",
12679
+ render: ({ field }) => {
12680
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
12949
12681
  }
12950
- ) }),
12951
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12952
- "path",
12682
+ }
12683
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12684
+ ] }),
12685
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12686
+ Form$2.Field,
12687
+ {
12688
+ control: form.control,
12689
+ name: "quantity",
12690
+ render: ({ field }) => {
12691
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12692
+ }
12693
+ }
12694
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12695
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12696
+ Form$2.Field,
12697
+ {
12698
+ control: form.control,
12699
+ name: "unit_price",
12700
+ render: ({ field: { onChange, ...field } }) => {
12701
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12702
+ ui.CurrencyInput,
12703
+ {
12704
+ ...field,
12705
+ symbol: getNativeSymbol(currencyCode),
12706
+ code: currencyCode,
12707
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12708
+ }
12709
+ ) }) });
12710
+ }
12711
+ }
12712
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12713
+ /* @__PURE__ */ jsxRuntime.jsx(
12714
+ ui.IconButton,
12715
+ {
12716
+ type: "button",
12717
+ size: "small",
12718
+ onClick: editing ? onSubmit : () => {
12719
+ setEditing(true);
12720
+ },
12721
+ disabled: isPending,
12722
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12723
+ }
12724
+ )
12725
+ ] }) }) });
12726
+ };
12727
+ const StackedModalTrigger = ({
12728
+ type,
12729
+ setModalContent
12730
+ }) => {
12731
+ const { setIsOpen } = useStackedModal();
12732
+ const onClick = React.useCallback(() => {
12733
+ setModalContent(type);
12734
+ setIsOpen(STACKED_MODAL_ID, true);
12735
+ }, [setModalContent, setIsOpen, type]);
12736
+ 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" }) });
12737
+ };
12738
+ const VARIANT_PREFIX = "items";
12739
+ const LIMIT = 50;
12740
+ const ExistingItemsForm = ({ orderId, items }) => {
12741
+ const { setIsOpen } = useStackedModal();
12742
+ const [rowSelection, setRowSelection] = React.useState(
12743
+ items.reduce((acc, item) => {
12744
+ acc[item.variant_id] = true;
12745
+ return acc;
12746
+ }, {})
12747
+ );
12748
+ React.useEffect(() => {
12749
+ setRowSelection(
12750
+ items.reduce((acc, item) => {
12751
+ if (item.variant_id) {
12752
+ acc[item.variant_id] = true;
12753
+ }
12754
+ return acc;
12755
+ }, {})
12756
+ );
12757
+ }, [items]);
12758
+ const { q, order, offset } = useQueryParams(
12759
+ ["q", "order", "offset"],
12760
+ VARIANT_PREFIX
12761
+ );
12762
+ const { variants, count, isPending, isError, error } = useProductVariants(
12763
+ {
12764
+ q,
12765
+ order,
12766
+ offset: offset ? parseInt(offset) : void 0,
12767
+ limit: LIMIT
12768
+ },
12769
+ {
12770
+ placeholderData: reactQuery.keepPreviousData
12771
+ }
12772
+ );
12773
+ const columns = useColumns();
12774
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12775
+ const onSubmit = async () => {
12776
+ const ids = Object.keys(rowSelection).filter(
12777
+ (id) => !items.find((i) => i.variant_id === id)
12778
+ );
12779
+ await mutateAsync(
12780
+ {
12781
+ items: ids.map((id) => ({
12782
+ variant_id: id,
12783
+ quantity: 1
12784
+ }))
12785
+ },
12786
+ {
12787
+ onSuccess: () => {
12788
+ setRowSelection({});
12789
+ setIsOpen(STACKED_MODAL_ID, false);
12790
+ },
12791
+ onError: (e) => {
12792
+ ui.toast.error(e.message);
12793
+ }
12794
+ }
12795
+ );
12796
+ };
12797
+ if (isError) {
12798
+ throw error;
12799
+ }
12800
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12801
+ StackedFocusModal.Content,
12802
+ {
12803
+ onOpenAutoFocus: (e) => {
12804
+ e.preventDefault();
12805
+ const searchInput = document.querySelector(
12806
+ "[data-modal-id='modal-search-input']"
12807
+ );
12808
+ if (searchInput) {
12809
+ searchInput.focus();
12810
+ }
12811
+ },
12812
+ children: [
12813
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12814
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12816
+ ] }),
12817
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12818
+ DataTable,
12953
12819
  {
12954
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12955
- stroke: "#A1A1AA",
12956
- strokeWidth: "1.5",
12957
- strokeLinecap: "round",
12958
- strokeLinejoin: "round"
12820
+ data: variants,
12821
+ columns,
12822
+ isLoading: isPending,
12823
+ getRowId: (row) => row.id,
12824
+ rowCount: count,
12825
+ prefix: VARIANT_PREFIX,
12826
+ layout: "fill",
12827
+ rowSelection: {
12828
+ state: rowSelection,
12829
+ onRowSelectionChange: setRowSelection,
12830
+ enableRowSelection: (row) => {
12831
+ return !items.find((i) => i.variant_id === row.original.id);
12832
+ }
12833
+ },
12834
+ autoFocusSearch: true
12959
12835
  }
12960
12836
  ) }),
12961
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12962
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12963
- "rect",
12964
- {
12965
- width: "12",
12966
- height: "12",
12967
- fill: "white",
12968
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12969
- }
12970
- ) }),
12971
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12972
- "rect",
12973
- {
12974
- width: "12",
12975
- height: "12",
12976
- fill: "white",
12977
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12978
- }
12979
- ) }),
12980
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12981
- "rect",
12982
- {
12983
- width: "12",
12984
- height: "12",
12985
- fill: "white",
12986
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12987
- }
12988
- ) }),
12989
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12990
- "rect",
12991
- {
12992
- width: "12",
12993
- height: "12",
12994
- fill: "white",
12995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12996
- }
12997
- ) }),
12998
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12999
- "rect",
12837
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12838
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12839
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12840
+ ] }) })
12841
+ ]
12842
+ }
12843
+ );
12844
+ };
12845
+ const columnHelper = ui.createDataTableColumnHelper();
12846
+ const useColumns = () => {
12847
+ return React.useMemo(() => {
12848
+ return [
12849
+ columnHelper.select(),
12850
+ columnHelper.accessor("product.title", {
12851
+ header: "Product",
12852
+ cell: ({ row }) => {
12853
+ var _a, _b, _c;
12854
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsx(
12856
+ Thumbnail,
12857
+ {
12858
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12859
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
12860
+ }
12861
+ ),
12862
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12863
+ ] });
12864
+ },
12865
+ enableSorting: true
12866
+ }),
12867
+ columnHelper.accessor("title", {
12868
+ header: "Variant",
12869
+ enableSorting: true
12870
+ }),
12871
+ columnHelper.accessor("sku", {
12872
+ header: "SKU",
12873
+ cell: ({ getValue }) => {
12874
+ return getValue() ?? "-";
12875
+ },
12876
+ enableSorting: true
12877
+ }),
12878
+ columnHelper.accessor("updated_at", {
12879
+ header: "Updated",
12880
+ cell: ({ getValue }) => {
12881
+ return /* @__PURE__ */ jsxRuntime.jsx(
12882
+ ui.Tooltip,
13000
12883
  {
13001
- width: "12",
13002
- height: "12",
13003
- fill: "white",
13004
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12884
+ content: getFullDate({ date: getValue(), includeTime: true }),
12885
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13005
12886
  }
13006
- ) }),
13007
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13008
- "rect",
12887
+ );
12888
+ },
12889
+ enableSorting: true,
12890
+ sortAscLabel: "Oldest first",
12891
+ sortDescLabel: "Newest first"
12892
+ }),
12893
+ columnHelper.accessor("created_at", {
12894
+ header: "Created",
12895
+ cell: ({ getValue }) => {
12896
+ return /* @__PURE__ */ jsxRuntime.jsx(
12897
+ ui.Tooltip,
13009
12898
  {
13010
- width: "12",
13011
- height: "12",
13012
- fill: "white",
13013
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12899
+ content: getFullDate({ date: getValue(), includeTime: true }),
12900
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13014
12901
  }
13015
- ) })
13016
- ] })
13017
- ]
13018
- }
13019
- );
12902
+ );
12903
+ },
12904
+ enableSorting: true,
12905
+ sortAscLabel: "Oldest first",
12906
+ sortDescLabel: "Newest first"
12907
+ })
12908
+ ];
12909
+ }, []);
13020
12910
  };
13021
- const schema = objectType({
13022
- customer_id: stringType().min(1)
12911
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12912
+ const { setIsOpen } = useStackedModal();
12913
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12914
+ const form = reactHookForm.useForm({
12915
+ defaultValues: {
12916
+ title: "",
12917
+ quantity: 1,
12918
+ unit_price: ""
12919
+ },
12920
+ resolver: zod.zodResolver(customItemSchema)
12921
+ });
12922
+ const onSubmit = form.handleSubmit(async (data) => {
12923
+ await addItems(
12924
+ {
12925
+ items: [
12926
+ {
12927
+ title: data.title,
12928
+ quantity: data.quantity,
12929
+ unit_price: convertNumber(data.unit_price)
12930
+ }
12931
+ ]
12932
+ },
12933
+ {
12934
+ onSuccess: () => {
12935
+ setIsOpen(STACKED_MODAL_ID, false);
12936
+ },
12937
+ onError: (e) => {
12938
+ ui.toast.error(e.message);
12939
+ }
12940
+ }
12941
+ );
12942
+ });
12943
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12944
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12945
+ /* @__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: [
12946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12947
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12948
+ /* @__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." }) })
12949
+ ] }),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "title",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12960
+ ] }),
12961
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12962
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12964
+ ] })
12965
+ ] }) })
12966
+ }
12967
+ ),
12968
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(
12970
+ Form$2.Field,
12971
+ {
12972
+ control: form.control,
12973
+ name: "unit_price",
12974
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12975
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12976
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12977
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12978
+ ] }),
12979
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12980
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12981
+ ui.CurrencyInput,
12982
+ {
12983
+ symbol: getNativeSymbol(currencyCode),
12984
+ code: currencyCode,
12985
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12986
+ ...field
12987
+ }
12988
+ ) }),
12989
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12990
+ ] })
12991
+ ] }) })
12992
+ }
12993
+ ),
12994
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "quantity",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13001
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13002
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
13003
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13004
+ ] }),
13005
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ ] }) })
13010
+ }
13011
+ )
13012
+ ] }) }) }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13014
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13015
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13016
+ ] }) })
13017
+ ] }) }) });
13018
+ };
13019
+ const customItemSchema = objectType({
13020
+ title: stringType().min(1),
13021
+ quantity: numberType(),
13022
+ unit_price: unionType([numberType(), stringType()])
13023
13023
  });
13024
13024
  const widgetModule = { widgets: [] };
13025
13025
  const routeModule = {
@@ -13049,6 +13049,10 @@ const routeModule = {
13049
13049
  Component: CustomItems,
13050
13050
  path: "/draft-orders/:id/custom-items"
13051
13051
  },
13052
+ {
13053
+ Component: Email,
13054
+ path: "/draft-orders/:id/email"
13055
+ },
13052
13056
  {
13053
13057
  Component: Metadata,
13054
13058
  path: "/draft-orders/:id/metadata"
@@ -13069,17 +13073,13 @@ const routeModule = {
13069
13073
  Component: ShippingAddress,
13070
13074
  path: "/draft-orders/:id/shipping-address"
13071
13075
  },
13072
- {
13073
- Component: Items,
13074
- path: "/draft-orders/:id/items"
13075
- },
13076
- {
13077
- Component: Email,
13078
- path: "/draft-orders/:id/email"
13079
- },
13080
13076
  {
13081
13077
  Component: TransferOwnership,
13082
13078
  path: "/draft-orders/:id/transfer-ownership"
13079
+ },
13080
+ {
13081
+ Component: Items,
13082
+ path: "/draft-orders/:id/items"
13083
13083
  }
13084
13084
  ]
13085
13085
  }