@medusajs/draft-order 2.12.0-preview-20251103180145 → 2.12.0

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.
@@ -352,10 +352,14 @@ const DataTableAction = ({
352
352
  }
353
353
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...buttonProps, onClick: props.onClick, children: label });
354
354
  };
355
+ const backendUrl = __BACKEND_URL__ ?? "/";
356
+ const authType = __AUTH_TYPE__ ?? "session";
357
+ const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
355
358
  const sdk = new Medusa__default.default({
356
- baseUrl: __BACKEND_URL__ || "/",
359
+ baseUrl: backendUrl,
357
360
  auth: {
358
- type: "session"
361
+ type: authType,
362
+ jwtTokenStorageKey
359
363
  }
360
364
  });
361
365
  const CUSTOMER_QUERY_KEY = "customers";
@@ -4654,9 +4658,6 @@ ZodReadonly.create = (type, params) => {
4654
4658
  ...processCreateParams(params)
4655
4659
  });
4656
4660
  };
4657
- ({
4658
- object: ZodObject.lazycreate
4659
- });
4660
4661
  var ZodFirstPartyTypeKind;
4661
4662
  (function(ZodFirstPartyTypeKind2) {
4662
4663
  ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
@@ -4703,7 +4704,6 @@ const anyType = ZodAny.create;
4703
4704
  ZodNever.create;
4704
4705
  const arrayType = ZodArray.create;
4705
4706
  const objectType = ZodObject.create;
4706
- ZodObject.strictCreate;
4707
4707
  const unionType = ZodUnion.create;
4708
4708
  ZodIntersection.create;
4709
4709
  ZodTuple.create;
@@ -8729,7 +8729,7 @@ const Contact = ({ order }) => {
8729
8729
  children: phone
8730
8730
  }
8731
8731
  ),
8732
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Copy, { content: email, className: "text-ui-fg-muted" }) })
8732
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Copy, { content: phone, className: "text-ui-fg-muted" }) })
8733
8733
  ] })
8734
8734
  ] })
8735
8735
  ] });
@@ -9762,95 +9762,6 @@ const BillingAddressForm = ({ order }) => {
9762
9762
  ) });
9763
9763
  };
9764
9764
  const schema$5 = addressSchema;
9765
- const CustomItems = () => {
9766
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
- ] });
9770
- };
9771
- const CustomItemsForm = () => {
9772
- const form = reactHookForm.useForm({
9773
- resolver: zod.zodResolver(schema$4)
9774
- });
9775
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
- ] }) })
9781
- ] }) });
9782
- };
9783
- const schema$4 = objectType({
9784
- email: stringType().email()
9785
- });
9786
- const Email = () => {
9787
- const { id } = reactRouterDom.useParams();
9788
- const { order, isPending, isError, error } = useOrder(id, {
9789
- fields: "+email"
9790
- });
9791
- if (isError) {
9792
- throw error;
9793
- }
9794
- const isReady = !isPending && !!order;
9795
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9796
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9799
- ] }),
9800
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9801
- ] });
9802
- };
9803
- const EmailForm = ({ order }) => {
9804
- const form = reactHookForm.useForm({
9805
- defaultValues: {
9806
- email: order.email ?? ""
9807
- },
9808
- resolver: zod.zodResolver(schema$3)
9809
- });
9810
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
- const { handleSuccess } = useRouteModal();
9812
- const onSubmit = form.handleSubmit(async (data) => {
9813
- await mutateAsync(
9814
- { email: data.email },
9815
- {
9816
- onSuccess: () => {
9817
- handleSuccess();
9818
- },
9819
- onError: (error) => {
9820
- ui.toast.error(error.message);
9821
- }
9822
- }
9823
- );
9824
- });
9825
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9826
- KeyboundForm,
9827
- {
9828
- className: "flex flex-1 flex-col overflow-hidden",
9829
- onSubmit,
9830
- children: [
9831
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9832
- Form$2.Field,
9833
- {
9834
- control: form.control,
9835
- name: "email",
9836
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
- ] })
9841
- }
9842
- ) }),
9843
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9845
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9846
- ] }) })
9847
- ]
9848
- }
9849
- ) });
9850
- };
9851
- const schema$3 = objectType({
9852
- email: stringType().email()
9853
- });
9854
9765
  const NumberInput = React.forwardRef(
9855
9766
  ({
9856
9767
  value,
@@ -10825,536 +10736,186 @@ const customItemSchema = objectType({
10825
10736
  quantity: numberType(),
10826
10737
  unit_price: unionType([numberType(), stringType()])
10827
10738
  });
10828
- const InlineTip = React.forwardRef(
10829
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10830
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10831
- return /* @__PURE__ */ jsxRuntime.jsxs(
10832
- "div",
10833
- {
10834
- ref,
10835
- className: ui.clx(
10836
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10837
- className
10838
- ),
10839
- ...props,
10840
- children: [
10841
- /* @__PURE__ */ jsxRuntime.jsx(
10842
- "div",
10843
- {
10844
- role: "presentation",
10845
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10846
- "bg-ui-tag-orange-icon": variant === "warning"
10847
- })
10848
- }
10849
- ),
10850
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10851
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10852
- labelValue,
10853
- ":"
10854
- ] }),
10855
- " ",
10856
- children
10857
- ] })
10858
- ]
10859
- }
10860
- );
10861
- }
10862
- );
10863
- InlineTip.displayName = "InlineTip";
10864
- const MetadataFieldSchema = objectType({
10865
- key: stringType(),
10866
- disabled: booleanType().optional(),
10867
- value: anyType()
10868
- });
10869
- const MetadataSchema = objectType({
10870
- metadata: arrayType(MetadataFieldSchema)
10871
- });
10872
- const Metadata = () => {
10873
- const { id } = reactRouterDom.useParams();
10874
- const { order, isPending, isError, error } = useOrder(id, {
10875
- fields: "metadata"
10739
+ const PROMOTION_QUERY_KEY = "promotions";
10740
+ const promotionsQueryKeys = {
10741
+ list: (query2) => [
10742
+ PROMOTION_QUERY_KEY,
10743
+ query2 ? query2 : void 0
10744
+ ],
10745
+ detail: (id, query2) => [
10746
+ PROMOTION_QUERY_KEY,
10747
+ id,
10748
+ query2 ? query2 : void 0
10749
+ ]
10750
+ };
10751
+ const usePromotions = (query2, options) => {
10752
+ const { data, ...rest } = reactQuery.useQuery({
10753
+ queryKey: promotionsQueryKeys.list(query2),
10754
+ queryFn: async () => sdk.admin.promotion.list(query2),
10755
+ ...options
10876
10756
  });
10877
- if (isError) {
10878
- throw error;
10757
+ return { ...data, ...rest };
10758
+ };
10759
+ const Promotions = () => {
10760
+ const { id } = reactRouterDom.useParams();
10761
+ const {
10762
+ order: preview,
10763
+ isError: isPreviewError,
10764
+ error: previewError
10765
+ } = useOrderPreview(id, void 0);
10766
+ useInitiateOrderEdit({ preview });
10767
+ const { onCancel } = useCancelOrderEdit({ preview });
10768
+ if (isPreviewError) {
10769
+ throw previewError;
10879
10770
  }
10880
- const isReady = !isPending && !!order;
10881
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10882
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10883
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10884
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10885
- ] }),
10886
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10771
+ const isReady = !!preview;
10772
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10773
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10774
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10887
10775
  ] });
10888
10776
  };
10889
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10890
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10891
- const MetadataForm = ({ orderId, metadata }) => {
10777
+ const PromotionForm = ({ preview }) => {
10778
+ const { items, shipping_methods } = preview;
10779
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10780
+ const [comboboxValue, setComboboxValue] = React.useState("");
10892
10781
  const { handleSuccess } = useRouteModal();
10893
- const hasUneditableRows = getHasUneditableRows(metadata);
10894
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10895
- const form = reactHookForm.useForm({
10896
- defaultValues: {
10897
- metadata: getDefaultValues(metadata)
10782
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10783
+ const promoIds = getPromotionIds(items, shipping_methods);
10784
+ const { promotions, isPending, isError, error } = usePromotions(
10785
+ {
10786
+ id: promoIds
10898
10787
  },
10899
- resolver: zod.zodResolver(MetadataSchema)
10788
+ {
10789
+ enabled: !!promoIds.length
10790
+ }
10791
+ );
10792
+ const comboboxData = useComboboxData({
10793
+ queryKey: ["promotions", "combobox", promoIds],
10794
+ queryFn: async (params) => {
10795
+ return await sdk.admin.promotion.list({
10796
+ ...params,
10797
+ id: {
10798
+ $nin: promoIds
10799
+ }
10800
+ });
10801
+ },
10802
+ getOptions: (data) => {
10803
+ return data.promotions.map((promotion) => ({
10804
+ label: promotion.code,
10805
+ value: promotion.code
10806
+ }));
10807
+ }
10900
10808
  });
10901
- const handleSubmit = form.handleSubmit(async (data) => {
10902
- const parsedData = parseValues(data);
10903
- await mutateAsync(
10809
+ const add = async (value) => {
10810
+ if (!value) {
10811
+ return;
10812
+ }
10813
+ addPromotions(
10904
10814
  {
10905
- metadata: parsedData
10815
+ promo_codes: [value]
10906
10816
  },
10907
10817
  {
10908
- onSuccess: () => {
10909
- ui.toast.success("Metadata updated");
10910
- handleSuccess();
10818
+ onError: (e) => {
10819
+ ui.toast.error(e.message);
10820
+ comboboxData.onSearchValueChange("");
10821
+ setComboboxValue("");
10911
10822
  },
10912
- onError: (error) => {
10913
- ui.toast.error(error.message);
10823
+ onSuccess: () => {
10824
+ comboboxData.onSearchValueChange("");
10825
+ setComboboxValue("");
10914
10826
  }
10915
10827
  }
10916
10828
  );
10917
- });
10918
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10919
- control: form.control,
10920
- name: "metadata"
10921
- });
10922
- function deleteRow(index) {
10923
- remove(index);
10924
- if (fields.length === 1) {
10925
- insert(0, {
10926
- key: "",
10927
- value: "",
10928
- disabled: false
10929
- });
10930
- }
10931
- }
10932
- function insertRow(index, position) {
10933
- insert(index + (position === "above" ? 0 : 1), {
10934
- key: "",
10935
- value: "",
10936
- disabled: false
10829
+ };
10830
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10831
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10832
+ const onSubmit = async () => {
10833
+ setIsSubmitting(true);
10834
+ let requestSucceeded = false;
10835
+ await requestOrderEdit(void 0, {
10836
+ onError: (e) => {
10837
+ ui.toast.error(e.message);
10838
+ },
10839
+ onSuccess: () => {
10840
+ requestSucceeded = true;
10841
+ }
10842
+ });
10843
+ if (!requestSucceeded) {
10844
+ setIsSubmitting(false);
10845
+ return;
10846
+ }
10847
+ await confirmOrderEdit(void 0, {
10848
+ onError: (e) => {
10849
+ ui.toast.error(e.message);
10850
+ },
10851
+ onSuccess: () => {
10852
+ handleSuccess();
10853
+ },
10854
+ onSettled: () => {
10855
+ setIsSubmitting(false);
10856
+ }
10937
10857
  });
10858
+ };
10859
+ if (isError) {
10860
+ throw error;
10938
10861
  }
10939
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10940
- KeyboundForm,
10941
- {
10942
- onSubmit: handleSubmit,
10943
- className: "flex flex-1 flex-col overflow-hidden",
10944
- children: [
10945
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10946
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10947
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10948
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10949
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10950
- ] }),
10951
- fields.map((field, index) => {
10952
- const isDisabled = field.disabled || false;
10953
- let placeholder = "-";
10954
- if (typeof field.value === "object") {
10955
- placeholder = "{ ... }";
10956
- }
10957
- if (Array.isArray(field.value)) {
10958
- placeholder = "[ ... ]";
10959
- }
10960
- return /* @__PURE__ */ jsxRuntime.jsx(
10961
- ConditionalTooltip,
10962
- {
10963
- showTooltip: isDisabled,
10964
- content: "This row is disabled because it contains non-primitive data.",
10965
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10966
- /* @__PURE__ */ jsxRuntime.jsxs(
10967
- "div",
10968
- {
10969
- className: ui.clx("grid grid-cols-2 divide-x", {
10970
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10971
- }),
10972
- children: [
10973
- /* @__PURE__ */ jsxRuntime.jsx(
10974
- Form$2.Field,
10975
- {
10976
- control: form.control,
10977
- name: `metadata.${index}.key`,
10978
- render: ({ field: field2 }) => {
10979
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10980
- GridInput,
10981
- {
10982
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10983
- ...field2,
10984
- disabled: isDisabled,
10985
- placeholder: "Key"
10986
- }
10987
- ) }) });
10988
- }
10989
- }
10990
- ),
10991
- /* @__PURE__ */ jsxRuntime.jsx(
10992
- Form$2.Field,
10993
- {
10994
- control: form.control,
10995
- name: `metadata.${index}.value`,
10996
- render: ({ field: { value, ...field2 } }) => {
10997
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10998
- GridInput,
10999
- {
11000
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11001
- ...field2,
11002
- value: isDisabled ? placeholder : value,
11003
- disabled: isDisabled,
11004
- placeholder: "Value"
11005
- }
11006
- ) }) });
11007
- }
11008
- }
11009
- )
11010
- ]
11011
- }
11012
- ),
11013
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11014
- /* @__PURE__ */ jsxRuntime.jsx(
11015
- ui.DropdownMenu.Trigger,
11016
- {
11017
- className: ui.clx(
11018
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11019
- {
11020
- hidden: isDisabled
11021
- }
11022
- ),
11023
- disabled: isDisabled,
11024
- asChild: true,
11025
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11026
- }
11027
- ),
11028
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11029
- /* @__PURE__ */ jsxRuntime.jsxs(
11030
- ui.DropdownMenu.Item,
11031
- {
11032
- className: "gap-x-2",
11033
- onClick: () => insertRow(index, "above"),
11034
- children: [
11035
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11036
- "Insert row above"
11037
- ]
11038
- }
11039
- ),
11040
- /* @__PURE__ */ jsxRuntime.jsxs(
11041
- ui.DropdownMenu.Item,
11042
- {
11043
- className: "gap-x-2",
11044
- onClick: () => insertRow(index, "below"),
11045
- children: [
11046
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11047
- "Insert row below"
11048
- ]
11049
- }
11050
- ),
11051
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11052
- /* @__PURE__ */ jsxRuntime.jsxs(
11053
- ui.DropdownMenu.Item,
11054
- {
11055
- className: "gap-x-2",
11056
- onClick: () => deleteRow(index),
11057
- children: [
11058
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11059
- "Delete row"
11060
- ]
11061
- }
11062
- )
11063
- ] })
11064
- ] })
11065
- ] })
11066
- },
11067
- field.id
11068
- );
11069
- })
11070
- ] }),
11071
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10862
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10863
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10864
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10865
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10866
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10867
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11072
10868
  ] }),
11073
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11075
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
- ] }) })
11077
- ]
11078
- }
11079
- ) });
11080
- };
11081
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11082
- return /* @__PURE__ */ jsxRuntime.jsx(
11083
- "input",
11084
- {
11085
- ref,
11086
- ...props,
11087
- autoComplete: "off",
11088
- className: ui.clx(
11089
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11090
- className
10869
+ /* @__PURE__ */ jsxRuntime.jsx(
10870
+ Combobox,
10871
+ {
10872
+ id: "promotion-combobox",
10873
+ "aria-describedby": "promotion-combobox-hint",
10874
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10875
+ fetchNextPage: comboboxData.fetchNextPage,
10876
+ options: comboboxData.options,
10877
+ onSearchValueChange: comboboxData.onSearchValueChange,
10878
+ searchValue: comboboxData.searchValue,
10879
+ disabled: comboboxData.disabled || isAddingPromotions,
10880
+ onChange: add,
10881
+ value: comboboxValue
10882
+ }
10883
+ )
10884
+ ] }),
10885
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10886
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10887
+ PromotionItem,
10888
+ {
10889
+ promotion,
10890
+ orderId: preview.id,
10891
+ isLoading: isPending
10892
+ },
10893
+ promotion.id
10894
+ )) })
10895
+ ] }) }),
10896
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10897
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10898
+ /* @__PURE__ */ jsxRuntime.jsx(
10899
+ ui.Button,
10900
+ {
10901
+ size: "small",
10902
+ type: "submit",
10903
+ isLoading: isSubmitting || isAddingPromotions,
10904
+ children: "Save"
10905
+ }
11091
10906
  )
11092
- }
11093
- );
11094
- });
11095
- GridInput.displayName = "MetadataForm.GridInput";
11096
- const PlaceholderInner = () => {
11097
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11098
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11099
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11100
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11102
10907
  ] }) })
11103
10908
  ] });
11104
10909
  };
11105
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11106
- function getDefaultValues(metadata) {
11107
- if (!metadata || !Object.keys(metadata).length) {
11108
- return [
11109
- {
11110
- key: "",
11111
- value: "",
11112
- disabled: false
11113
- }
11114
- ];
11115
- }
11116
- return Object.entries(metadata).map(([key, value]) => {
11117
- if (!EDITABLE_TYPES.includes(typeof value)) {
11118
- return {
11119
- key,
11120
- value,
11121
- disabled: true
11122
- };
11123
- }
11124
- let stringValue = value;
11125
- if (typeof value !== "string") {
11126
- stringValue = JSON.stringify(value);
11127
- }
11128
- return {
11129
- key,
11130
- value: stringValue,
11131
- original_key: key
11132
- };
11133
- });
11134
- }
11135
- function parseValues(values) {
11136
- const metadata = values.metadata;
11137
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11138
- if (isEmpty) {
11139
- return null;
11140
- }
11141
- const update = {};
11142
- metadata.forEach((field) => {
11143
- let key = field.key;
11144
- let value = field.value;
11145
- const disabled = field.disabled;
11146
- if (!key || !value) {
11147
- return;
11148
- }
11149
- if (disabled) {
11150
- update[key] = value;
11151
- return;
11152
- }
11153
- key = key.trim();
11154
- value = value.trim();
11155
- if (value === "true") {
11156
- update[key] = true;
11157
- } else if (value === "false") {
11158
- update[key] = false;
11159
- } else {
11160
- const parsedNumber = parseFloat(value);
11161
- if (!isNaN(parsedNumber)) {
11162
- update[key] = parsedNumber;
11163
- } else {
11164
- update[key] = value;
11165
- }
11166
- }
11167
- });
11168
- return update;
11169
- }
11170
- function getHasUneditableRows(metadata) {
11171
- if (!metadata) {
11172
- return false;
11173
- }
11174
- return Object.values(metadata).some(
11175
- (value) => !EDITABLE_TYPES.includes(typeof value)
11176
- );
11177
- }
11178
- const PROMOTION_QUERY_KEY = "promotions";
11179
- const promotionsQueryKeys = {
11180
- list: (query2) => [
11181
- PROMOTION_QUERY_KEY,
11182
- query2 ? query2 : void 0
11183
- ],
11184
- detail: (id, query2) => [
11185
- PROMOTION_QUERY_KEY,
11186
- id,
11187
- query2 ? query2 : void 0
11188
- ]
11189
- };
11190
- const usePromotions = (query2, options) => {
11191
- const { data, ...rest } = reactQuery.useQuery({
11192
- queryKey: promotionsQueryKeys.list(query2),
11193
- queryFn: async () => sdk.admin.promotion.list(query2),
11194
- ...options
11195
- });
11196
- return { ...data, ...rest };
11197
- };
11198
- const Promotions = () => {
11199
- const { id } = reactRouterDom.useParams();
11200
- const {
11201
- order: preview,
11202
- isError: isPreviewError,
11203
- error: previewError
11204
- } = useOrderPreview(id, void 0);
11205
- useInitiateOrderEdit({ preview });
11206
- const { onCancel } = useCancelOrderEdit({ preview });
11207
- if (isPreviewError) {
11208
- throw previewError;
11209
- }
11210
- const isReady = !!preview;
11211
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11212
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11213
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11214
- ] });
11215
- };
11216
- const PromotionForm = ({ preview }) => {
11217
- const { items, shipping_methods } = preview;
11218
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11219
- const [comboboxValue, setComboboxValue] = React.useState("");
11220
- const { handleSuccess } = useRouteModal();
11221
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11222
- const promoIds = getPromotionIds(items, shipping_methods);
11223
- const { promotions, isPending, isError, error } = usePromotions(
11224
- {
11225
- id: promoIds
11226
- },
11227
- {
11228
- enabled: !!promoIds.length
11229
- }
11230
- );
11231
- const comboboxData = useComboboxData({
11232
- queryKey: ["promotions", "combobox", promoIds],
11233
- queryFn: async (params) => {
11234
- return await sdk.admin.promotion.list({
11235
- ...params,
11236
- id: {
11237
- $nin: promoIds
11238
- }
11239
- });
11240
- },
11241
- getOptions: (data) => {
11242
- return data.promotions.map((promotion) => ({
11243
- label: promotion.code,
11244
- value: promotion.code
11245
- }));
11246
- }
11247
- });
11248
- const add = async (value) => {
11249
- if (!value) {
11250
- return;
11251
- }
11252
- addPromotions(
11253
- {
11254
- promo_codes: [value]
11255
- },
11256
- {
11257
- onError: (e) => {
11258
- ui.toast.error(e.message);
11259
- comboboxData.onSearchValueChange("");
11260
- setComboboxValue("");
11261
- },
11262
- onSuccess: () => {
11263
- comboboxData.onSearchValueChange("");
11264
- setComboboxValue("");
11265
- }
11266
- }
11267
- );
11268
- };
11269
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11270
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11271
- const onSubmit = async () => {
11272
- setIsSubmitting(true);
11273
- let requestSucceeded = false;
11274
- await requestOrderEdit(void 0, {
11275
- onError: (e) => {
11276
- ui.toast.error(e.message);
11277
- },
11278
- onSuccess: () => {
11279
- requestSucceeded = true;
11280
- }
11281
- });
11282
- if (!requestSucceeded) {
11283
- setIsSubmitting(false);
11284
- return;
11285
- }
11286
- await confirmOrderEdit(void 0, {
11287
- onError: (e) => {
11288
- ui.toast.error(e.message);
11289
- },
11290
- onSuccess: () => {
11291
- handleSuccess();
11292
- },
11293
- onSettled: () => {
11294
- setIsSubmitting(false);
11295
- }
11296
- });
11297
- };
11298
- if (isError) {
11299
- throw error;
11300
- }
11301
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11302
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11304
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11306
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11307
- ] }),
11308
- /* @__PURE__ */ jsxRuntime.jsx(
11309
- Combobox,
11310
- {
11311
- id: "promotion-combobox",
11312
- "aria-describedby": "promotion-combobox-hint",
11313
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11314
- fetchNextPage: comboboxData.fetchNextPage,
11315
- options: comboboxData.options,
11316
- onSearchValueChange: comboboxData.onSearchValueChange,
11317
- searchValue: comboboxData.searchValue,
11318
- disabled: comboboxData.disabled || isAddingPromotions,
11319
- onChange: add,
11320
- value: comboboxValue
11321
- }
11322
- )
11323
- ] }),
11324
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11325
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11326
- PromotionItem,
11327
- {
11328
- promotion,
11329
- orderId: preview.id,
11330
- isLoading: isPending
11331
- },
11332
- promotion.id
11333
- )) })
11334
- ] }) }),
11335
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11336
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11337
- /* @__PURE__ */ jsxRuntime.jsx(
11338
- ui.Button,
11339
- {
11340
- size: "small",
11341
- type: "submit",
11342
- isLoading: isSubmitting || isAddingPromotions,
11343
- children: "Save"
11344
- }
11345
- )
11346
- ] }) })
11347
- ] });
11348
- };
11349
- const PromotionItem = ({
11350
- promotion,
11351
- orderId,
11352
- isLoading
11353
- }) => {
11354
- var _a;
11355
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11356
- const onRemove = async () => {
11357
- removePromotions(
10910
+ const PromotionItem = ({
10911
+ promotion,
10912
+ orderId,
10913
+ isLoading
10914
+ }) => {
10915
+ var _a;
10916
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10917
+ const onRemove = async () => {
10918
+ removePromotions(
11358
10919
  {
11359
10920
  promo_codes: [promotion.code]
11360
10921
  },
@@ -11452,15 +11013,83 @@ function getPromotionIds(items, shippingMethods) {
11452
11013
  }
11453
11014
  return Array.from(promotionIds);
11454
11015
  }
11455
- const SalesChannel = () => {
11016
+ const Email = () => {
11456
11017
  const { id } = reactRouterDom.useParams();
11457
- const { draft_order, isPending, isError, error } = useDraftOrder(
11458
- id,
11459
- {
11460
- fields: "+sales_channel_id"
11461
- },
11462
- {
11463
- enabled: !!id
11018
+ const { order, isPending, isError, error } = useOrder(id, {
11019
+ fields: "+email"
11020
+ });
11021
+ if (isError) {
11022
+ throw error;
11023
+ }
11024
+ const isReady = !isPending && !!order;
11025
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11026
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
11028
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11029
+ ] }),
11030
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
11031
+ ] });
11032
+ };
11033
+ const EmailForm = ({ order }) => {
11034
+ const form = reactHookForm.useForm({
11035
+ defaultValues: {
11036
+ email: order.email ?? ""
11037
+ },
11038
+ resolver: zod.zodResolver(schema$4)
11039
+ });
11040
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11041
+ const { handleSuccess } = useRouteModal();
11042
+ const onSubmit = form.handleSubmit(async (data) => {
11043
+ await mutateAsync(
11044
+ { email: data.email },
11045
+ {
11046
+ onSuccess: () => {
11047
+ handleSuccess();
11048
+ },
11049
+ onError: (error) => {
11050
+ ui.toast.error(error.message);
11051
+ }
11052
+ }
11053
+ );
11054
+ });
11055
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11056
+ KeyboundForm,
11057
+ {
11058
+ className: "flex flex-1 flex-col overflow-hidden",
11059
+ onSubmit,
11060
+ children: [
11061
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
11062
+ Form$2.Field,
11063
+ {
11064
+ control: form.control,
11065
+ name: "email",
11066
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11067
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
11068
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11069
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11070
+ ] })
11071
+ }
11072
+ ) }),
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11074
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11075
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
+ ] }) })
11077
+ ]
11078
+ }
11079
+ ) });
11080
+ };
11081
+ const schema$4 = objectType({
11082
+ email: stringType().email()
11083
+ });
11084
+ const SalesChannel = () => {
11085
+ const { id } = reactRouterDom.useParams();
11086
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11087
+ id,
11088
+ {
11089
+ fields: "+sales_channel_id"
11090
+ },
11091
+ {
11092
+ enabled: !!id
11464
11093
  }
11465
11094
  );
11466
11095
  if (isError) {
@@ -11480,7 +11109,7 @@ const SalesChannelForm = ({ order }) => {
11480
11109
  defaultValues: {
11481
11110
  sales_channel_id: order.sales_channel_id || ""
11482
11111
  },
11483
- resolver: zod.zodResolver(schema$2)
11112
+ resolver: zod.zodResolver(schema$3)
11484
11113
  });
11485
11114
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
11115
  const { handleSuccess } = useRouteModal();
@@ -11555,129 +11184,332 @@ const SalesChannelField = ({ control, order }) => {
11555
11184
  }
11556
11185
  );
11557
11186
  };
11558
- const schema$2 = objectType({
11187
+ const schema$3 = objectType({
11559
11188
  sales_channel_id: stringType().min(1)
11560
11189
  });
11561
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11562
- const Shipping = () => {
11563
- var _a;
11190
+ const ShippingAddress = () => {
11564
11191
  const { id } = reactRouterDom.useParams();
11565
11192
  const { order, isPending, isError, error } = useOrder(id, {
11566
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11193
+ fields: "+shipping_address"
11567
11194
  });
11568
- const {
11569
- order: preview,
11570
- isPending: isPreviewPending,
11571
- isError: isPreviewError,
11572
- error: previewError
11573
- } = useOrderPreview(id);
11574
- useInitiateOrderEdit({ preview });
11575
- const { onCancel } = useCancelOrderEdit({ preview });
11576
11195
  if (isError) {
11577
11196
  throw error;
11578
11197
  }
11579
- if (isPreviewError) {
11580
- throw previewError;
11581
- }
11582
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11583
- const isReady = preview && !isPreviewPending && order && !isPending;
11584
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11585
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11587
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11588
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11589
- ] }) }) }),
11590
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11591
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11592
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11593
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11594
- ] }) });
11198
+ const isReady = !isPending && !!order;
11199
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11200
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11201
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11202
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11203
+ ] }),
11204
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11205
+ ] });
11595
11206
  };
11596
- const ShippingForm = ({ preview, order }) => {
11597
- var _a;
11598
- const { setIsOpen } = useStackedModal();
11599
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11600
- const [data, setData] = React.useState(null);
11601
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11602
- const { shipping_options } = useShippingOptions(
11603
- {
11604
- id: appliedShippingOptionIds,
11605
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11207
+ const ShippingAddressForm = ({ order }) => {
11208
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11209
+ const form = reactHookForm.useForm({
11210
+ defaultValues: {
11211
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11212
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11213
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11214
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11215
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11216
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11217
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11218
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11219
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11220
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11606
11221
  },
11607
- {
11608
- enabled: appliedShippingOptionIds.length > 0
11609
- }
11610
- );
11611
- const uniqueShippingProfiles = React.useMemo(() => {
11612
- const profiles = /* @__PURE__ */ new Map();
11613
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11614
- profiles.set(profile.id, profile);
11615
- });
11616
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11617
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11618
- });
11619
- return Array.from(profiles.values());
11620
- }, [order.items, shipping_options]);
11222
+ resolver: zod.zodResolver(schema$2)
11223
+ });
11224
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11621
11225
  const { handleSuccess } = useRouteModal();
11622
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11623
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11624
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11625
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11626
- const onSubmit = async () => {
11627
- setIsSubmitting(true);
11628
- let requestSucceeded = false;
11629
- await requestOrderEdit(void 0, {
11630
- onError: (e) => {
11631
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11632
- },
11633
- onSuccess: () => {
11634
- requestSucceeded = true;
11635
- }
11636
- });
11637
- if (!requestSucceeded) {
11638
- setIsSubmitting(false);
11639
- return;
11640
- }
11641
- await confirmOrderEdit(void 0, {
11642
- onError: (e) => {
11643
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11644
- },
11645
- onSuccess: () => {
11646
- handleSuccess();
11226
+ const onSubmit = form.handleSubmit(async (data) => {
11227
+ await mutateAsync(
11228
+ {
11229
+ shipping_address: {
11230
+ first_name: data.first_name,
11231
+ last_name: data.last_name,
11232
+ company: data.company,
11233
+ address_1: data.address_1,
11234
+ address_2: data.address_2,
11235
+ city: data.city,
11236
+ province: data.province,
11237
+ country_code: data.country_code,
11238
+ postal_code: data.postal_code,
11239
+ phone: data.phone
11240
+ }
11647
11241
  },
11648
- onSettled: () => {
11649
- setIsSubmitting(false);
11650
- }
11651
- });
11652
- };
11653
- const onKeydown = React.useCallback(
11654
- (e) => {
11655
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11656
- if (data || isSubmitting) {
11657
- return;
11242
+ {
11243
+ onSuccess: () => {
11244
+ handleSuccess();
11245
+ },
11246
+ onError: (error) => {
11247
+ ui.toast.error(error.message);
11658
11248
  }
11659
- onSubmit();
11660
11249
  }
11661
- },
11662
- [data, isSubmitting, onSubmit]
11663
- );
11664
- React.useEffect(() => {
11665
- document.addEventListener("keydown", onKeydown);
11666
- return () => {
11667
- document.removeEventListener("keydown", onKeydown);
11668
- };
11669
- }, [onKeydown]);
11670
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11671
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11672
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11673
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11674
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11675
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11677
- ] }),
11678
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11679
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11680
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11250
+ );
11251
+ });
11252
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11253
+ KeyboundForm,
11254
+ {
11255
+ className: "flex flex-1 flex-col overflow-hidden",
11256
+ onSubmit,
11257
+ children: [
11258
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11259
+ /* @__PURE__ */ jsxRuntime.jsx(
11260
+ Form$2.Field,
11261
+ {
11262
+ control: form.control,
11263
+ name: "country_code",
11264
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11265
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11266
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11267
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11268
+ ] })
11269
+ }
11270
+ ),
11271
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11272
+ /* @__PURE__ */ jsxRuntime.jsx(
11273
+ Form$2.Field,
11274
+ {
11275
+ control: form.control,
11276
+ name: "first_name",
11277
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11278
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11279
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11280
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11281
+ ] })
11282
+ }
11283
+ ),
11284
+ /* @__PURE__ */ jsxRuntime.jsx(
11285
+ Form$2.Field,
11286
+ {
11287
+ control: form.control,
11288
+ name: "last_name",
11289
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11291
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11292
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11293
+ ] })
11294
+ }
11295
+ )
11296
+ ] }),
11297
+ /* @__PURE__ */ jsxRuntime.jsx(
11298
+ Form$2.Field,
11299
+ {
11300
+ control: form.control,
11301
+ name: "company",
11302
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11304
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11305
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11306
+ ] })
11307
+ }
11308
+ ),
11309
+ /* @__PURE__ */ jsxRuntime.jsx(
11310
+ Form$2.Field,
11311
+ {
11312
+ control: form.control,
11313
+ name: "address_1",
11314
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11315
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11316
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11317
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11318
+ ] })
11319
+ }
11320
+ ),
11321
+ /* @__PURE__ */ jsxRuntime.jsx(
11322
+ Form$2.Field,
11323
+ {
11324
+ control: form.control,
11325
+ name: "address_2",
11326
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
+ ] })
11331
+ }
11332
+ ),
11333
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11334
+ /* @__PURE__ */ jsxRuntime.jsx(
11335
+ Form$2.Field,
11336
+ {
11337
+ control: form.control,
11338
+ name: "postal_code",
11339
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
+ ] })
11344
+ }
11345
+ ),
11346
+ /* @__PURE__ */ jsxRuntime.jsx(
11347
+ Form$2.Field,
11348
+ {
11349
+ control: form.control,
11350
+ name: "city",
11351
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
+ ] })
11356
+ }
11357
+ )
11358
+ ] }),
11359
+ /* @__PURE__ */ jsxRuntime.jsx(
11360
+ Form$2.Field,
11361
+ {
11362
+ control: form.control,
11363
+ name: "province",
11364
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
+ ] })
11369
+ }
11370
+ ),
11371
+ /* @__PURE__ */ jsxRuntime.jsx(
11372
+ Form$2.Field,
11373
+ {
11374
+ control: form.control,
11375
+ name: "phone",
11376
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11378
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
+ ] })
11381
+ }
11382
+ )
11383
+ ] }) }),
11384
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11385
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11386
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11387
+ ] }) })
11388
+ ]
11389
+ }
11390
+ ) });
11391
+ };
11392
+ const schema$2 = addressSchema;
11393
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11394
+ const Shipping = () => {
11395
+ var _a;
11396
+ const { id } = reactRouterDom.useParams();
11397
+ const { order, isPending, isError, error } = useOrder(id, {
11398
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11399
+ });
11400
+ const {
11401
+ order: preview,
11402
+ isPending: isPreviewPending,
11403
+ isError: isPreviewError,
11404
+ error: previewError
11405
+ } = useOrderPreview(id);
11406
+ useInitiateOrderEdit({ preview });
11407
+ const { onCancel } = useCancelOrderEdit({ preview });
11408
+ if (isError) {
11409
+ throw error;
11410
+ }
11411
+ if (isPreviewError) {
11412
+ throw previewError;
11413
+ }
11414
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11415
+ const isReady = preview && !isPreviewPending && order && !isPending;
11416
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11417
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11418
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11419
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11420
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11421
+ ] }) }) }),
11422
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11423
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11424
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11425
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11426
+ ] }) });
11427
+ };
11428
+ const ShippingForm = ({ preview, order }) => {
11429
+ var _a;
11430
+ const { setIsOpen } = useStackedModal();
11431
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11432
+ const [data, setData] = React.useState(null);
11433
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11434
+ const { shipping_options } = useShippingOptions(
11435
+ {
11436
+ id: appliedShippingOptionIds,
11437
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11438
+ },
11439
+ {
11440
+ enabled: appliedShippingOptionIds.length > 0
11441
+ }
11442
+ );
11443
+ const uniqueShippingProfiles = React.useMemo(() => {
11444
+ const profiles = /* @__PURE__ */ new Map();
11445
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11446
+ profiles.set(profile.id, profile);
11447
+ });
11448
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11449
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11450
+ });
11451
+ return Array.from(profiles.values());
11452
+ }, [order.items, shipping_options]);
11453
+ const { handleSuccess } = useRouteModal();
11454
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11455
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11456
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11457
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11458
+ const onSubmit = async () => {
11459
+ setIsSubmitting(true);
11460
+ let requestSucceeded = false;
11461
+ await requestOrderEdit(void 0, {
11462
+ onError: (e) => {
11463
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11464
+ },
11465
+ onSuccess: () => {
11466
+ requestSucceeded = true;
11467
+ }
11468
+ });
11469
+ if (!requestSucceeded) {
11470
+ setIsSubmitting(false);
11471
+ return;
11472
+ }
11473
+ await confirmOrderEdit(void 0, {
11474
+ onError: (e) => {
11475
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11476
+ },
11477
+ onSuccess: () => {
11478
+ handleSuccess();
11479
+ },
11480
+ onSettled: () => {
11481
+ setIsSubmitting(false);
11482
+ }
11483
+ });
11484
+ };
11485
+ const onKeydown = React.useCallback(
11486
+ (e) => {
11487
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11488
+ if (data || isSubmitting) {
11489
+ return;
11490
+ }
11491
+ onSubmit();
11492
+ }
11493
+ },
11494
+ [data, isSubmitting, onSubmit]
11495
+ );
11496
+ React.useEffect(() => {
11497
+ document.addEventListener("keydown", onKeydown);
11498
+ return () => {
11499
+ document.removeEventListener("keydown", onKeydown);
11500
+ };
11501
+ }, [onKeydown]);
11502
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11503
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11504
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11505
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11506
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11507
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11508
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11509
+ ] }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11681
11513
  /* @__PURE__ */ jsxRuntime.jsx(
11682
11514
  ui.Text,
11683
11515
  {
@@ -11976,598 +11808,766 @@ const ShippingForm = ({ preview, order }) => {
11976
11808
  ] }) })
11977
11809
  ] });
11978
11810
  };
11979
- const StackedModalTrigger = ({
11811
+ const StackedModalTrigger = ({
11812
+ shippingProfileId,
11813
+ shippingOption,
11814
+ shippingMethod,
11815
+ setData,
11816
+ children
11817
+ }) => {
11818
+ const { setIsOpen, getIsOpen } = useStackedModal();
11819
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11820
+ const onToggle = () => {
11821
+ if (isOpen) {
11822
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11823
+ setData(null);
11824
+ } else {
11825
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11826
+ setData({
11827
+ shippingProfileId,
11828
+ shippingOption,
11829
+ shippingMethod
11830
+ });
11831
+ }
11832
+ };
11833
+ return /* @__PURE__ */ jsxRuntime.jsx(
11834
+ ui.Button,
11835
+ {
11836
+ size: "small",
11837
+ variant: "secondary",
11838
+ onClick: onToggle,
11839
+ className: "text-ui-fg-primary shrink-0",
11840
+ children
11841
+ }
11842
+ );
11843
+ };
11844
+ const ShippingProfileForm = ({
11845
+ data,
11846
+ order,
11847
+ preview
11848
+ }) => {
11849
+ var _a, _b, _c, _d, _e, _f;
11850
+ const { setIsOpen } = useStackedModal();
11851
+ const form = reactHookForm.useForm({
11852
+ resolver: zod.zodResolver(shippingMethodSchema),
11853
+ defaultValues: {
11854
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11855
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11856
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11857
+ }
11858
+ });
11859
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11860
+ const {
11861
+ mutateAsync: updateShippingMethod,
11862
+ isPending: isUpdatingShippingMethod
11863
+ } = useDraftOrderUpdateShippingMethod(order.id);
11864
+ const onSubmit = form.handleSubmit(async (values) => {
11865
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
11866
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11867
+ return;
11868
+ }
11869
+ if (data.shippingMethod) {
11870
+ await updateShippingMethod(
11871
+ {
11872
+ method_id: data.shippingMethod.id,
11873
+ shipping_option_id: values.shipping_option_id,
11874
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11875
+ },
11876
+ {
11877
+ onError: (e) => {
11878
+ ui.toast.error(e.message);
11879
+ },
11880
+ onSuccess: () => {
11881
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11882
+ }
11883
+ }
11884
+ );
11885
+ return;
11886
+ }
11887
+ await addShippingMethod(
11888
+ {
11889
+ shipping_option_id: values.shipping_option_id,
11890
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11891
+ },
11892
+ {
11893
+ onError: (e) => {
11894
+ ui.toast.error(e.message);
11895
+ },
11896
+ onSuccess: () => {
11897
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11898
+ }
11899
+ }
11900
+ );
11901
+ });
11902
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11903
+ KeyboundForm,
11904
+ {
11905
+ className: "flex h-full flex-col overflow-hidden",
11906
+ onSubmit,
11907
+ children: [
11908
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11909
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11910
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11912
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11913
+ ] }),
11914
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11915
+ /* @__PURE__ */ jsxRuntime.jsx(
11916
+ LocationField,
11917
+ {
11918
+ control: form.control,
11919
+ setValue: form.setValue
11920
+ }
11921
+ ),
11922
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11923
+ /* @__PURE__ */ jsxRuntime.jsx(
11924
+ ShippingOptionField,
11925
+ {
11926
+ shippingProfileId: data.shippingProfileId,
11927
+ preview,
11928
+ control: form.control
11929
+ }
11930
+ ),
11931
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11932
+ /* @__PURE__ */ jsxRuntime.jsx(
11933
+ CustomAmountField,
11934
+ {
11935
+ control: form.control,
11936
+ currencyCode: order.currency_code
11937
+ }
11938
+ ),
11939
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11940
+ /* @__PURE__ */ jsxRuntime.jsx(
11941
+ ItemsPreview,
11942
+ {
11943
+ order,
11944
+ shippingProfileId: data.shippingProfileId
11945
+ }
11946
+ )
11947
+ ] }) }) }),
11948
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11949
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11950
+ /* @__PURE__ */ jsxRuntime.jsx(
11951
+ ui.Button,
11952
+ {
11953
+ size: "small",
11954
+ type: "submit",
11955
+ isLoading: isPending || isUpdatingShippingMethod,
11956
+ children: data.shippingMethod ? "Update" : "Add"
11957
+ }
11958
+ )
11959
+ ] }) })
11960
+ ]
11961
+ }
11962
+ ) }) });
11963
+ };
11964
+ const shippingMethodSchema = objectType({
11965
+ location_id: stringType(),
11966
+ shipping_option_id: stringType(),
11967
+ custom_amount: unionType([numberType(), stringType()]).optional()
11968
+ });
11969
+ const ItemsPreview = ({ order, shippingProfileId }) => {
11970
+ const matches = order.items.filter(
11971
+ (item) => {
11972
+ var _a, _b, _c;
11973
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11974
+ }
11975
+ );
11976
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11977
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11978
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11979
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11980
+ ] }) }),
11981
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11982
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11983
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11984
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11985
+ ] }),
11986
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11987
+ "div",
11988
+ {
11989
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11990
+ children: [
11991
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11992
+ /* @__PURE__ */ jsxRuntime.jsx(
11993
+ Thumbnail,
11994
+ {
11995
+ thumbnail: item.thumbnail,
11996
+ alt: item.product_title ?? void 0
11997
+ }
11998
+ ),
11999
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12000
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12001
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12002
+ /* @__PURE__ */ jsxRuntime.jsxs(
12003
+ ui.Text,
12004
+ {
12005
+ size: "small",
12006
+ leading: "compact",
12007
+ className: "text-ui-fg-subtle",
12008
+ children: [
12009
+ "(",
12010
+ item.variant_title,
12011
+ ")"
12012
+ ]
12013
+ }
12014
+ )
12015
+ ] }),
12016
+ /* @__PURE__ */ jsxRuntime.jsx(
12017
+ ui.Text,
12018
+ {
12019
+ size: "small",
12020
+ leading: "compact",
12021
+ className: "text-ui-fg-subtle",
12022
+ children: item.variant_sku
12023
+ }
12024
+ )
12025
+ ] })
12026
+ ] }),
12027
+ /* @__PURE__ */ jsxRuntime.jsxs(
12028
+ ui.Text,
12029
+ {
12030
+ size: "small",
12031
+ leading: "compact",
12032
+ className: "text-ui-fg-subtle",
12033
+ children: [
12034
+ item.quantity,
12035
+ "x"
12036
+ ]
12037
+ }
12038
+ )
12039
+ ]
12040
+ },
12041
+ item.id
12042
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12043
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12044
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12045
+ 'No items found for "',
12046
+ query,
12047
+ '".'
12048
+ ] })
12049
+ ] }) })
12050
+ ] })
12051
+ ] });
12052
+ };
12053
+ const LocationField = ({ control, setValue }) => {
12054
+ const locations = useComboboxData({
12055
+ queryKey: ["locations"],
12056
+ queryFn: async (params) => {
12057
+ return await sdk.admin.stockLocation.list(params);
12058
+ },
12059
+ getOptions: (data) => {
12060
+ return data.stock_locations.map((location) => ({
12061
+ label: location.name,
12062
+ value: location.id
12063
+ }));
12064
+ }
12065
+ });
12066
+ return /* @__PURE__ */ jsxRuntime.jsx(
12067
+ Form$2.Field,
12068
+ {
12069
+ control,
12070
+ name: "location_id",
12071
+ render: ({ field: { onChange, ...field } }) => {
12072
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12073
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12074
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12075
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12076
+ ] }),
12077
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12078
+ Combobox,
12079
+ {
12080
+ options: locations.options,
12081
+ fetchNextPage: locations.fetchNextPage,
12082
+ isFetchingNextPage: locations.isFetchingNextPage,
12083
+ searchValue: locations.searchValue,
12084
+ onSearchValueChange: locations.onSearchValueChange,
12085
+ placeholder: "Select location",
12086
+ onChange: (value) => {
12087
+ setValue("shipping_option_id", "", {
12088
+ shouldDirty: true,
12089
+ shouldTouch: true
12090
+ });
12091
+ onChange(value);
12092
+ },
12093
+ ...field
12094
+ }
12095
+ ) })
12096
+ ] }) });
12097
+ }
12098
+ }
12099
+ );
12100
+ };
12101
+ const ShippingOptionField = ({
11980
12102
  shippingProfileId,
11981
- shippingOption,
11982
- shippingMethod,
11983
- setData,
11984
- children
12103
+ preview,
12104
+ control
11985
12105
  }) => {
11986
- const { setIsOpen, getIsOpen } = useStackedModal();
11987
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11988
- const onToggle = () => {
11989
- if (isOpen) {
11990
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11991
- setData(null);
11992
- } else {
11993
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11994
- setData({
11995
- shippingProfileId,
11996
- shippingOption,
11997
- shippingMethod
12106
+ var _a;
12107
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12108
+ const shippingOptions = useComboboxData({
12109
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12110
+ queryFn: async (params) => {
12111
+ return await sdk.admin.shippingOption.list({
12112
+ ...params,
12113
+ stock_location_id: locationId,
12114
+ shipping_profile_id: shippingProfileId
11998
12115
  });
11999
- }
12000
- };
12116
+ },
12117
+ getOptions: (data) => {
12118
+ return data.shipping_options.map((option) => {
12119
+ var _a2;
12120
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12121
+ (r) => r.attribute === "is_return" && r.value === "true"
12122
+ )) {
12123
+ return void 0;
12124
+ }
12125
+ return {
12126
+ label: option.name,
12127
+ value: option.id
12128
+ };
12129
+ }).filter(Boolean);
12130
+ },
12131
+ enabled: !!locationId && !!shippingProfileId,
12132
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12133
+ });
12134
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12001
12135
  return /* @__PURE__ */ jsxRuntime.jsx(
12002
- ui.Button,
12136
+ Form$2.Field,
12003
12137
  {
12004
- size: "small",
12005
- variant: "secondary",
12006
- onClick: onToggle,
12007
- className: "text-ui-fg-primary shrink-0",
12008
- children
12138
+ control,
12139
+ name: "shipping_option_id",
12140
+ render: ({ field }) => {
12141
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12142
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12143
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12144
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12145
+ ] }),
12146
+ /* @__PURE__ */ jsxRuntime.jsx(
12147
+ ConditionalTooltip,
12148
+ {
12149
+ content: tooltipContent,
12150
+ showTooltip: !locationId || !shippingProfileId,
12151
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12152
+ Combobox,
12153
+ {
12154
+ options: shippingOptions.options,
12155
+ fetchNextPage: shippingOptions.fetchNextPage,
12156
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12157
+ searchValue: shippingOptions.searchValue,
12158
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12159
+ placeholder: "Select shipping option",
12160
+ ...field,
12161
+ disabled: !locationId || !shippingProfileId
12162
+ }
12163
+ ) }) })
12164
+ }
12165
+ )
12166
+ ] }) });
12167
+ }
12009
12168
  }
12010
12169
  );
12011
12170
  };
12012
- const ShippingProfileForm = ({
12013
- data,
12014
- order,
12015
- preview
12171
+ const CustomAmountField = ({
12172
+ control,
12173
+ currencyCode
12016
12174
  }) => {
12017
- var _a, _b, _c, _d, _e, _f;
12018
- const { setIsOpen } = useStackedModal();
12175
+ return /* @__PURE__ */ jsxRuntime.jsx(
12176
+ Form$2.Field,
12177
+ {
12178
+ control,
12179
+ name: "custom_amount",
12180
+ render: ({ field: { onChange, ...field } }) => {
12181
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12182
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12183
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12184
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12185
+ ] }),
12186
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12187
+ ui.CurrencyInput,
12188
+ {
12189
+ ...field,
12190
+ onValueChange: (value) => onChange(value),
12191
+ symbol: getNativeSymbol(currencyCode),
12192
+ code: currencyCode
12193
+ }
12194
+ ) })
12195
+ ] });
12196
+ }
12197
+ }
12198
+ );
12199
+ };
12200
+ const InlineTip = React.forwardRef(
12201
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
12202
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12203
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12204
+ "div",
12205
+ {
12206
+ ref,
12207
+ className: ui.clx(
12208
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12209
+ className
12210
+ ),
12211
+ ...props,
12212
+ children: [
12213
+ /* @__PURE__ */ jsxRuntime.jsx(
12214
+ "div",
12215
+ {
12216
+ role: "presentation",
12217
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12218
+ "bg-ui-tag-orange-icon": variant === "warning"
12219
+ })
12220
+ }
12221
+ ),
12222
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12223
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12224
+ labelValue,
12225
+ ":"
12226
+ ] }),
12227
+ " ",
12228
+ children
12229
+ ] })
12230
+ ]
12231
+ }
12232
+ );
12233
+ }
12234
+ );
12235
+ InlineTip.displayName = "InlineTip";
12236
+ const MetadataFieldSchema = objectType({
12237
+ key: stringType(),
12238
+ disabled: booleanType().optional(),
12239
+ value: anyType()
12240
+ });
12241
+ const MetadataSchema = objectType({
12242
+ metadata: arrayType(MetadataFieldSchema)
12243
+ });
12244
+ const Metadata = () => {
12245
+ const { id } = reactRouterDom.useParams();
12246
+ const { order, isPending, isError, error } = useOrder(id, {
12247
+ fields: "metadata"
12248
+ });
12249
+ if (isError) {
12250
+ throw error;
12251
+ }
12252
+ const isReady = !isPending && !!order;
12253
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12255
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12256
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12257
+ ] }),
12258
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12259
+ ] });
12260
+ };
12261
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12262
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12263
+ const MetadataForm = ({ orderId, metadata }) => {
12264
+ const { handleSuccess } = useRouteModal();
12265
+ const hasUneditableRows = getHasUneditableRows(metadata);
12266
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12019
12267
  const form = reactHookForm.useForm({
12020
- resolver: zod.zodResolver(shippingMethodSchema),
12021
12268
  defaultValues: {
12022
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12023
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12024
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12025
- }
12269
+ metadata: getDefaultValues(metadata)
12270
+ },
12271
+ resolver: zod.zodResolver(MetadataSchema)
12026
12272
  });
12027
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12028
- const {
12029
- mutateAsync: updateShippingMethod,
12030
- isPending: isUpdatingShippingMethod
12031
- } = useDraftOrderUpdateShippingMethod(order.id);
12032
- const onSubmit = form.handleSubmit(async (values) => {
12033
- if (isEqual__default.default(values, form.formState.defaultValues)) {
12034
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12035
- return;
12036
- }
12037
- if (data.shippingMethod) {
12038
- await updateShippingMethod(
12039
- {
12040
- method_id: data.shippingMethod.id,
12041
- shipping_option_id: values.shipping_option_id,
12042
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12043
- },
12044
- {
12045
- onError: (e) => {
12046
- ui.toast.error(e.message);
12047
- },
12048
- onSuccess: () => {
12049
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12050
- }
12051
- }
12052
- );
12053
- return;
12054
- }
12055
- await addShippingMethod(
12056
- {
12057
- shipping_option_id: values.shipping_option_id,
12058
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12059
- },
12273
+ const handleSubmit = form.handleSubmit(async (data) => {
12274
+ const parsedData = parseValues(data);
12275
+ await mutateAsync(
12276
+ {
12277
+ metadata: parsedData
12278
+ },
12060
12279
  {
12061
- onError: (e) => {
12062
- ui.toast.error(e.message);
12063
- },
12064
12280
  onSuccess: () => {
12065
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12281
+ ui.toast.success("Metadata updated");
12282
+ handleSuccess();
12283
+ },
12284
+ onError: (error) => {
12285
+ ui.toast.error(error.message);
12066
12286
  }
12067
12287
  }
12068
12288
  );
12069
12289
  });
12070
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12290
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
12291
+ control: form.control,
12292
+ name: "metadata"
12293
+ });
12294
+ function deleteRow(index) {
12295
+ remove(index);
12296
+ if (fields.length === 1) {
12297
+ insert(0, {
12298
+ key: "",
12299
+ value: "",
12300
+ disabled: false
12301
+ });
12302
+ }
12303
+ }
12304
+ function insertRow(index, position) {
12305
+ insert(index + (position === "above" ? 0 : 1), {
12306
+ key: "",
12307
+ value: "",
12308
+ disabled: false
12309
+ });
12310
+ }
12311
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12071
12312
  KeyboundForm,
12072
12313
  {
12073
- className: "flex h-full flex-col overflow-hidden",
12074
- onSubmit,
12314
+ onSubmit: handleSubmit,
12315
+ className: "flex flex-1 flex-col overflow-hidden",
12075
12316
  children: [
12076
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12077
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12078
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12079
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12080
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12081
- ] }),
12082
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12083
- /* @__PURE__ */ jsxRuntime.jsx(
12084
- LocationField,
12085
- {
12086
- control: form.control,
12087
- setValue: form.setValue
12088
- }
12089
- ),
12090
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12091
- /* @__PURE__ */ jsxRuntime.jsx(
12092
- ShippingOptionField,
12093
- {
12094
- shippingProfileId: data.shippingProfileId,
12095
- preview,
12096
- control: form.control
12097
- }
12098
- ),
12099
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12100
- /* @__PURE__ */ jsxRuntime.jsx(
12101
- CustomAmountField,
12102
- {
12103
- control: form.control,
12104
- currencyCode: order.currency_code
12105
- }
12106
- ),
12107
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12108
- /* @__PURE__ */ jsxRuntime.jsx(
12109
- ItemsPreview,
12110
- {
12111
- order,
12112
- shippingProfileId: data.shippingProfileId
12113
- }
12114
- )
12115
- ] }) }) }),
12116
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12117
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12118
- /* @__PURE__ */ jsxRuntime.jsx(
12119
- ui.Button,
12120
- {
12121
- size: "small",
12122
- type: "submit",
12123
- isLoading: isPending || isUpdatingShippingMethod,
12124
- children: data.shippingMethod ? "Update" : "Add"
12125
- }
12126
- )
12127
- ] }) })
12128
- ]
12129
- }
12130
- ) }) });
12131
- };
12132
- const shippingMethodSchema = objectType({
12133
- location_id: stringType(),
12134
- shipping_option_id: stringType(),
12135
- custom_amount: unionType([numberType(), stringType()]).optional()
12136
- });
12137
- const ItemsPreview = ({ order, shippingProfileId }) => {
12138
- const matches = order.items.filter(
12139
- (item) => {
12140
- var _a, _b, _c;
12141
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12142
- }
12143
- );
12144
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12145
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12146
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12147
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12148
- ] }) }),
12149
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12150
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12151
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12152
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12153
- ] }),
12154
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12155
- "div",
12156
- {
12157
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12158
- children: [
12159
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12160
- /* @__PURE__ */ jsxRuntime.jsx(
12161
- Thumbnail,
12162
- {
12163
- thumbnail: item.thumbnail,
12164
- alt: item.product_title ?? void 0
12165
- }
12166
- ),
12167
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12168
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12169
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12170
- /* @__PURE__ */ jsxRuntime.jsxs(
12171
- ui.Text,
12172
- {
12173
- size: "small",
12174
- leading: "compact",
12175
- className: "text-ui-fg-subtle",
12176
- children: [
12177
- "(",
12178
- item.variant_title,
12179
- ")"
12180
- ]
12181
- }
12182
- )
12183
- ] }),
12184
- /* @__PURE__ */ jsxRuntime.jsx(
12185
- ui.Text,
12186
- {
12187
- size: "small",
12188
- leading: "compact",
12189
- className: "text-ui-fg-subtle",
12190
- children: item.variant_sku
12191
- }
12192
- )
12193
- ] })
12317
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12318
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12320
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
12321
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12194
12322
  ] }),
12195
- /* @__PURE__ */ jsxRuntime.jsxs(
12196
- ui.Text,
12197
- {
12198
- size: "small",
12199
- leading: "compact",
12200
- className: "text-ui-fg-subtle",
12201
- children: [
12202
- item.quantity,
12203
- "x"
12204
- ]
12323
+ fields.map((field, index) => {
12324
+ const isDisabled = field.disabled || false;
12325
+ let placeholder = "-";
12326
+ if (typeof field.value === "object") {
12327
+ placeholder = "{ ... }";
12205
12328
  }
12206
- )
12207
- ]
12208
- },
12209
- item.id
12210
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12211
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12212
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12213
- 'No items found for "',
12214
- query,
12215
- '".'
12216
- ] })
12217
- ] }) })
12218
- ] })
12219
- ] });
12220
- };
12221
- const LocationField = ({ control, setValue }) => {
12222
- const locations = useComboboxData({
12223
- queryKey: ["locations"],
12224
- queryFn: async (params) => {
12225
- return await sdk.admin.stockLocation.list(params);
12226
- },
12227
- getOptions: (data) => {
12228
- return data.stock_locations.map((location) => ({
12229
- label: location.name,
12230
- value: location.id
12231
- }));
12232
- }
12233
- });
12234
- return /* @__PURE__ */ jsxRuntime.jsx(
12235
- Form$2.Field,
12236
- {
12237
- control,
12238
- name: "location_id",
12239
- render: ({ field: { onChange, ...field } }) => {
12240
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12241
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12242
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12243
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12329
+ if (Array.isArray(field.value)) {
12330
+ placeholder = "[ ... ]";
12331
+ }
12332
+ return /* @__PURE__ */ jsxRuntime.jsx(
12333
+ ConditionalTooltip,
12334
+ {
12335
+ showTooltip: isDisabled,
12336
+ content: "This row is disabled because it contains non-primitive data.",
12337
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12338
+ /* @__PURE__ */ jsxRuntime.jsxs(
12339
+ "div",
12340
+ {
12341
+ className: ui.clx("grid grid-cols-2 divide-x", {
12342
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
12343
+ }),
12344
+ children: [
12345
+ /* @__PURE__ */ jsxRuntime.jsx(
12346
+ Form$2.Field,
12347
+ {
12348
+ control: form.control,
12349
+ name: `metadata.${index}.key`,
12350
+ render: ({ field: field2 }) => {
12351
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12352
+ GridInput,
12353
+ {
12354
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
12355
+ ...field2,
12356
+ disabled: isDisabled,
12357
+ placeholder: "Key"
12358
+ }
12359
+ ) }) });
12360
+ }
12361
+ }
12362
+ ),
12363
+ /* @__PURE__ */ jsxRuntime.jsx(
12364
+ Form$2.Field,
12365
+ {
12366
+ control: form.control,
12367
+ name: `metadata.${index}.value`,
12368
+ render: ({ field: { value, ...field2 } }) => {
12369
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12370
+ GridInput,
12371
+ {
12372
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
12373
+ ...field2,
12374
+ value: isDisabled ? placeholder : value,
12375
+ disabled: isDisabled,
12376
+ placeholder: "Value"
12377
+ }
12378
+ ) }) });
12379
+ }
12380
+ }
12381
+ )
12382
+ ]
12383
+ }
12384
+ ),
12385
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12386
+ /* @__PURE__ */ jsxRuntime.jsx(
12387
+ ui.DropdownMenu.Trigger,
12388
+ {
12389
+ className: ui.clx(
12390
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12391
+ {
12392
+ hidden: isDisabled
12393
+ }
12394
+ ),
12395
+ disabled: isDisabled,
12396
+ asChild: true,
12397
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12398
+ }
12399
+ ),
12400
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12401
+ /* @__PURE__ */ jsxRuntime.jsxs(
12402
+ ui.DropdownMenu.Item,
12403
+ {
12404
+ className: "gap-x-2",
12405
+ onClick: () => insertRow(index, "above"),
12406
+ children: [
12407
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12408
+ "Insert row above"
12409
+ ]
12410
+ }
12411
+ ),
12412
+ /* @__PURE__ */ jsxRuntime.jsxs(
12413
+ ui.DropdownMenu.Item,
12414
+ {
12415
+ className: "gap-x-2",
12416
+ onClick: () => insertRow(index, "below"),
12417
+ children: [
12418
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12419
+ "Insert row below"
12420
+ ]
12421
+ }
12422
+ ),
12423
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12424
+ /* @__PURE__ */ jsxRuntime.jsxs(
12425
+ ui.DropdownMenu.Item,
12426
+ {
12427
+ className: "gap-x-2",
12428
+ onClick: () => deleteRow(index),
12429
+ children: [
12430
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12431
+ "Delete row"
12432
+ ]
12433
+ }
12434
+ )
12435
+ ] })
12436
+ ] })
12437
+ ] })
12438
+ },
12439
+ field.id
12440
+ );
12441
+ })
12244
12442
  ] }),
12245
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12246
- Combobox,
12247
- {
12248
- options: locations.options,
12249
- fetchNextPage: locations.fetchNextPage,
12250
- isFetchingNextPage: locations.isFetchingNextPage,
12251
- searchValue: locations.searchValue,
12252
- onSearchValueChange: locations.onSearchValueChange,
12253
- placeholder: "Select location",
12254
- onChange: (value) => {
12255
- setValue("shipping_option_id", "", {
12256
- shouldDirty: true,
12257
- shouldTouch: true
12258
- });
12259
- onChange(value);
12260
- },
12261
- ...field
12262
- }
12263
- ) })
12264
- ] }) });
12265
- }
12443
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
12444
+ ] }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12446
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12447
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12448
+ ] }) })
12449
+ ]
12266
12450
  }
12267
- );
12451
+ ) });
12268
12452
  };
12269
- const ShippingOptionField = ({
12270
- shippingProfileId,
12271
- preview,
12272
- control
12273
- }) => {
12274
- var _a;
12275
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12276
- const shippingOptions = useComboboxData({
12277
- queryKey: ["shipping_options", locationId, shippingProfileId],
12278
- queryFn: async (params) => {
12279
- return await sdk.admin.shippingOption.list({
12280
- ...params,
12281
- stock_location_id: locationId,
12282
- shipping_profile_id: shippingProfileId
12283
- });
12284
- },
12285
- getOptions: (data) => {
12286
- return data.shipping_options.map((option) => {
12287
- var _a2;
12288
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12289
- (r) => r.attribute === "is_return" && r.value === "true"
12290
- )) {
12291
- return void 0;
12292
- }
12293
- return {
12294
- label: option.name,
12295
- value: option.id
12296
- };
12297
- }).filter(Boolean);
12298
- },
12299
- enabled: !!locationId && !!shippingProfileId,
12300
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12301
- });
12302
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12453
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12303
12454
  return /* @__PURE__ */ jsxRuntime.jsx(
12304
- Form$2.Field,
12455
+ "input",
12305
12456
  {
12306
- control,
12307
- name: "shipping_option_id",
12308
- render: ({ field }) => {
12309
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12310
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12311
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12312
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12313
- ] }),
12314
- /* @__PURE__ */ jsxRuntime.jsx(
12315
- ConditionalTooltip,
12316
- {
12317
- content: tooltipContent,
12318
- showTooltip: !locationId || !shippingProfileId,
12319
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12320
- Combobox,
12321
- {
12322
- options: shippingOptions.options,
12323
- fetchNextPage: shippingOptions.fetchNextPage,
12324
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12325
- searchValue: shippingOptions.searchValue,
12326
- onSearchValueChange: shippingOptions.onSearchValueChange,
12327
- placeholder: "Select shipping option",
12328
- ...field,
12329
- disabled: !locationId || !shippingProfileId
12330
- }
12331
- ) }) })
12332
- }
12333
- )
12334
- ] }) });
12335
- }
12457
+ ref,
12458
+ ...props,
12459
+ autoComplete: "off",
12460
+ className: ui.clx(
12461
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
12462
+ className
12463
+ )
12336
12464
  }
12337
12465
  );
12466
+ });
12467
+ GridInput.displayName = "MetadataForm.GridInput";
12468
+ const PlaceholderInner = () => {
12469
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12470
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12472
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12473
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12474
+ ] }) })
12475
+ ] });
12338
12476
  };
12339
- const CustomAmountField = ({
12340
- control,
12341
- currencyCode
12342
- }) => {
12343
- return /* @__PURE__ */ jsxRuntime.jsx(
12344
- Form$2.Field,
12345
- {
12346
- control,
12347
- name: "custom_amount",
12348
- render: ({ field: { onChange, ...field } }) => {
12349
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12350
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12353
- ] }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12355
- ui.CurrencyInput,
12356
- {
12357
- ...field,
12358
- onValueChange: (value) => onChange(value),
12359
- symbol: getNativeSymbol(currencyCode),
12360
- code: currencyCode
12361
- }
12362
- ) })
12363
- ] });
12477
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
12478
+ function getDefaultValues(metadata) {
12479
+ if (!metadata || !Object.keys(metadata).length) {
12480
+ return [
12481
+ {
12482
+ key: "",
12483
+ value: "",
12484
+ disabled: false
12485
+ }
12486
+ ];
12487
+ }
12488
+ return Object.entries(metadata).map(([key, value]) => {
12489
+ if (!EDITABLE_TYPES.includes(typeof value)) {
12490
+ return {
12491
+ key,
12492
+ value,
12493
+ disabled: true
12494
+ };
12495
+ }
12496
+ let stringValue = value;
12497
+ if (typeof value !== "string") {
12498
+ stringValue = JSON.stringify(value);
12499
+ }
12500
+ return {
12501
+ key,
12502
+ value: stringValue,
12503
+ original_key: key
12504
+ };
12505
+ });
12506
+ }
12507
+ function parseValues(values) {
12508
+ const metadata = values.metadata;
12509
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
12510
+ if (isEmpty) {
12511
+ return null;
12512
+ }
12513
+ const update = {};
12514
+ metadata.forEach((field) => {
12515
+ let key = field.key;
12516
+ let value = field.value;
12517
+ const disabled = field.disabled;
12518
+ if (!key || !value) {
12519
+ return;
12520
+ }
12521
+ if (disabled) {
12522
+ update[key] = value;
12523
+ return;
12524
+ }
12525
+ key = key.trim();
12526
+ value = value.trim();
12527
+ if (value === "true") {
12528
+ update[key] = true;
12529
+ } else if (value === "false") {
12530
+ update[key] = false;
12531
+ } else {
12532
+ const parsedNumber = parseFloat(value);
12533
+ if (!isNaN(parsedNumber)) {
12534
+ update[key] = parsedNumber;
12535
+ } else {
12536
+ update[key] = value;
12364
12537
  }
12365
12538
  }
12366
- );
12367
- };
12368
- const ShippingAddress = () => {
12369
- const { id } = reactRouterDom.useParams();
12370
- const { order, isPending, isError, error } = useOrder(id, {
12371
- fields: "+shipping_address"
12372
12539
  });
12373
- if (isError) {
12374
- throw error;
12540
+ return update;
12541
+ }
12542
+ function getHasUneditableRows(metadata) {
12543
+ if (!metadata) {
12544
+ return false;
12375
12545
  }
12376
- const isReady = !isPending && !!order;
12546
+ return Object.values(metadata).some(
12547
+ (value) => !EDITABLE_TYPES.includes(typeof value)
12548
+ );
12549
+ }
12550
+ const CustomItems = () => {
12377
12551
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12378
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12380
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12381
- ] }),
12382
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12552
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
12553
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12383
12554
  ] });
12384
12555
  };
12385
- const ShippingAddressForm = ({ order }) => {
12386
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12556
+ const CustomItemsForm = () => {
12387
12557
  const form = reactHookForm.useForm({
12388
- defaultValues: {
12389
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12390
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12391
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12392
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12393
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12394
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12395
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12396
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12397
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12398
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12399
- },
12400
12558
  resolver: zod.zodResolver(schema$1)
12401
12559
  });
12402
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12403
- const { handleSuccess } = useRouteModal();
12404
- const onSubmit = form.handleSubmit(async (data) => {
12405
- await mutateAsync(
12406
- {
12407
- shipping_address: {
12408
- first_name: data.first_name,
12409
- last_name: data.last_name,
12410
- company: data.company,
12411
- address_1: data.address_1,
12412
- address_2: data.address_2,
12413
- city: data.city,
12414
- province: data.province,
12415
- country_code: data.country_code,
12416
- postal_code: data.postal_code,
12417
- phone: data.phone
12418
- }
12419
- },
12420
- {
12421
- onSuccess: () => {
12422
- handleSuccess();
12423
- },
12424
- onError: (error) => {
12425
- ui.toast.error(error.message);
12426
- }
12427
- }
12428
- );
12429
- });
12430
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12431
- KeyboundForm,
12432
- {
12433
- className: "flex flex-1 flex-col overflow-hidden",
12434
- onSubmit,
12435
- children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(
12438
- Form$2.Field,
12439
- {
12440
- control: form.control,
12441
- name: "country_code",
12442
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12443
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12446
- ] })
12447
- }
12448
- ),
12449
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12450
- /* @__PURE__ */ jsxRuntime.jsx(
12451
- Form$2.Field,
12452
- {
12453
- control: form.control,
12454
- name: "first_name",
12455
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
- ] })
12460
- }
12461
- ),
12462
- /* @__PURE__ */ jsxRuntime.jsx(
12463
- Form$2.Field,
12464
- {
12465
- control: form.control,
12466
- name: "last_name",
12467
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12468
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12471
- ] })
12472
- }
12473
- )
12474
- ] }),
12475
- /* @__PURE__ */ jsxRuntime.jsx(
12476
- Form$2.Field,
12477
- {
12478
- control: form.control,
12479
- name: "company",
12480
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
- ] })
12485
- }
12486
- ),
12487
- /* @__PURE__ */ jsxRuntime.jsx(
12488
- Form$2.Field,
12489
- {
12490
- control: form.control,
12491
- name: "address_1",
12492
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
- ] })
12497
- }
12498
- ),
12499
- /* @__PURE__ */ jsxRuntime.jsx(
12500
- Form$2.Field,
12501
- {
12502
- control: form.control,
12503
- name: "address_2",
12504
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12505
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12508
- ] })
12509
- }
12510
- ),
12511
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12512
- /* @__PURE__ */ jsxRuntime.jsx(
12513
- Form$2.Field,
12514
- {
12515
- control: form.control,
12516
- name: "postal_code",
12517
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
- ] })
12522
- }
12523
- ),
12524
- /* @__PURE__ */ jsxRuntime.jsx(
12525
- Form$2.Field,
12526
- {
12527
- control: form.control,
12528
- name: "city",
12529
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12533
- ] })
12534
- }
12535
- )
12536
- ] }),
12537
- /* @__PURE__ */ jsxRuntime.jsx(
12538
- Form$2.Field,
12539
- {
12540
- control: form.control,
12541
- name: "province",
12542
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
- ] })
12547
- }
12548
- ),
12549
- /* @__PURE__ */ jsxRuntime.jsx(
12550
- Form$2.Field,
12551
- {
12552
- control: form.control,
12553
- name: "phone",
12554
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12558
- ] })
12559
- }
12560
- )
12561
- ] }) }),
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12565
- ] }) })
12566
- ]
12567
- }
12568
- ) });
12560
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12561
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
12565
+ ] }) })
12566
+ ] }) });
12569
12567
  };
12570
- const schema$1 = addressSchema;
12568
+ const schema$1 = objectType({
12569
+ email: stringType().email()
12570
+ });
12571
12571
  const TransferOwnership = () => {
12572
12572
  const { id } = reactRouterDom.useParams();
12573
12573
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13068,37 +13068,37 @@ const routeModule = {
13068
13068
  Component: BillingAddress,
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
- {
13072
- Component: CustomItems,
13073
- path: "/draft-orders/:id/custom-items"
13074
- },
13075
- {
13076
- Component: Email,
13077
- path: "/draft-orders/:id/email"
13078
- },
13079
13071
  {
13080
13072
  Component: Items,
13081
13073
  path: "/draft-orders/:id/items"
13082
13074
  },
13083
- {
13084
- Component: Metadata,
13085
- path: "/draft-orders/:id/metadata"
13086
- },
13087
13075
  {
13088
13076
  Component: Promotions,
13089
13077
  path: "/draft-orders/:id/promotions"
13090
13078
  },
13079
+ {
13080
+ Component: Email,
13081
+ path: "/draft-orders/:id/email"
13082
+ },
13091
13083
  {
13092
13084
  Component: SalesChannel,
13093
13085
  path: "/draft-orders/:id/sales-channel"
13094
13086
  },
13087
+ {
13088
+ Component: ShippingAddress,
13089
+ path: "/draft-orders/:id/shipping-address"
13090
+ },
13095
13091
  {
13096
13092
  Component: Shipping,
13097
13093
  path: "/draft-orders/:id/shipping"
13098
13094
  },
13099
13095
  {
13100
- Component: ShippingAddress,
13101
- path: "/draft-orders/:id/shipping-address"
13096
+ Component: Metadata,
13097
+ path: "/draft-orders/:id/metadata"
13098
+ },
13099
+ {
13100
+ Component: CustomItems,
13101
+ path: "/draft-orders/:id/custom-items"
13102
13102
  },
13103
13103
  {
13104
13104
  Component: TransferOwnership,
@@ -13114,7 +13114,9 @@ const menuItemModule = {
13114
13114
  label: config.label,
13115
13115
  icon: void 0,
13116
13116
  path: "/draft-orders",
13117
- nested: "/orders"
13117
+ nested: "/orders",
13118
+ rank: void 0,
13119
+ translationNs: void 0
13118
13120
  }
13119
13121
  ]
13120
13122
  };