@medusajs/draft-order 0.0.13-preview.1 → 0.0.14

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