@medusajs/draft-order 2.10.4-snapshot-20251003141424 → 2.10.4-snapshot-20251004142159

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.
@@ -9573,6 +9573,196 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const BillingAddress = () => {
9577
+ const { id } = reactRouterDom.useParams();
9578
+ const { order, isPending, isError, error } = useOrder(id, {
9579
+ fields: "+billing_address"
9580
+ });
9581
+ if (isError) {
9582
+ throw error;
9583
+ }
9584
+ const isReady = !isPending && !!order;
9585
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
+ ] }),
9590
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
+ ] });
9592
+ };
9593
+ const BillingAddressForm = ({ order }) => {
9594
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
+ const form = reactHookForm.useForm({
9596
+ defaultValues: {
9597
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
+ },
9608
+ resolver: zod.zodResolver(schema$5)
9609
+ });
9610
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
+ const { handleSuccess } = useRouteModal();
9612
+ const onSubmit = form.handleSubmit(async (data) => {
9613
+ await mutateAsync(
9614
+ { billing_address: data },
9615
+ {
9616
+ onSuccess: () => {
9617
+ handleSuccess();
9618
+ },
9619
+ onError: (error) => {
9620
+ ui.toast.error(error.message);
9621
+ }
9622
+ }
9623
+ );
9624
+ });
9625
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
+ KeyboundForm,
9627
+ {
9628
+ className: "flex flex-1 flex-col overflow-hidden",
9629
+ onSubmit,
9630
+ children: [
9631
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
+ /* @__PURE__ */ jsxRuntime.jsx(
9633
+ Form$2.Field,
9634
+ {
9635
+ control: form.control,
9636
+ name: "country_code",
9637
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
+ ] })
9642
+ }
9643
+ ),
9644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
+ /* @__PURE__ */ jsxRuntime.jsx(
9646
+ Form$2.Field,
9647
+ {
9648
+ control: form.control,
9649
+ name: "first_name",
9650
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
+ ] })
9655
+ }
9656
+ ),
9657
+ /* @__PURE__ */ jsxRuntime.jsx(
9658
+ Form$2.Field,
9659
+ {
9660
+ control: form.control,
9661
+ name: "last_name",
9662
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
+ ] })
9667
+ }
9668
+ )
9669
+ ] }),
9670
+ /* @__PURE__ */ jsxRuntime.jsx(
9671
+ Form$2.Field,
9672
+ {
9673
+ control: form.control,
9674
+ name: "company",
9675
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
+ ] })
9680
+ }
9681
+ ),
9682
+ /* @__PURE__ */ jsxRuntime.jsx(
9683
+ Form$2.Field,
9684
+ {
9685
+ control: form.control,
9686
+ name: "address_1",
9687
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
+ ] })
9692
+ }
9693
+ ),
9694
+ /* @__PURE__ */ jsxRuntime.jsx(
9695
+ Form$2.Field,
9696
+ {
9697
+ control: form.control,
9698
+ name: "address_2",
9699
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
+ ] })
9704
+ }
9705
+ ),
9706
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
+ /* @__PURE__ */ jsxRuntime.jsx(
9708
+ Form$2.Field,
9709
+ {
9710
+ control: form.control,
9711
+ name: "postal_code",
9712
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
+ ] })
9717
+ }
9718
+ ),
9719
+ /* @__PURE__ */ jsxRuntime.jsx(
9720
+ Form$2.Field,
9721
+ {
9722
+ control: form.control,
9723
+ name: "city",
9724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
+ ] })
9729
+ }
9730
+ )
9731
+ ] }),
9732
+ /* @__PURE__ */ jsxRuntime.jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "province",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
+ ] })
9742
+ }
9743
+ ),
9744
+ /* @__PURE__ */ jsxRuntime.jsx(
9745
+ Form$2.Field,
9746
+ {
9747
+ control: form.control,
9748
+ name: "phone",
9749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
+ ] })
9754
+ }
9755
+ )
9756
+ ] }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
+ ] }) })
9761
+ ]
9762
+ }
9763
+ ) });
9764
+ };
9765
+ const schema$5 = addressSchema;
9576
9766
  const CustomItems = () => {
9577
9767
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
9768
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9581,7 +9771,7 @@ const CustomItems = () => {
9581
9771
  };
9582
9772
  const CustomItemsForm = () => {
9583
9773
  const form = reactHookForm.useForm({
9584
- resolver: zod.zodResolver(schema$5)
9774
+ resolver: zod.zodResolver(schema$4)
9585
9775
  });
9586
9776
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
9777
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9591,7 +9781,7 @@ const CustomItemsForm = () => {
9591
9781
  ] }) })
9592
9782
  ] }) });
9593
9783
  };
9594
- const schema$5 = objectType({
9784
+ const schema$4 = objectType({
9595
9785
  email: stringType().email()
9596
9786
  });
9597
9787
  const Email = () => {
@@ -9616,7 +9806,7 @@ const EmailForm = ({ order }) => {
9616
9806
  defaultValues: {
9617
9807
  email: order.email ?? ""
9618
9808
  },
9619
- resolver: zod.zodResolver(schema$4)
9809
+ resolver: zod.zodResolver(schema$3)
9620
9810
  });
9621
9811
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
9812
  const { handleSuccess } = useRouteModal();
@@ -9659,7 +9849,7 @@ const EmailForm = ({ order }) => {
9659
9849
  }
9660
9850
  ) });
9661
9851
  };
9662
- const schema$4 = objectType({
9852
+ const schema$3 = objectType({
9663
9853
  email: stringType().email()
9664
9854
  });
9665
9855
  const InlineTip = React.forwardRef(
@@ -10012,144 +10202,39 @@ function getHasUneditableRows(metadata) {
10012
10202
  (value) => !EDITABLE_TYPES.includes(typeof value)
10013
10203
  );
10014
10204
  }
10015
- const NumberInput = React.forwardRef(
10016
- ({
10017
- value,
10018
- onChange,
10019
- size = "base",
10020
- min = 0,
10021
- max = 100,
10022
- step = 1,
10023
- className,
10024
- disabled,
10025
- ...props
10026
- }, ref) => {
10027
- const handleChange = (event) => {
10028
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10029
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10030
- onChange(newValue);
10031
- }
10032
- };
10033
- const handleIncrement = () => {
10034
- const newValue = value + step;
10035
- if (max === void 0 || newValue <= max) {
10036
- onChange(newValue);
10037
- }
10038
- };
10039
- const handleDecrement = () => {
10040
- const newValue = value - step;
10041
- if (min === void 0 || newValue >= min) {
10042
- onChange(newValue);
10043
- }
10044
- };
10045
- return /* @__PURE__ */ jsxRuntime.jsxs(
10046
- "div",
10047
- {
10048
- className: ui.clx(
10049
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10050
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10051
- {
10052
- "h-7": size === "small",
10053
- "h-8": size === "base"
10054
- },
10055
- className
10056
- ),
10057
- children: [
10058
- /* @__PURE__ */ jsxRuntime.jsx(
10059
- "input",
10060
- {
10061
- ref,
10062
- type: "number",
10063
- value,
10064
- onChange: handleChange,
10065
- min,
10066
- max,
10067
- step,
10068
- className: ui.clx(
10069
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10070
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10071
- "placeholder:text-ui-fg-muted"
10072
- ),
10073
- ...props
10074
- }
10075
- ),
10076
- /* @__PURE__ */ jsxRuntime.jsxs(
10077
- "button",
10078
- {
10079
- className: ui.clx(
10080
- "flex items-center justify-center outline-none transition-fg",
10081
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10082
- "focus:bg-ui-bg-field-component-hover",
10083
- "hover:bg-ui-bg-field-component-hover",
10084
- {
10085
- "size-7": size === "small",
10086
- "size-8": size === "base"
10087
- }
10088
- ),
10089
- type: "button",
10090
- onClick: handleDecrement,
10091
- disabled: min !== void 0 && value <= min || disabled,
10092
- children: [
10093
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10094
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10095
- ]
10096
- }
10097
- ),
10098
- /* @__PURE__ */ jsxRuntime.jsxs(
10099
- "button",
10100
- {
10101
- className: ui.clx(
10102
- "flex items-center justify-center outline-none transition-fg",
10103
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10104
- "focus:bg-ui-bg-field-hover",
10105
- "hover:bg-ui-bg-field-hover",
10106
- {
10107
- "size-7": size === "small",
10108
- "size-8": size === "base"
10109
- }
10110
- ),
10111
- type: "button",
10112
- onClick: handleIncrement,
10113
- disabled: max !== void 0 && value >= max || disabled,
10114
- children: [
10115
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10116
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10117
- ]
10118
- }
10119
- )
10120
- ]
10121
- }
10122
- );
10123
- }
10124
- );
10125
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10126
- const productVariantsQueryKeys = {
10127
- list: (query2) => [
10128
- PRODUCT_VARIANTS_QUERY_KEY,
10129
- query2 ? query2 : void 0
10130
- ]
10131
- };
10132
- const useProductVariants = (query2, options) => {
10133
- const { data, ...rest } = reactQuery.useQuery({
10134
- queryKey: productVariantsQueryKeys.list(query2),
10135
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10136
- ...options
10137
- });
10138
- return { ...data, ...rest };
10139
- };
10140
- const useCancelOrderEdit = ({ preview }) => {
10141
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10142
- const onCancel = React.useCallback(async () => {
10143
- if (!preview) {
10144
- return true;
10145
- }
10146
- let res = false;
10147
- await cancelOrderEdit(void 0, {
10148
- onError: (e) => {
10149
- ui.toast.error(e.message);
10150
- },
10151
- onSuccess: () => {
10152
- res = true;
10205
+ const PROMOTION_QUERY_KEY = "promotions";
10206
+ const promotionsQueryKeys = {
10207
+ list: (query2) => [
10208
+ PROMOTION_QUERY_KEY,
10209
+ query2 ? query2 : void 0
10210
+ ],
10211
+ detail: (id, query2) => [
10212
+ PROMOTION_QUERY_KEY,
10213
+ id,
10214
+ query2 ? query2 : void 0
10215
+ ]
10216
+ };
10217
+ const usePromotions = (query2, options) => {
10218
+ const { data, ...rest } = reactQuery.useQuery({
10219
+ queryKey: promotionsQueryKeys.list(query2),
10220
+ queryFn: async () => sdk.admin.promotion.list(query2),
10221
+ ...options
10222
+ });
10223
+ return { ...data, ...rest };
10224
+ };
10225
+ const useCancelOrderEdit = ({ preview }) => {
10226
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10227
+ const onCancel = React.useCallback(async () => {
10228
+ if (!preview) {
10229
+ return true;
10230
+ }
10231
+ let res = false;
10232
+ await cancelOrderEdit(void 0, {
10233
+ onError: (e) => {
10234
+ ui.toast.error(e.message);
10235
+ },
10236
+ onSuccess: () => {
10237
+ res = true;
10153
10238
  }
10154
10239
  });
10155
10240
  return res;
@@ -10183,65 +10268,85 @@ const useInitiateOrderEdit = ({
10183
10268
  run();
10184
10269
  }, [preview, navigate, mutateAsync]);
10185
10270
  };
10186
- function convertNumber(value) {
10187
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10188
- }
10189
- const STACKED_MODAL_ID = "items_stacked_modal";
10190
- const Items = () => {
10271
+ const Promotions = () => {
10191
10272
  const { id } = reactRouterDom.useParams();
10192
10273
  const {
10193
10274
  order: preview,
10194
- isPending: isPreviewPending,
10195
10275
  isError: isPreviewError,
10196
10276
  error: previewError
10197
- } = useOrderPreview(id, void 0, {
10198
- placeholderData: reactQuery.keepPreviousData
10199
- });
10277
+ } = useOrderPreview(id, void 0);
10200
10278
  useInitiateOrderEdit({ preview });
10201
- const { draft_order, isPending, isError, error } = useDraftOrder(
10202
- id,
10203
- {
10204
- fields: "currency_code"
10205
- },
10206
- {
10207
- enabled: !!id
10208
- }
10209
- );
10210
10279
  const { onCancel } = useCancelOrderEdit({ preview });
10211
- if (isError) {
10212
- throw error;
10213
- }
10214
10280
  if (isPreviewError) {
10215
10281
  throw previewError;
10216
10282
  }
10217
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10218
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10219
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10220
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10221
- ] }) });
10283
+ const isReady = !!preview;
10284
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10285
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10286
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10287
+ ] });
10222
10288
  };
10223
- const ItemsForm = ({ preview, currencyCode }) => {
10224
- var _a;
10289
+ const PromotionForm = ({ preview }) => {
10290
+ const { items, shipping_methods } = preview;
10225
10291
  const [isSubmitting, setIsSubmitting] = React.useState(false);
10226
- const [modalContent, setModalContent] = React.useState(
10227
- null
10228
- );
10292
+ const [comboboxValue, setComboboxValue] = React.useState("");
10229
10293
  const { handleSuccess } = useRouteModal();
10230
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10294
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10295
+ const promoIds = getPromotionIds(items, shipping_methods);
10296
+ const { promotions, isPending, isError, error } = usePromotions(
10297
+ {
10298
+ id: promoIds
10299
+ },
10300
+ {
10301
+ enabled: !!promoIds.length
10302
+ }
10303
+ );
10304
+ const comboboxData = useComboboxData({
10305
+ queryKey: ["promotions", "combobox", promoIds],
10306
+ queryFn: async (params) => {
10307
+ return await sdk.admin.promotion.list({
10308
+ ...params,
10309
+ id: {
10310
+ $nin: promoIds
10311
+ }
10312
+ });
10313
+ },
10314
+ getOptions: (data) => {
10315
+ return data.promotions.map((promotion) => ({
10316
+ label: promotion.code,
10317
+ value: promotion.code
10318
+ }));
10319
+ }
10320
+ });
10321
+ const add = async (value) => {
10322
+ if (!value) {
10323
+ return;
10324
+ }
10325
+ addPromotions(
10326
+ {
10327
+ promo_codes: [value]
10328
+ },
10329
+ {
10330
+ onError: (e) => {
10331
+ ui.toast.error(e.message);
10332
+ comboboxData.onSearchValueChange("");
10333
+ setComboboxValue("");
10334
+ },
10335
+ onSuccess: () => {
10336
+ comboboxData.onSearchValueChange("");
10337
+ setComboboxValue("");
10338
+ }
10339
+ }
10340
+ );
10341
+ };
10231
10342
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10232
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10233
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10234
- const matches = React.useMemo(() => {
10235
- return matchSorter.matchSorter(preview.items, query2, {
10236
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10237
- });
10238
- }, [preview.items, query2]);
10343
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10239
10344
  const onSubmit = async () => {
10240
10345
  setIsSubmitting(true);
10241
10346
  let requestSucceeded = false;
10242
10347
  await requestOrderEdit(void 0, {
10243
10348
  onError: (e) => {
10244
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10349
+ ui.toast.error(e.message);
10245
10350
  },
10246
10351
  onSuccess: () => {
10247
10352
  requestSucceeded = true;
@@ -10253,7 +10358,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
10253
10358
  }
10254
10359
  await confirmOrderEdit(void 0, {
10255
10360
  onError: (e) => {
10256
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10361
+ ui.toast.error(e.message);
10257
10362
  },
10258
10363
  onSuccess: () => {
10259
10364
  handleSuccess();
@@ -10263,1442 +10368,293 @@ const ItemsForm = ({ preview, currencyCode }) => {
10263
10368
  }
10264
10369
  });
10265
10370
  };
10266
- const onKeyDown = React.useCallback(
10267
- (e) => {
10268
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10269
- if (modalContent || isSubmitting) {
10270
- return;
10271
- }
10272
- onSubmit();
10273
- }
10274
- },
10275
- [modalContent, isSubmitting, onSubmit]
10276
- );
10277
- React.useEffect(() => {
10278
- document.addEventListener("keydown", onKeyDown);
10279
- return () => {
10280
- document.removeEventListener("keydown", onKeyDown);
10281
- };
10282
- }, [onKeyDown]);
10283
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10284
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10285
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10286
- StackedFocusModal,
10287
- {
10288
- id: STACKED_MODAL_ID,
10289
- onOpenChangeCallback: (open) => {
10290
- if (!open) {
10291
- setModalContent(null);
10292
- }
10293
- },
10294
- children: [
10295
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10296
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10297
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10298
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10299
- ] }),
10300
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10301
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10304
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10306
- ] }),
10307
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10308
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10309
- ui.Input,
10310
- {
10311
- type: "search",
10312
- placeholder: "Search items",
10313
- value: searchValue,
10314
- onChange: (e) => onSearchValueChange(e.target.value)
10315
- }
10316
- ) }),
10317
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10318
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10319
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10320
- /* @__PURE__ */ jsxRuntime.jsx(
10321
- StackedModalTrigger$1,
10322
- {
10323
- type: "add-items",
10324
- setModalContent
10325
- }
10326
- ),
10327
- /* @__PURE__ */ jsxRuntime.jsx(
10328
- StackedModalTrigger$1,
10329
- {
10330
- type: "add-custom-item",
10331
- setModalContent
10332
- }
10333
- )
10334
- ] })
10335
- ] })
10336
- ] })
10337
- ] }),
10338
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10339
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10340
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10341
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10342
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10343
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10344
- ] }) }),
10345
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10346
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10347
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10348
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10349
- Item,
10350
- {
10351
- item,
10352
- preview,
10353
- currencyCode
10354
- },
10355
- item.id
10356
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10357
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10358
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10359
- 'No items found for "',
10360
- query2,
10361
- '".'
10362
- ] })
10363
- ] }) })
10364
- ] })
10365
- ] }),
10366
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10367
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10368
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10369
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10370
- ui.Text,
10371
- {
10372
- size: "small",
10373
- leading: "compact",
10374
- className: "text-ui-fg-subtle",
10375
- children: [
10376
- itemCount,
10377
- " ",
10378
- itemCount === 1 ? "item" : "items"
10379
- ]
10380
- }
10381
- ) }),
10382
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10383
- ] })
10384
- ] }) }),
10385
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10386
- CustomItemForm,
10387
- {
10388
- orderId: preview.id,
10389
- currencyCode
10390
- }
10391
- ) : null)
10392
- ]
10393
- }
10394
- ) }),
10395
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10396
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10371
+ if (isError) {
10372
+ throw error;
10373
+ }
10374
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10376
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10377
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10378
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10379
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10380
+ ] }),
10381
+ /* @__PURE__ */ jsxRuntime.jsx(
10382
+ Combobox,
10383
+ {
10384
+ id: "promotion-combobox",
10385
+ "aria-describedby": "promotion-combobox-hint",
10386
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10387
+ fetchNextPage: comboboxData.fetchNextPage,
10388
+ options: comboboxData.options,
10389
+ onSearchValueChange: comboboxData.onSearchValueChange,
10390
+ searchValue: comboboxData.searchValue,
10391
+ disabled: comboboxData.disabled || isAddingPromotions,
10392
+ onChange: add,
10393
+ value: comboboxValue
10394
+ }
10395
+ )
10396
+ ] }),
10397
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10398
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10399
+ PromotionItem,
10400
+ {
10401
+ promotion,
10402
+ orderId: preview.id,
10403
+ isLoading: isPending
10404
+ },
10405
+ promotion.id
10406
+ )) })
10407
+ ] }) }),
10408
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10409
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10397
10410
  /* @__PURE__ */ jsxRuntime.jsx(
10398
10411
  ui.Button,
10399
10412
  {
10400
10413
  size: "small",
10401
- type: "button",
10402
- onClick: onSubmit,
10403
- isLoading: isSubmitting,
10414
+ type: "submit",
10415
+ isLoading: isSubmitting || isAddingPromotions,
10404
10416
  children: "Save"
10405
10417
  }
10406
10418
  )
10407
10419
  ] }) })
10408
10420
  ] });
10409
10421
  };
10410
- const Item = ({ item, preview, currencyCode }) => {
10411
- if (item.variant_id) {
10412
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10413
- }
10414
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10415
- };
10416
- const VariantItem = ({ item, preview, currencyCode }) => {
10417
- const [editing, setEditing] = React.useState(false);
10418
- const form = reactHookForm.useForm({
10419
- defaultValues: {
10420
- quantity: item.quantity,
10421
- unit_price: item.unit_price
10422
- },
10423
- resolver: zod.zodResolver(variantItemSchema)
10424
- });
10425
- const actionId = React.useMemo(() => {
10426
- var _a, _b;
10427
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10428
- }, [item]);
10429
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10430
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10431
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10432
- const onSubmit = form.handleSubmit(async (data) => {
10433
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10434
- setEditing(false);
10435
- return;
10436
- }
10437
- if (!actionId) {
10438
- await updateOriginalItem(
10439
- {
10440
- item_id: item.id,
10441
- quantity: data.quantity,
10442
- unit_price: convertNumber(data.unit_price)
10443
- },
10444
- {
10445
- onSuccess: () => {
10446
- setEditing(false);
10447
- },
10448
- onError: (e) => {
10449
- ui.toast.error(e.message);
10450
- }
10451
- }
10452
- );
10453
- return;
10454
- }
10455
- await updateActionItem(
10422
+ const PromotionItem = ({
10423
+ promotion,
10424
+ orderId,
10425
+ isLoading
10426
+ }) => {
10427
+ var _a;
10428
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10429
+ const onRemove = async () => {
10430
+ removePromotions(
10456
10431
  {
10457
- action_id: actionId,
10458
- quantity: data.quantity,
10459
- unit_price: convertNumber(data.unit_price)
10432
+ promo_codes: [promotion.code]
10460
10433
  },
10461
10434
  {
10462
- onSuccess: () => {
10463
- setEditing(false);
10464
- },
10465
10435
  onError: (e) => {
10466
10436
  ui.toast.error(e.message);
10467
10437
  }
10468
10438
  }
10469
10439
  );
10470
- });
10471
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10472
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10473
- /* @__PURE__ */ jsxRuntime.jsx(
10474
- Thumbnail,
10440
+ };
10441
+ const displayValue = getDisplayValue(promotion);
10442
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10443
+ "div",
10444
+ {
10445
+ className: ui.clx(
10446
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10475
10447
  {
10476
- thumbnail: item.thumbnail,
10477
- alt: item.product_title ?? void 0
10448
+ "animate-pulse": isLoading
10478
10449
  }
10479
10450
  ),
10480
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10481
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10482
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10483
- /* @__PURE__ */ jsxRuntime.jsxs(
10484
- ui.Text,
10485
- {
10486
- size: "small",
10487
- leading: "compact",
10488
- className: "text-ui-fg-subtle",
10489
- children: [
10490
- "(",
10491
- item.variant_title,
10492
- ")"
10493
- ]
10494
- }
10495
- )
10451
+ children: [
10452
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10453
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10454
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10455
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
10456
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
10457
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10458
+ ] }),
10459
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10460
+ ] })
10496
10461
  ] }),
10497
10462
  /* @__PURE__ */ jsxRuntime.jsx(
10498
- ui.Text,
10463
+ ui.IconButton,
10499
10464
  {
10500
10465
  size: "small",
10501
- leading: "compact",
10502
- className: "text-ui-fg-subtle",
10503
- children: item.variant_sku
10466
+ type: "button",
10467
+ variant: "transparent",
10468
+ onClick: onRemove,
10469
+ isLoading: isPending || isLoading,
10470
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
10504
10471
  }
10505
10472
  )
10506
- ] })
10507
- ] }),
10508
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10509
- Form$2.Field,
10510
- {
10511
- control: form.control,
10512
- name: "quantity",
10513
- render: ({ field }) => {
10514
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10515
- }
10516
- }
10517
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10518
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10519
- Form$2.Field,
10520
- {
10521
- control: form.control,
10522
- name: "unit_price",
10523
- render: ({ field: { onChange, ...field } }) => {
10524
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10525
- ui.CurrencyInput,
10526
- {
10527
- ...field,
10528
- symbol: getNativeSymbol(currencyCode),
10529
- code: currencyCode,
10530
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10531
- }
10532
- ) }) });
10473
+ ]
10474
+ },
10475
+ promotion.id
10476
+ );
10477
+ };
10478
+ function getDisplayValue(promotion) {
10479
+ var _a, _b, _c, _d;
10480
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10481
+ if (!value) {
10482
+ return null;
10483
+ }
10484
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10485
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10486
+ if (!currency) {
10487
+ return null;
10488
+ }
10489
+ return getLocaleAmount(value, currency);
10490
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10491
+ return formatPercentage(value);
10492
+ }
10493
+ return null;
10494
+ }
10495
+ const formatter = new Intl.NumberFormat([], {
10496
+ style: "percent",
10497
+ minimumFractionDigits: 2
10498
+ });
10499
+ const formatPercentage = (value, isPercentageValue = false) => {
10500
+ let val = value || 0;
10501
+ if (!isPercentageValue) {
10502
+ val = val / 100;
10503
+ }
10504
+ return formatter.format(val);
10505
+ };
10506
+ function getPromotionIds(items, shippingMethods) {
10507
+ const promotionIds = /* @__PURE__ */ new Set();
10508
+ for (const item of items) {
10509
+ if (item.adjustments) {
10510
+ for (const adjustment of item.adjustments) {
10511
+ if (adjustment.promotion_id) {
10512
+ promotionIds.add(adjustment.promotion_id);
10533
10513
  }
10534
10514
  }
10535
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10536
- /* @__PURE__ */ jsxRuntime.jsx(
10537
- ui.IconButton,
10538
- {
10539
- type: "button",
10540
- size: "small",
10541
- onClick: editing ? onSubmit : () => {
10542
- setEditing(true);
10543
- },
10544
- disabled: isPending,
10545
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10515
+ }
10516
+ }
10517
+ for (const shippingMethod of shippingMethods) {
10518
+ if (shippingMethod.adjustments) {
10519
+ for (const adjustment of shippingMethod.adjustments) {
10520
+ if (adjustment.promotion_id) {
10521
+ promotionIds.add(adjustment.promotion_id);
10522
+ }
10546
10523
  }
10547
- )
10548
- ] }) }) });
10524
+ }
10525
+ }
10526
+ return Array.from(promotionIds);
10527
+ }
10528
+ function convertNumber(value) {
10529
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10530
+ }
10531
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
10532
+ const Shipping = () => {
10533
+ var _a;
10534
+ const { id } = reactRouterDom.useParams();
10535
+ const { order, isPending, isError, error } = useOrder(id, {
10536
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10537
+ });
10538
+ const {
10539
+ order: preview,
10540
+ isPending: isPreviewPending,
10541
+ isError: isPreviewError,
10542
+ error: previewError
10543
+ } = useOrderPreview(id);
10544
+ useInitiateOrderEdit({ preview });
10545
+ const { onCancel } = useCancelOrderEdit({ preview });
10546
+ if (isError) {
10547
+ throw error;
10548
+ }
10549
+ if (isPreviewError) {
10550
+ throw previewError;
10551
+ }
10552
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10553
+ const isReady = preview && !isPreviewPending && order && !isPending;
10554
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10555
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10556
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10557
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10558
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
10559
+ ] }) }) }),
10560
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10561
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10564
+ ] }) });
10549
10565
  };
10550
- const variantItemSchema = objectType({
10551
- quantity: numberType(),
10552
- unit_price: unionType([numberType(), stringType()])
10553
- });
10554
- const CustomItem = ({ item, preview, currencyCode }) => {
10555
- const [editing, setEditing] = React.useState(false);
10556
- const { quantity, unit_price, title } = item;
10557
- const form = reactHookForm.useForm({
10558
- defaultValues: {
10559
- title,
10560
- quantity,
10561
- unit_price
10566
+ const ShippingForm = ({ preview, order }) => {
10567
+ var _a;
10568
+ const { setIsOpen } = useStackedModal();
10569
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10570
+ const [data, setData] = React.useState(null);
10571
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10572
+ const { shipping_options } = useShippingOptions(
10573
+ {
10574
+ id: appliedShippingOptionIds,
10575
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10562
10576
  },
10563
- resolver: zod.zodResolver(customItemSchema)
10564
- });
10565
- React.useEffect(() => {
10566
- form.reset({
10567
- title,
10568
- quantity,
10569
- unit_price
10570
- });
10571
- }, [form, title, quantity, unit_price]);
10572
- const actionId = React.useMemo(() => {
10573
- var _a, _b;
10574
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10575
- }, [item]);
10576
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10577
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10578
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10579
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10580
- const onSubmit = form.handleSubmit(async (data) => {
10581
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10582
- setEditing(false);
10583
- return;
10584
- }
10585
- if (!actionId) {
10586
- await updateOriginalItem(
10587
- {
10588
- item_id: item.id,
10589
- quantity: data.quantity,
10590
- unit_price: convertNumber(data.unit_price)
10591
- },
10592
- {
10593
- onSuccess: () => {
10594
- setEditing(false);
10595
- },
10596
- onError: (e) => {
10597
- ui.toast.error(e.message);
10598
- }
10599
- }
10600
- );
10601
- return;
10577
+ {
10578
+ enabled: appliedShippingOptionIds.length > 0
10602
10579
  }
10603
- if (data.quantity === 0) {
10604
- await removeActionItem(actionId, {
10605
- onSuccess: () => {
10606
- setEditing(false);
10607
- },
10608
- onError: (e) => {
10609
- ui.toast.error(e.message);
10610
- }
10611
- });
10580
+ );
10581
+ const uniqueShippingProfiles = React.useMemo(() => {
10582
+ const profiles = /* @__PURE__ */ new Map();
10583
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
10584
+ profiles.set(profile.id, profile);
10585
+ });
10586
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10587
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
10588
+ });
10589
+ return Array.from(profiles.values());
10590
+ }, [order.items, shipping_options]);
10591
+ const { handleSuccess } = useRouteModal();
10592
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10593
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10594
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10595
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10596
+ const onSubmit = async () => {
10597
+ setIsSubmitting(true);
10598
+ let requestSucceeded = false;
10599
+ await requestOrderEdit(void 0, {
10600
+ onError: (e) => {
10601
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10602
+ },
10603
+ onSuccess: () => {
10604
+ requestSucceeded = true;
10605
+ }
10606
+ });
10607
+ if (!requestSucceeded) {
10608
+ setIsSubmitting(false);
10612
10609
  return;
10613
10610
  }
10614
- await updateActionItem(
10615
- {
10616
- action_id: actionId,
10617
- quantity: data.quantity,
10618
- unit_price: convertNumber(data.unit_price)
10611
+ await confirmOrderEdit(void 0, {
10612
+ onError: (e) => {
10613
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10619
10614
  },
10620
- {
10621
- onSuccess: () => {
10622
- setEditing(false);
10623
- },
10624
- onError: (e) => {
10625
- ui.toast.error(e.message);
10626
- }
10615
+ onSuccess: () => {
10616
+ handleSuccess();
10617
+ },
10618
+ onSettled: () => {
10619
+ setIsSubmitting(false);
10627
10620
  }
10628
- );
10629
- });
10630
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10632
- /* @__PURE__ */ jsxRuntime.jsx(
10633
- Thumbnail,
10634
- {
10635
- thumbnail: item.thumbnail,
10636
- alt: item.title ?? void 0
10621
+ });
10622
+ };
10623
+ const onKeydown = React.useCallback(
10624
+ (e) => {
10625
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10626
+ if (data || isSubmitting) {
10627
+ return;
10637
10628
  }
10638
- ),
10639
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10640
- Form$2.Field,
10641
- {
10642
- control: form.control,
10643
- name: "title",
10644
- render: ({ field }) => {
10645
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10646
- }
10647
- }
10648
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10649
- ] }),
10650
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10651
- Form$2.Field,
10652
- {
10653
- control: form.control,
10654
- name: "quantity",
10655
- render: ({ field }) => {
10656
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10657
- }
10658
- }
10659
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10660
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10661
- Form$2.Field,
10662
- {
10663
- control: form.control,
10664
- name: "unit_price",
10665
- render: ({ field: { onChange, ...field } }) => {
10666
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10667
- ui.CurrencyInput,
10668
- {
10669
- ...field,
10670
- symbol: getNativeSymbol(currencyCode),
10671
- code: currencyCode,
10672
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10673
- }
10674
- ) }) });
10675
- }
10676
- }
10677
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10678
- /* @__PURE__ */ jsxRuntime.jsx(
10679
- ui.IconButton,
10680
- {
10681
- type: "button",
10682
- size: "small",
10683
- onClick: editing ? onSubmit : () => {
10684
- setEditing(true);
10685
- },
10686
- disabled: isPending,
10687
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10629
+ onSubmit();
10688
10630
  }
10689
- )
10690
- ] }) }) });
10691
- };
10692
- const StackedModalTrigger$1 = ({
10693
- type,
10694
- setModalContent
10695
- }) => {
10696
- const { setIsOpen } = useStackedModal();
10697
- const onClick = React.useCallback(() => {
10698
- setModalContent(type);
10699
- setIsOpen(STACKED_MODAL_ID, true);
10700
- }, [setModalContent, setIsOpen, type]);
10701
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10702
- };
10703
- const VARIANT_PREFIX = "items";
10704
- const LIMIT = 50;
10705
- const ExistingItemsForm = ({ orderId, items }) => {
10706
- const { setIsOpen } = useStackedModal();
10707
- const [rowSelection, setRowSelection] = React.useState(
10708
- items.reduce((acc, item) => {
10709
- acc[item.variant_id] = true;
10710
- return acc;
10711
- }, {})
10712
- );
10713
- React.useEffect(() => {
10714
- setRowSelection(
10715
- items.reduce((acc, item) => {
10716
- if (item.variant_id) {
10717
- acc[item.variant_id] = true;
10718
- }
10719
- return acc;
10720
- }, {})
10721
- );
10722
- }, [items]);
10723
- const { q, order, offset } = useQueryParams(
10724
- ["q", "order", "offset"],
10725
- VARIANT_PREFIX
10726
- );
10727
- const { variants, count, isPending, isError, error } = useProductVariants(
10728
- {
10729
- q,
10730
- order,
10731
- offset: offset ? parseInt(offset) : void 0,
10732
- limit: LIMIT
10733
10631
  },
10734
- {
10735
- placeholderData: reactQuery.keepPreviousData
10736
- }
10632
+ [data, isSubmitting, onSubmit]
10737
10633
  );
10738
- const columns = useColumns();
10739
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10740
- const onSubmit = async () => {
10741
- const ids = Object.keys(rowSelection).filter(
10742
- (id) => !items.find((i) => i.variant_id === id)
10743
- );
10744
- await mutateAsync(
10745
- {
10746
- items: ids.map((id) => ({
10747
- variant_id: id,
10748
- quantity: 1
10749
- }))
10750
- },
10751
- {
10752
- onSuccess: () => {
10753
- setRowSelection({});
10754
- setIsOpen(STACKED_MODAL_ID, false);
10755
- },
10756
- onError: (e) => {
10757
- ui.toast.error(e.message);
10758
- }
10759
- }
10760
- );
10761
- };
10762
- if (isError) {
10763
- throw error;
10764
- }
10765
- return /* @__PURE__ */ jsxRuntime.jsxs(
10766
- StackedFocusModal.Content,
10767
- {
10768
- onOpenAutoFocus: (e) => {
10769
- e.preventDefault();
10770
- const searchInput = document.querySelector(
10771
- "[data-modal-id='modal-search-input']"
10772
- );
10773
- if (searchInput) {
10774
- searchInput.focus();
10775
- }
10776
- },
10777
- children: [
10778
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10779
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10780
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10634
+ React.useEffect(() => {
10635
+ document.addEventListener("keydown", onKeydown);
10636
+ return () => {
10637
+ document.removeEventListener("keydown", onKeydown);
10638
+ };
10639
+ }, [onKeydown]);
10640
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10641
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10642
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10643
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10645
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10646
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
10781
10647
  ] }),
10782
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10783
- DataTable,
10784
- {
10785
- data: variants,
10786
- columns,
10787
- isLoading: isPending,
10788
- getRowId: (row) => row.id,
10789
- rowCount: count,
10790
- prefix: VARIANT_PREFIX,
10791
- layout: "fill",
10792
- rowSelection: {
10793
- state: rowSelection,
10794
- onRowSelectionChange: setRowSelection,
10795
- enableRowSelection: (row) => {
10796
- return !items.find((i) => i.variant_id === row.original.id);
10797
- }
10798
- },
10799
- autoFocusSearch: true
10800
- }
10801
- ) }),
10802
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10803
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10804
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10805
- ] }) })
10806
- ]
10807
- }
10808
- );
10809
- };
10810
- const columnHelper = ui.createDataTableColumnHelper();
10811
- const useColumns = () => {
10812
- return React.useMemo(() => {
10813
- return [
10814
- columnHelper.select(),
10815
- columnHelper.accessor("product.title", {
10816
- header: "Product",
10817
- cell: ({ row }) => {
10818
- var _a, _b, _c;
10819
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10648
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10649
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
10650
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10820
10651
  /* @__PURE__ */ jsxRuntime.jsx(
10821
- Thumbnail,
10652
+ ui.Text,
10822
10653
  {
10823
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10824
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10825
- }
10826
- ),
10827
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10828
- ] });
10829
- },
10830
- enableSorting: true
10831
- }),
10832
- columnHelper.accessor("title", {
10833
- header: "Variant",
10834
- enableSorting: true
10835
- }),
10836
- columnHelper.accessor("sku", {
10837
- header: "SKU",
10838
- cell: ({ getValue }) => {
10839
- return getValue() ?? "-";
10840
- },
10841
- enableSorting: true
10842
- }),
10843
- columnHelper.accessor("updated_at", {
10844
- header: "Updated",
10845
- cell: ({ getValue }) => {
10846
- return /* @__PURE__ */ jsxRuntime.jsx(
10847
- ui.Tooltip,
10848
- {
10849
- content: getFullDate({ date: getValue(), includeTime: true }),
10850
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10851
- }
10852
- );
10853
- },
10854
- enableSorting: true,
10855
- sortAscLabel: "Oldest first",
10856
- sortDescLabel: "Newest first"
10857
- }),
10858
- columnHelper.accessor("created_at", {
10859
- header: "Created",
10860
- cell: ({ getValue }) => {
10861
- return /* @__PURE__ */ jsxRuntime.jsx(
10862
- ui.Tooltip,
10863
- {
10864
- content: getFullDate({ date: getValue(), includeTime: true }),
10865
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10866
- }
10867
- );
10868
- },
10869
- enableSorting: true,
10870
- sortAscLabel: "Oldest first",
10871
- sortDescLabel: "Newest first"
10872
- })
10873
- ];
10874
- }, []);
10875
- };
10876
- const CustomItemForm = ({ orderId, currencyCode }) => {
10877
- const { setIsOpen } = useStackedModal();
10878
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10879
- const form = reactHookForm.useForm({
10880
- defaultValues: {
10881
- title: "",
10882
- quantity: 1,
10883
- unit_price: ""
10884
- },
10885
- resolver: zod.zodResolver(customItemSchema)
10886
- });
10887
- const onSubmit = form.handleSubmit(async (data) => {
10888
- await addItems(
10889
- {
10890
- items: [
10891
- {
10892
- title: data.title,
10893
- quantity: data.quantity,
10894
- unit_price: convertNumber(data.unit_price)
10895
- }
10896
- ]
10897
- },
10898
- {
10899
- onSuccess: () => {
10900
- setIsOpen(STACKED_MODAL_ID, false);
10901
- },
10902
- onError: (e) => {
10903
- ui.toast.error(e.message);
10904
- }
10905
- }
10906
- );
10907
- });
10908
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10909
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10910
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10911
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10912
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10913
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10914
- ] }),
10915
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10916
- /* @__PURE__ */ jsxRuntime.jsx(
10917
- Form$2.Field,
10918
- {
10919
- control: form.control,
10920
- name: "title",
10921
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10922
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10923
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10924
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10925
- ] }),
10926
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10927
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10928
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10929
- ] })
10930
- ] }) })
10931
- }
10932
- ),
10933
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10934
- /* @__PURE__ */ jsxRuntime.jsx(
10935
- Form$2.Field,
10936
- {
10937
- control: form.control,
10938
- name: "unit_price",
10939
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10940
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10941
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10942
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10943
- ] }),
10944
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10946
- ui.CurrencyInput,
10947
- {
10948
- symbol: getNativeSymbol(currencyCode),
10949
- code: currencyCode,
10950
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10951
- ...field
10952
- }
10953
- ) }),
10954
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10955
- ] })
10956
- ] }) })
10957
- }
10958
- ),
10959
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10960
- /* @__PURE__ */ jsxRuntime.jsx(
10961
- Form$2.Field,
10962
- {
10963
- control: form.control,
10964
- name: "quantity",
10965
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10966
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10967
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10968
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10969
- ] }),
10970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10972
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10973
- ] })
10974
- ] }) })
10975
- }
10976
- )
10977
- ] }) }) }),
10978
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10979
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10980
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10981
- ] }) })
10982
- ] }) }) });
10983
- };
10984
- const customItemSchema = objectType({
10985
- title: stringType().min(1),
10986
- quantity: numberType(),
10987
- unit_price: unionType([numberType(), stringType()])
10988
- });
10989
- const PROMOTION_QUERY_KEY = "promotions";
10990
- const promotionsQueryKeys = {
10991
- list: (query2) => [
10992
- PROMOTION_QUERY_KEY,
10993
- query2 ? query2 : void 0
10994
- ],
10995
- detail: (id, query2) => [
10996
- PROMOTION_QUERY_KEY,
10997
- id,
10998
- query2 ? query2 : void 0
10999
- ]
11000
- };
11001
- const usePromotions = (query2, options) => {
11002
- const { data, ...rest } = reactQuery.useQuery({
11003
- queryKey: promotionsQueryKeys.list(query2),
11004
- queryFn: async () => sdk.admin.promotion.list(query2),
11005
- ...options
11006
- });
11007
- return { ...data, ...rest };
11008
- };
11009
- const Promotions = () => {
11010
- const { id } = reactRouterDom.useParams();
11011
- const {
11012
- order: preview,
11013
- isError: isPreviewError,
11014
- error: previewError
11015
- } = useOrderPreview(id, void 0);
11016
- useInitiateOrderEdit({ preview });
11017
- const { onCancel } = useCancelOrderEdit({ preview });
11018
- if (isPreviewError) {
11019
- throw previewError;
11020
- }
11021
- const isReady = !!preview;
11022
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11023
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11024
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11025
- ] });
11026
- };
11027
- const PromotionForm = ({ preview }) => {
11028
- const { items, shipping_methods } = preview;
11029
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11030
- const [comboboxValue, setComboboxValue] = React.useState("");
11031
- const { handleSuccess } = useRouteModal();
11032
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11033
- const promoIds = getPromotionIds(items, shipping_methods);
11034
- const { promotions, isPending, isError, error } = usePromotions(
11035
- {
11036
- id: promoIds
11037
- },
11038
- {
11039
- enabled: !!promoIds.length
11040
- }
11041
- );
11042
- const comboboxData = useComboboxData({
11043
- queryKey: ["promotions", "combobox", promoIds],
11044
- queryFn: async (params) => {
11045
- return await sdk.admin.promotion.list({
11046
- ...params,
11047
- id: {
11048
- $nin: promoIds
11049
- }
11050
- });
11051
- },
11052
- getOptions: (data) => {
11053
- return data.promotions.map((promotion) => ({
11054
- label: promotion.code,
11055
- value: promotion.code
11056
- }));
11057
- }
11058
- });
11059
- const add = async (value) => {
11060
- if (!value) {
11061
- return;
11062
- }
11063
- addPromotions(
11064
- {
11065
- promo_codes: [value]
11066
- },
11067
- {
11068
- onError: (e) => {
11069
- ui.toast.error(e.message);
11070
- comboboxData.onSearchValueChange("");
11071
- setComboboxValue("");
11072
- },
11073
- onSuccess: () => {
11074
- comboboxData.onSearchValueChange("");
11075
- setComboboxValue("");
11076
- }
11077
- }
11078
- );
11079
- };
11080
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11081
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11082
- const onSubmit = async () => {
11083
- setIsSubmitting(true);
11084
- let requestSucceeded = false;
11085
- await requestOrderEdit(void 0, {
11086
- onError: (e) => {
11087
- ui.toast.error(e.message);
11088
- },
11089
- onSuccess: () => {
11090
- requestSucceeded = true;
11091
- }
11092
- });
11093
- if (!requestSucceeded) {
11094
- setIsSubmitting(false);
11095
- return;
11096
- }
11097
- await confirmOrderEdit(void 0, {
11098
- onError: (e) => {
11099
- ui.toast.error(e.message);
11100
- },
11101
- onSuccess: () => {
11102
- handleSuccess();
11103
- },
11104
- onSettled: () => {
11105
- setIsSubmitting(false);
11106
- }
11107
- });
11108
- };
11109
- if (isError) {
11110
- throw error;
11111
- }
11112
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11113
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11114
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11115
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11116
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11118
- ] }),
11119
- /* @__PURE__ */ jsxRuntime.jsx(
11120
- Combobox,
11121
- {
11122
- id: "promotion-combobox",
11123
- "aria-describedby": "promotion-combobox-hint",
11124
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11125
- fetchNextPage: comboboxData.fetchNextPage,
11126
- options: comboboxData.options,
11127
- onSearchValueChange: comboboxData.onSearchValueChange,
11128
- searchValue: comboboxData.searchValue,
11129
- disabled: comboboxData.disabled || isAddingPromotions,
11130
- onChange: add,
11131
- value: comboboxValue
11132
- }
11133
- )
11134
- ] }),
11135
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11136
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11137
- PromotionItem,
11138
- {
11139
- promotion,
11140
- orderId: preview.id,
11141
- isLoading: isPending
11142
- },
11143
- promotion.id
11144
- )) })
11145
- ] }) }),
11146
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11147
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11148
- /* @__PURE__ */ jsxRuntime.jsx(
11149
- ui.Button,
11150
- {
11151
- size: "small",
11152
- type: "submit",
11153
- isLoading: isSubmitting || isAddingPromotions,
11154
- children: "Save"
11155
- }
11156
- )
11157
- ] }) })
11158
- ] });
11159
- };
11160
- const PromotionItem = ({
11161
- promotion,
11162
- orderId,
11163
- isLoading
11164
- }) => {
11165
- var _a;
11166
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11167
- const onRemove = async () => {
11168
- removePromotions(
11169
- {
11170
- promo_codes: [promotion.code]
11171
- },
11172
- {
11173
- onError: (e) => {
11174
- ui.toast.error(e.message);
11175
- }
11176
- }
11177
- );
11178
- };
11179
- const displayValue = getDisplayValue(promotion);
11180
- return /* @__PURE__ */ jsxRuntime.jsxs(
11181
- "div",
11182
- {
11183
- className: ui.clx(
11184
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11185
- {
11186
- "animate-pulse": isLoading
11187
- }
11188
- ),
11189
- children: [
11190
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11191
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11192
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11193
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11194
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11195
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11196
- ] }),
11197
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11198
- ] })
11199
- ] }),
11200
- /* @__PURE__ */ jsxRuntime.jsx(
11201
- ui.IconButton,
11202
- {
11203
- size: "small",
11204
- type: "button",
11205
- variant: "transparent",
11206
- onClick: onRemove,
11207
- isLoading: isPending || isLoading,
11208
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11209
- }
11210
- )
11211
- ]
11212
- },
11213
- promotion.id
11214
- );
11215
- };
11216
- function getDisplayValue(promotion) {
11217
- var _a, _b, _c, _d;
11218
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11219
- if (!value) {
11220
- return null;
11221
- }
11222
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11223
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11224
- if (!currency) {
11225
- return null;
11226
- }
11227
- return getLocaleAmount(value, currency);
11228
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11229
- return formatPercentage(value);
11230
- }
11231
- return null;
11232
- }
11233
- const formatter = new Intl.NumberFormat([], {
11234
- style: "percent",
11235
- minimumFractionDigits: 2
11236
- });
11237
- const formatPercentage = (value, isPercentageValue = false) => {
11238
- let val = value || 0;
11239
- if (!isPercentageValue) {
11240
- val = val / 100;
11241
- }
11242
- return formatter.format(val);
11243
- };
11244
- function getPromotionIds(items, shippingMethods) {
11245
- const promotionIds = /* @__PURE__ */ new Set();
11246
- for (const item of items) {
11247
- if (item.adjustments) {
11248
- for (const adjustment of item.adjustments) {
11249
- if (adjustment.promotion_id) {
11250
- promotionIds.add(adjustment.promotion_id);
11251
- }
11252
- }
11253
- }
11254
- }
11255
- for (const shippingMethod of shippingMethods) {
11256
- if (shippingMethod.adjustments) {
11257
- for (const adjustment of shippingMethod.adjustments) {
11258
- if (adjustment.promotion_id) {
11259
- promotionIds.add(adjustment.promotion_id);
11260
- }
11261
- }
11262
- }
11263
- }
11264
- return Array.from(promotionIds);
11265
- }
11266
- const SalesChannel = () => {
11267
- const { id } = reactRouterDom.useParams();
11268
- const { draft_order, isPending, isError, error } = useDraftOrder(
11269
- id,
11270
- {
11271
- fields: "+sales_channel_id"
11272
- },
11273
- {
11274
- enabled: !!id
11275
- }
11276
- );
11277
- if (isError) {
11278
- throw error;
11279
- }
11280
- const ISrEADY = !!draft_order && !isPending;
11281
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11285
- ] }),
11286
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
- ] });
11288
- };
11289
- const SalesChannelForm = ({ order }) => {
11290
- const form = reactHookForm.useForm({
11291
- defaultValues: {
11292
- sales_channel_id: order.sales_channel_id || ""
11293
- },
11294
- resolver: zod.zodResolver(schema$3)
11295
- });
11296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
- const { handleSuccess } = useRouteModal();
11298
- const onSubmit = form.handleSubmit(async (data) => {
11299
- await mutateAsync(
11300
- {
11301
- sales_channel_id: data.sales_channel_id
11302
- },
11303
- {
11304
- onSuccess: () => {
11305
- ui.toast.success("Sales channel updated");
11306
- handleSuccess();
11307
- },
11308
- onError: (error) => {
11309
- ui.toast.error(error.message);
11310
- }
11311
- }
11312
- );
11313
- });
11314
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
- KeyboundForm,
11316
- {
11317
- className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
- children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
- ] }) })
11325
- ]
11326
- }
11327
- ) });
11328
- };
11329
- const SalesChannelField = ({ control, order }) => {
11330
- const salesChannels = useComboboxData({
11331
- queryFn: async (params) => {
11332
- return await sdk.admin.salesChannel.list(params);
11333
- },
11334
- queryKey: ["sales-channels"],
11335
- getOptions: (data) => {
11336
- return data.sales_channels.map((salesChannel) => ({
11337
- label: salesChannel.name,
11338
- value: salesChannel.id
11339
- }));
11340
- },
11341
- defaultValue: order.sales_channel_id || void 0
11342
- });
11343
- return /* @__PURE__ */ jsxRuntime.jsx(
11344
- Form$2.Field,
11345
- {
11346
- control,
11347
- name: "sales_channel_id",
11348
- render: ({ field }) => {
11349
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
- Combobox,
11353
- {
11354
- options: salesChannels.options,
11355
- fetchNextPage: salesChannels.fetchNextPage,
11356
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
- searchValue: salesChannels.searchValue,
11358
- onSearchValueChange: salesChannels.onSearchValueChange,
11359
- placeholder: "Select sales channel",
11360
- ...field
11361
- }
11362
- ) }),
11363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
- ] });
11365
- }
11366
- }
11367
- );
11368
- };
11369
- const schema$3 = objectType({
11370
- sales_channel_id: stringType().min(1)
11371
- });
11372
- const ShippingAddress = () => {
11373
- const { id } = reactRouterDom.useParams();
11374
- const { order, isPending, isError, error } = useOrder(id, {
11375
- fields: "+shipping_address"
11376
- });
11377
- if (isError) {
11378
- throw error;
11379
- }
11380
- const isReady = !isPending && !!order;
11381
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
- ] }),
11386
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11387
- ] });
11388
- };
11389
- const ShippingAddressForm = ({ order }) => {
11390
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
- const form = reactHookForm.useForm({
11392
- defaultValues: {
11393
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11403
- },
11404
- resolver: zod.zodResolver(schema$2)
11405
- });
11406
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11407
- const { handleSuccess } = useRouteModal();
11408
- const onSubmit = form.handleSubmit(async (data) => {
11409
- await mutateAsync(
11410
- {
11411
- shipping_address: {
11412
- first_name: data.first_name,
11413
- last_name: data.last_name,
11414
- company: data.company,
11415
- address_1: data.address_1,
11416
- address_2: data.address_2,
11417
- city: data.city,
11418
- province: data.province,
11419
- country_code: data.country_code,
11420
- postal_code: data.postal_code,
11421
- phone: data.phone
11422
- }
11423
- },
11424
- {
11425
- onSuccess: () => {
11426
- handleSuccess();
11427
- },
11428
- onError: (error) => {
11429
- ui.toast.error(error.message);
11430
- }
11431
- }
11432
- );
11433
- });
11434
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11435
- KeyboundForm,
11436
- {
11437
- className: "flex flex-1 flex-col overflow-hidden",
11438
- onSubmit,
11439
- children: [
11440
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11441
- /* @__PURE__ */ jsxRuntime.jsx(
11442
- Form$2.Field,
11443
- {
11444
- control: form.control,
11445
- name: "country_code",
11446
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
- ] })
11451
- }
11452
- ),
11453
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11454
- /* @__PURE__ */ jsxRuntime.jsx(
11455
- Form$2.Field,
11456
- {
11457
- control: form.control,
11458
- name: "first_name",
11459
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
- ] })
11464
- }
11465
- ),
11466
- /* @__PURE__ */ jsxRuntime.jsx(
11467
- Form$2.Field,
11468
- {
11469
- control: form.control,
11470
- name: "last_name",
11471
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
- ] })
11476
- }
11477
- )
11478
- ] }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(
11480
- Form$2.Field,
11481
- {
11482
- control: form.control,
11483
- name: "company",
11484
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
- ] })
11489
- }
11490
- ),
11491
- /* @__PURE__ */ jsxRuntime.jsx(
11492
- Form$2.Field,
11493
- {
11494
- control: form.control,
11495
- name: "address_1",
11496
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
- ] })
11501
- }
11502
- ),
11503
- /* @__PURE__ */ jsxRuntime.jsx(
11504
- Form$2.Field,
11505
- {
11506
- control: form.control,
11507
- name: "address_2",
11508
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
- ] })
11513
- }
11514
- ),
11515
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
- /* @__PURE__ */ jsxRuntime.jsx(
11517
- Form$2.Field,
11518
- {
11519
- control: form.control,
11520
- name: "postal_code",
11521
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
- ] })
11526
- }
11527
- ),
11528
- /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control: form.control,
11532
- name: "city",
11533
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
- ] })
11538
- }
11539
- )
11540
- ] }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(
11542
- Form$2.Field,
11543
- {
11544
- control: form.control,
11545
- name: "province",
11546
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
- ] })
11551
- }
11552
- ),
11553
- /* @__PURE__ */ jsxRuntime.jsx(
11554
- Form$2.Field,
11555
- {
11556
- control: form.control,
11557
- name: "phone",
11558
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
- ] })
11563
- }
11564
- )
11565
- ] }) }),
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
- ] }) })
11570
- ]
11571
- }
11572
- ) });
11573
- };
11574
- const schema$2 = addressSchema;
11575
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11576
- const Shipping = () => {
11577
- var _a;
11578
- const { id } = reactRouterDom.useParams();
11579
- const { order, isPending, isError, error } = useOrder(id, {
11580
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11581
- });
11582
- const {
11583
- order: preview,
11584
- isPending: isPreviewPending,
11585
- isError: isPreviewError,
11586
- error: previewError
11587
- } = useOrderPreview(id);
11588
- useInitiateOrderEdit({ preview });
11589
- const { onCancel } = useCancelOrderEdit({ preview });
11590
- if (isError) {
11591
- throw error;
11592
- }
11593
- if (isPreviewError) {
11594
- throw previewError;
11595
- }
11596
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11597
- const isReady = preview && !isPreviewPending && order && !isPending;
11598
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11599
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11600
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11601
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11602
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11603
- ] }) }) }),
11604
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11605
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11606
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11607
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11608
- ] }) });
11609
- };
11610
- const ShippingForm = ({ preview, order }) => {
11611
- var _a;
11612
- const { setIsOpen } = useStackedModal();
11613
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11614
- const [data, setData] = React.useState(null);
11615
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11616
- const { shipping_options } = useShippingOptions(
11617
- {
11618
- id: appliedShippingOptionIds,
11619
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11620
- },
11621
- {
11622
- enabled: appliedShippingOptionIds.length > 0
11623
- }
11624
- );
11625
- const uniqueShippingProfiles = React.useMemo(() => {
11626
- const profiles = /* @__PURE__ */ new Map();
11627
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11628
- profiles.set(profile.id, profile);
11629
- });
11630
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11631
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11632
- });
11633
- return Array.from(profiles.values());
11634
- }, [order.items, shipping_options]);
11635
- const { handleSuccess } = useRouteModal();
11636
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11637
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11638
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11639
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11640
- const onSubmit = async () => {
11641
- setIsSubmitting(true);
11642
- let requestSucceeded = false;
11643
- await requestOrderEdit(void 0, {
11644
- onError: (e) => {
11645
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11646
- },
11647
- onSuccess: () => {
11648
- requestSucceeded = true;
11649
- }
11650
- });
11651
- if (!requestSucceeded) {
11652
- setIsSubmitting(false);
11653
- return;
11654
- }
11655
- await confirmOrderEdit(void 0, {
11656
- onError: (e) => {
11657
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11658
- },
11659
- onSuccess: () => {
11660
- handleSuccess();
11661
- },
11662
- onSettled: () => {
11663
- setIsSubmitting(false);
11664
- }
11665
- });
11666
- };
11667
- const onKeydown = React.useCallback(
11668
- (e) => {
11669
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11670
- if (data || isSubmitting) {
11671
- return;
11672
- }
11673
- onSubmit();
11674
- }
11675
- },
11676
- [data, isSubmitting, onSubmit]
11677
- );
11678
- React.useEffect(() => {
11679
- document.addEventListener("keydown", onKeydown);
11680
- return () => {
11681
- document.removeEventListener("keydown", onKeydown);
11682
- };
11683
- }, [onKeydown]);
11684
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11685
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11686
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11687
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11688
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11689
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11690
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11691
- ] }),
11692
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11693
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11694
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11695
- /* @__PURE__ */ jsxRuntime.jsx(
11696
- ui.Text,
11697
- {
11698
- size: "xsmall",
11699
- weight: "plus",
11700
- className: "text-ui-fg-muted",
11701
- children: "Shipping profile"
10654
+ size: "xsmall",
10655
+ weight: "plus",
10656
+ className: "text-ui-fg-muted",
10657
+ children: "Shipping profile"
11702
10658
  }
11703
10659
  ),
11704
10660
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -11879,7 +10835,7 @@ const ShippingForm = ({ preview, order }) => {
11879
10835
  ]
11880
10836
  }
11881
10837
  ) : /* @__PURE__ */ jsxRuntime.jsx(
11882
- StackedModalTrigger,
10838
+ StackedModalTrigger$1,
11883
10839
  {
11884
10840
  shippingProfileId: profile.id,
11885
10841
  shippingOption,
@@ -11990,7 +10946,7 @@ const ShippingForm = ({ preview, order }) => {
11990
10946
  ] }) })
11991
10947
  ] });
11992
10948
  };
11993
- const StackedModalTrigger = ({
10949
+ const StackedModalTrigger$1 = ({
11994
10950
  shippingProfileId,
11995
10951
  shippingOption,
11996
10952
  shippingMethod,
@@ -12326,59 +11282,262 @@ const ShippingOptionField = ({
12326
11282
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12327
11283
  ] }),
12328
11284
  /* @__PURE__ */ jsxRuntime.jsx(
12329
- ConditionalTooltip,
11285
+ ConditionalTooltip,
11286
+ {
11287
+ content: tooltipContent,
11288
+ showTooltip: !locationId || !shippingProfileId,
11289
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11290
+ Combobox,
11291
+ {
11292
+ options: shippingOptions.options,
11293
+ fetchNextPage: shippingOptions.fetchNextPage,
11294
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
11295
+ searchValue: shippingOptions.searchValue,
11296
+ onSearchValueChange: shippingOptions.onSearchValueChange,
11297
+ placeholder: "Select shipping option",
11298
+ ...field,
11299
+ disabled: !locationId || !shippingProfileId
11300
+ }
11301
+ ) }) })
11302
+ }
11303
+ )
11304
+ ] }) });
11305
+ }
11306
+ }
11307
+ );
11308
+ };
11309
+ const CustomAmountField = ({
11310
+ control,
11311
+ currencyCode
11312
+ }) => {
11313
+ return /* @__PURE__ */ jsxRuntime.jsx(
11314
+ Form$2.Field,
11315
+ {
11316
+ control,
11317
+ name: "custom_amount",
11318
+ render: ({ field: { onChange, ...field } }) => {
11319
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11320
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11321
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11322
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11323
+ ] }),
11324
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11325
+ ui.CurrencyInput,
11326
+ {
11327
+ ...field,
11328
+ onValueChange: (value) => onChange(value),
11329
+ symbol: getNativeSymbol(currencyCode),
11330
+ code: currencyCode
11331
+ }
11332
+ ) })
11333
+ ] });
11334
+ }
11335
+ }
11336
+ );
11337
+ };
11338
+ const ShippingAddress = () => {
11339
+ const { id } = reactRouterDom.useParams();
11340
+ const { order, isPending, isError, error } = useOrder(id, {
11341
+ fields: "+shipping_address"
11342
+ });
11343
+ if (isError) {
11344
+ throw error;
11345
+ }
11346
+ const isReady = !isPending && !!order;
11347
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11348
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11349
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11351
+ ] }),
11352
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11353
+ ] });
11354
+ };
11355
+ const ShippingAddressForm = ({ order }) => {
11356
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11357
+ const form = reactHookForm.useForm({
11358
+ defaultValues: {
11359
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11360
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11361
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11362
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11363
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11364
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11365
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11366
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11367
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11368
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11369
+ },
11370
+ resolver: zod.zodResolver(schema$2)
11371
+ });
11372
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11373
+ const { handleSuccess } = useRouteModal();
11374
+ const onSubmit = form.handleSubmit(async (data) => {
11375
+ await mutateAsync(
11376
+ {
11377
+ shipping_address: {
11378
+ first_name: data.first_name,
11379
+ last_name: data.last_name,
11380
+ company: data.company,
11381
+ address_1: data.address_1,
11382
+ address_2: data.address_2,
11383
+ city: data.city,
11384
+ province: data.province,
11385
+ country_code: data.country_code,
11386
+ postal_code: data.postal_code,
11387
+ phone: data.phone
11388
+ }
11389
+ },
11390
+ {
11391
+ onSuccess: () => {
11392
+ handleSuccess();
11393
+ },
11394
+ onError: (error) => {
11395
+ ui.toast.error(error.message);
11396
+ }
11397
+ }
11398
+ );
11399
+ });
11400
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11401
+ KeyboundForm,
11402
+ {
11403
+ className: "flex flex-1 flex-col overflow-hidden",
11404
+ onSubmit,
11405
+ children: [
11406
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11407
+ /* @__PURE__ */ jsxRuntime.jsx(
11408
+ Form$2.Field,
11409
+ {
11410
+ control: form.control,
11411
+ name: "country_code",
11412
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11413
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11415
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11416
+ ] })
11417
+ }
11418
+ ),
11419
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11420
+ /* @__PURE__ */ jsxRuntime.jsx(
11421
+ Form$2.Field,
11422
+ {
11423
+ control: form.control,
11424
+ name: "first_name",
11425
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11428
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11429
+ ] })
11430
+ }
11431
+ ),
11432
+ /* @__PURE__ */ jsxRuntime.jsx(
11433
+ Form$2.Field,
11434
+ {
11435
+ control: form.control,
11436
+ name: "last_name",
11437
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11441
+ ] })
11442
+ }
11443
+ )
11444
+ ] }),
11445
+ /* @__PURE__ */ jsxRuntime.jsx(
11446
+ Form$2.Field,
11447
+ {
11448
+ control: form.control,
11449
+ name: "company",
11450
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11451
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11452
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11453
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11454
+ ] })
11455
+ }
11456
+ ),
11457
+ /* @__PURE__ */ jsxRuntime.jsx(
11458
+ Form$2.Field,
11459
+ {
11460
+ control: form.control,
11461
+ name: "address_1",
11462
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11466
+ ] })
11467
+ }
11468
+ ),
11469
+ /* @__PURE__ */ jsxRuntime.jsx(
11470
+ Form$2.Field,
11471
+ {
11472
+ control: form.control,
11473
+ name: "address_2",
11474
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11475
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11476
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11478
+ ] })
11479
+ }
11480
+ ),
11481
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11482
+ /* @__PURE__ */ jsxRuntime.jsx(
11483
+ Form$2.Field,
11484
+ {
11485
+ control: form.control,
11486
+ name: "postal_code",
11487
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11490
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11491
+ ] })
11492
+ }
11493
+ ),
11494
+ /* @__PURE__ */ jsxRuntime.jsx(
11495
+ Form$2.Field,
11496
+ {
11497
+ control: form.control,
11498
+ name: "city",
11499
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11500
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11501
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11502
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11503
+ ] })
11504
+ }
11505
+ )
11506
+ ] }),
11507
+ /* @__PURE__ */ jsxRuntime.jsx(
11508
+ Form$2.Field,
12330
11509
  {
12331
- content: tooltipContent,
12332
- showTooltip: !locationId || !shippingProfileId,
12333
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12334
- Combobox,
12335
- {
12336
- options: shippingOptions.options,
12337
- fetchNextPage: shippingOptions.fetchNextPage,
12338
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12339
- searchValue: shippingOptions.searchValue,
12340
- onSearchValueChange: shippingOptions.onSearchValueChange,
12341
- placeholder: "Select shipping option",
12342
- ...field,
12343
- disabled: !locationId || !shippingProfileId
12344
- }
12345
- ) }) })
11510
+ control: form.control,
11511
+ name: "province",
11512
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11513
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11514
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11515
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11516
+ ] })
12346
11517
  }
12347
- )
12348
- ] }) });
12349
- }
12350
- }
12351
- );
12352
- };
12353
- const CustomAmountField = ({
12354
- control,
12355
- currencyCode
12356
- }) => {
12357
- return /* @__PURE__ */ jsxRuntime.jsx(
12358
- Form$2.Field,
12359
- {
12360
- control,
12361
- name: "custom_amount",
12362
- render: ({ field: { onChange, ...field } }) => {
12363
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12364
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12367
- ] }),
12368
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12369
- ui.CurrencyInput,
11518
+ ),
11519
+ /* @__PURE__ */ jsxRuntime.jsx(
11520
+ Form$2.Field,
12370
11521
  {
12371
- ...field,
12372
- onValueChange: (value) => onChange(value),
12373
- symbol: getNativeSymbol(currencyCode),
12374
- code: currencyCode
11522
+ control: form.control,
11523
+ name: "phone",
11524
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11525
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11526
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11527
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11528
+ ] })
12375
11529
  }
12376
- ) })
12377
- ] });
12378
- }
11530
+ )
11531
+ ] }) }),
11532
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11533
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11534
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11535
+ ] }) })
11536
+ ]
12379
11537
  }
12380
- );
11538
+ ) });
12381
11539
  };
11540
+ const schema$2 = addressSchema;
12382
11541
  const TransferOwnership = () => {
12383
11542
  const { id } = reactRouterDom.useParams();
12384
11543
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12728,323 +11887,1164 @@ const Illustration = () => {
12728
11887
  /* @__PURE__ */ jsxRuntime.jsx(
12729
11888
  "path",
12730
11889
  {
12731
- 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",
12732
- fill: "#52525B"
12733
- }
11890
+ 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",
11891
+ fill: "#52525B"
11892
+ }
11893
+ ),
11894
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11895
+ "path",
11896
+ {
11897
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11898
+ stroke: "#A1A1AA",
11899
+ strokeWidth: "1.5",
11900
+ strokeLinecap: "round",
11901
+ strokeLinejoin: "round"
11902
+ }
11903
+ ) }),
11904
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11905
+ "path",
11906
+ {
11907
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11908
+ stroke: "#A1A1AA",
11909
+ strokeWidth: "1.5",
11910
+ strokeLinecap: "round",
11911
+ strokeLinejoin: "round"
11912
+ }
11913
+ ) }),
11914
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11915
+ "path",
11916
+ {
11917
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11918
+ stroke: "#A1A1AA",
11919
+ strokeWidth: "1.5",
11920
+ strokeLinecap: "round",
11921
+ strokeLinejoin: "round"
11922
+ }
11923
+ ) }),
11924
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11925
+ "path",
11926
+ {
11927
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11928
+ stroke: "#A1A1AA",
11929
+ strokeWidth: "1.5",
11930
+ strokeLinecap: "round",
11931
+ strokeLinejoin: "round"
11932
+ }
11933
+ ) }),
11934
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11935
+ "path",
11936
+ {
11937
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11938
+ stroke: "#A1A1AA",
11939
+ strokeWidth: "1.5",
11940
+ strokeLinecap: "round",
11941
+ strokeLinejoin: "round"
11942
+ }
11943
+ ) }),
11944
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11945
+ "path",
11946
+ {
11947
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11948
+ stroke: "#A1A1AA",
11949
+ strokeWidth: "1.5",
11950
+ strokeLinecap: "round",
11951
+ strokeLinejoin: "round"
11952
+ }
11953
+ ) }),
11954
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11955
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11956
+ "rect",
11957
+ {
11958
+ width: "12",
11959
+ height: "12",
11960
+ fill: "white",
11961
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11962
+ }
11963
+ ) }),
11964
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11965
+ "rect",
11966
+ {
11967
+ width: "12",
11968
+ height: "12",
11969
+ fill: "white",
11970
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11971
+ }
11972
+ ) }),
11973
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11974
+ "rect",
11975
+ {
11976
+ width: "12",
11977
+ height: "12",
11978
+ fill: "white",
11979
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11980
+ }
11981
+ ) }),
11982
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11983
+ "rect",
11984
+ {
11985
+ width: "12",
11986
+ height: "12",
11987
+ fill: "white",
11988
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11989
+ }
11990
+ ) }),
11991
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11992
+ "rect",
11993
+ {
11994
+ width: "12",
11995
+ height: "12",
11996
+ fill: "white",
11997
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11998
+ }
11999
+ ) }),
12000
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12001
+ "rect",
12002
+ {
12003
+ width: "12",
12004
+ height: "12",
12005
+ fill: "white",
12006
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12007
+ }
12008
+ ) })
12009
+ ] })
12010
+ ]
12011
+ }
12012
+ );
12013
+ };
12014
+ const schema$1 = objectType({
12015
+ customer_id: stringType().min(1)
12016
+ });
12017
+ const SalesChannel = () => {
12018
+ const { id } = reactRouterDom.useParams();
12019
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12020
+ id,
12021
+ {
12022
+ fields: "+sales_channel_id"
12023
+ },
12024
+ {
12025
+ enabled: !!id
12026
+ }
12027
+ );
12028
+ if (isError) {
12029
+ throw error;
12030
+ }
12031
+ const ISrEADY = !!draft_order && !isPending;
12032
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12033
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12034
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12035
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12036
+ ] }),
12037
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12038
+ ] });
12039
+ };
12040
+ const SalesChannelForm = ({ order }) => {
12041
+ const form = reactHookForm.useForm({
12042
+ defaultValues: {
12043
+ sales_channel_id: order.sales_channel_id || ""
12044
+ },
12045
+ resolver: zod.zodResolver(schema)
12046
+ });
12047
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12048
+ const { handleSuccess } = useRouteModal();
12049
+ const onSubmit = form.handleSubmit(async (data) => {
12050
+ await mutateAsync(
12051
+ {
12052
+ sales_channel_id: data.sales_channel_id
12053
+ },
12054
+ {
12055
+ onSuccess: () => {
12056
+ ui.toast.success("Sales channel updated");
12057
+ handleSuccess();
12058
+ },
12059
+ onError: (error) => {
12060
+ ui.toast.error(error.message);
12061
+ }
12062
+ }
12063
+ );
12064
+ });
12065
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12066
+ KeyboundForm,
12067
+ {
12068
+ className: "flex flex-1 flex-col overflow-hidden",
12069
+ onSubmit,
12070
+ children: [
12071
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12072
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12075
+ ] }) })
12076
+ ]
12077
+ }
12078
+ ) });
12079
+ };
12080
+ const SalesChannelField = ({ control, order }) => {
12081
+ const salesChannels = useComboboxData({
12082
+ queryFn: async (params) => {
12083
+ return await sdk.admin.salesChannel.list(params);
12084
+ },
12085
+ queryKey: ["sales-channels"],
12086
+ getOptions: (data) => {
12087
+ return data.sales_channels.map((salesChannel) => ({
12088
+ label: salesChannel.name,
12089
+ value: salesChannel.id
12090
+ }));
12091
+ },
12092
+ defaultValue: order.sales_channel_id || void 0
12093
+ });
12094
+ return /* @__PURE__ */ jsxRuntime.jsx(
12095
+ Form$2.Field,
12096
+ {
12097
+ control,
12098
+ name: "sales_channel_id",
12099
+ render: ({ field }) => {
12100
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12101
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12102
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12103
+ Combobox,
12104
+ {
12105
+ options: salesChannels.options,
12106
+ fetchNextPage: salesChannels.fetchNextPage,
12107
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12108
+ searchValue: salesChannels.searchValue,
12109
+ onSearchValueChange: salesChannels.onSearchValueChange,
12110
+ placeholder: "Select sales channel",
12111
+ ...field
12112
+ }
12113
+ ) }),
12114
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12115
+ ] });
12116
+ }
12117
+ }
12118
+ );
12119
+ };
12120
+ const schema = objectType({
12121
+ sales_channel_id: stringType().min(1)
12122
+ });
12123
+ const NumberInput = React.forwardRef(
12124
+ ({
12125
+ value,
12126
+ onChange,
12127
+ size = "base",
12128
+ min = 0,
12129
+ max = 100,
12130
+ step = 1,
12131
+ className,
12132
+ disabled,
12133
+ ...props
12134
+ }, ref) => {
12135
+ const handleChange = (event) => {
12136
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12137
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12138
+ onChange(newValue);
12139
+ }
12140
+ };
12141
+ const handleIncrement = () => {
12142
+ const newValue = value + step;
12143
+ if (max === void 0 || newValue <= max) {
12144
+ onChange(newValue);
12145
+ }
12146
+ };
12147
+ const handleDecrement = () => {
12148
+ const newValue = value - step;
12149
+ if (min === void 0 || newValue >= min) {
12150
+ onChange(newValue);
12151
+ }
12152
+ };
12153
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12154
+ "div",
12155
+ {
12156
+ className: ui.clx(
12157
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12158
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12159
+ {
12160
+ "h-7": size === "small",
12161
+ "h-8": size === "base"
12162
+ },
12163
+ className
12734
12164
  ),
12735
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12736
- "path",
12737
- {
12738
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12739
- stroke: "#A1A1AA",
12740
- strokeWidth: "1.5",
12741
- strokeLinecap: "round",
12742
- strokeLinejoin: "round"
12743
- }
12744
- ) }),
12745
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12746
- "path",
12747
- {
12748
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12749
- stroke: "#A1A1AA",
12750
- strokeWidth: "1.5",
12751
- strokeLinecap: "round",
12752
- strokeLinejoin: "round"
12753
- }
12754
- ) }),
12755
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12756
- "path",
12757
- {
12758
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12759
- stroke: "#A1A1AA",
12760
- strokeWidth: "1.5",
12761
- strokeLinecap: "round",
12762
- strokeLinejoin: "round"
12763
- }
12764
- ) }),
12765
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12766
- "path",
12767
- {
12768
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12769
- stroke: "#A1A1AA",
12770
- strokeWidth: "1.5",
12771
- strokeLinecap: "round",
12772
- strokeLinejoin: "round"
12773
- }
12774
- ) }),
12775
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12776
- "path",
12777
- {
12778
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12779
- stroke: "#A1A1AA",
12780
- strokeWidth: "1.5",
12781
- strokeLinecap: "round",
12782
- strokeLinejoin: "round"
12165
+ children: [
12166
+ /* @__PURE__ */ jsxRuntime.jsx(
12167
+ "input",
12168
+ {
12169
+ ref,
12170
+ type: "number",
12171
+ value,
12172
+ onChange: handleChange,
12173
+ min,
12174
+ max,
12175
+ step,
12176
+ className: ui.clx(
12177
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12178
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12179
+ "placeholder:text-ui-fg-muted"
12180
+ ),
12181
+ ...props
12182
+ }
12183
+ ),
12184
+ /* @__PURE__ */ jsxRuntime.jsxs(
12185
+ "button",
12186
+ {
12187
+ className: ui.clx(
12188
+ "flex items-center justify-center outline-none transition-fg",
12189
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12190
+ "focus:bg-ui-bg-field-component-hover",
12191
+ "hover:bg-ui-bg-field-component-hover",
12192
+ {
12193
+ "size-7": size === "small",
12194
+ "size-8": size === "base"
12195
+ }
12196
+ ),
12197
+ type: "button",
12198
+ onClick: handleDecrement,
12199
+ disabled: min !== void 0 && value <= min || disabled,
12200
+ children: [
12201
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
12202
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12203
+ ]
12204
+ }
12205
+ ),
12206
+ /* @__PURE__ */ jsxRuntime.jsxs(
12207
+ "button",
12208
+ {
12209
+ className: ui.clx(
12210
+ "flex items-center justify-center outline-none transition-fg",
12211
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12212
+ "focus:bg-ui-bg-field-hover",
12213
+ "hover:bg-ui-bg-field-hover",
12214
+ {
12215
+ "size-7": size === "small",
12216
+ "size-8": size === "base"
12217
+ }
12218
+ ),
12219
+ type: "button",
12220
+ onClick: handleIncrement,
12221
+ disabled: max !== void 0 && value >= max || disabled,
12222
+ children: [
12223
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
12224
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12225
+ ]
12226
+ }
12227
+ )
12228
+ ]
12229
+ }
12230
+ );
12231
+ }
12232
+ );
12233
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12234
+ const productVariantsQueryKeys = {
12235
+ list: (query2) => [
12236
+ PRODUCT_VARIANTS_QUERY_KEY,
12237
+ query2 ? query2 : void 0
12238
+ ]
12239
+ };
12240
+ const useProductVariants = (query2, options) => {
12241
+ const { data, ...rest } = reactQuery.useQuery({
12242
+ queryKey: productVariantsQueryKeys.list(query2),
12243
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12244
+ ...options
12245
+ });
12246
+ return { ...data, ...rest };
12247
+ };
12248
+ const STACKED_MODAL_ID = "items_stacked_modal";
12249
+ const Items = () => {
12250
+ const { id } = reactRouterDom.useParams();
12251
+ const {
12252
+ order: preview,
12253
+ isPending: isPreviewPending,
12254
+ isError: isPreviewError,
12255
+ error: previewError
12256
+ } = useOrderPreview(id, void 0, {
12257
+ placeholderData: reactQuery.keepPreviousData
12258
+ });
12259
+ useInitiateOrderEdit({ preview });
12260
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12261
+ id,
12262
+ {
12263
+ fields: "currency_code"
12264
+ },
12265
+ {
12266
+ enabled: !!id
12267
+ }
12268
+ );
12269
+ const { onCancel } = useCancelOrderEdit({ preview });
12270
+ if (isError) {
12271
+ throw error;
12272
+ }
12273
+ if (isPreviewError) {
12274
+ throw previewError;
12275
+ }
12276
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12277
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12278
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12279
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12280
+ ] }) });
12281
+ };
12282
+ const ItemsForm = ({ preview, currencyCode }) => {
12283
+ var _a;
12284
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12285
+ const [modalContent, setModalContent] = React.useState(
12286
+ null
12287
+ );
12288
+ const { handleSuccess } = useRouteModal();
12289
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12290
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12291
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12292
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12293
+ const matches = React.useMemo(() => {
12294
+ return matchSorter.matchSorter(preview.items, query2, {
12295
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12296
+ });
12297
+ }, [preview.items, query2]);
12298
+ const onSubmit = async () => {
12299
+ setIsSubmitting(true);
12300
+ let requestSucceeded = false;
12301
+ await requestOrderEdit(void 0, {
12302
+ onError: (e) => {
12303
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12304
+ },
12305
+ onSuccess: () => {
12306
+ requestSucceeded = true;
12307
+ }
12308
+ });
12309
+ if (!requestSucceeded) {
12310
+ setIsSubmitting(false);
12311
+ return;
12312
+ }
12313
+ await confirmOrderEdit(void 0, {
12314
+ onError: (e) => {
12315
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12316
+ },
12317
+ onSuccess: () => {
12318
+ handleSuccess();
12319
+ },
12320
+ onSettled: () => {
12321
+ setIsSubmitting(false);
12322
+ }
12323
+ });
12324
+ };
12325
+ const onKeyDown = React.useCallback(
12326
+ (e) => {
12327
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12328
+ if (modalContent || isSubmitting) {
12329
+ return;
12330
+ }
12331
+ onSubmit();
12332
+ }
12333
+ },
12334
+ [modalContent, isSubmitting, onSubmit]
12335
+ );
12336
+ React.useEffect(() => {
12337
+ document.addEventListener("keydown", onKeyDown);
12338
+ return () => {
12339
+ document.removeEventListener("keydown", onKeyDown);
12340
+ };
12341
+ }, [onKeyDown]);
12342
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12343
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12344
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
12345
+ StackedFocusModal,
12346
+ {
12347
+ id: STACKED_MODAL_ID,
12348
+ onOpenChangeCallback: (open) => {
12349
+ if (!open) {
12350
+ setModalContent(null);
12783
12351
  }
12784
- ) }),
12785
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12786
- "path",
12787
- {
12788
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12789
- stroke: "#A1A1AA",
12790
- strokeWidth: "1.5",
12791
- strokeLinecap: "round",
12792
- strokeLinejoin: "round"
12352
+ },
12353
+ children: [
12354
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12355
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12356
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
12357
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
12358
+ ] }),
12359
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12360
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12361
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12363
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12364
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12365
+ ] }),
12366
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
12367
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12368
+ ui.Input,
12369
+ {
12370
+ type: "search",
12371
+ placeholder: "Search items",
12372
+ value: searchValue,
12373
+ onChange: (e) => onSearchValueChange(e.target.value)
12374
+ }
12375
+ ) }),
12376
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
12378
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsx(
12380
+ StackedModalTrigger,
12381
+ {
12382
+ type: "add-items",
12383
+ setModalContent
12384
+ }
12385
+ ),
12386
+ /* @__PURE__ */ jsxRuntime.jsx(
12387
+ StackedModalTrigger,
12388
+ {
12389
+ type: "add-custom-item",
12390
+ setModalContent
12391
+ }
12392
+ )
12393
+ ] })
12394
+ ] })
12395
+ ] })
12396
+ ] }),
12397
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12398
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
12399
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12400
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12401
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
12402
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
12403
+ ] }) }),
12404
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12405
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12406
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12407
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
12408
+ Item,
12409
+ {
12410
+ item,
12411
+ preview,
12412
+ currencyCode
12413
+ },
12414
+ item.id
12415
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12417
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12418
+ 'No items found for "',
12419
+ query2,
12420
+ '".'
12421
+ ] })
12422
+ ] }) })
12423
+ ] })
12424
+ ] }),
12425
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12426
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12427
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12428
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
12429
+ ui.Text,
12430
+ {
12431
+ size: "small",
12432
+ leading: "compact",
12433
+ className: "text-ui-fg-subtle",
12434
+ children: [
12435
+ itemCount,
12436
+ " ",
12437
+ itemCount === 1 ? "item" : "items"
12438
+ ]
12439
+ }
12440
+ ) }),
12441
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12442
+ ] })
12443
+ ] }) }),
12444
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
12445
+ CustomItemForm,
12446
+ {
12447
+ orderId: preview.id,
12448
+ currencyCode
12449
+ }
12450
+ ) : null)
12451
+ ]
12452
+ }
12453
+ ) }),
12454
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(
12457
+ ui.Button,
12458
+ {
12459
+ size: "small",
12460
+ type: "button",
12461
+ onClick: onSubmit,
12462
+ isLoading: isSubmitting,
12463
+ children: "Save"
12464
+ }
12465
+ )
12466
+ ] }) })
12467
+ ] });
12468
+ };
12469
+ const Item = ({ item, preview, currencyCode }) => {
12470
+ if (item.variant_id) {
12471
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
12472
+ }
12473
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
12474
+ };
12475
+ const VariantItem = ({ item, preview, currencyCode }) => {
12476
+ const [editing, setEditing] = React.useState(false);
12477
+ const form = reactHookForm.useForm({
12478
+ defaultValues: {
12479
+ quantity: item.quantity,
12480
+ unit_price: item.unit_price
12481
+ },
12482
+ resolver: zod.zodResolver(variantItemSchema)
12483
+ });
12484
+ const actionId = React.useMemo(() => {
12485
+ var _a, _b;
12486
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12487
+ }, [item]);
12488
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12489
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12490
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12491
+ const onSubmit = form.handleSubmit(async (data) => {
12492
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12493
+ setEditing(false);
12494
+ return;
12495
+ }
12496
+ if (!actionId) {
12497
+ await updateOriginalItem(
12498
+ {
12499
+ item_id: item.id,
12500
+ quantity: data.quantity,
12501
+ unit_price: convertNumber(data.unit_price)
12502
+ },
12503
+ {
12504
+ onSuccess: () => {
12505
+ setEditing(false);
12506
+ },
12507
+ onError: (e) => {
12508
+ ui.toast.error(e.message);
12793
12509
  }
12794
- ) }),
12795
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12796
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12797
- "rect",
12798
- {
12799
- width: "12",
12800
- height: "12",
12801
- fill: "white",
12802
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12803
- }
12804
- ) }),
12805
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12806
- "rect",
12807
- {
12808
- width: "12",
12809
- height: "12",
12810
- fill: "white",
12811
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12812
- }
12813
- ) }),
12814
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12815
- "rect",
12816
- {
12817
- width: "12",
12818
- height: "12",
12819
- fill: "white",
12820
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12821
- }
12822
- ) }),
12823
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12824
- "rect",
12510
+ }
12511
+ );
12512
+ return;
12513
+ }
12514
+ await updateActionItem(
12515
+ {
12516
+ action_id: actionId,
12517
+ quantity: data.quantity,
12518
+ unit_price: convertNumber(data.unit_price)
12519
+ },
12520
+ {
12521
+ onSuccess: () => {
12522
+ setEditing(false);
12523
+ },
12524
+ onError: (e) => {
12525
+ ui.toast.error(e.message);
12526
+ }
12527
+ }
12528
+ );
12529
+ });
12530
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
12532
+ /* @__PURE__ */ jsxRuntime.jsx(
12533
+ Thumbnail,
12534
+ {
12535
+ thumbnail: item.thumbnail,
12536
+ alt: item.product_title ?? void 0
12537
+ }
12538
+ ),
12539
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12540
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12541
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12542
+ /* @__PURE__ */ jsxRuntime.jsxs(
12543
+ ui.Text,
12825
12544
  {
12826
- width: "12",
12827
- height: "12",
12828
- fill: "white",
12829
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12545
+ size: "small",
12546
+ leading: "compact",
12547
+ className: "text-ui-fg-subtle",
12548
+ children: [
12549
+ "(",
12550
+ item.variant_title,
12551
+ ")"
12552
+ ]
12830
12553
  }
12831
- ) }),
12832
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12833
- "rect",
12554
+ )
12555
+ ] }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(
12557
+ ui.Text,
12558
+ {
12559
+ size: "small",
12560
+ leading: "compact",
12561
+ className: "text-ui-fg-subtle",
12562
+ children: item.variant_sku
12563
+ }
12564
+ )
12565
+ ] })
12566
+ ] }),
12567
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12568
+ Form$2.Field,
12569
+ {
12570
+ control: form.control,
12571
+ name: "quantity",
12572
+ render: ({ field }) => {
12573
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12574
+ }
12575
+ }
12576
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12577
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12578
+ Form$2.Field,
12579
+ {
12580
+ control: form.control,
12581
+ name: "unit_price",
12582
+ render: ({ field: { onChange, ...field } }) => {
12583
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12584
+ ui.CurrencyInput,
12834
12585
  {
12835
- width: "12",
12836
- height: "12",
12837
- fill: "white",
12838
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12586
+ ...field,
12587
+ symbol: getNativeSymbol(currencyCode),
12588
+ code: currencyCode,
12589
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12839
12590
  }
12840
- ) }),
12841
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12842
- "rect",
12591
+ ) }) });
12592
+ }
12593
+ }
12594
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12595
+ /* @__PURE__ */ jsxRuntime.jsx(
12596
+ ui.IconButton,
12597
+ {
12598
+ type: "button",
12599
+ size: "small",
12600
+ onClick: editing ? onSubmit : () => {
12601
+ setEditing(true);
12602
+ },
12603
+ disabled: isPending,
12604
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12605
+ }
12606
+ )
12607
+ ] }) }) });
12608
+ };
12609
+ const variantItemSchema = objectType({
12610
+ quantity: numberType(),
12611
+ unit_price: unionType([numberType(), stringType()])
12612
+ });
12613
+ const CustomItem = ({ item, preview, currencyCode }) => {
12614
+ const [editing, setEditing] = React.useState(false);
12615
+ const { quantity, unit_price, title } = item;
12616
+ const form = reactHookForm.useForm({
12617
+ defaultValues: {
12618
+ title,
12619
+ quantity,
12620
+ unit_price
12621
+ },
12622
+ resolver: zod.zodResolver(customItemSchema)
12623
+ });
12624
+ React.useEffect(() => {
12625
+ form.reset({
12626
+ title,
12627
+ quantity,
12628
+ unit_price
12629
+ });
12630
+ }, [form, title, quantity, unit_price]);
12631
+ const actionId = React.useMemo(() => {
12632
+ var _a, _b;
12633
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12634
+ }, [item]);
12635
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12636
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12637
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12638
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12639
+ const onSubmit = form.handleSubmit(async (data) => {
12640
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12641
+ setEditing(false);
12642
+ return;
12643
+ }
12644
+ if (!actionId) {
12645
+ await updateOriginalItem(
12646
+ {
12647
+ item_id: item.id,
12648
+ quantity: data.quantity,
12649
+ unit_price: convertNumber(data.unit_price)
12650
+ },
12651
+ {
12652
+ onSuccess: () => {
12653
+ setEditing(false);
12654
+ },
12655
+ onError: (e) => {
12656
+ ui.toast.error(e.message);
12657
+ }
12658
+ }
12659
+ );
12660
+ return;
12661
+ }
12662
+ if (data.quantity === 0) {
12663
+ await removeActionItem(actionId, {
12664
+ onSuccess: () => {
12665
+ setEditing(false);
12666
+ },
12667
+ onError: (e) => {
12668
+ ui.toast.error(e.message);
12669
+ }
12670
+ });
12671
+ return;
12672
+ }
12673
+ await updateActionItem(
12674
+ {
12675
+ action_id: actionId,
12676
+ quantity: data.quantity,
12677
+ unit_price: convertNumber(data.unit_price)
12678
+ },
12679
+ {
12680
+ onSuccess: () => {
12681
+ setEditing(false);
12682
+ },
12683
+ onError: (e) => {
12684
+ ui.toast.error(e.message);
12685
+ }
12686
+ }
12687
+ );
12688
+ });
12689
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12690
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12691
+ /* @__PURE__ */ jsxRuntime.jsx(
12692
+ Thumbnail,
12693
+ {
12694
+ thumbnail: item.thumbnail,
12695
+ alt: item.title ?? void 0
12696
+ }
12697
+ ),
12698
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12699
+ Form$2.Field,
12700
+ {
12701
+ control: form.control,
12702
+ name: "title",
12703
+ render: ({ field }) => {
12704
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
12705
+ }
12706
+ }
12707
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12708
+ ] }),
12709
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12710
+ Form$2.Field,
12711
+ {
12712
+ control: form.control,
12713
+ name: "quantity",
12714
+ render: ({ field }) => {
12715
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12716
+ }
12717
+ }
12718
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12719
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12720
+ Form$2.Field,
12721
+ {
12722
+ control: form.control,
12723
+ name: "unit_price",
12724
+ render: ({ field: { onChange, ...field } }) => {
12725
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12726
+ ui.CurrencyInput,
12843
12727
  {
12844
- width: "12",
12845
- height: "12",
12846
- fill: "white",
12847
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12728
+ ...field,
12729
+ symbol: getNativeSymbol(currencyCode),
12730
+ code: currencyCode,
12731
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12848
12732
  }
12849
- ) })
12850
- ] })
12851
- ]
12852
- }
12853
- );
12733
+ ) }) });
12734
+ }
12735
+ }
12736
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12737
+ /* @__PURE__ */ jsxRuntime.jsx(
12738
+ ui.IconButton,
12739
+ {
12740
+ type: "button",
12741
+ size: "small",
12742
+ onClick: editing ? onSubmit : () => {
12743
+ setEditing(true);
12744
+ },
12745
+ disabled: isPending,
12746
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12747
+ }
12748
+ )
12749
+ ] }) }) });
12854
12750
  };
12855
- const schema$1 = objectType({
12856
- customer_id: stringType().min(1)
12857
- });
12858
- const BillingAddress = () => {
12859
- const { id } = reactRouterDom.useParams();
12860
- const { order, isPending, isError, error } = useOrder(id, {
12861
- fields: "+billing_address"
12862
- });
12863
- if (isError) {
12864
- throw error;
12865
- }
12866
- const isReady = !isPending && !!order;
12867
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12869
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12871
- ] }),
12872
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12873
- ] });
12751
+ const StackedModalTrigger = ({
12752
+ type,
12753
+ setModalContent
12754
+ }) => {
12755
+ const { setIsOpen } = useStackedModal();
12756
+ const onClick = React.useCallback(() => {
12757
+ setModalContent(type);
12758
+ setIsOpen(STACKED_MODAL_ID, true);
12759
+ }, [setModalContent, setIsOpen, type]);
12760
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12874
12761
  };
12875
- const BillingAddressForm = ({ order }) => {
12876
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
- const form = reactHookForm.useForm({
12878
- defaultValues: {
12879
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12762
+ const VARIANT_PREFIX = "items";
12763
+ const LIMIT = 50;
12764
+ const ExistingItemsForm = ({ orderId, items }) => {
12765
+ const { setIsOpen } = useStackedModal();
12766
+ const [rowSelection, setRowSelection] = React.useState(
12767
+ items.reduce((acc, item) => {
12768
+ acc[item.variant_id] = true;
12769
+ return acc;
12770
+ }, {})
12771
+ );
12772
+ React.useEffect(() => {
12773
+ setRowSelection(
12774
+ items.reduce((acc, item) => {
12775
+ if (item.variant_id) {
12776
+ acc[item.variant_id] = true;
12777
+ }
12778
+ return acc;
12779
+ }, {})
12780
+ );
12781
+ }, [items]);
12782
+ const { q, order, offset } = useQueryParams(
12783
+ ["q", "order", "offset"],
12784
+ VARIANT_PREFIX
12785
+ );
12786
+ const { variants, count, isPending, isError, error } = useProductVariants(
12787
+ {
12788
+ q,
12789
+ order,
12790
+ offset: offset ? parseInt(offset) : void 0,
12791
+ limit: LIMIT
12889
12792
  },
12890
- resolver: zod.zodResolver(schema)
12891
- });
12892
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
- const { handleSuccess } = useRouteModal();
12894
- const onSubmit = form.handleSubmit(async (data) => {
12793
+ {
12794
+ placeholderData: reactQuery.keepPreviousData
12795
+ }
12796
+ );
12797
+ const columns = useColumns();
12798
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12799
+ const onSubmit = async () => {
12800
+ const ids = Object.keys(rowSelection).filter(
12801
+ (id) => !items.find((i) => i.variant_id === id)
12802
+ );
12895
12803
  await mutateAsync(
12896
- { billing_address: data },
12804
+ {
12805
+ items: ids.map((id) => ({
12806
+ variant_id: id,
12807
+ quantity: 1
12808
+ }))
12809
+ },
12897
12810
  {
12898
12811
  onSuccess: () => {
12899
- handleSuccess();
12812
+ setRowSelection({});
12813
+ setIsOpen(STACKED_MODAL_ID, false);
12900
12814
  },
12901
- onError: (error) => {
12902
- ui.toast.error(error.message);
12815
+ onError: (e) => {
12816
+ ui.toast.error(e.message);
12903
12817
  }
12904
12818
  }
12905
12819
  );
12906
- });
12907
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
- KeyboundForm,
12820
+ };
12821
+ if (isError) {
12822
+ throw error;
12823
+ }
12824
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12825
+ StackedFocusModal.Content,
12909
12826
  {
12910
- className: "flex flex-1 flex-col overflow-hidden",
12911
- onSubmit,
12827
+ onOpenAutoFocus: (e) => {
12828
+ e.preventDefault();
12829
+ const searchInput = document.querySelector(
12830
+ "[data-modal-id='modal-search-input']"
12831
+ );
12832
+ if (searchInput) {
12833
+ searchInput.focus();
12834
+ }
12835
+ },
12912
12836
  children: [
12913
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12914
- /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12916
- {
12917
- control: form.control,
12918
- name: "country_code",
12919
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
- ] })
12924
- }
12925
- ),
12926
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
- /* @__PURE__ */ jsxRuntime.jsx(
12928
- Form$2.Field,
12929
- {
12930
- control: form.control,
12931
- name: "first_name",
12932
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
- ] })
12937
- }
12938
- ),
12939
- /* @__PURE__ */ jsxRuntime.jsx(
12940
- Form$2.Field,
12941
- {
12942
- control: form.control,
12943
- name: "last_name",
12944
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
- ] })
12949
- }
12950
- )
12951
- ] }),
12952
- /* @__PURE__ */ jsxRuntime.jsx(
12953
- Form$2.Field,
12954
- {
12955
- control: form.control,
12956
- name: "company",
12957
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
- ] })
12962
- }
12963
- ),
12964
- /* @__PURE__ */ jsxRuntime.jsx(
12965
- Form$2.Field,
12966
- {
12967
- control: form.control,
12968
- name: "address_1",
12969
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
- ] })
12974
- }
12975
- ),
12976
- /* @__PURE__ */ jsxRuntime.jsx(
12977
- Form$2.Field,
12978
- {
12979
- control: form.control,
12980
- name: "address_2",
12981
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
- ] })
12986
- }
12987
- ),
12988
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
- /* @__PURE__ */ jsxRuntime.jsx(
12990
- Form$2.Field,
12991
- {
12992
- control: form.control,
12993
- name: "postal_code",
12994
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
- ] })
12837
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12838
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12839
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12840
+ ] }),
12841
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12842
+ DataTable,
12843
+ {
12844
+ data: variants,
12845
+ columns,
12846
+ isLoading: isPending,
12847
+ getRowId: (row) => row.id,
12848
+ rowCount: count,
12849
+ prefix: VARIANT_PREFIX,
12850
+ layout: "fill",
12851
+ rowSelection: {
12852
+ state: rowSelection,
12853
+ onRowSelectionChange: setRowSelection,
12854
+ enableRowSelection: (row) => {
12855
+ return !items.find((i) => i.variant_id === row.original.id);
12999
12856
  }
13000
- ),
12857
+ },
12858
+ autoFocusSearch: true
12859
+ }
12860
+ ) }),
12861
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12862
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12863
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12864
+ ] }) })
12865
+ ]
12866
+ }
12867
+ );
12868
+ };
12869
+ const columnHelper = ui.createDataTableColumnHelper();
12870
+ const useColumns = () => {
12871
+ return React.useMemo(() => {
12872
+ return [
12873
+ columnHelper.select(),
12874
+ columnHelper.accessor("product.title", {
12875
+ header: "Product",
12876
+ cell: ({ row }) => {
12877
+ var _a, _b, _c;
12878
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
13001
12879
  /* @__PURE__ */ jsxRuntime.jsx(
13002
- Form$2.Field,
12880
+ Thumbnail,
13003
12881
  {
13004
- control: form.control,
13005
- name: "city",
13006
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
- ] })
12882
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12883
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
13011
12884
  }
13012
- )
13013
- ] }),
13014
- /* @__PURE__ */ jsxRuntime.jsx(
13015
- Form$2.Field,
12885
+ ),
12886
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12887
+ ] });
12888
+ },
12889
+ enableSorting: true
12890
+ }),
12891
+ columnHelper.accessor("title", {
12892
+ header: "Variant",
12893
+ enableSorting: true
12894
+ }),
12895
+ columnHelper.accessor("sku", {
12896
+ header: "SKU",
12897
+ cell: ({ getValue }) => {
12898
+ return getValue() ?? "-";
12899
+ },
12900
+ enableSorting: true
12901
+ }),
12902
+ columnHelper.accessor("updated_at", {
12903
+ header: "Updated",
12904
+ cell: ({ getValue }) => {
12905
+ return /* @__PURE__ */ jsxRuntime.jsx(
12906
+ ui.Tooltip,
13016
12907
  {
13017
- control: form.control,
13018
- name: "province",
13019
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
- ] })
12908
+ content: getFullDate({ date: getValue(), includeTime: true }),
12909
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13024
12910
  }
13025
- ),
13026
- /* @__PURE__ */ jsxRuntime.jsx(
13027
- Form$2.Field,
12911
+ );
12912
+ },
12913
+ enableSorting: true,
12914
+ sortAscLabel: "Oldest first",
12915
+ sortDescLabel: "Newest first"
12916
+ }),
12917
+ columnHelper.accessor("created_at", {
12918
+ header: "Created",
12919
+ cell: ({ getValue }) => {
12920
+ return /* @__PURE__ */ jsxRuntime.jsx(
12921
+ ui.Tooltip,
13028
12922
  {
13029
- control: form.control,
13030
- name: "phone",
13031
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
- ] })
12923
+ content: getFullDate({ date: getValue(), includeTime: true }),
12924
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13036
12925
  }
13037
- )
13038
- ] }) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
- ] }) })
13043
- ]
13044
- }
13045
- ) });
12926
+ );
12927
+ },
12928
+ enableSorting: true,
12929
+ sortAscLabel: "Oldest first",
12930
+ sortDescLabel: "Newest first"
12931
+ })
12932
+ ];
12933
+ }, []);
12934
+ };
12935
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12936
+ const { setIsOpen } = useStackedModal();
12937
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12938
+ const form = reactHookForm.useForm({
12939
+ defaultValues: {
12940
+ title: "",
12941
+ quantity: 1,
12942
+ unit_price: ""
12943
+ },
12944
+ resolver: zod.zodResolver(customItemSchema)
12945
+ });
12946
+ const onSubmit = form.handleSubmit(async (data) => {
12947
+ await addItems(
12948
+ {
12949
+ items: [
12950
+ {
12951
+ title: data.title,
12952
+ quantity: data.quantity,
12953
+ unit_price: convertNumber(data.unit_price)
12954
+ }
12955
+ ]
12956
+ },
12957
+ {
12958
+ onSuccess: () => {
12959
+ setIsOpen(STACKED_MODAL_ID, false);
12960
+ },
12961
+ onError: (e) => {
12962
+ ui.toast.error(e.message);
12963
+ }
12964
+ }
12965
+ );
12966
+ });
12967
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12968
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12971
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12973
+ ] }),
12974
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(
12976
+ Form$2.Field,
12977
+ {
12978
+ control: form.control,
12979
+ name: "title",
12980
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12981
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12984
+ ] }),
12985
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12986
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12987
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12988
+ ] })
12989
+ ] }) })
12990
+ }
12991
+ ),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx(
12994
+ Form$2.Field,
12995
+ {
12996
+ control: form.control,
12997
+ name: "unit_price",
12998
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12999
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13000
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
13002
+ ] }),
13003
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13005
+ ui.CurrencyInput,
13006
+ {
13007
+ symbol: getNativeSymbol(currencyCode),
13008
+ code: currencyCode,
13009
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
13010
+ ...field
13011
+ }
13012
+ ) }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13014
+ ] })
13015
+ ] }) })
13016
+ }
13017
+ ),
13018
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(
13020
+ Form$2.Field,
13021
+ {
13022
+ control: form.control,
13023
+ name: "quantity",
13024
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
13027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13028
+ ] }),
13029
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13032
+ ] })
13033
+ ] }) })
13034
+ }
13035
+ )
13036
+ ] }) }) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13040
+ ] }) })
13041
+ ] }) }) });
13046
13042
  };
13047
- const schema = addressSchema;
13043
+ const customItemSchema = objectType({
13044
+ title: stringType().min(1),
13045
+ quantity: numberType(),
13046
+ unit_price: unionType([numberType(), stringType()])
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,6 +13065,10 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
+ {
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
+ },
13068
13072
  {
13069
13073
  Component: CustomItems,
13070
13074
  path: "/draft-orders/:id/custom-items"
@@ -13077,33 +13081,29 @@ const routeModule = {
13077
13081
  Component: Metadata,
13078
13082
  path: "/draft-orders/:id/metadata"
13079
13083
  },
13080
- {
13081
- Component: Items,
13082
- path: "/draft-orders/:id/items"
13083
- },
13084
13084
  {
13085
13085
  Component: Promotions,
13086
13086
  path: "/draft-orders/:id/promotions"
13087
13087
  },
13088
13088
  {
13089
- Component: SalesChannel,
13090
- path: "/draft-orders/:id/sales-channel"
13089
+ Component: Shipping,
13090
+ path: "/draft-orders/:id/shipping"
13091
13091
  },
13092
13092
  {
13093
13093
  Component: ShippingAddress,
13094
13094
  path: "/draft-orders/:id/shipping-address"
13095
13095
  },
13096
- {
13097
- Component: Shipping,
13098
- path: "/draft-orders/:id/shipping"
13099
- },
13100
13096
  {
13101
13097
  Component: TransferOwnership,
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
13103
13099
  },
13104
13100
  {
13105
- Component: BillingAddress,
13106
- path: "/draft-orders/:id/billing-address"
13101
+ Component: SalesChannel,
13102
+ path: "/draft-orders/:id/sales-channel"
13103
+ },
13104
+ {
13105
+ Component: Items,
13106
+ path: "/draft-orders/:id/items"
13107
13107
  }
13108
13108
  ]
13109
13109
  }