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