@medusajs/draft-order 2.10.2-snapshot-20250901132949 → 2.10.2-snapshot-20250902104934

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.
@@ -9750,6 +9750,27 @@ const BillingAddressForm = ({ order }) => {
9750
9750
  ) });
9751
9751
  };
9752
9752
  const schema$5 = addressSchema;
9753
+ const CustomItems = () => {
9754
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9756
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9757
+ ] });
9758
+ };
9759
+ const CustomItemsForm = () => {
9760
+ const form = reactHookForm.useForm({
9761
+ resolver: zod.zodResolver(schema$4)
9762
+ });
9763
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9764
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9765
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9766
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9767
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9768
+ ] }) })
9769
+ ] }) });
9770
+ };
9771
+ const schema$4 = objectType({
9772
+ email: stringType().email()
9773
+ });
9753
9774
  const Email = () => {
9754
9775
  const { id } = reactRouterDom.useParams();
9755
9776
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9772,7 +9793,7 @@ const EmailForm = ({ order }) => {
9772
9793
  defaultValues: {
9773
9794
  email: order.email ?? ""
9774
9795
  },
9775
- resolver: zod.zodResolver(schema$4)
9796
+ resolver: zod.zodResolver(schema$3)
9776
9797
  });
9777
9798
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9778
9799
  const { handleSuccess } = useRouteModal();
@@ -9815,27 +9836,6 @@ const EmailForm = ({ order }) => {
9815
9836
  }
9816
9837
  ) });
9817
9838
  };
9818
- const schema$4 = objectType({
9819
- email: stringType().email()
9820
- });
9821
- const CustomItems = () => {
9822
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9823
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9824
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9825
- ] });
9826
- };
9827
- const CustomItemsForm = () => {
9828
- const form = reactHookForm.useForm({
9829
- resolver: zod.zodResolver(schema$3)
9830
- });
9831
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9833
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9834
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9835
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9836
- ] }) })
9837
- ] }) });
9838
- };
9839
9839
  const schema$3 = objectType({
9840
9840
  email: stringType().email()
9841
9841
  });
@@ -10813,543 +10813,193 @@ const customItemSchema = objectType({
10813
10813
  quantity: numberType(),
10814
10814
  unit_price: unionType([numberType(), stringType()])
10815
10815
  });
10816
- const InlineTip = React.forwardRef(
10817
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10818
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10819
- return /* @__PURE__ */ jsxRuntime.jsxs(
10820
- "div",
10821
- {
10822
- ref,
10823
- className: ui.clx(
10824
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10825
- className
10826
- ),
10827
- ...props,
10828
- children: [
10829
- /* @__PURE__ */ jsxRuntime.jsx(
10830
- "div",
10831
- {
10832
- role: "presentation",
10833
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10834
- "bg-ui-tag-orange-icon": variant === "warning"
10835
- })
10836
- }
10837
- ),
10838
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10839
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10840
- labelValue,
10841
- ":"
10842
- ] }),
10843
- " ",
10844
- children
10845
- ] })
10846
- ]
10847
- }
10848
- );
10849
- }
10850
- );
10851
- InlineTip.displayName = "InlineTip";
10852
- const MetadataFieldSchema = objectType({
10853
- key: stringType(),
10854
- disabled: booleanType().optional(),
10855
- value: anyType()
10856
- });
10857
- const MetadataSchema = objectType({
10858
- metadata: arrayType(MetadataFieldSchema)
10859
- });
10860
- const Metadata = () => {
10861
- const { id } = reactRouterDom.useParams();
10862
- const { order, isPending, isError, error } = useOrder(id, {
10863
- fields: "metadata"
10816
+ const PROMOTION_QUERY_KEY = "promotions";
10817
+ const promotionsQueryKeys = {
10818
+ list: (query2) => [
10819
+ PROMOTION_QUERY_KEY,
10820
+ query2 ? query2 : void 0
10821
+ ],
10822
+ detail: (id, query2) => [
10823
+ PROMOTION_QUERY_KEY,
10824
+ id,
10825
+ query2 ? query2 : void 0
10826
+ ]
10827
+ };
10828
+ const usePromotions = (query2, options) => {
10829
+ const { data, ...rest } = reactQuery.useQuery({
10830
+ queryKey: promotionsQueryKeys.list(query2),
10831
+ queryFn: async () => sdk.admin.promotion.list(query2),
10832
+ ...options
10864
10833
  });
10865
- if (isError) {
10866
- throw error;
10834
+ return { ...data, ...rest };
10835
+ };
10836
+ const Promotions = () => {
10837
+ const { id } = reactRouterDom.useParams();
10838
+ const {
10839
+ order: preview,
10840
+ isError: isPreviewError,
10841
+ error: previewError
10842
+ } = useOrderPreview(id, void 0);
10843
+ useInitiateOrderEdit({ preview });
10844
+ const { onCancel } = useCancelOrderEdit({ preview });
10845
+ if (isPreviewError) {
10846
+ throw previewError;
10867
10847
  }
10868
- const isReady = !isPending && !!order;
10869
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10870
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10871
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10872
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10873
- ] }),
10874
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10848
+ const isReady = !!preview;
10849
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10850
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10851
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10875
10852
  ] });
10876
10853
  };
10877
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10878
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10879
- const MetadataForm = ({ orderId, metadata }) => {
10854
+ const PromotionForm = ({ preview }) => {
10855
+ const { items, shipping_methods } = preview;
10856
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10857
+ const [comboboxValue, setComboboxValue] = React.useState("");
10880
10858
  const { handleSuccess } = useRouteModal();
10881
- const hasUneditableRows = getHasUneditableRows(metadata);
10882
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10883
- const form = reactHookForm.useForm({
10884
- defaultValues: {
10885
- metadata: getDefaultValues(metadata)
10859
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10860
+ const promoCodes = getPromotionCodes(items, shipping_methods);
10861
+ const { promotions, isPending, isError, error } = usePromotions(
10862
+ {
10863
+ code: promoCodes
10886
10864
  },
10887
- resolver: zod.zodResolver(MetadataSchema)
10865
+ {
10866
+ enabled: !!promoCodes.length
10867
+ }
10868
+ );
10869
+ const comboboxData = useComboboxData({
10870
+ queryKey: ["promotions", "combobox", promoCodes],
10871
+ queryFn: async (params) => {
10872
+ return await sdk.admin.promotion.list({
10873
+ ...params,
10874
+ code: {
10875
+ $nin: promoCodes
10876
+ }
10877
+ });
10878
+ },
10879
+ getOptions: (data) => {
10880
+ return data.promotions.map((promotion) => ({
10881
+ label: promotion.code,
10882
+ value: promotion.code
10883
+ }));
10884
+ }
10888
10885
  });
10889
- const handleSubmit = form.handleSubmit(async (data) => {
10890
- const parsedData = parseValues(data);
10891
- await mutateAsync(
10886
+ const add = async (value) => {
10887
+ if (!value) {
10888
+ return;
10889
+ }
10890
+ addPromotions(
10892
10891
  {
10893
- metadata: parsedData
10892
+ promo_codes: [value]
10894
10893
  },
10895
10894
  {
10896
- onSuccess: () => {
10897
- ui.toast.success("Metadata updated");
10898
- handleSuccess();
10895
+ onError: (e) => {
10896
+ ui.toast.error(e.message);
10897
+ comboboxData.onSearchValueChange("");
10898
+ setComboboxValue("");
10899
10899
  },
10900
- onError: (error) => {
10901
- ui.toast.error(error.message);
10900
+ onSuccess: () => {
10901
+ comboboxData.onSearchValueChange("");
10902
+ setComboboxValue("");
10902
10903
  }
10903
10904
  }
10904
10905
  );
10905
- });
10906
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10907
- control: form.control,
10908
- name: "metadata"
10909
- });
10910
- function deleteRow(index) {
10911
- remove(index);
10912
- if (fields.length === 1) {
10913
- insert(0, {
10914
- key: "",
10915
- value: "",
10916
- disabled: false
10917
- });
10906
+ };
10907
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10908
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10909
+ const onSubmit = async () => {
10910
+ setIsSubmitting(true);
10911
+ let requestSucceeded = false;
10912
+ await requestOrderEdit(void 0, {
10913
+ onError: (e) => {
10914
+ ui.toast.error(e.message);
10915
+ },
10916
+ onSuccess: () => {
10917
+ requestSucceeded = true;
10918
+ }
10919
+ });
10920
+ if (!requestSucceeded) {
10921
+ setIsSubmitting(false);
10922
+ return;
10918
10923
  }
10919
- }
10920
- function insertRow(index, position) {
10921
- insert(index + (position === "above" ? 0 : 1), {
10922
- key: "",
10923
- value: "",
10924
- disabled: false
10924
+ await confirmOrderEdit(void 0, {
10925
+ onError: (e) => {
10926
+ ui.toast.error(e.message);
10927
+ },
10928
+ onSuccess: () => {
10929
+ handleSuccess();
10930
+ },
10931
+ onSettled: () => {
10932
+ setIsSubmitting(false);
10933
+ }
10925
10934
  });
10935
+ };
10936
+ if (isError) {
10937
+ throw error;
10926
10938
  }
10927
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10928
- KeyboundForm,
10929
- {
10930
- onSubmit: handleSubmit,
10931
- className: "flex flex-1 flex-col overflow-hidden",
10932
- children: [
10933
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10934
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10935
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10936
- /* @__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" }) }),
10937
- /* @__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" }) })
10938
- ] }),
10939
- fields.map((field, index) => {
10940
- const isDisabled = field.disabled || false;
10941
- let placeholder = "-";
10942
- if (typeof field.value === "object") {
10943
- placeholder = "{ ... }";
10944
- }
10945
- if (Array.isArray(field.value)) {
10946
- placeholder = "[ ... ]";
10947
- }
10948
- return /* @__PURE__ */ jsxRuntime.jsx(
10949
- ConditionalTooltip,
10950
- {
10951
- showTooltip: isDisabled,
10952
- content: "This row is disabled because it contains non-primitive data.",
10953
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsxs(
10955
- "div",
10956
- {
10957
- className: ui.clx("grid grid-cols-2 divide-x", {
10958
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10959
- }),
10960
- children: [
10961
- /* @__PURE__ */ jsxRuntime.jsx(
10962
- Form$2.Field,
10963
- {
10964
- control: form.control,
10965
- name: `metadata.${index}.key`,
10966
- render: ({ field: field2 }) => {
10967
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10968
- GridInput,
10969
- {
10970
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10971
- ...field2,
10972
- disabled: isDisabled,
10973
- placeholder: "Key"
10974
- }
10975
- ) }) });
10976
- }
10977
- }
10978
- ),
10979
- /* @__PURE__ */ jsxRuntime.jsx(
10980
- Form$2.Field,
10981
- {
10982
- control: form.control,
10983
- name: `metadata.${index}.value`,
10984
- render: ({ field: { value, ...field2 } }) => {
10985
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10986
- GridInput,
10987
- {
10988
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10989
- ...field2,
10990
- value: isDisabled ? placeholder : value,
10991
- disabled: isDisabled,
10992
- placeholder: "Value"
10993
- }
10994
- ) }) });
10995
- }
10996
- }
10997
- )
10998
- ]
10999
- }
11000
- ),
11001
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11002
- /* @__PURE__ */ jsxRuntime.jsx(
11003
- ui.DropdownMenu.Trigger,
11004
- {
11005
- className: ui.clx(
11006
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11007
- {
11008
- hidden: isDisabled
11009
- }
11010
- ),
11011
- disabled: isDisabled,
11012
- asChild: true,
11013
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11014
- }
11015
- ),
11016
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11017
- /* @__PURE__ */ jsxRuntime.jsxs(
11018
- ui.DropdownMenu.Item,
11019
- {
11020
- className: "gap-x-2",
11021
- onClick: () => insertRow(index, "above"),
11022
- children: [
11023
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11024
- "Insert row above"
11025
- ]
11026
- }
11027
- ),
11028
- /* @__PURE__ */ jsxRuntime.jsxs(
11029
- ui.DropdownMenu.Item,
11030
- {
11031
- className: "gap-x-2",
11032
- onClick: () => insertRow(index, "below"),
11033
- children: [
11034
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11035
- "Insert row below"
11036
- ]
11037
- }
11038
- ),
11039
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11040
- /* @__PURE__ */ jsxRuntime.jsxs(
11041
- ui.DropdownMenu.Item,
11042
- {
11043
- className: "gap-x-2",
11044
- onClick: () => deleteRow(index),
11045
- children: [
11046
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11047
- "Delete row"
11048
- ]
11049
- }
11050
- )
11051
- ] })
11052
- ] })
11053
- ] })
11054
- },
11055
- field.id
11056
- );
11057
- })
11058
- ] }),
11059
- 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." })
10939
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10940
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10941
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10942
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10943
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10944
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11060
10945
  ] }),
11061
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11062
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11063
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11064
- ] }) })
11065
- ]
11066
- }
11067
- ) });
11068
- };
11069
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11070
- return /* @__PURE__ */ jsxRuntime.jsx(
11071
- "input",
11072
- {
11073
- ref,
11074
- ...props,
11075
- autoComplete: "off",
11076
- className: ui.clx(
11077
- "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",
11078
- className
10946
+ /* @__PURE__ */ jsxRuntime.jsx(
10947
+ Combobox,
10948
+ {
10949
+ id: "promotion-combobox",
10950
+ "aria-describedby": "promotion-combobox-hint",
10951
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10952
+ fetchNextPage: comboboxData.fetchNextPage,
10953
+ options: comboboxData.options,
10954
+ onSearchValueChange: comboboxData.onSearchValueChange,
10955
+ searchValue: comboboxData.searchValue,
10956
+ disabled: comboboxData.disabled || isAddingPromotions,
10957
+ onChange: add,
10958
+ value: comboboxValue
10959
+ }
10960
+ )
10961
+ ] }),
10962
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10963
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10964
+ PromotionItem,
10965
+ {
10966
+ promotion,
10967
+ orderId: preview.id,
10968
+ isLoading: isPending
10969
+ },
10970
+ promotion.id
10971
+ )) })
10972
+ ] }) }),
10973
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10974
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10975
+ /* @__PURE__ */ jsxRuntime.jsx(
10976
+ ui.Button,
10977
+ {
10978
+ size: "small",
10979
+ type: "submit",
10980
+ isLoading: isSubmitting || isAddingPromotions,
10981
+ children: "Save"
10982
+ }
11079
10983
  )
11080
- }
11081
- );
11082
- });
11083
- GridInput.displayName = "MetadataForm.GridInput";
11084
- const PlaceholderInner = () => {
11085
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11086
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11087
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11088
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11089
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11090
10984
  ] }) })
11091
10985
  ] });
11092
10986
  };
11093
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11094
- function getDefaultValues(metadata) {
11095
- if (!metadata || !Object.keys(metadata).length) {
11096
- return [
10987
+ const PromotionItem = ({
10988
+ promotion,
10989
+ orderId,
10990
+ isLoading
10991
+ }) => {
10992
+ var _a;
10993
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10994
+ const onRemove = async () => {
10995
+ removePromotions(
11097
10996
  {
11098
- key: "",
11099
- value: "",
11100
- disabled: false
11101
- }
11102
- ];
11103
- }
11104
- return Object.entries(metadata).map(([key, value]) => {
11105
- if (!EDITABLE_TYPES.includes(typeof value)) {
11106
- return {
11107
- key,
11108
- value,
11109
- disabled: true
11110
- };
11111
- }
11112
- let stringValue = value;
11113
- if (typeof value !== "string") {
11114
- stringValue = JSON.stringify(value);
11115
- }
11116
- return {
11117
- key,
11118
- value: stringValue,
11119
- original_key: key
11120
- };
11121
- });
11122
- }
11123
- function parseValues(values) {
11124
- const metadata = values.metadata;
11125
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11126
- if (isEmpty) {
11127
- return null;
11128
- }
11129
- const update = {};
11130
- metadata.forEach((field) => {
11131
- let key = field.key;
11132
- let value = field.value;
11133
- const disabled = field.disabled;
11134
- if (!key || !value) {
11135
- return;
11136
- }
11137
- if (disabled) {
11138
- update[key] = value;
11139
- return;
11140
- }
11141
- key = key.trim();
11142
- value = value.trim();
11143
- if (value === "true") {
11144
- update[key] = true;
11145
- } else if (value === "false") {
11146
- update[key] = false;
11147
- } else {
11148
- const parsedNumber = parseFloat(value);
11149
- if (!isNaN(parsedNumber)) {
11150
- update[key] = parsedNumber;
11151
- } else {
11152
- update[key] = value;
11153
- }
11154
- }
11155
- });
11156
- return update;
11157
- }
11158
- function getHasUneditableRows(metadata) {
11159
- if (!metadata) {
11160
- return false;
11161
- }
11162
- return Object.values(metadata).some(
11163
- (value) => !EDITABLE_TYPES.includes(typeof value)
11164
- );
11165
- }
11166
- const PROMOTION_QUERY_KEY = "promotions";
11167
- const promotionsQueryKeys = {
11168
- list: (query2) => [
11169
- PROMOTION_QUERY_KEY,
11170
- query2 ? query2 : void 0
11171
- ],
11172
- detail: (id, query2) => [
11173
- PROMOTION_QUERY_KEY,
11174
- id,
11175
- query2 ? query2 : void 0
11176
- ]
11177
- };
11178
- const usePromotions = (query2, options) => {
11179
- const { data, ...rest } = reactQuery.useQuery({
11180
- queryKey: promotionsQueryKeys.list(query2),
11181
- queryFn: async () => sdk.admin.promotion.list(query2),
11182
- ...options
11183
- });
11184
- return { ...data, ...rest };
11185
- };
11186
- const Promotions = () => {
11187
- const { id } = reactRouterDom.useParams();
11188
- const {
11189
- order: preview,
11190
- isError: isPreviewError,
11191
- error: previewError
11192
- } = useOrderPreview(id, void 0);
11193
- useInitiateOrderEdit({ preview });
11194
- const { onCancel } = useCancelOrderEdit({ preview });
11195
- if (isPreviewError) {
11196
- throw previewError;
11197
- }
11198
- const isReady = !!preview;
11199
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11200
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11201
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11202
- ] });
11203
- };
11204
- const PromotionForm = ({ preview }) => {
11205
- const { items, shipping_methods } = preview;
11206
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11207
- const [comboboxValue, setComboboxValue] = React.useState("");
11208
- const { handleSuccess } = useRouteModal();
11209
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11210
- const promoCodes = getPromotionCodes(items, shipping_methods);
11211
- const { promotions, isPending, isError, error } = usePromotions(
11212
- {
11213
- code: promoCodes
11214
- },
11215
- {
11216
- enabled: !!promoCodes.length
11217
- }
11218
- );
11219
- const comboboxData = useComboboxData({
11220
- queryKey: ["promotions", "combobox", promoCodes],
11221
- queryFn: async (params) => {
11222
- return await sdk.admin.promotion.list({
11223
- ...params,
11224
- code: {
11225
- $nin: promoCodes
11226
- }
11227
- });
11228
- },
11229
- getOptions: (data) => {
11230
- return data.promotions.map((promotion) => ({
11231
- label: promotion.code,
11232
- value: promotion.code
11233
- }));
11234
- }
11235
- });
11236
- const add = async (value) => {
11237
- if (!value) {
11238
- return;
11239
- }
11240
- addPromotions(
11241
- {
11242
- promo_codes: [value]
11243
- },
11244
- {
11245
- onError: (e) => {
11246
- ui.toast.error(e.message);
11247
- comboboxData.onSearchValueChange("");
11248
- setComboboxValue("");
11249
- },
11250
- onSuccess: () => {
11251
- comboboxData.onSearchValueChange("");
11252
- setComboboxValue("");
11253
- }
11254
- }
11255
- );
11256
- };
11257
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11258
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11259
- const onSubmit = async () => {
11260
- setIsSubmitting(true);
11261
- let requestSucceeded = false;
11262
- await requestOrderEdit(void 0, {
11263
- onError: (e) => {
11264
- ui.toast.error(e.message);
11265
- },
11266
- onSuccess: () => {
11267
- requestSucceeded = true;
11268
- }
11269
- });
11270
- if (!requestSucceeded) {
11271
- setIsSubmitting(false);
11272
- return;
11273
- }
11274
- await confirmOrderEdit(void 0, {
11275
- onError: (e) => {
11276
- ui.toast.error(e.message);
11277
- },
11278
- onSuccess: () => {
11279
- handleSuccess();
11280
- },
11281
- onSettled: () => {
11282
- setIsSubmitting(false);
11283
- }
11284
- });
11285
- };
11286
- if (isError) {
11287
- throw error;
11288
- }
11289
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11290
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11291
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11292
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11293
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11294
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11295
- ] }),
11296
- /* @__PURE__ */ jsxRuntime.jsx(
11297
- Combobox,
11298
- {
11299
- id: "promotion-combobox",
11300
- "aria-describedby": "promotion-combobox-hint",
11301
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11302
- fetchNextPage: comboboxData.fetchNextPage,
11303
- options: comboboxData.options,
11304
- onSearchValueChange: comboboxData.onSearchValueChange,
11305
- searchValue: comboboxData.searchValue,
11306
- disabled: comboboxData.disabled || isAddingPromotions,
11307
- onChange: add,
11308
- value: comboboxValue
11309
- }
11310
- )
11311
- ] }),
11312
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11313
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11314
- PromotionItem,
11315
- {
11316
- promotion,
11317
- orderId: preview.id,
11318
- isLoading: isPending
11319
- },
11320
- promotion.id
11321
- )) })
11322
- ] }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11324
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11325
- /* @__PURE__ */ jsxRuntime.jsx(
11326
- ui.Button,
11327
- {
11328
- size: "small",
11329
- type: "submit",
11330
- isLoading: isSubmitting || isAddingPromotions,
11331
- children: "Save"
11332
- }
11333
- )
11334
- ] }) })
11335
- ] });
11336
- };
11337
- const PromotionItem = ({
11338
- promotion,
11339
- orderId,
11340
- isLoading
11341
- }) => {
11342
- var _a;
11343
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11344
- const onRemove = async () => {
11345
- removePromotions(
11346
- {
11347
- promo_codes: [promotion.code]
11348
- },
11349
- {
11350
- onError: (e) => {
11351
- ui.toast.error(e.message);
11352
- }
10997
+ promo_codes: [promotion.code]
10998
+ },
10999
+ {
11000
+ onError: (e) => {
11001
+ ui.toast.error(e.message);
11002
+ }
11353
11003
  }
11354
11004
  );
11355
11005
  };
@@ -11440,1008 +11090,648 @@ function getPromotionCodes(items, shippingMethods) {
11440
11090
  }
11441
11091
  return Array.from(codes);
11442
11092
  }
11443
- const SalesChannel = () => {
11444
- const { id } = reactRouterDom.useParams();
11445
- const { draft_order, isPending, isError, error } = useDraftOrder(
11446
- id,
11447
- {
11448
- fields: "+sales_channel_id"
11449
- },
11450
- {
11451
- enabled: !!id
11452
- }
11453
- );
11454
- if (isError) {
11455
- throw error;
11456
- }
11457
- const ISrEADY = !!draft_order && !isPending;
11458
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11462
- ] }),
11463
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11464
- ] });
11465
- };
11466
- const SalesChannelForm = ({ order }) => {
11467
- const form = reactHookForm.useForm({
11468
- defaultValues: {
11469
- sales_channel_id: order.sales_channel_id || ""
11470
- },
11471
- resolver: zod.zodResolver(schema$2)
11472
- });
11473
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11474
- const { handleSuccess } = useRouteModal();
11475
- const onSubmit = form.handleSubmit(async (data) => {
11476
- await mutateAsync(
11477
- {
11478
- sales_channel_id: data.sales_channel_id
11479
- },
11093
+ const InlineTip = React.forwardRef(
11094
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11095
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11096
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11097
+ "div",
11480
11098
  {
11481
- onSuccess: () => {
11482
- ui.toast.success("Sales channel updated");
11483
- handleSuccess();
11484
- },
11099
+ ref,
11100
+ className: ui.clx(
11101
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11102
+ className
11103
+ ),
11104
+ ...props,
11105
+ children: [
11106
+ /* @__PURE__ */ jsxRuntime.jsx(
11107
+ "div",
11108
+ {
11109
+ role: "presentation",
11110
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11111
+ "bg-ui-tag-orange-icon": variant === "warning"
11112
+ })
11113
+ }
11114
+ ),
11115
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11116
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11117
+ labelValue,
11118
+ ":"
11119
+ ] }),
11120
+ " ",
11121
+ children
11122
+ ] })
11123
+ ]
11124
+ }
11125
+ );
11126
+ }
11127
+ );
11128
+ InlineTip.displayName = "InlineTip";
11129
+ const MetadataFieldSchema = objectType({
11130
+ key: stringType(),
11131
+ disabled: booleanType().optional(),
11132
+ value: anyType()
11133
+ });
11134
+ const MetadataSchema = objectType({
11135
+ metadata: arrayType(MetadataFieldSchema)
11136
+ });
11137
+ const Metadata = () => {
11138
+ const { id } = reactRouterDom.useParams();
11139
+ const { order, isPending, isError, error } = useOrder(id, {
11140
+ fields: "metadata"
11141
+ });
11142
+ if (isError) {
11143
+ throw error;
11144
+ }
11145
+ const isReady = !isPending && !!order;
11146
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11147
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11148
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11149
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11150
+ ] }),
11151
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11152
+ ] });
11153
+ };
11154
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11155
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11156
+ const MetadataForm = ({ orderId, metadata }) => {
11157
+ const { handleSuccess } = useRouteModal();
11158
+ const hasUneditableRows = getHasUneditableRows(metadata);
11159
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11160
+ const form = reactHookForm.useForm({
11161
+ defaultValues: {
11162
+ metadata: getDefaultValues(metadata)
11163
+ },
11164
+ resolver: zod.zodResolver(MetadataSchema)
11165
+ });
11166
+ const handleSubmit = form.handleSubmit(async (data) => {
11167
+ const parsedData = parseValues(data);
11168
+ await mutateAsync(
11169
+ {
11170
+ metadata: parsedData
11171
+ },
11172
+ {
11173
+ onSuccess: () => {
11174
+ ui.toast.success("Metadata updated");
11175
+ handleSuccess();
11176
+ },
11485
11177
  onError: (error) => {
11486
11178
  ui.toast.error(error.message);
11487
11179
  }
11488
11180
  }
11489
11181
  );
11490
11182
  });
11183
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11184
+ control: form.control,
11185
+ name: "metadata"
11186
+ });
11187
+ function deleteRow(index) {
11188
+ remove(index);
11189
+ if (fields.length === 1) {
11190
+ insert(0, {
11191
+ key: "",
11192
+ value: "",
11193
+ disabled: false
11194
+ });
11195
+ }
11196
+ }
11197
+ function insertRow(index, position) {
11198
+ insert(index + (position === "above" ? 0 : 1), {
11199
+ key: "",
11200
+ value: "",
11201
+ disabled: false
11202
+ });
11203
+ }
11491
11204
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
11205
  KeyboundForm,
11493
11206
  {
11207
+ onSubmit: handleSubmit,
11494
11208
  className: "flex flex-1 flex-col overflow-hidden",
11495
- onSubmit,
11496
11209
  children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11210
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11211
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11212
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11213
+ /* @__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" }) }),
11214
+ /* @__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" }) })
11215
+ ] }),
11216
+ fields.map((field, index) => {
11217
+ const isDisabled = field.disabled || false;
11218
+ let placeholder = "-";
11219
+ if (typeof field.value === "object") {
11220
+ placeholder = "{ ... }";
11221
+ }
11222
+ if (Array.isArray(field.value)) {
11223
+ placeholder = "[ ... ]";
11224
+ }
11225
+ return /* @__PURE__ */ jsxRuntime.jsx(
11226
+ ConditionalTooltip,
11227
+ {
11228
+ showTooltip: isDisabled,
11229
+ content: "This row is disabled because it contains non-primitive data.",
11230
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11231
+ /* @__PURE__ */ jsxRuntime.jsxs(
11232
+ "div",
11233
+ {
11234
+ className: ui.clx("grid grid-cols-2 divide-x", {
11235
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11236
+ }),
11237
+ children: [
11238
+ /* @__PURE__ */ jsxRuntime.jsx(
11239
+ Form$2.Field,
11240
+ {
11241
+ control: form.control,
11242
+ name: `metadata.${index}.key`,
11243
+ render: ({ field: field2 }) => {
11244
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11245
+ GridInput,
11246
+ {
11247
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11248
+ ...field2,
11249
+ disabled: isDisabled,
11250
+ placeholder: "Key"
11251
+ }
11252
+ ) }) });
11253
+ }
11254
+ }
11255
+ ),
11256
+ /* @__PURE__ */ jsxRuntime.jsx(
11257
+ Form$2.Field,
11258
+ {
11259
+ control: form.control,
11260
+ name: `metadata.${index}.value`,
11261
+ render: ({ field: { value, ...field2 } }) => {
11262
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11263
+ GridInput,
11264
+ {
11265
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11266
+ ...field2,
11267
+ value: isDisabled ? placeholder : value,
11268
+ disabled: isDisabled,
11269
+ placeholder: "Value"
11270
+ }
11271
+ ) }) });
11272
+ }
11273
+ }
11274
+ )
11275
+ ]
11276
+ }
11277
+ ),
11278
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11279
+ /* @__PURE__ */ jsxRuntime.jsx(
11280
+ ui.DropdownMenu.Trigger,
11281
+ {
11282
+ className: ui.clx(
11283
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11284
+ {
11285
+ hidden: isDisabled
11286
+ }
11287
+ ),
11288
+ disabled: isDisabled,
11289
+ asChild: true,
11290
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11291
+ }
11292
+ ),
11293
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11294
+ /* @__PURE__ */ jsxRuntime.jsxs(
11295
+ ui.DropdownMenu.Item,
11296
+ {
11297
+ className: "gap-x-2",
11298
+ onClick: () => insertRow(index, "above"),
11299
+ children: [
11300
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11301
+ "Insert row above"
11302
+ ]
11303
+ }
11304
+ ),
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(
11306
+ ui.DropdownMenu.Item,
11307
+ {
11308
+ className: "gap-x-2",
11309
+ onClick: () => insertRow(index, "below"),
11310
+ children: [
11311
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11312
+ "Insert row below"
11313
+ ]
11314
+ }
11315
+ ),
11316
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11317
+ /* @__PURE__ */ jsxRuntime.jsxs(
11318
+ ui.DropdownMenu.Item,
11319
+ {
11320
+ className: "gap-x-2",
11321
+ onClick: () => deleteRow(index),
11322
+ children: [
11323
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11324
+ "Delete row"
11325
+ ]
11326
+ }
11327
+ )
11328
+ ] })
11329
+ ] })
11330
+ ] })
11331
+ },
11332
+ field.id
11333
+ );
11334
+ })
11335
+ ] }),
11336
+ 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." })
11337
+ ] }),
11338
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11339
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11500
11340
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
11341
  ] }) })
11502
11342
  ]
11503
11343
  }
11504
11344
  ) });
11505
11345
  };
11506
- const SalesChannelField = ({ control, order }) => {
11507
- const salesChannels = useComboboxData({
11508
- queryFn: async (params) => {
11509
- return await sdk.admin.salesChannel.list(params);
11510
- },
11511
- queryKey: ["sales-channels"],
11512
- getOptions: (data) => {
11513
- return data.sales_channels.map((salesChannel) => ({
11514
- label: salesChannel.name,
11515
- value: salesChannel.id
11516
- }));
11517
- },
11518
- defaultValue: order.sales_channel_id || void 0
11519
- });
11346
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11520
11347
  return /* @__PURE__ */ jsxRuntime.jsx(
11521
- Form$2.Field,
11348
+ "input",
11522
11349
  {
11523
- control,
11524
- name: "sales_channel_id",
11525
- render: ({ field }) => {
11526
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
- Combobox,
11530
- {
11531
- options: salesChannels.options,
11532
- fetchNextPage: salesChannels.fetchNextPage,
11533
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
- searchValue: salesChannels.searchValue,
11535
- onSearchValueChange: salesChannels.onSearchValueChange,
11536
- placeholder: "Select sales channel",
11537
- ...field
11538
- }
11539
- ) }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
- ] });
11542
- }
11350
+ ref,
11351
+ ...props,
11352
+ autoComplete: "off",
11353
+ className: ui.clx(
11354
+ "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",
11355
+ className
11356
+ )
11543
11357
  }
11544
11358
  );
11545
- };
11546
- const schema$2 = objectType({
11547
- sales_channel_id: stringType().min(1)
11548
11359
  });
11549
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
- const Shipping = () => {
11551
- var _a;
11360
+ GridInput.displayName = "MetadataForm.GridInput";
11361
+ const PlaceholderInner = () => {
11362
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11363
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11364
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11365
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11366
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11367
+ ] }) })
11368
+ ] });
11369
+ };
11370
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11371
+ function getDefaultValues(metadata) {
11372
+ if (!metadata || !Object.keys(metadata).length) {
11373
+ return [
11374
+ {
11375
+ key: "",
11376
+ value: "",
11377
+ disabled: false
11378
+ }
11379
+ ];
11380
+ }
11381
+ return Object.entries(metadata).map(([key, value]) => {
11382
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11383
+ return {
11384
+ key,
11385
+ value,
11386
+ disabled: true
11387
+ };
11388
+ }
11389
+ let stringValue = value;
11390
+ if (typeof value !== "string") {
11391
+ stringValue = JSON.stringify(value);
11392
+ }
11393
+ return {
11394
+ key,
11395
+ value: stringValue,
11396
+ original_key: key
11397
+ };
11398
+ });
11399
+ }
11400
+ function parseValues(values) {
11401
+ const metadata = values.metadata;
11402
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11403
+ if (isEmpty) {
11404
+ return null;
11405
+ }
11406
+ const update = {};
11407
+ metadata.forEach((field) => {
11408
+ let key = field.key;
11409
+ let value = field.value;
11410
+ const disabled = field.disabled;
11411
+ if (!key || !value) {
11412
+ return;
11413
+ }
11414
+ if (disabled) {
11415
+ update[key] = value;
11416
+ return;
11417
+ }
11418
+ key = key.trim();
11419
+ value = value.trim();
11420
+ if (value === "true") {
11421
+ update[key] = true;
11422
+ } else if (value === "false") {
11423
+ update[key] = false;
11424
+ } else {
11425
+ const parsedNumber = parseFloat(value);
11426
+ if (!isNaN(parsedNumber)) {
11427
+ update[key] = parsedNumber;
11428
+ } else {
11429
+ update[key] = value;
11430
+ }
11431
+ }
11432
+ });
11433
+ return update;
11434
+ }
11435
+ function getHasUneditableRows(metadata) {
11436
+ if (!metadata) {
11437
+ return false;
11438
+ }
11439
+ return Object.values(metadata).some(
11440
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11441
+ );
11442
+ }
11443
+ const ShippingAddress = () => {
11552
11444
  const { id } = reactRouterDom.useParams();
11553
11445
  const { order, isPending, isError, error } = useOrder(id, {
11554
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11446
+ fields: "+shipping_address"
11555
11447
  });
11556
- const {
11557
- order: preview,
11558
- isPending: isPreviewPending,
11559
- isError: isPreviewError,
11560
- error: previewError
11561
- } = useOrderPreview(id);
11562
- useInitiateOrderEdit({ preview });
11563
- const { onCancel } = useCancelOrderEdit({ preview });
11564
11448
  if (isError) {
11565
11449
  throw error;
11566
11450
  }
11567
- if (isPreviewError) {
11568
- throw previewError;
11569
- }
11570
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11571
- const isReady = preview && !isPreviewPending && order && !isPending;
11572
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11574
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11575
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11576
- /* @__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." }) })
11577
- ] }) }) }),
11578
- /* @__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" }) }) })
11579
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11580
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11581
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11582
- ] }) });
11451
+ const isReady = !isPending && !!order;
11452
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11453
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11454
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11455
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11456
+ ] }),
11457
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11458
+ ] });
11583
11459
  };
11584
- const ShippingForm = ({ preview, order }) => {
11585
- var _a;
11586
- const { setIsOpen } = useStackedModal();
11587
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11588
- const [data, setData] = React.useState(null);
11589
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11590
- const { shipping_options } = useShippingOptions(
11591
- {
11592
- id: appliedShippingOptionIds,
11593
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11460
+ const ShippingAddressForm = ({ order }) => {
11461
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11462
+ const form = reactHookForm.useForm({
11463
+ defaultValues: {
11464
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11465
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11466
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11467
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11468
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11469
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11470
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11471
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11472
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11473
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11594
11474
  },
11595
- {
11596
- enabled: appliedShippingOptionIds.length > 0
11597
- }
11598
- );
11599
- const uniqueShippingProfiles = React.useMemo(() => {
11600
- const profiles = /* @__PURE__ */ new Map();
11601
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11602
- profiles.set(profile.id, profile);
11603
- });
11604
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11605
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11606
- });
11607
- return Array.from(profiles.values());
11608
- }, [order.items, shipping_options]);
11475
+ resolver: zod.zodResolver(schema$2)
11476
+ });
11477
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11609
11478
  const { handleSuccess } = useRouteModal();
11610
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11611
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11612
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11613
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11614
- const onSubmit = async () => {
11615
- setIsSubmitting(true);
11616
- let requestSucceeded = false;
11617
- await requestOrderEdit(void 0, {
11618
- onError: (e) => {
11619
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11620
- },
11621
- onSuccess: () => {
11622
- requestSucceeded = true;
11623
- }
11624
- });
11625
- if (!requestSucceeded) {
11626
- setIsSubmitting(false);
11627
- return;
11628
- }
11629
- await confirmOrderEdit(void 0, {
11630
- onError: (e) => {
11631
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11632
- },
11633
- onSuccess: () => {
11634
- handleSuccess();
11479
+ const onSubmit = form.handleSubmit(async (data) => {
11480
+ await mutateAsync(
11481
+ {
11482
+ shipping_address: {
11483
+ first_name: data.first_name,
11484
+ last_name: data.last_name,
11485
+ company: data.company,
11486
+ address_1: data.address_1,
11487
+ address_2: data.address_2,
11488
+ city: data.city,
11489
+ province: data.province,
11490
+ country_code: data.country_code,
11491
+ postal_code: data.postal_code,
11492
+ phone: data.phone
11493
+ }
11635
11494
  },
11636
- onSettled: () => {
11637
- setIsSubmitting(false);
11638
- }
11639
- });
11640
- };
11641
- const onKeydown = React.useCallback(
11642
- (e) => {
11643
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11644
- if (data || isSubmitting) {
11645
- return;
11495
+ {
11496
+ onSuccess: () => {
11497
+ handleSuccess();
11498
+ },
11499
+ onError: (error) => {
11500
+ ui.toast.error(error.message);
11646
11501
  }
11647
- onSubmit();
11648
11502
  }
11649
- },
11650
- [data, isSubmitting, onSubmit]
11651
- );
11652
- React.useEffect(() => {
11653
- document.addEventListener("keydown", onKeydown);
11654
- return () => {
11655
- document.removeEventListener("keydown", onKeydown);
11656
- };
11657
- }, [onKeydown]);
11658
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11659
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11660
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11661
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11662
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11663
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11664
- /* @__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." }) })
11665
- ] }),
11666
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11667
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11668
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11503
+ );
11504
+ });
11505
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11506
+ KeyboundForm,
11507
+ {
11508
+ className: "flex flex-1 flex-col overflow-hidden",
11509
+ onSubmit,
11510
+ children: [
11511
+ /* @__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: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(
11513
+ Form$2.Field,
11514
+ {
11515
+ control: form.control,
11516
+ name: "country_code",
11517
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11521
+ ] })
11522
+ }
11523
+ ),
11524
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11669
11525
  /* @__PURE__ */ jsxRuntime.jsx(
11670
- ui.Text,
11526
+ Form$2.Field,
11671
11527
  {
11672
- size: "xsmall",
11673
- weight: "plus",
11674
- className: "text-ui-fg-muted",
11675
- children: "Shipping profile"
11528
+ control: form.control,
11529
+ name: "first_name",
11530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11534
+ ] })
11676
11535
  }
11677
11536
  ),
11678
11537
  /* @__PURE__ */ jsxRuntime.jsx(
11679
- ui.Text,
11538
+ Form$2.Field,
11680
11539
  {
11681
- size: "xsmall",
11682
- weight: "plus",
11683
- className: "text-ui-fg-muted",
11684
- children: "Action"
11540
+ control: form.control,
11541
+ name: "last_name",
11542
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11546
+ ] })
11685
11547
  }
11686
11548
  )
11687
11549
  ] }),
11688
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11689
- var _a2, _b, _c, _d, _e, _f, _g;
11690
- const items = getItemsWithShippingProfile(
11691
- profile.id,
11692
- order.items
11693
- );
11694
- const hasItems = items.length > 0;
11695
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11696
- (option) => option.shipping_profile_id === profile.id
11697
- );
11698
- const shippingMethod = preview.shipping_methods.find(
11699
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11700
- );
11701
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11702
- (action) => action.action === "SHIPPING_ADD"
11703
- );
11704
- return /* @__PURE__ */ jsxRuntime.jsxs(
11705
- radixUi.Accordion.Item,
11550
+ /* @__PURE__ */ jsxRuntime.jsx(
11551
+ Form$2.Field,
11552
+ {
11553
+ control: form.control,
11554
+ name: "company",
11555
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11559
+ ] })
11560
+ }
11561
+ ),
11562
+ /* @__PURE__ */ jsxRuntime.jsx(
11563
+ Form$2.Field,
11564
+ {
11565
+ control: form.control,
11566
+ name: "address_1",
11567
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11568
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11569
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11570
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11571
+ ] })
11572
+ }
11573
+ ),
11574
+ /* @__PURE__ */ jsxRuntime.jsx(
11575
+ Form$2.Field,
11576
+ {
11577
+ control: form.control,
11578
+ name: "address_2",
11579
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11580
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11581
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11582
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11583
+ ] })
11584
+ }
11585
+ ),
11586
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11587
+ /* @__PURE__ */ jsxRuntime.jsx(
11588
+ Form$2.Field,
11706
11589
  {
11707
- value: profile.id,
11708
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11709
- children: [
11710
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11711
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11712
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11713
- ui.IconButton,
11714
- {
11715
- size: "2xsmall",
11716
- variant: "transparent",
11717
- className: "group/trigger",
11718
- disabled: !hasItems,
11719
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11720
- }
11721
- ) }),
11722
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11723
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11724
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11725
- /* @__PURE__ */ jsxRuntime.jsx(
11726
- ui.Text,
11727
- {
11728
- size: "small",
11729
- weight: "plus",
11730
- leading: "compact",
11731
- children: profile.name
11732
- }
11733
- ),
11734
- /* @__PURE__ */ jsxRuntime.jsxs(
11735
- ui.Text,
11736
- {
11737
- size: "small",
11738
- leading: "compact",
11739
- className: "text-ui-fg-subtle",
11740
- children: [
11741
- items.length,
11742
- " ",
11743
- pluralize(items.length, "items", "item")
11744
- ]
11745
- }
11746
- )
11747
- ] })
11748
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11749
- /* @__PURE__ */ jsxRuntime.jsx(
11750
- ui.Tooltip,
11751
- {
11752
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11753
- var _a3, _b2, _c2;
11754
- return /* @__PURE__ */ jsxRuntime.jsx(
11755
- "li",
11756
- {
11757
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11758
- },
11759
- item.id
11760
- );
11761
- }) }),
11762
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11763
- ui.Badge,
11764
- {
11765
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11766
- size: "xsmall",
11767
- children: [
11768
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11769
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11770
- items.reduce(
11771
- (acc, item) => acc + item.quantity,
11772
- 0
11773
- ),
11774
- "x",
11775
- " ",
11776
- pluralize(items.length, "items", "item")
11777
- ] })
11778
- ]
11779
- }
11780
- )
11781
- }
11782
- ),
11783
- /* @__PURE__ */ jsxRuntime.jsx(
11784
- ui.Tooltip,
11785
- {
11786
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11787
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11788
- ui.Badge,
11789
- {
11790
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11791
- size: "xsmall",
11792
- children: [
11793
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11794
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11795
- ]
11796
- }
11797
- )
11798
- }
11799
- ),
11800
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11801
- ui.Badge,
11802
- {
11803
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11804
- size: "xsmall",
11805
- children: [
11806
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11807
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11808
- ]
11809
- }
11810
- ) })
11811
- ] })
11812
- ] }),
11813
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11814
- ActionMenu,
11815
- {
11816
- groups: [
11817
- {
11818
- actions: [
11819
- hasItems ? {
11820
- label: "Edit shipping option",
11821
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11822
- onClick: () => {
11823
- setIsOpen(
11824
- STACKED_FOCUS_MODAL_ID,
11825
- true
11826
- );
11827
- setData({
11828
- shippingProfileId: profile.id,
11829
- shippingOption,
11830
- shippingMethod
11831
- });
11832
- }
11833
- } : void 0,
11834
- {
11835
- label: "Remove shipping option",
11836
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11837
- onClick: () => {
11838
- if (shippingMethod) {
11839
- if (addShippingMethodAction) {
11840
- removeActionShippingMethod(
11841
- addShippingMethodAction.id
11842
- );
11843
- } else {
11844
- removeShippingMethod(
11845
- shippingMethod.id
11846
- );
11847
- }
11848
- }
11849
- }
11850
- }
11851
- ].filter(Boolean)
11852
- }
11853
- ]
11854
- }
11855
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11856
- StackedModalTrigger,
11857
- {
11858
- shippingProfileId: profile.id,
11859
- shippingOption,
11860
- shippingMethod,
11861
- setData,
11862
- children: "Add shipping option"
11863
- }
11864
- )
11865
- ] }),
11866
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11867
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11868
- items.map((item, idx) => {
11869
- var _a3, _b2, _c2, _d2, _e2;
11870
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11871
- /* @__PURE__ */ jsxRuntime.jsxs(
11872
- "div",
11873
- {
11874
- className: "px-3 flex items-center gap-x-3",
11875
- children: [
11876
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11877
- ui.Divider,
11878
- {
11879
- variant: "dashed",
11880
- orientation: "vertical"
11881
- }
11882
- ) }),
11883
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11884
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11885
- ui.Text,
11886
- {
11887
- size: "small",
11888
- leading: "compact",
11889
- className: "text-ui-fg-subtle",
11890
- children: [
11891
- item.quantity,
11892
- "x"
11893
- ]
11894
- }
11895
- ) }),
11896
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11897
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11898
- /* @__PURE__ */ jsxRuntime.jsxs(
11899
- ui.Text,
11900
- {
11901
- size: "small",
11902
- leading: "compact",
11903
- weight: "plus",
11904
- children: [
11905
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11906
- " (",
11907
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11908
- ")"
11909
- ]
11910
- }
11911
- ),
11912
- /* @__PURE__ */ jsxRuntime.jsx(
11913
- ui.Text,
11914
- {
11915
- size: "small",
11916
- leading: "compact",
11917
- className: "text-ui-fg-subtle",
11918
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11919
- }
11920
- )
11921
- ] })
11922
- ] })
11923
- ]
11924
- },
11925
- item.id
11926
- ),
11927
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11928
- ] }, item.id);
11929
- })
11930
- ] })
11931
- ]
11932
- },
11933
- profile.id
11934
- );
11935
- }) })
11936
- ] }) })
11937
- ] }) }),
11938
- /* @__PURE__ */ jsxRuntime.jsx(
11939
- StackedFocusModal,
11940
- {
11941
- id: STACKED_FOCUS_MODAL_ID,
11942
- onOpenChangeCallback: (open) => {
11943
- if (!open) {
11944
- setData(null);
11945
- }
11946
- return open;
11947
- },
11948
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11949
- }
11950
- )
11951
- ] }),
11952
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11953
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11954
- /* @__PURE__ */ jsxRuntime.jsx(
11955
- ui.Button,
11956
- {
11957
- size: "small",
11958
- type: "button",
11959
- isLoading: isSubmitting,
11960
- onClick: onSubmit,
11961
- children: "Save"
11962
- }
11963
- )
11964
- ] }) })
11965
- ] });
11966
- };
11967
- const StackedModalTrigger = ({
11968
- shippingProfileId,
11969
- shippingOption,
11970
- shippingMethod,
11971
- setData,
11972
- children
11973
- }) => {
11974
- const { setIsOpen, getIsOpen } = useStackedModal();
11975
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11976
- const onToggle = () => {
11977
- if (isOpen) {
11978
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11979
- setData(null);
11980
- } else {
11981
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11982
- setData({
11983
- shippingProfileId,
11984
- shippingOption,
11985
- shippingMethod
11986
- });
11987
- }
11988
- };
11989
- return /* @__PURE__ */ jsxRuntime.jsx(
11990
- ui.Button,
11991
- {
11992
- size: "small",
11993
- variant: "secondary",
11994
- onClick: onToggle,
11995
- className: "text-ui-fg-primary shrink-0",
11996
- children
11997
- }
11998
- );
11999
- };
12000
- const ShippingProfileForm = ({
12001
- data,
12002
- order,
12003
- preview
12004
- }) => {
12005
- var _a, _b, _c, _d, _e, _f;
12006
- const { setIsOpen } = useStackedModal();
12007
- const form = reactHookForm.useForm({
12008
- resolver: zod.zodResolver(shippingMethodSchema),
12009
- defaultValues: {
12010
- 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,
12011
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12012
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12013
- }
12014
- });
12015
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12016
- const {
12017
- mutateAsync: updateShippingMethod,
12018
- isPending: isUpdatingShippingMethod
12019
- } = useDraftOrderUpdateShippingMethod(order.id);
12020
- const onSubmit = form.handleSubmit(async (values) => {
12021
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12022
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12023
- return;
12024
- }
12025
- if (data.shippingMethod) {
12026
- await updateShippingMethod(
12027
- {
12028
- method_id: data.shippingMethod.id,
12029
- shipping_option_id: values.shipping_option_id,
12030
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12031
- },
12032
- {
12033
- onError: (e) => {
12034
- ui.toast.error(e.message);
12035
- },
12036
- onSuccess: () => {
12037
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12038
- }
12039
- }
12040
- );
12041
- return;
12042
- }
12043
- await addShippingMethod(
12044
- {
12045
- shipping_option_id: values.shipping_option_id,
12046
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12047
- },
12048
- {
12049
- onError: (e) => {
12050
- ui.toast.error(e.message);
12051
- },
12052
- onSuccess: () => {
12053
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12054
- }
12055
- }
12056
- );
12057
- });
12058
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12059
- KeyboundForm,
12060
- {
12061
- className: "flex h-full flex-col overflow-hidden",
12062
- onSubmit,
12063
- children: [
12064
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12065
- /* @__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 py-16 px-6", children: [
12066
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12067
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12068
- /* @__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." }) })
11590
+ control: form.control,
11591
+ name: "postal_code",
11592
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11595
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11596
+ ] })
11597
+ }
11598
+ ),
11599
+ /* @__PURE__ */ jsxRuntime.jsx(
11600
+ Form$2.Field,
11601
+ {
11602
+ control: form.control,
11603
+ name: "city",
11604
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11605
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11606
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11607
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11608
+ ] })
11609
+ }
11610
+ )
12069
11611
  ] }),
12070
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12071
11612
  /* @__PURE__ */ jsxRuntime.jsx(
12072
- LocationField,
11613
+ Form$2.Field,
12073
11614
  {
12074
11615
  control: form.control,
12075
- setValue: form.setValue
11616
+ name: "province",
11617
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11618
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11619
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11620
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11621
+ ] })
12076
11622
  }
12077
11623
  ),
12078
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12079
11624
  /* @__PURE__ */ jsxRuntime.jsx(
12080
- ShippingOptionField,
12081
- {
12082
- shippingProfileId: data.shippingProfileId,
12083
- preview,
12084
- control: form.control
12085
- }
12086
- ),
12087
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12088
- /* @__PURE__ */ jsxRuntime.jsx(
12089
- CustomAmountField,
11625
+ Form$2.Field,
12090
11626
  {
12091
11627
  control: form.control,
12092
- currencyCode: order.currency_code
12093
- }
12094
- ),
12095
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12096
- /* @__PURE__ */ jsxRuntime.jsx(
12097
- ItemsPreview,
12098
- {
12099
- order,
12100
- shippingProfileId: data.shippingProfileId
12101
- }
12102
- )
12103
- ] }) }) }),
12104
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12105
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12106
- /* @__PURE__ */ jsxRuntime.jsx(
12107
- ui.Button,
12108
- {
12109
- size: "small",
12110
- type: "submit",
12111
- isLoading: isPending || isUpdatingShippingMethod,
12112
- children: data.shippingMethod ? "Update" : "Add"
11628
+ name: "phone",
11629
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11630
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11631
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11632
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11633
+ ] })
12113
11634
  }
12114
11635
  )
11636
+ ] }) }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11638
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11639
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12115
11640
  ] }) })
12116
11641
  ]
12117
11642
  }
12118
- ) }) });
11643
+ ) });
12119
11644
  };
12120
- const shippingMethodSchema = objectType({
12121
- location_id: stringType(),
12122
- shipping_option_id: stringType(),
12123
- custom_amount: unionType([numberType(), stringType()]).optional()
12124
- });
12125
- const ItemsPreview = ({ order, shippingProfileId }) => {
12126
- const matches = order.items.filter(
12127
- (item) => {
12128
- var _a, _b, _c;
12129
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12130
- }
12131
- );
12132
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12133
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12134
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12135
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12136
- ] }) }),
12137
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12138
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12139
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12140
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12141
- ] }),
12142
- /* @__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(
12143
- "div",
12144
- {
12145
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12146
- children: [
12147
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12148
- /* @__PURE__ */ jsxRuntime.jsx(
12149
- Thumbnail,
12150
- {
12151
- thumbnail: item.thumbnail,
12152
- alt: item.product_title ?? void 0
12153
- }
12154
- ),
12155
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12156
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12157
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12158
- /* @__PURE__ */ jsxRuntime.jsxs(
12159
- ui.Text,
12160
- {
12161
- size: "small",
12162
- leading: "compact",
12163
- className: "text-ui-fg-subtle",
12164
- children: [
12165
- "(",
12166
- item.variant_title,
12167
- ")"
12168
- ]
12169
- }
12170
- )
12171
- ] }),
12172
- /* @__PURE__ */ jsxRuntime.jsx(
12173
- ui.Text,
12174
- {
12175
- size: "small",
12176
- leading: "compact",
12177
- className: "text-ui-fg-subtle",
12178
- children: item.variant_sku
12179
- }
12180
- )
12181
- ] })
12182
- ] }),
12183
- /* @__PURE__ */ jsxRuntime.jsxs(
12184
- ui.Text,
12185
- {
12186
- size: "small",
12187
- leading: "compact",
12188
- className: "text-ui-fg-subtle",
12189
- children: [
12190
- item.quantity,
12191
- "x"
12192
- ]
12193
- }
12194
- )
12195
- ]
12196
- },
12197
- item.id
12198
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12199
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12200
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12201
- 'No items found for "',
12202
- query,
12203
- '".'
12204
- ] })
12205
- ] }) })
12206
- ] })
11645
+ const schema$2 = addressSchema;
11646
+ const TransferOwnership = () => {
11647
+ const { id } = reactRouterDom.useParams();
11648
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11649
+ fields: "id,customer_id,customer.*"
11650
+ });
11651
+ if (isError) {
11652
+ throw error;
11653
+ }
11654
+ const isReady = !isPending && !!draft_order;
11655
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11656
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11657
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11658
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11659
+ ] }),
11660
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12207
11661
  ] });
12208
11662
  };
12209
- const LocationField = ({ control, setValue }) => {
12210
- const locations = useComboboxData({
12211
- queryKey: ["locations"],
12212
- queryFn: async (params) => {
12213
- return await sdk.admin.stockLocation.list(params);
11663
+ const TransferOwnershipForm = ({ order }) => {
11664
+ var _a, _b;
11665
+ const form = reactHookForm.useForm({
11666
+ defaultValues: {
11667
+ customer_id: order.customer_id || ""
12214
11668
  },
12215
- getOptions: (data) => {
12216
- return data.stock_locations.map((location) => ({
12217
- label: location.name,
12218
- value: location.id
12219
- }));
12220
- }
11669
+ resolver: zod.zodResolver(schema$1)
12221
11670
  });
12222
- return /* @__PURE__ */ jsxRuntime.jsx(
12223
- Form$2.Field,
11671
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11672
+ const { handleSuccess } = useRouteModal();
11673
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11674
+ const currentCustomer = order.customer ? {
11675
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11676
+ value: order.customer.id
11677
+ } : null;
11678
+ const onSubmit = form.handleSubmit(async (data) => {
11679
+ await mutateAsync(
11680
+ { customer_id: data.customer_id },
11681
+ {
11682
+ onSuccess: () => {
11683
+ ui.toast.success("Customer updated");
11684
+ handleSuccess();
11685
+ },
11686
+ onError: (error) => {
11687
+ ui.toast.error(error.message);
11688
+ }
11689
+ }
11690
+ );
11691
+ });
11692
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11693
+ KeyboundForm,
12224
11694
  {
12225
- control,
12226
- name: "location_id",
12227
- render: ({ field: { onChange, ...field } }) => {
12228
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12229
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12230
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12231
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11695
+ className: "flex flex-1 flex-col overflow-hidden",
11696
+ onSubmit,
11697
+ children: [
11698
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11699
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11700
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11701
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11702
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11703
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11704
+ ] }),
11705
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11706
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11707
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11708
+ ] })
12232
11709
  ] }),
12233
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12234
- Combobox,
11710
+ /* @__PURE__ */ jsxRuntime.jsx(
11711
+ CustomerField,
12235
11712
  {
12236
- options: locations.options,
12237
- fetchNextPage: locations.fetchNextPage,
12238
- isFetchingNextPage: locations.isFetchingNextPage,
12239
- searchValue: locations.searchValue,
12240
- onSearchValueChange: locations.onSearchValueChange,
12241
- placeholder: "Select location",
12242
- onChange: (value) => {
12243
- setValue("shipping_option_id", "", {
12244
- shouldDirty: true,
12245
- shouldTouch: true
12246
- });
12247
- onChange(value);
12248
- },
12249
- ...field
11713
+ control: form.control,
11714
+ currentCustomerId: order.customer_id
12250
11715
  }
12251
- ) })
12252
- ] }) });
12253
- }
11716
+ )
11717
+ ] }),
11718
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11719
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11720
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11721
+ ] }) })
11722
+ ]
12254
11723
  }
12255
- );
11724
+ ) });
12256
11725
  };
12257
- const ShippingOptionField = ({
12258
- shippingProfileId,
12259
- preview,
12260
- control
12261
- }) => {
12262
- var _a;
12263
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12264
- const shippingOptions = useComboboxData({
12265
- queryKey: ["shipping_options", locationId, shippingProfileId],
11726
+ const CustomerField = ({ control, currentCustomerId }) => {
11727
+ const customers = useComboboxData({
12266
11728
  queryFn: async (params) => {
12267
- return await sdk.admin.shippingOption.list({
11729
+ return await sdk.admin.customer.list({
12268
11730
  ...params,
12269
- stock_location_id: locationId,
12270
- shipping_profile_id: shippingProfileId
11731
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12271
11732
  });
12272
11733
  },
12273
- getOptions: (data) => {
12274
- return data.shipping_options.map((option) => {
12275
- var _a2;
12276
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12277
- (r) => r.attribute === "is_return" && r.value === "true"
12278
- )) {
12279
- return void 0;
12280
- }
12281
- return {
12282
- label: option.name,
12283
- value: option.id
12284
- };
12285
- }).filter(Boolean);
12286
- },
12287
- enabled: !!locationId && !!shippingProfileId,
12288
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12289
- });
12290
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12291
- return /* @__PURE__ */ jsxRuntime.jsx(
12292
- Form$2.Field,
12293
- {
12294
- control,
12295
- name: "shipping_option_id",
12296
- render: ({ field }) => {
12297
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12298
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12299
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12300
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12301
- ] }),
12302
- /* @__PURE__ */ jsxRuntime.jsx(
12303
- ConditionalTooltip,
12304
- {
12305
- content: tooltipContent,
12306
- showTooltip: !locationId || !shippingProfileId,
12307
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12308
- Combobox,
12309
- {
12310
- options: shippingOptions.options,
12311
- fetchNextPage: shippingOptions.fetchNextPage,
12312
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12313
- searchValue: shippingOptions.searchValue,
12314
- onSearchValueChange: shippingOptions.onSearchValueChange,
12315
- placeholder: "Select shipping option",
12316
- ...field,
12317
- disabled: !locationId || !shippingProfileId
12318
- }
12319
- ) }) })
12320
- }
12321
- )
12322
- ] }) });
12323
- }
12324
- }
12325
- );
12326
- };
12327
- const CustomAmountField = ({
12328
- control,
12329
- currencyCode
12330
- }) => {
12331
- return /* @__PURE__ */ jsxRuntime.jsx(
12332
- Form$2.Field,
12333
- {
12334
- control,
12335
- name: "custom_amount",
12336
- render: ({ field: { onChange, ...field } }) => {
12337
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12338
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12341
- ] }),
12342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12343
- ui.CurrencyInput,
12344
- {
12345
- ...field,
12346
- onValueChange: (value) => onChange(value),
12347
- symbol: getNativeSymbol(currencyCode),
12348
- code: currencyCode
12349
- }
12350
- ) })
12351
- ] });
12352
- }
12353
- }
12354
- );
12355
- };
12356
- const TransferOwnership = () => {
12357
- const { id } = reactRouterDom.useParams();
12358
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12359
- fields: "id,customer_id,customer.*"
12360
- });
12361
- if (isError) {
12362
- throw error;
12363
- }
12364
- const isReady = !isPending && !!draft_order;
12365
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12366
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12367
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12368
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12369
- ] }),
12370
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12371
- ] });
12372
- };
12373
- const TransferOwnershipForm = ({ order }) => {
12374
- var _a, _b;
12375
- const form = reactHookForm.useForm({
12376
- defaultValues: {
12377
- customer_id: order.customer_id || ""
12378
- },
12379
- resolver: zod.zodResolver(schema$1)
12380
- });
12381
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12382
- const { handleSuccess } = useRouteModal();
12383
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12384
- const currentCustomer = order.customer ? {
12385
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12386
- value: order.customer.id
12387
- } : null;
12388
- const onSubmit = form.handleSubmit(async (data) => {
12389
- await mutateAsync(
12390
- { customer_id: data.customer_id },
12391
- {
12392
- onSuccess: () => {
12393
- ui.toast.success("Customer updated");
12394
- handleSuccess();
12395
- },
12396
- onError: (error) => {
12397
- ui.toast.error(error.message);
12398
- }
12399
- }
12400
- );
12401
- });
12402
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12403
- KeyboundForm,
12404
- {
12405
- className: "flex flex-1 flex-col overflow-hidden",
12406
- onSubmit,
12407
- children: [
12408
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12409
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12410
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12411
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12412
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12413
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12414
- ] }),
12415
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12416
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12417
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12418
- ] })
12419
- ] }),
12420
- /* @__PURE__ */ jsxRuntime.jsx(
12421
- CustomerField,
12422
- {
12423
- control: form.control,
12424
- currentCustomerId: order.customer_id
12425
- }
12426
- )
12427
- ] }),
12428
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12429
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12430
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12431
- ] }) })
12432
- ]
12433
- }
12434
- ) });
12435
- };
12436
- const CustomerField = ({ control, currentCustomerId }) => {
12437
- const customers = useComboboxData({
12438
- queryFn: async (params) => {
12439
- return await sdk.admin.customer.list({
12440
- ...params,
12441
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12442
- });
12443
- },
12444
- queryKey: ["customers"],
11734
+ queryKey: ["customers"],
12445
11735
  getOptions: (data) => {
12446
11736
  return data.customers.map((customer) => {
12447
11737
  const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
@@ -12821,45 +12111,848 @@ const Illustration = () => {
12821
12111
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12822
12112
  }
12823
12113
  ) })
12824
- ] })
12825
- ]
12114
+ ] })
12115
+ ]
12116
+ }
12117
+ );
12118
+ };
12119
+ const schema$1 = objectType({
12120
+ customer_id: stringType().min(1)
12121
+ });
12122
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12123
+ const Shipping = () => {
12124
+ var _a;
12125
+ const { id } = reactRouterDom.useParams();
12126
+ const { order, isPending, isError, error } = useOrder(id, {
12127
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12128
+ });
12129
+ const {
12130
+ order: preview,
12131
+ isPending: isPreviewPending,
12132
+ isError: isPreviewError,
12133
+ error: previewError
12134
+ } = useOrderPreview(id);
12135
+ useInitiateOrderEdit({ preview });
12136
+ const { onCancel } = useCancelOrderEdit({ preview });
12137
+ if (isError) {
12138
+ throw error;
12139
+ }
12140
+ if (isPreviewError) {
12141
+ throw previewError;
12142
+ }
12143
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12144
+ const isReady = preview && !isPreviewPending && order && !isPending;
12145
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12146
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12147
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12148
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12149
+ /* @__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." }) })
12150
+ ] }) }) }),
12151
+ /* @__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" }) }) })
12152
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12153
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12154
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12155
+ ] }) });
12156
+ };
12157
+ const ShippingForm = ({ preview, order }) => {
12158
+ var _a;
12159
+ const { setIsOpen } = useStackedModal();
12160
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12161
+ const [data, setData] = React.useState(null);
12162
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12163
+ const { shipping_options } = useShippingOptions(
12164
+ {
12165
+ id: appliedShippingOptionIds,
12166
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12167
+ },
12168
+ {
12169
+ enabled: appliedShippingOptionIds.length > 0
12170
+ }
12171
+ );
12172
+ const uniqueShippingProfiles = React.useMemo(() => {
12173
+ const profiles = /* @__PURE__ */ new Map();
12174
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12175
+ profiles.set(profile.id, profile);
12176
+ });
12177
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12178
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12179
+ });
12180
+ return Array.from(profiles.values());
12181
+ }, [order.items, shipping_options]);
12182
+ const { handleSuccess } = useRouteModal();
12183
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12184
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12185
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12186
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12187
+ const onSubmit = async () => {
12188
+ setIsSubmitting(true);
12189
+ let requestSucceeded = false;
12190
+ await requestOrderEdit(void 0, {
12191
+ onError: (e) => {
12192
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12193
+ },
12194
+ onSuccess: () => {
12195
+ requestSucceeded = true;
12196
+ }
12197
+ });
12198
+ if (!requestSucceeded) {
12199
+ setIsSubmitting(false);
12200
+ return;
12201
+ }
12202
+ await confirmOrderEdit(void 0, {
12203
+ onError: (e) => {
12204
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12205
+ },
12206
+ onSuccess: () => {
12207
+ handleSuccess();
12208
+ },
12209
+ onSettled: () => {
12210
+ setIsSubmitting(false);
12211
+ }
12212
+ });
12213
+ };
12214
+ const onKeydown = React.useCallback(
12215
+ (e) => {
12216
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12217
+ if (data || isSubmitting) {
12218
+ return;
12219
+ }
12220
+ onSubmit();
12221
+ }
12222
+ },
12223
+ [data, isSubmitting, onSubmit]
12224
+ );
12225
+ React.useEffect(() => {
12226
+ document.addEventListener("keydown", onKeydown);
12227
+ return () => {
12228
+ document.removeEventListener("keydown", onKeydown);
12229
+ };
12230
+ }, [onKeydown]);
12231
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12232
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12233
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12234
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12235
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12236
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12237
+ /* @__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." }) })
12238
+ ] }),
12239
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12240
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12241
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12242
+ /* @__PURE__ */ jsxRuntime.jsx(
12243
+ ui.Text,
12244
+ {
12245
+ size: "xsmall",
12246
+ weight: "plus",
12247
+ className: "text-ui-fg-muted",
12248
+ children: "Shipping profile"
12249
+ }
12250
+ ),
12251
+ /* @__PURE__ */ jsxRuntime.jsx(
12252
+ ui.Text,
12253
+ {
12254
+ size: "xsmall",
12255
+ weight: "plus",
12256
+ className: "text-ui-fg-muted",
12257
+ children: "Action"
12258
+ }
12259
+ )
12260
+ ] }),
12261
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12262
+ var _a2, _b, _c, _d, _e, _f, _g;
12263
+ const items = getItemsWithShippingProfile(
12264
+ profile.id,
12265
+ order.items
12266
+ );
12267
+ const hasItems = items.length > 0;
12268
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12269
+ (option) => option.shipping_profile_id === profile.id
12270
+ );
12271
+ const shippingMethod = preview.shipping_methods.find(
12272
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12273
+ );
12274
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12275
+ (action) => action.action === "SHIPPING_ADD"
12276
+ );
12277
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12278
+ radixUi.Accordion.Item,
12279
+ {
12280
+ value: profile.id,
12281
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12282
+ children: [
12283
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12284
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12285
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12286
+ ui.IconButton,
12287
+ {
12288
+ size: "2xsmall",
12289
+ variant: "transparent",
12290
+ className: "group/trigger",
12291
+ disabled: !hasItems,
12292
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12293
+ }
12294
+ ) }),
12295
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12296
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12297
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
12298
+ /* @__PURE__ */ jsxRuntime.jsx(
12299
+ ui.Text,
12300
+ {
12301
+ size: "small",
12302
+ weight: "plus",
12303
+ leading: "compact",
12304
+ children: profile.name
12305
+ }
12306
+ ),
12307
+ /* @__PURE__ */ jsxRuntime.jsxs(
12308
+ ui.Text,
12309
+ {
12310
+ size: "small",
12311
+ leading: "compact",
12312
+ className: "text-ui-fg-subtle",
12313
+ children: [
12314
+ items.length,
12315
+ " ",
12316
+ pluralize(items.length, "items", "item")
12317
+ ]
12318
+ }
12319
+ )
12320
+ ] })
12321
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
12322
+ /* @__PURE__ */ jsxRuntime.jsx(
12323
+ ui.Tooltip,
12324
+ {
12325
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12326
+ var _a3, _b2, _c2;
12327
+ return /* @__PURE__ */ jsxRuntime.jsx(
12328
+ "li",
12329
+ {
12330
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12331
+ },
12332
+ item.id
12333
+ );
12334
+ }) }),
12335
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12336
+ ui.Badge,
12337
+ {
12338
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12339
+ size: "xsmall",
12340
+ children: [
12341
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12342
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12343
+ items.reduce(
12344
+ (acc, item) => acc + item.quantity,
12345
+ 0
12346
+ ),
12347
+ "x",
12348
+ " ",
12349
+ pluralize(items.length, "items", "item")
12350
+ ] })
12351
+ ]
12352
+ }
12353
+ )
12354
+ }
12355
+ ),
12356
+ /* @__PURE__ */ jsxRuntime.jsx(
12357
+ ui.Tooltip,
12358
+ {
12359
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12360
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12361
+ ui.Badge,
12362
+ {
12363
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12364
+ size: "xsmall",
12365
+ children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12367
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12368
+ ]
12369
+ }
12370
+ )
12371
+ }
12372
+ ),
12373
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12374
+ ui.Badge,
12375
+ {
12376
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12377
+ size: "xsmall",
12378
+ children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12380
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12381
+ ]
12382
+ }
12383
+ ) })
12384
+ ] })
12385
+ ] }),
12386
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12387
+ ActionMenu,
12388
+ {
12389
+ groups: [
12390
+ {
12391
+ actions: [
12392
+ hasItems ? {
12393
+ label: "Edit shipping option",
12394
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12395
+ onClick: () => {
12396
+ setIsOpen(
12397
+ STACKED_FOCUS_MODAL_ID,
12398
+ true
12399
+ );
12400
+ setData({
12401
+ shippingProfileId: profile.id,
12402
+ shippingOption,
12403
+ shippingMethod
12404
+ });
12405
+ }
12406
+ } : void 0,
12407
+ {
12408
+ label: "Remove shipping option",
12409
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12410
+ onClick: () => {
12411
+ if (shippingMethod) {
12412
+ if (addShippingMethodAction) {
12413
+ removeActionShippingMethod(
12414
+ addShippingMethodAction.id
12415
+ );
12416
+ } else {
12417
+ removeShippingMethod(
12418
+ shippingMethod.id
12419
+ );
12420
+ }
12421
+ }
12422
+ }
12423
+ }
12424
+ ].filter(Boolean)
12425
+ }
12426
+ ]
12427
+ }
12428
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12429
+ StackedModalTrigger,
12430
+ {
12431
+ shippingProfileId: profile.id,
12432
+ shippingOption,
12433
+ shippingMethod,
12434
+ setData,
12435
+ children: "Add shipping option"
12436
+ }
12437
+ )
12438
+ ] }),
12439
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12440
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12441
+ items.map((item, idx) => {
12442
+ var _a3, _b2, _c2, _d2, _e2;
12443
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsxs(
12445
+ "div",
12446
+ {
12447
+ className: "px-3 flex items-center gap-x-3",
12448
+ children: [
12449
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12450
+ ui.Divider,
12451
+ {
12452
+ variant: "dashed",
12453
+ orientation: "vertical"
12454
+ }
12455
+ ) }),
12456
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12458
+ ui.Text,
12459
+ {
12460
+ size: "small",
12461
+ leading: "compact",
12462
+ className: "text-ui-fg-subtle",
12463
+ children: [
12464
+ item.quantity,
12465
+ "x"
12466
+ ]
12467
+ }
12468
+ ) }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12470
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12471
+ /* @__PURE__ */ jsxRuntime.jsxs(
12472
+ ui.Text,
12473
+ {
12474
+ size: "small",
12475
+ leading: "compact",
12476
+ weight: "plus",
12477
+ children: [
12478
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12479
+ " (",
12480
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12481
+ ")"
12482
+ ]
12483
+ }
12484
+ ),
12485
+ /* @__PURE__ */ jsxRuntime.jsx(
12486
+ ui.Text,
12487
+ {
12488
+ size: "small",
12489
+ leading: "compact",
12490
+ className: "text-ui-fg-subtle",
12491
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12492
+ }
12493
+ )
12494
+ ] })
12495
+ ] })
12496
+ ]
12497
+ },
12498
+ item.id
12499
+ ),
12500
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12501
+ ] }, item.id);
12502
+ })
12503
+ ] })
12504
+ ]
12505
+ },
12506
+ profile.id
12507
+ );
12508
+ }) })
12509
+ ] }) })
12510
+ ] }) }),
12511
+ /* @__PURE__ */ jsxRuntime.jsx(
12512
+ StackedFocusModal,
12513
+ {
12514
+ id: STACKED_FOCUS_MODAL_ID,
12515
+ onOpenChangeCallback: (open) => {
12516
+ if (!open) {
12517
+ setData(null);
12518
+ }
12519
+ return open;
12520
+ },
12521
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12522
+ }
12523
+ )
12524
+ ] }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12526
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12527
+ /* @__PURE__ */ jsxRuntime.jsx(
12528
+ ui.Button,
12529
+ {
12530
+ size: "small",
12531
+ type: "button",
12532
+ isLoading: isSubmitting,
12533
+ onClick: onSubmit,
12534
+ children: "Save"
12535
+ }
12536
+ )
12537
+ ] }) })
12538
+ ] });
12539
+ };
12540
+ const StackedModalTrigger = ({
12541
+ shippingProfileId,
12542
+ shippingOption,
12543
+ shippingMethod,
12544
+ setData,
12545
+ children
12546
+ }) => {
12547
+ const { setIsOpen, getIsOpen } = useStackedModal();
12548
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12549
+ const onToggle = () => {
12550
+ if (isOpen) {
12551
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12552
+ setData(null);
12553
+ } else {
12554
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12555
+ setData({
12556
+ shippingProfileId,
12557
+ shippingOption,
12558
+ shippingMethod
12559
+ });
12560
+ }
12561
+ };
12562
+ return /* @__PURE__ */ jsxRuntime.jsx(
12563
+ ui.Button,
12564
+ {
12565
+ size: "small",
12566
+ variant: "secondary",
12567
+ onClick: onToggle,
12568
+ className: "text-ui-fg-primary shrink-0",
12569
+ children
12570
+ }
12571
+ );
12572
+ };
12573
+ const ShippingProfileForm = ({
12574
+ data,
12575
+ order,
12576
+ preview
12577
+ }) => {
12578
+ var _a, _b, _c, _d, _e, _f;
12579
+ const { setIsOpen } = useStackedModal();
12580
+ const form = reactHookForm.useForm({
12581
+ resolver: zod.zodResolver(shippingMethodSchema),
12582
+ defaultValues: {
12583
+ 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,
12584
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12585
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12586
+ }
12587
+ });
12588
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12589
+ const {
12590
+ mutateAsync: updateShippingMethod,
12591
+ isPending: isUpdatingShippingMethod
12592
+ } = useDraftOrderUpdateShippingMethod(order.id);
12593
+ const onSubmit = form.handleSubmit(async (values) => {
12594
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12595
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12596
+ return;
12597
+ }
12598
+ if (data.shippingMethod) {
12599
+ await updateShippingMethod(
12600
+ {
12601
+ method_id: data.shippingMethod.id,
12602
+ shipping_option_id: values.shipping_option_id,
12603
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12604
+ },
12605
+ {
12606
+ onError: (e) => {
12607
+ ui.toast.error(e.message);
12608
+ },
12609
+ onSuccess: () => {
12610
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12611
+ }
12612
+ }
12613
+ );
12614
+ return;
12615
+ }
12616
+ await addShippingMethod(
12617
+ {
12618
+ shipping_option_id: values.shipping_option_id,
12619
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12620
+ },
12621
+ {
12622
+ onError: (e) => {
12623
+ ui.toast.error(e.message);
12624
+ },
12625
+ onSuccess: () => {
12626
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12627
+ }
12628
+ }
12629
+ );
12630
+ });
12631
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12632
+ KeyboundForm,
12633
+ {
12634
+ className: "flex h-full flex-col overflow-hidden",
12635
+ onSubmit,
12636
+ children: [
12637
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12638
+ /* @__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 py-16 px-6", children: [
12639
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12640
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12641
+ /* @__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." }) })
12642
+ ] }),
12643
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(
12645
+ LocationField,
12646
+ {
12647
+ control: form.control,
12648
+ setValue: form.setValue
12649
+ }
12650
+ ),
12651
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12652
+ /* @__PURE__ */ jsxRuntime.jsx(
12653
+ ShippingOptionField,
12654
+ {
12655
+ shippingProfileId: data.shippingProfileId,
12656
+ preview,
12657
+ control: form.control
12658
+ }
12659
+ ),
12660
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12661
+ /* @__PURE__ */ jsxRuntime.jsx(
12662
+ CustomAmountField,
12663
+ {
12664
+ control: form.control,
12665
+ currencyCode: order.currency_code
12666
+ }
12667
+ ),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12669
+ /* @__PURE__ */ jsxRuntime.jsx(
12670
+ ItemsPreview,
12671
+ {
12672
+ order,
12673
+ shippingProfileId: data.shippingProfileId
12674
+ }
12675
+ )
12676
+ ] }) }) }),
12677
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12678
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12679
+ /* @__PURE__ */ jsxRuntime.jsx(
12680
+ ui.Button,
12681
+ {
12682
+ size: "small",
12683
+ type: "submit",
12684
+ isLoading: isPending || isUpdatingShippingMethod,
12685
+ children: data.shippingMethod ? "Update" : "Add"
12686
+ }
12687
+ )
12688
+ ] }) })
12689
+ ]
12690
+ }
12691
+ ) }) });
12692
+ };
12693
+ const shippingMethodSchema = objectType({
12694
+ location_id: stringType(),
12695
+ shipping_option_id: stringType(),
12696
+ custom_amount: unionType([numberType(), stringType()]).optional()
12697
+ });
12698
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12699
+ const matches = order.items.filter(
12700
+ (item) => {
12701
+ var _a, _b, _c;
12702
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12703
+ }
12704
+ );
12705
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12706
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12707
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12708
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12709
+ ] }) }),
12710
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12711
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12712
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12713
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12714
+ ] }),
12715
+ /* @__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(
12716
+ "div",
12717
+ {
12718
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12719
+ children: [
12720
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12721
+ /* @__PURE__ */ jsxRuntime.jsx(
12722
+ Thumbnail,
12723
+ {
12724
+ thumbnail: item.thumbnail,
12725
+ alt: item.product_title ?? void 0
12726
+ }
12727
+ ),
12728
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12729
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12730
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12731
+ /* @__PURE__ */ jsxRuntime.jsxs(
12732
+ ui.Text,
12733
+ {
12734
+ size: "small",
12735
+ leading: "compact",
12736
+ className: "text-ui-fg-subtle",
12737
+ children: [
12738
+ "(",
12739
+ item.variant_title,
12740
+ ")"
12741
+ ]
12742
+ }
12743
+ )
12744
+ ] }),
12745
+ /* @__PURE__ */ jsxRuntime.jsx(
12746
+ ui.Text,
12747
+ {
12748
+ size: "small",
12749
+ leading: "compact",
12750
+ className: "text-ui-fg-subtle",
12751
+ children: item.variant_sku
12752
+ }
12753
+ )
12754
+ ] })
12755
+ ] }),
12756
+ /* @__PURE__ */ jsxRuntime.jsxs(
12757
+ ui.Text,
12758
+ {
12759
+ size: "small",
12760
+ leading: "compact",
12761
+ className: "text-ui-fg-subtle",
12762
+ children: [
12763
+ item.quantity,
12764
+ "x"
12765
+ ]
12766
+ }
12767
+ )
12768
+ ]
12769
+ },
12770
+ item.id
12771
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12772
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12773
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12774
+ 'No items found for "',
12775
+ query,
12776
+ '".'
12777
+ ] })
12778
+ ] }) })
12779
+ ] })
12780
+ ] });
12781
+ };
12782
+ const LocationField = ({ control, setValue }) => {
12783
+ const locations = useComboboxData({
12784
+ queryKey: ["locations"],
12785
+ queryFn: async (params) => {
12786
+ return await sdk.admin.stockLocation.list(params);
12787
+ },
12788
+ getOptions: (data) => {
12789
+ return data.stock_locations.map((location) => ({
12790
+ label: location.name,
12791
+ value: location.id
12792
+ }));
12793
+ }
12794
+ });
12795
+ return /* @__PURE__ */ jsxRuntime.jsx(
12796
+ Form$2.Field,
12797
+ {
12798
+ control,
12799
+ name: "location_id",
12800
+ render: ({ field: { onChange, ...field } }) => {
12801
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12802
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12803
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12804
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12805
+ ] }),
12806
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12807
+ Combobox,
12808
+ {
12809
+ options: locations.options,
12810
+ fetchNextPage: locations.fetchNextPage,
12811
+ isFetchingNextPage: locations.isFetchingNextPage,
12812
+ searchValue: locations.searchValue,
12813
+ onSearchValueChange: locations.onSearchValueChange,
12814
+ placeholder: "Select location",
12815
+ onChange: (value) => {
12816
+ setValue("shipping_option_id", "", {
12817
+ shouldDirty: true,
12818
+ shouldTouch: true
12819
+ });
12820
+ onChange(value);
12821
+ },
12822
+ ...field
12823
+ }
12824
+ ) })
12825
+ ] }) });
12826
+ }
12827
+ }
12828
+ );
12829
+ };
12830
+ const ShippingOptionField = ({
12831
+ shippingProfileId,
12832
+ preview,
12833
+ control
12834
+ }) => {
12835
+ var _a;
12836
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12837
+ const shippingOptions = useComboboxData({
12838
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12839
+ queryFn: async (params) => {
12840
+ return await sdk.admin.shippingOption.list({
12841
+ ...params,
12842
+ stock_location_id: locationId,
12843
+ shipping_profile_id: shippingProfileId
12844
+ });
12845
+ },
12846
+ getOptions: (data) => {
12847
+ return data.shipping_options.map((option) => {
12848
+ var _a2;
12849
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12850
+ (r) => r.attribute === "is_return" && r.value === "true"
12851
+ )) {
12852
+ return void 0;
12853
+ }
12854
+ return {
12855
+ label: option.name,
12856
+ value: option.id
12857
+ };
12858
+ }).filter(Boolean);
12859
+ },
12860
+ enabled: !!locationId && !!shippingProfileId,
12861
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12862
+ });
12863
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12864
+ return /* @__PURE__ */ jsxRuntime.jsx(
12865
+ Form$2.Field,
12866
+ {
12867
+ control,
12868
+ name: "shipping_option_id",
12869
+ render: ({ field }) => {
12870
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12871
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12872
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12873
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12874
+ ] }),
12875
+ /* @__PURE__ */ jsxRuntime.jsx(
12876
+ ConditionalTooltip,
12877
+ {
12878
+ content: tooltipContent,
12879
+ showTooltip: !locationId || !shippingProfileId,
12880
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12881
+ Combobox,
12882
+ {
12883
+ options: shippingOptions.options,
12884
+ fetchNextPage: shippingOptions.fetchNextPage,
12885
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12886
+ searchValue: shippingOptions.searchValue,
12887
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12888
+ placeholder: "Select shipping option",
12889
+ ...field,
12890
+ disabled: !locationId || !shippingProfileId
12891
+ }
12892
+ ) }) })
12893
+ }
12894
+ )
12895
+ ] }) });
12896
+ }
12897
+ }
12898
+ );
12899
+ };
12900
+ const CustomAmountField = ({
12901
+ control,
12902
+ currencyCode
12903
+ }) => {
12904
+ return /* @__PURE__ */ jsxRuntime.jsx(
12905
+ Form$2.Field,
12906
+ {
12907
+ control,
12908
+ name: "custom_amount",
12909
+ render: ({ field: { onChange, ...field } }) => {
12910
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12911
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12913
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12914
+ ] }),
12915
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12916
+ ui.CurrencyInput,
12917
+ {
12918
+ ...field,
12919
+ onValueChange: (value) => onChange(value),
12920
+ symbol: getNativeSymbol(currencyCode),
12921
+ code: currencyCode
12922
+ }
12923
+ ) })
12924
+ ] });
12925
+ }
12826
12926
  }
12827
12927
  );
12828
12928
  };
12829
- const schema$1 = objectType({
12830
- customer_id: stringType().min(1)
12831
- });
12832
- const ShippingAddress = () => {
12929
+ const SalesChannel = () => {
12833
12930
  const { id } = reactRouterDom.useParams();
12834
- const { order, isPending, isError, error } = useOrder(id, {
12835
- fields: "+shipping_address"
12836
- });
12931
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12932
+ id,
12933
+ {
12934
+ fields: "+sales_channel_id"
12935
+ },
12936
+ {
12937
+ enabled: !!id
12938
+ }
12939
+ );
12837
12940
  if (isError) {
12838
12941
  throw error;
12839
12942
  }
12840
- const isReady = !isPending && !!order;
12943
+ const ISrEADY = !!draft_order && !isPending;
12841
12944
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12842
12945
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12843
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12946
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12845
12948
  ] }),
12846
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12949
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12847
12950
  ] });
12848
12951
  };
12849
- const ShippingAddressForm = ({ order }) => {
12850
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12952
+ const SalesChannelForm = ({ order }) => {
12851
12953
  const form = reactHookForm.useForm({
12852
12954
  defaultValues: {
12853
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12854
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12855
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12856
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12857
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12858
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12859
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12860
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12861
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12862
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12955
+ sales_channel_id: order.sales_channel_id || ""
12863
12956
  },
12864
12957
  resolver: zod.zodResolver(schema)
12865
12958
  });
@@ -12868,21 +12961,11 @@ const ShippingAddressForm = ({ order }) => {
12868
12961
  const onSubmit = form.handleSubmit(async (data) => {
12869
12962
  await mutateAsync(
12870
12963
  {
12871
- shipping_address: {
12872
- first_name: data.first_name,
12873
- last_name: data.last_name,
12874
- company: data.company,
12875
- address_1: data.address_1,
12876
- address_2: data.address_2,
12877
- city: data.city,
12878
- province: data.province,
12879
- country_code: data.country_code,
12880
- postal_code: data.postal_code,
12881
- phone: data.phone
12882
- }
12964
+ sales_channel_id: data.sales_channel_id
12883
12965
  },
12884
12966
  {
12885
12967
  onSuccess: () => {
12968
+ ui.toast.success("Sales channel updated");
12886
12969
  handleSuccess();
12887
12970
  },
12888
12971
  onError: (error) => {
@@ -12897,132 +12980,7 @@ const ShippingAddressForm = ({ order }) => {
12897
12980
  className: "flex flex-1 flex-col overflow-hidden",
12898
12981
  onSubmit,
12899
12982
  children: [
12900
- /* @__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: [
12901
- /* @__PURE__ */ jsxRuntime.jsx(
12902
- Form$2.Field,
12903
- {
12904
- control: form.control,
12905
- name: "country_code",
12906
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12907
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12908
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12909
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12910
- ] })
12911
- }
12912
- ),
12913
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12914
- /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12916
- {
12917
- control: form.control,
12918
- name: "first_name",
12919
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
- ] })
12924
- }
12925
- ),
12926
- /* @__PURE__ */ jsxRuntime.jsx(
12927
- Form$2.Field,
12928
- {
12929
- control: form.control,
12930
- name: "last_name",
12931
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
- ] })
12936
- }
12937
- )
12938
- ] }),
12939
- /* @__PURE__ */ jsxRuntime.jsx(
12940
- Form$2.Field,
12941
- {
12942
- control: form.control,
12943
- name: "company",
12944
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
- ] })
12949
- }
12950
- ),
12951
- /* @__PURE__ */ jsxRuntime.jsx(
12952
- Form$2.Field,
12953
- {
12954
- control: form.control,
12955
- name: "address_1",
12956
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
- ] })
12961
- }
12962
- ),
12963
- /* @__PURE__ */ jsxRuntime.jsx(
12964
- Form$2.Field,
12965
- {
12966
- control: form.control,
12967
- name: "address_2",
12968
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
- ] })
12973
- }
12974
- ),
12975
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12976
- /* @__PURE__ */ jsxRuntime.jsx(
12977
- Form$2.Field,
12978
- {
12979
- control: form.control,
12980
- name: "postal_code",
12981
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
- ] })
12986
- }
12987
- ),
12988
- /* @__PURE__ */ jsxRuntime.jsx(
12989
- Form$2.Field,
12990
- {
12991
- control: form.control,
12992
- name: "city",
12993
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
- ] })
12998
- }
12999
- )
13000
- ] }),
13001
- /* @__PURE__ */ jsxRuntime.jsx(
13002
- Form$2.Field,
13003
- {
13004
- control: form.control,
13005
- name: "province",
13006
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13008
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
- ] })
13011
- }
13012
- ),
13013
- /* @__PURE__ */ jsxRuntime.jsx(
13014
- Form$2.Field,
13015
- {
13016
- control: form.control,
13017
- name: "phone",
13018
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
- ] })
13023
- }
13024
- )
13025
- ] }) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
13026
12984
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13027
12985
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13028
12986
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13031,7 +12989,49 @@ const ShippingAddressForm = ({ order }) => {
13031
12989
  }
13032
12990
  ) });
13033
12991
  };
13034
- const schema = addressSchema;
12992
+ const SalesChannelField = ({ control, order }) => {
12993
+ const salesChannels = useComboboxData({
12994
+ queryFn: async (params) => {
12995
+ return await sdk.admin.salesChannel.list(params);
12996
+ },
12997
+ queryKey: ["sales-channels"],
12998
+ getOptions: (data) => {
12999
+ return data.sales_channels.map((salesChannel) => ({
13000
+ label: salesChannel.name,
13001
+ value: salesChannel.id
13002
+ }));
13003
+ },
13004
+ defaultValue: order.sales_channel_id || void 0
13005
+ });
13006
+ return /* @__PURE__ */ jsxRuntime.jsx(
13007
+ Form$2.Field,
13008
+ {
13009
+ control,
13010
+ name: "sales_channel_id",
13011
+ render: ({ field }) => {
13012
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Combobox,
13016
+ {
13017
+ options: salesChannels.options,
13018
+ fetchNextPage: salesChannels.fetchNextPage,
13019
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13020
+ searchValue: salesChannels.searchValue,
13021
+ onSearchValueChange: salesChannels.onSearchValueChange,
13022
+ placeholder: "Select sales channel",
13023
+ ...field
13024
+ }
13025
+ ) }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13027
+ ] });
13028
+ }
13029
+ }
13030
+ );
13031
+ };
13032
+ const schema = objectType({
13033
+ sales_channel_id: stringType().min(1)
13034
+ });
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13056,41 +13056,41 @@ const routeModule = {
13056
13056
  Component: BillingAddress,
13057
13057
  path: "/draft-orders/:id/billing-address"
13058
13058
  },
13059
- {
13060
- Component: Email,
13061
- path: "/draft-orders/:id/email"
13062
- },
13063
13059
  {
13064
13060
  Component: CustomItems,
13065
13061
  path: "/draft-orders/:id/custom-items"
13066
13062
  },
13067
13063
  {
13068
- Component: Items,
13069
- path: "/draft-orders/:id/items"
13064
+ Component: Email,
13065
+ path: "/draft-orders/:id/email"
13070
13066
  },
13071
13067
  {
13072
- Component: Metadata,
13073
- path: "/draft-orders/:id/metadata"
13068
+ Component: Items,
13069
+ path: "/draft-orders/:id/items"
13074
13070
  },
13075
13071
  {
13076
13072
  Component: Promotions,
13077
13073
  path: "/draft-orders/:id/promotions"
13078
13074
  },
13079
13075
  {
13080
- Component: SalesChannel,
13081
- path: "/draft-orders/:id/sales-channel"
13076
+ Component: Metadata,
13077
+ path: "/draft-orders/:id/metadata"
13082
13078
  },
13083
13079
  {
13084
- Component: Shipping,
13085
- path: "/draft-orders/:id/shipping"
13080
+ Component: ShippingAddress,
13081
+ path: "/draft-orders/:id/shipping-address"
13086
13082
  },
13087
13083
  {
13088
13084
  Component: TransferOwnership,
13089
13085
  path: "/draft-orders/:id/transfer-ownership"
13090
13086
  },
13091
13087
  {
13092
- Component: ShippingAddress,
13093
- path: "/draft-orders/:id/shipping-address"
13088
+ Component: Shipping,
13089
+ path: "/draft-orders/:id/shipping"
13090
+ },
13091
+ {
13092
+ Component: SalesChannel,
13093
+ path: "/draft-orders/:id/sales-channel"
13094
13094
  }
13095
13095
  ]
13096
13096
  }