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

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.
@@ -10813,392 +10813,115 @@ const customItemSchema = objectType({
10813
10813
  quantity: numberType(),
10814
10814
  unit_price: unionType([numberType(), stringType()])
10815
10815
  });
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
10833
- });
10834
- return { ...data, ...rest };
10835
- };
10836
- const Promotions = () => {
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 = () => {
10837
10861
  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;
10862
+ const { order, isPending, isError, error } = useOrder(id, {
10863
+ fields: "metadata"
10864
+ });
10865
+ if (isError) {
10866
+ throw error;
10847
10867
  }
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 })
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 })
10852
10875
  ] });
10853
10876
  };
10854
- const PromotionForm = ({ preview }) => {
10855
- const { items, shipping_methods } = preview;
10856
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10857
- const [comboboxValue, setComboboxValue] = React.useState("");
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 }) => {
10858
10880
  const { handleSuccess } = useRouteModal();
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
10864
- },
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
- });
10881
+ const hasUneditableRows = getHasUneditableRows(metadata);
10882
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10883
+ const form = reactHookForm.useForm({
10884
+ defaultValues: {
10885
+ metadata: getDefaultValues(metadata)
10878
10886
  },
10879
- getOptions: (data) => {
10880
- return data.promotions.map((promotion) => ({
10881
- label: promotion.code,
10882
- value: promotion.code
10883
- }));
10884
- }
10887
+ resolver: zod.zodResolver(MetadataSchema)
10885
10888
  });
10886
- const add = async (value) => {
10887
- if (!value) {
10888
- return;
10889
- }
10890
- addPromotions(
10889
+ const handleSubmit = form.handleSubmit(async (data) => {
10890
+ const parsedData = parseValues(data);
10891
+ await mutateAsync(
10891
10892
  {
10892
- promo_codes: [value]
10893
+ metadata: parsedData
10893
10894
  },
10894
10895
  {
10895
- onError: (e) => {
10896
- ui.toast.error(e.message);
10897
- comboboxData.onSearchValueChange("");
10898
- setComboboxValue("");
10899
- },
10900
10896
  onSuccess: () => {
10901
- comboboxData.onSearchValueChange("");
10902
- setComboboxValue("");
10897
+ ui.toast.success("Metadata updated");
10898
+ handleSuccess();
10899
+ },
10900
+ onError: (error) => {
10901
+ ui.toast.error(error.message);
10903
10902
  }
10904
10903
  }
10905
10904
  );
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;
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
+ });
10923
10918
  }
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
- }
10934
- });
10935
- };
10936
- if (isError) {
10937
- throw error;
10938
- }
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." })
10945
- ] }),
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
- }
10983
- )
10984
- ] }) })
10985
- ] });
10986
- };
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(
10996
- {
10997
- promo_codes: [promotion.code]
10998
- },
10999
- {
11000
- onError: (e) => {
11001
- ui.toast.error(e.message);
11002
- }
11003
- }
11004
- );
11005
- };
11006
- const displayValue = getDisplayValue(promotion);
11007
- return /* @__PURE__ */ jsxRuntime.jsxs(
11008
- "div",
11009
- {
11010
- className: ui.clx(
11011
- "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11012
- {
11013
- "animate-pulse": isLoading
11014
- }
11015
- ),
11016
- children: [
11017
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11018
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11019
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11020
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11021
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11022
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11023
- ] }),
11024
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11025
- ] })
11026
- ] }),
11027
- /* @__PURE__ */ jsxRuntime.jsx(
11028
- ui.IconButton,
11029
- {
11030
- size: "small",
11031
- type: "button",
11032
- variant: "transparent",
11033
- onClick: onRemove,
11034
- isLoading: isPending || isLoading,
11035
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11036
- }
11037
- )
11038
- ]
11039
- },
11040
- promotion.id
11041
- );
11042
- };
11043
- function getDisplayValue(promotion) {
11044
- var _a, _b, _c, _d;
11045
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11046
- if (!value) {
11047
- return null;
11048
- }
11049
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11050
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11051
- if (!currency) {
11052
- return null;
11053
- }
11054
- return getLocaleAmount(value, currency);
11055
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11056
- return formatPercentage(value);
11057
- }
11058
- return null;
11059
- }
11060
- const formatter = new Intl.NumberFormat([], {
11061
- style: "percent",
11062
- minimumFractionDigits: 2
11063
- });
11064
- const formatPercentage = (value, isPercentageValue = false) => {
11065
- let val = value || 0;
11066
- if (!isPercentageValue) {
11067
- val = val / 100;
11068
- }
11069
- return formatter.format(val);
11070
- };
11071
- function getPromotionCodes(items, shippingMethods) {
11072
- const codes = /* @__PURE__ */ new Set();
11073
- for (const item of items) {
11074
- if (item.adjustments) {
11075
- for (const adjustment of item.adjustments) {
11076
- if (adjustment.code) {
11077
- codes.add(adjustment.code);
11078
- }
11079
- }
11080
- }
11081
- }
11082
- for (const shippingMethod of shippingMethods) {
11083
- if (shippingMethod.adjustments) {
11084
- for (const adjustment of shippingMethod.adjustments) {
11085
- if (adjustment.code) {
11086
- codes.add(adjustment.code);
11087
- }
11088
- }
11089
- }
11090
- }
11091
- return Array.from(codes);
11092
- }
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",
11098
- {
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
- },
11177
- onError: (error) => {
11178
- ui.toast.error(error.message);
11179
- }
11180
- }
11181
- );
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
10919
+ }
10920
+ function insertRow(index, position) {
10921
+ insert(index + (position === "above" ? 0 : 1), {
10922
+ key: "",
10923
+ value: "",
10924
+ disabled: false
11202
10925
  });
11203
10926
  }
11204
10927
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -11440,247 +11163,323 @@ function getHasUneditableRows(metadata) {
11440
11163
  (value) => !EDITABLE_TYPES.includes(typeof value)
11441
11164
  );
11442
11165
  }
11443
- const ShippingAddress = () => {
11444
- const { id } = reactRouterDom.useParams();
11445
- const { order, isPending, isError, error } = useOrder(id, {
11446
- fields: "+shipping_address"
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
11447
11183
  });
11448
- if (isError) {
11449
- throw error;
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;
11450
11197
  }
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 })
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 })
11458
11202
  ] });
11459
11203
  };
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) ?? ""
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
11474
11214
  },
11475
- resolver: zod.zodResolver(schema$2)
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
+ }
11476
11235
  });
11477
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11478
- const { handleSuccess } = useRouteModal();
11479
- const onSubmit = form.handleSubmit(async (data) => {
11480
- await mutateAsync(
11236
+ const add = async (value) => {
11237
+ if (!value) {
11238
+ return;
11239
+ }
11240
+ addPromotions(
11481
11241
  {
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
- }
11242
+ promo_codes: [value]
11494
11243
  },
11495
11244
  {
11496
- onSuccess: () => {
11497
- handleSuccess();
11245
+ onError: (e) => {
11246
+ ui.toast.error(e.message);
11247
+ comboboxData.onSearchValueChange("");
11248
+ setComboboxValue("");
11498
11249
  },
11499
- onError: (error) => {
11500
- ui.toast.error(error.message);
11250
+ onSuccess: () => {
11251
+ comboboxData.onSearchValueChange("");
11252
+ setComboboxValue("");
11501
11253
  }
11502
11254
  }
11503
11255
  );
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: [
11525
- /* @__PURE__ */ jsxRuntime.jsx(
11526
- Form$2.Field,
11527
- {
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
- ] })
11535
- }
11536
- ),
11537
- /* @__PURE__ */ jsxRuntime.jsx(
11538
- Form$2.Field,
11539
- {
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
- ] })
11547
- }
11548
- )
11549
- ] }),
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,
11589
- {
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
- )
11611
- ] }),
11612
- /* @__PURE__ */ jsxRuntime.jsx(
11613
- Form$2.Field,
11614
- {
11615
- control: form.control,
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
- ] })
11622
- }
11623
- ),
11624
- /* @__PURE__ */ jsxRuntime.jsx(
11625
- Form$2.Field,
11626
- {
11627
- control: form.control,
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
- ] })
11634
- }
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" })
11640
- ] }) })
11641
- ]
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;
11642
11273
  }
11643
- ) });
11644
- };
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
- });
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
+ };
11651
11286
  if (isError) {
11652
11287
  throw error;
11653
11288
  }
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" }) })
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
+ }
11353
+ }
11354
+ );
11355
+ };
11356
+ const displayValue = getDisplayValue(promotion);
11357
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11358
+ "div",
11359
+ {
11360
+ className: ui.clx(
11361
+ "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11362
+ {
11363
+ "animate-pulse": isLoading
11364
+ }
11365
+ ),
11366
+ children: [
11367
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11368
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11369
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11370
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11371
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11372
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11373
+ ] }),
11374
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11375
+ ] })
11376
+ ] }),
11377
+ /* @__PURE__ */ jsxRuntime.jsx(
11378
+ ui.IconButton,
11379
+ {
11380
+ size: "small",
11381
+ type: "button",
11382
+ variant: "transparent",
11383
+ onClick: onRemove,
11384
+ isLoading: isPending || isLoading,
11385
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11386
+ }
11387
+ )
11388
+ ]
11389
+ },
11390
+ promotion.id
11391
+ );
11392
+ };
11393
+ function getDisplayValue(promotion) {
11394
+ var _a, _b, _c, _d;
11395
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11396
+ if (!value) {
11397
+ return null;
11398
+ }
11399
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11400
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11401
+ if (!currency) {
11402
+ return null;
11403
+ }
11404
+ return getLocaleAmount(value, currency);
11405
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11406
+ return formatPercentage(value);
11407
+ }
11408
+ return null;
11409
+ }
11410
+ const formatter = new Intl.NumberFormat([], {
11411
+ style: "percent",
11412
+ minimumFractionDigits: 2
11413
+ });
11414
+ const formatPercentage = (value, isPercentageValue = false) => {
11415
+ let val = value || 0;
11416
+ if (!isPercentageValue) {
11417
+ val = val / 100;
11418
+ }
11419
+ return formatter.format(val);
11420
+ };
11421
+ function getPromotionCodes(items, shippingMethods) {
11422
+ const codes = /* @__PURE__ */ new Set();
11423
+ for (const item of items) {
11424
+ if (item.adjustments) {
11425
+ for (const adjustment of item.adjustments) {
11426
+ if (adjustment.code) {
11427
+ codes.add(adjustment.code);
11428
+ }
11429
+ }
11430
+ }
11431
+ }
11432
+ for (const shippingMethod of shippingMethods) {
11433
+ if (shippingMethod.adjustments) {
11434
+ for (const adjustment of shippingMethod.adjustments) {
11435
+ if (adjustment.code) {
11436
+ codes.add(adjustment.code);
11437
+ }
11438
+ }
11439
+ }
11440
+ }
11441
+ return Array.from(codes);
11442
+ }
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" }) })
11659
11462
  ] }),
11660
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11463
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11661
11464
  ] });
11662
11465
  };
11663
- const TransferOwnershipForm = ({ order }) => {
11664
- var _a, _b;
11466
+ const SalesChannelForm = ({ order }) => {
11665
11467
  const form = reactHookForm.useForm({
11666
11468
  defaultValues: {
11667
- customer_id: order.customer_id || ""
11469
+ sales_channel_id: order.sales_channel_id || ""
11668
11470
  },
11669
- resolver: zod.zodResolver(schema$1)
11471
+ resolver: zod.zodResolver(schema$2)
11670
11472
  });
11671
11473
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11672
11474
  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
11475
  const onSubmit = form.handleSubmit(async (data) => {
11679
11476
  await mutateAsync(
11680
- { customer_id: data.customer_id },
11477
+ {
11478
+ sales_channel_id: data.sales_channel_id
11479
+ },
11681
11480
  {
11682
11481
  onSuccess: () => {
11683
- ui.toast.success("Customer updated");
11482
+ ui.toast.success("Sales channel updated");
11684
11483
  handleSuccess();
11685
11484
  },
11686
11485
  onError: (error) => {
@@ -11695,472 +11494,100 @@ const TransferOwnershipForm = ({ order }) => {
11695
11494
  className: "flex flex-1 flex-col overflow-hidden",
11696
11495
  onSubmit,
11697
11496
  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
- ] })
11709
- ] }),
11710
- /* @__PURE__ */ jsxRuntime.jsx(
11711
- CustomerField,
11712
- {
11713
- control: form.control,
11714
- currentCustomerId: order.customer_id
11715
- }
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" }) }),
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" }) }),
11720
11500
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11721
11501
  ] }) })
11722
11502
  ]
11723
11503
  }
11724
11504
  ) });
11725
11505
  };
11726
- const CustomerField = ({ control, currentCustomerId }) => {
11727
- const customers = useComboboxData({
11506
+ const SalesChannelField = ({ control, order }) => {
11507
+ const salesChannels = useComboboxData({
11728
11508
  queryFn: async (params) => {
11729
- return await sdk.admin.customer.list({
11730
- ...params,
11731
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11732
- });
11509
+ return await sdk.admin.salesChannel.list(params);
11733
11510
  },
11734
- queryKey: ["customers"],
11511
+ queryKey: ["sales-channels"],
11735
11512
  getOptions: (data) => {
11736
- return data.customers.map((customer) => {
11737
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11738
- return {
11739
- label: name ? `${name} (${customer.email})` : customer.email,
11740
- value: customer.id
11741
- };
11742
- });
11743
- }
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
11744
11519
  });
11745
11520
  return /* @__PURE__ */ jsxRuntime.jsx(
11746
11521
  Form$2.Field,
11747
11522
  {
11748
- name: "customer_id",
11749
11523
  control,
11750
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11751
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11753
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11754
- ] }),
11755
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11756
- Combobox,
11757
- {
11758
- options: customers.options,
11759
- fetchNextPage: customers.fetchNextPage,
11760
- isFetchingNextPage: customers.isFetchingNextPage,
11761
- searchValue: customers.searchValue,
11762
- onSearchValueChange: customers.onSearchValueChange,
11763
- placeholder: "Select customer",
11764
- ...field
11765
- }
11766
- ) }),
11767
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11768
- ] })
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
+ }
11769
11543
  }
11770
11544
  );
11771
11545
  };
11772
- const Illustration = () => {
11773
- return /* @__PURE__ */ jsxRuntime.jsxs(
11774
- "svg",
11775
- {
11776
- width: "280",
11777
- height: "180",
11778
- viewBox: "0 0 280 180",
11779
- fill: "none",
11780
- xmlns: "http://www.w3.org/2000/svg",
11781
- children: [
11782
- /* @__PURE__ */ jsxRuntime.jsx(
11783
- "rect",
11784
- {
11785
- x: "0.00428286",
11786
- y: "-0.742904",
11787
- width: "33.5",
11788
- height: "65.5",
11789
- rx: "6.75",
11790
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11791
- fill: "#D4D4D8",
11792
- stroke: "#52525B",
11793
- strokeWidth: "1.5"
11794
- }
11795
- ),
11796
- /* @__PURE__ */ jsxRuntime.jsx(
11797
- "rect",
11798
- {
11799
- x: "0.00428286",
11800
- y: "-0.742904",
11801
- width: "33.5",
11802
- height: "65.5",
11803
- rx: "6.75",
11804
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11805
- fill: "white",
11806
- stroke: "#52525B",
11807
- strokeWidth: "1.5"
11808
- }
11809
- ),
11810
- /* @__PURE__ */ jsxRuntime.jsx(
11811
- "path",
11812
- {
11813
- d: "M180.579 107.142L179.126 107.959",
11814
- stroke: "#52525B",
11815
- strokeWidth: "1.5",
11816
- strokeLinecap: "round",
11817
- strokeLinejoin: "round"
11818
- }
11819
- ),
11820
- /* @__PURE__ */ jsxRuntime.jsx(
11821
- "path",
11822
- {
11823
- opacity: "0.88",
11824
- d: "M182.305 109.546L180.257 109.534",
11825
- stroke: "#52525B",
11826
- strokeWidth: "1.5",
11827
- strokeLinecap: "round",
11828
- strokeLinejoin: "round"
11829
- }
11830
- ),
11831
- /* @__PURE__ */ jsxRuntime.jsx(
11832
- "path",
11833
- {
11834
- opacity: "0.75",
11835
- d: "M180.551 111.93L179.108 111.096",
11836
- stroke: "#52525B",
11837
- strokeWidth: "1.5",
11838
- strokeLinecap: "round",
11839
- strokeLinejoin: "round"
11840
- }
11841
- ),
11842
- /* @__PURE__ */ jsxRuntime.jsx(
11843
- "path",
11844
- {
11845
- opacity: "0.63",
11846
- d: "M176.347 112.897L176.354 111.73",
11847
- stroke: "#52525B",
11848
- strokeWidth: "1.5",
11849
- strokeLinecap: "round",
11850
- strokeLinejoin: "round"
11851
- }
11852
- ),
11853
- /* @__PURE__ */ jsxRuntime.jsx(
11854
- "path",
11855
- {
11856
- opacity: "0.5",
11857
- d: "M172.153 111.881L173.606 111.064",
11858
- stroke: "#52525B",
11859
- strokeWidth: "1.5",
11860
- strokeLinecap: "round",
11861
- strokeLinejoin: "round"
11862
- }
11863
- ),
11864
- /* @__PURE__ */ jsxRuntime.jsx(
11865
- "path",
11866
- {
11867
- opacity: "0.38",
11868
- d: "M170.428 109.478L172.476 109.489",
11869
- stroke: "#52525B",
11870
- strokeWidth: "1.5",
11871
- strokeLinecap: "round",
11872
- strokeLinejoin: "round"
11873
- }
11874
- ),
11875
- /* @__PURE__ */ jsxRuntime.jsx(
11876
- "path",
11877
- {
11878
- opacity: "0.25",
11879
- d: "M172.181 107.094L173.624 107.928",
11880
- stroke: "#52525B",
11881
- strokeWidth: "1.5",
11882
- strokeLinecap: "round",
11883
- strokeLinejoin: "round"
11884
- }
11885
- ),
11886
- /* @__PURE__ */ jsxRuntime.jsx(
11887
- "path",
11888
- {
11889
- opacity: "0.13",
11890
- d: "M176.386 106.126L176.379 107.294",
11891
- stroke: "#52525B",
11892
- strokeWidth: "1.5",
11893
- strokeLinecap: "round",
11894
- strokeLinejoin: "round"
11895
- }
11896
- ),
11897
- /* @__PURE__ */ jsxRuntime.jsx(
11898
- "rect",
11899
- {
11900
- width: "12",
11901
- height: "3",
11902
- rx: "1.5",
11903
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11904
- fill: "#D4D4D8"
11905
- }
11906
- ),
11907
- /* @__PURE__ */ jsxRuntime.jsx(
11908
- "rect",
11909
- {
11910
- x: "0.00428286",
11911
- y: "-0.742904",
11912
- width: "33.5",
11913
- height: "65.5",
11914
- rx: "6.75",
11915
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11916
- fill: "#D4D4D8",
11917
- stroke: "#52525B",
11918
- strokeWidth: "1.5"
11919
- }
11920
- ),
11921
- /* @__PURE__ */ jsxRuntime.jsx(
11922
- "rect",
11923
- {
11924
- x: "0.00428286",
11925
- y: "-0.742904",
11926
- width: "33.5",
11927
- height: "65.5",
11928
- rx: "6.75",
11929
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11930
- fill: "white",
11931
- stroke: "#52525B",
11932
- strokeWidth: "1.5"
11933
- }
11934
- ),
11935
- /* @__PURE__ */ jsxRuntime.jsx(
11936
- "rect",
11937
- {
11938
- width: "12",
11939
- height: "3",
11940
- rx: "1.5",
11941
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11942
- fill: "#D4D4D8"
11943
- }
11944
- ),
11945
- /* @__PURE__ */ jsxRuntime.jsx(
11946
- "rect",
11947
- {
11948
- width: "17",
11949
- height: "3",
11950
- rx: "1.5",
11951
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11952
- fill: "#D4D4D8"
11953
- }
11954
- ),
11955
- /* @__PURE__ */ jsxRuntime.jsx(
11956
- "rect",
11957
- {
11958
- width: "12",
11959
- height: "3",
11960
- rx: "1.5",
11961
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11962
- fill: "#D4D4D8"
11963
- }
11964
- ),
11965
- /* @__PURE__ */ jsxRuntime.jsx(
11966
- "path",
11967
- {
11968
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11969
- fill: "#A1A1AA"
11970
- }
11971
- ),
11972
- /* @__PURE__ */ jsxRuntime.jsx(
11973
- "rect",
11974
- {
11975
- width: "17",
11976
- height: "3",
11977
- rx: "1.5",
11978
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11979
- fill: "#A1A1AA"
11980
- }
11981
- ),
11982
- /* @__PURE__ */ jsxRuntime.jsx(
11983
- "rect",
11984
- {
11985
- width: "12",
11986
- height: "3",
11987
- rx: "1.5",
11988
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11989
- fill: "#A1A1AA"
11990
- }
11991
- ),
11992
- /* @__PURE__ */ jsxRuntime.jsx(
11993
- "path",
11994
- {
11995
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11996
- fill: "#52525B"
11997
- }
11998
- ),
11999
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12000
- "path",
12001
- {
12002
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12003
- stroke: "#A1A1AA",
12004
- strokeWidth: "1.5",
12005
- strokeLinecap: "round",
12006
- strokeLinejoin: "round"
12007
- }
12008
- ) }),
12009
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12010
- "path",
12011
- {
12012
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12013
- stroke: "#A1A1AA",
12014
- strokeWidth: "1.5",
12015
- strokeLinecap: "round",
12016
- strokeLinejoin: "round"
12017
- }
12018
- ) }),
12019
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12020
- "path",
12021
- {
12022
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12023
- stroke: "#A1A1AA",
12024
- strokeWidth: "1.5",
12025
- strokeLinecap: "round",
12026
- strokeLinejoin: "round"
12027
- }
12028
- ) }),
12029
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12030
- "path",
12031
- {
12032
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12033
- stroke: "#A1A1AA",
12034
- strokeWidth: "1.5",
12035
- strokeLinecap: "round",
12036
- strokeLinejoin: "round"
12037
- }
12038
- ) }),
12039
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12040
- "path",
12041
- {
12042
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12043
- stroke: "#A1A1AA",
12044
- strokeWidth: "1.5",
12045
- strokeLinecap: "round",
12046
- strokeLinejoin: "round"
12047
- }
12048
- ) }),
12049
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12050
- "path",
12051
- {
12052
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12053
- stroke: "#A1A1AA",
12054
- strokeWidth: "1.5",
12055
- strokeLinecap: "round",
12056
- strokeLinejoin: "round"
12057
- }
12058
- ) }),
12059
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12060
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12061
- "rect",
12062
- {
12063
- width: "12",
12064
- height: "12",
12065
- fill: "white",
12066
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12067
- }
12068
- ) }),
12069
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12070
- "rect",
12071
- {
12072
- width: "12",
12073
- height: "12",
12074
- fill: "white",
12075
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12076
- }
12077
- ) }),
12078
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12079
- "rect",
12080
- {
12081
- width: "12",
12082
- height: "12",
12083
- fill: "white",
12084
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12085
- }
12086
- ) }),
12087
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12088
- "rect",
12089
- {
12090
- width: "12",
12091
- height: "12",
12092
- fill: "white",
12093
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12094
- }
12095
- ) }),
12096
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12097
- "rect",
12098
- {
12099
- width: "12",
12100
- height: "12",
12101
- fill: "white",
12102
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12103
- }
12104
- ) }),
12105
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12106
- "rect",
12107
- {
12108
- width: "12",
12109
- height: "12",
12110
- fill: "white",
12111
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12112
- }
12113
- ) })
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(
11546
+ const schema$2 = objectType({
11547
+ sales_channel_id: stringType().min(1)
11548
+ });
11549
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
+ const Shipping = () => {
11551
+ var _a;
11552
+ const { id } = reactRouterDom.useParams();
11553
+ const { order, isPending, isError, error } = useOrder(id, {
11554
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11555
+ });
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
+ if (isError) {
11565
+ throw error;
11566
+ }
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
+ ] }) });
11583
+ };
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(
12164
11591
  {
12165
11592
  id: appliedShippingOptionIds,
12166
11593
  fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
@@ -12609,428 +12036,1001 @@ const ShippingProfileForm = ({
12609
12036
  onSuccess: () => {
12610
12037
  setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12611
12038
  }
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,
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." }) })
12069
+ ] }),
12070
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12071
+ /* @__PURE__ */ jsxRuntime.jsx(
12072
+ LocationField,
12073
+ {
12074
+ control: form.control,
12075
+ setValue: form.setValue
12076
+ }
12077
+ ),
12078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12079
+ /* @__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,
12090
+ {
12091
+ 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"
12113
+ }
12114
+ )
12115
+ ] }) })
12116
+ ]
12117
+ }
12118
+ ) }) });
12119
+ };
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
+ ] })
12207
+ ] });
12208
+ };
12209
+ const LocationField = ({ control, setValue }) => {
12210
+ const locations = useComboboxData({
12211
+ queryKey: ["locations"],
12212
+ queryFn: async (params) => {
12213
+ return await sdk.admin.stockLocation.list(params);
12214
+ },
12215
+ getOptions: (data) => {
12216
+ return data.stock_locations.map((location) => ({
12217
+ label: location.name,
12218
+ value: location.id
12219
+ }));
12220
+ }
12221
+ });
12222
+ return /* @__PURE__ */ jsxRuntime.jsx(
12223
+ Form$2.Field,
12224
+ {
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." })
12232
+ ] }),
12233
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12234
+ Combobox,
12235
+ {
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
12250
+ }
12251
+ ) })
12252
+ ] }) });
12253
+ }
12254
+ }
12255
+ );
12256
+ };
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],
12266
+ queryFn: async (params) => {
12267
+ return await sdk.admin.shippingOption.list({
12268
+ ...params,
12269
+ stock_location_id: locationId,
12270
+ shipping_profile_id: shippingProfileId
12271
+ });
12272
+ },
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 ShippingAddress = () => {
12357
+ const { id } = reactRouterDom.useParams();
12358
+ const { order, isPending, isError, error } = useOrder(id, {
12359
+ fields: "+shipping_address"
12360
+ });
12361
+ if (isError) {
12362
+ throw error;
12363
+ }
12364
+ const isReady = !isPending && !!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: "Edit Shipping Address" }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12369
+ ] }),
12370
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12371
+ ] });
12372
+ };
12373
+ const ShippingAddressForm = ({ order }) => {
12374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12375
+ const form = reactHookForm.useForm({
12376
+ defaultValues: {
12377
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12378
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12379
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12380
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12381
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12382
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12383
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12384
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12385
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12386
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12387
+ },
12388
+ resolver: zod.zodResolver(schema$1)
12389
+ });
12390
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12391
+ const { handleSuccess } = useRouteModal();
12392
+ const onSubmit = form.handleSubmit(async (data) => {
12393
+ await mutateAsync(
12394
+ {
12395
+ shipping_address: {
12396
+ first_name: data.first_name,
12397
+ last_name: data.last_name,
12398
+ company: data.company,
12399
+ address_1: data.address_1,
12400
+ address_2: data.address_2,
12401
+ city: data.city,
12402
+ province: data.province,
12403
+ country_code: data.country_code,
12404
+ postal_code: data.postal_code,
12405
+ phone: data.phone
12406
+ }
12407
+ },
12408
+ {
12409
+ onSuccess: () => {
12410
+ handleSuccess();
12411
+ },
12412
+ onError: (error) => {
12413
+ ui.toast.error(error.message);
12414
+ }
12415
+ }
12416
+ );
12417
+ });
12418
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12419
+ KeyboundForm,
12420
+ {
12421
+ className: "flex flex-1 flex-col overflow-hidden",
12422
+ onSubmit,
12423
+ children: [
12424
+ /* @__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: [
12425
+ /* @__PURE__ */ jsxRuntime.jsx(
12426
+ Form$2.Field,
12427
+ {
12428
+ control: form.control,
12429
+ name: "country_code",
12430
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12431
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12432
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12433
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12434
+ ] })
12435
+ }
12436
+ ),
12437
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "first_name",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(
12451
+ Form$2.Field,
12452
+ {
12453
+ control: form.control,
12454
+ name: "last_name",
12455
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
+ ] })
12460
+ }
12461
+ )
12462
+ ] }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "company",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12473
+ }
12474
+ ),
12475
+ /* @__PURE__ */ jsxRuntime.jsx(
12476
+ Form$2.Field,
12477
+ {
12478
+ control: form.control,
12479
+ name: "address_1",
12480
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
+ ] })
12485
+ }
12486
+ ),
12487
+ /* @__PURE__ */ jsxRuntime.jsx(
12488
+ Form$2.Field,
12489
+ {
12490
+ control: form.control,
12491
+ name: "address_2",
12492
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
+ ] })
12497
+ }
12498
+ ),
12499
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "postal_code",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
+ ] })
12510
+ }
12511
+ ),
12512
+ /* @__PURE__ */ jsxRuntime.jsx(
12513
+ Form$2.Field,
12514
+ {
12515
+ control: form.control,
12516
+ name: "city",
12517
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
+ ] })
12522
+ }
12523
+ )
12524
+ ] }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "province",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
+ ] })
12535
+ }
12536
+ ),
12537
+ /* @__PURE__ */ jsxRuntime.jsx(
12538
+ Form$2.Field,
12539
+ {
12540
+ control: form.control,
12541
+ name: "phone",
12542
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
+ ] })
12547
+ }
12548
+ )
12549
+ ] }) }),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12551
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12552
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12553
+ ] }) })
12554
+ ]
12555
+ }
12556
+ ) });
12557
+ };
12558
+ const schema$1 = addressSchema;
12559
+ const TransferOwnership = () => {
12560
+ const { id } = reactRouterDom.useParams();
12561
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12562
+ fields: "id,customer_id,customer.*"
12563
+ });
12564
+ if (isError) {
12565
+ throw error;
12566
+ }
12567
+ const isReady = !isPending && !!draft_order;
12568
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12569
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12570
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12571
+ /* @__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" }) })
12572
+ ] }),
12573
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12574
+ ] });
12575
+ };
12576
+ const TransferOwnershipForm = ({ order }) => {
12577
+ var _a, _b;
12578
+ const form = reactHookForm.useForm({
12579
+ defaultValues: {
12580
+ customer_id: order.customer_id || ""
12581
+ },
12582
+ resolver: zod.zodResolver(schema)
12583
+ });
12584
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12585
+ const { handleSuccess } = useRouteModal();
12586
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12587
+ const currentCustomer = order.customer ? {
12588
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12589
+ value: order.customer.id
12590
+ } : null;
12591
+ const onSubmit = form.handleSubmit(async (data) => {
12592
+ await mutateAsync(
12593
+ { customer_id: data.customer_id },
12594
+ {
12595
+ onSuccess: () => {
12596
+ ui.toast.success("Customer updated");
12597
+ handleSuccess();
12598
+ },
12599
+ onError: (error) => {
12600
+ ui.toast.error(error.message);
12601
+ }
12602
+ }
12603
+ );
12604
+ });
12605
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12606
+ KeyboundForm,
12607
+ {
12608
+ className: "flex flex-1 flex-col overflow-hidden",
12609
+ onSubmit,
12610
+ children: [
12611
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12612
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12613
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12614
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12615
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12616
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12617
+ ] }),
12618
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12619
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12620
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12621
+ ] })
12622
+ ] }),
12623
+ /* @__PURE__ */ jsxRuntime.jsx(
12624
+ CustomerField,
12625
+ {
12626
+ control: form.control,
12627
+ currentCustomerId: order.customer_id
12628
+ }
12629
+ )
12630
+ ] }),
12631
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12632
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12633
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12634
+ ] }) })
12635
+ ]
12636
+ }
12637
+ ) });
12638
+ };
12639
+ const CustomerField = ({ control, currentCustomerId }) => {
12640
+ const customers = useComboboxData({
12641
+ queryFn: async (params) => {
12642
+ return await sdk.admin.customer.list({
12643
+ ...params,
12644
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12645
+ });
12646
+ },
12647
+ queryKey: ["customers"],
12648
+ getOptions: (data) => {
12649
+ return data.customers.map((customer) => {
12650
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12651
+ return {
12652
+ label: name ? `${name} (${customer.email})` : customer.email,
12653
+ value: customer.id
12654
+ };
12655
+ });
12656
+ }
12657
+ });
12658
+ return /* @__PURE__ */ jsxRuntime.jsx(
12659
+ Form$2.Field,
12660
+ {
12661
+ name: "customer_id",
12662
+ control,
12663
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12664
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12665
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12666
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12667
+ ] }),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12669
+ Combobox,
12670
+ {
12671
+ options: customers.options,
12672
+ fetchNextPage: customers.fetchNextPage,
12673
+ isFetchingNextPage: customers.isFetchingNextPage,
12674
+ searchValue: customers.searchValue,
12675
+ onSearchValueChange: customers.onSearchValueChange,
12676
+ placeholder: "Select customer",
12677
+ ...field
12678
+ }
12679
+ ) }),
12680
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12681
+ ] })
12682
+ }
12683
+ );
12684
+ };
12685
+ const Illustration = () => {
12686
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12687
+ "svg",
12688
+ {
12689
+ width: "280",
12690
+ height: "180",
12691
+ viewBox: "0 0 280 180",
12692
+ fill: "none",
12693
+ xmlns: "http://www.w3.org/2000/svg",
12694
+ children: [
12695
+ /* @__PURE__ */ jsxRuntime.jsx(
12696
+ "rect",
12697
+ {
12698
+ x: "0.00428286",
12699
+ y: "-0.742904",
12700
+ width: "33.5",
12701
+ height: "65.5",
12702
+ rx: "6.75",
12703
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12704
+ fill: "#D4D4D8",
12705
+ stroke: "#52525B",
12706
+ strokeWidth: "1.5"
12707
+ }
12708
+ ),
12709
+ /* @__PURE__ */ jsxRuntime.jsx(
12710
+ "rect",
12711
+ {
12712
+ x: "0.00428286",
12713
+ y: "-0.742904",
12714
+ width: "33.5",
12715
+ height: "65.5",
12716
+ rx: "6.75",
12717
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12718
+ fill: "white",
12719
+ stroke: "#52525B",
12720
+ strokeWidth: "1.5"
12721
+ }
12722
+ ),
12723
+ /* @__PURE__ */ jsxRuntime.jsx(
12724
+ "path",
12725
+ {
12726
+ d: "M180.579 107.142L179.126 107.959",
12727
+ stroke: "#52525B",
12728
+ strokeWidth: "1.5",
12729
+ strokeLinecap: "round",
12730
+ strokeLinejoin: "round"
12731
+ }
12732
+ ),
12733
+ /* @__PURE__ */ jsxRuntime.jsx(
12734
+ "path",
12735
+ {
12736
+ opacity: "0.88",
12737
+ d: "M182.305 109.546L180.257 109.534",
12738
+ stroke: "#52525B",
12739
+ strokeWidth: "1.5",
12740
+ strokeLinecap: "round",
12741
+ strokeLinejoin: "round"
12742
+ }
12743
+ ),
12744
+ /* @__PURE__ */ jsxRuntime.jsx(
12745
+ "path",
12746
+ {
12747
+ opacity: "0.75",
12748
+ d: "M180.551 111.93L179.108 111.096",
12749
+ stroke: "#52525B",
12750
+ strokeWidth: "1.5",
12751
+ strokeLinecap: "round",
12752
+ strokeLinejoin: "round"
12753
+ }
12754
+ ),
12755
+ /* @__PURE__ */ jsxRuntime.jsx(
12756
+ "path",
12757
+ {
12758
+ opacity: "0.63",
12759
+ d: "M176.347 112.897L176.354 111.73",
12760
+ stroke: "#52525B",
12761
+ strokeWidth: "1.5",
12762
+ strokeLinecap: "round",
12763
+ strokeLinejoin: "round"
12764
+ }
12765
+ ),
12766
+ /* @__PURE__ */ jsxRuntime.jsx(
12767
+ "path",
12768
+ {
12769
+ opacity: "0.5",
12770
+ d: "M172.153 111.881L173.606 111.064",
12771
+ stroke: "#52525B",
12772
+ strokeWidth: "1.5",
12773
+ strokeLinecap: "round",
12774
+ strokeLinejoin: "round"
12775
+ }
12776
+ ),
12777
+ /* @__PURE__ */ jsxRuntime.jsx(
12778
+ "path",
12779
+ {
12780
+ opacity: "0.38",
12781
+ d: "M170.428 109.478L172.476 109.489",
12782
+ stroke: "#52525B",
12783
+ strokeWidth: "1.5",
12784
+ strokeLinecap: "round",
12785
+ strokeLinejoin: "round"
12786
+ }
12787
+ ),
12788
+ /* @__PURE__ */ jsxRuntime.jsx(
12789
+ "path",
12790
+ {
12791
+ opacity: "0.25",
12792
+ d: "M172.181 107.094L173.624 107.928",
12793
+ stroke: "#52525B",
12794
+ strokeWidth: "1.5",
12795
+ strokeLinecap: "round",
12796
+ strokeLinejoin: "round"
12797
+ }
12798
+ ),
12799
+ /* @__PURE__ */ jsxRuntime.jsx(
12800
+ "path",
12801
+ {
12802
+ opacity: "0.13",
12803
+ d: "M176.386 106.126L176.379 107.294",
12804
+ stroke: "#52525B",
12805
+ strokeWidth: "1.5",
12806
+ strokeLinecap: "round",
12807
+ strokeLinejoin: "round"
12808
+ }
12809
+ ),
12810
+ /* @__PURE__ */ jsxRuntime.jsx(
12811
+ "rect",
12812
+ {
12813
+ width: "12",
12814
+ height: "3",
12815
+ rx: "1.5",
12816
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12817
+ fill: "#D4D4D8"
12818
+ }
12819
+ ),
12820
+ /* @__PURE__ */ jsxRuntime.jsx(
12821
+ "rect",
12822
+ {
12823
+ x: "0.00428286",
12824
+ y: "-0.742904",
12825
+ width: "33.5",
12826
+ height: "65.5",
12827
+ rx: "6.75",
12828
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12829
+ fill: "#D4D4D8",
12830
+ stroke: "#52525B",
12831
+ strokeWidth: "1.5"
12832
+ }
12833
+ ),
12834
+ /* @__PURE__ */ jsxRuntime.jsx(
12835
+ "rect",
12836
+ {
12837
+ x: "0.00428286",
12838
+ y: "-0.742904",
12839
+ width: "33.5",
12840
+ height: "65.5",
12841
+ rx: "6.75",
12842
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12843
+ fill: "white",
12844
+ stroke: "#52525B",
12845
+ strokeWidth: "1.5"
12846
+ }
12847
+ ),
12848
+ /* @__PURE__ */ jsxRuntime.jsx(
12849
+ "rect",
12850
+ {
12851
+ width: "12",
12852
+ height: "3",
12853
+ rx: "1.5",
12854
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12855
+ fill: "#D4D4D8"
12856
+ }
12857
+ ),
12858
+ /* @__PURE__ */ jsxRuntime.jsx(
12859
+ "rect",
12860
+ {
12861
+ width: "17",
12862
+ height: "3",
12863
+ rx: "1.5",
12864
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12865
+ fill: "#D4D4D8"
12866
+ }
12867
+ ),
12868
+ /* @__PURE__ */ jsxRuntime.jsx(
12869
+ "rect",
12870
+ {
12871
+ width: "12",
12872
+ height: "3",
12873
+ rx: "1.5",
12874
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12875
+ fill: "#D4D4D8"
12876
+ }
12877
+ ),
12878
+ /* @__PURE__ */ jsxRuntime.jsx(
12879
+ "path",
12880
+ {
12881
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12882
+ fill: "#A1A1AA"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsxRuntime.jsx(
12886
+ "rect",
12887
+ {
12888
+ width: "17",
12889
+ height: "3",
12890
+ rx: "1.5",
12891
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12892
+ fill: "#A1A1AA"
12893
+ }
12894
+ ),
12895
+ /* @__PURE__ */ jsxRuntime.jsx(
12896
+ "rect",
12897
+ {
12898
+ width: "12",
12899
+ height: "3",
12900
+ rx: "1.5",
12901
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12902
+ fill: "#A1A1AA"
12903
+ }
12904
+ ),
12905
+ /* @__PURE__ */ jsxRuntime.jsx(
12906
+ "path",
12907
+ {
12908
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12909
+ fill: "#52525B"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12913
+ "path",
12914
+ {
12915
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12916
+ stroke: "#A1A1AA",
12917
+ strokeWidth: "1.5",
12918
+ strokeLinecap: "round",
12919
+ strokeLinejoin: "round"
12920
+ }
12921
+ ) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12923
+ "path",
12924
+ {
12925
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12926
+ stroke: "#A1A1AA",
12927
+ strokeWidth: "1.5",
12928
+ strokeLinecap: "round",
12929
+ strokeLinejoin: "round"
12930
+ }
12931
+ ) }),
12932
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12933
+ "path",
12934
+ {
12935
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12936
+ stroke: "#A1A1AA",
12937
+ strokeWidth: "1.5",
12938
+ strokeLinecap: "round",
12939
+ strokeLinejoin: "round"
12940
+ }
12941
+ ) }),
12942
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12943
+ "path",
12944
+ {
12945
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12946
+ stroke: "#A1A1AA",
12947
+ strokeWidth: "1.5",
12948
+ strokeLinecap: "round",
12949
+ strokeLinejoin: "round"
12950
+ }
12951
+ ) }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12953
+ "path",
12954
+ {
12955
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12956
+ stroke: "#A1A1AA",
12957
+ strokeWidth: "1.5",
12958
+ strokeLinecap: "round",
12959
+ strokeLinejoin: "round"
12960
+ }
12961
+ ) }),
12962
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12963
+ "path",
12964
+ {
12965
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12966
+ stroke: "#A1A1AA",
12967
+ strokeWidth: "1.5",
12968
+ strokeLinecap: "round",
12969
+ strokeLinejoin: "round"
12970
+ }
12971
+ ) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12973
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12974
+ "rect",
12681
12975
  {
12682
- size: "small",
12683
- type: "submit",
12684
- isLoading: isPending || isUpdatingShippingMethod,
12685
- children: data.shippingMethod ? "Update" : "Add"
12976
+ width: "12",
12977
+ height: "12",
12978
+ fill: "white",
12979
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12686
12980
  }
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,
12981
+ ) }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12983
+ "rect",
12808
12984
  {
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
12985
+ width: "12",
12986
+ height: "12",
12987
+ fill: "white",
12988
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12823
12989
  }
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,
12990
+ ) }),
12991
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12992
+ "rect",
12877
12993
  {
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
- ) }) })
12994
+ width: "12",
12995
+ height: "12",
12996
+ fill: "white",
12997
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12893
12998
  }
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,
12999
+ ) }),
13000
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13001
+ "rect",
12917
13002
  {
12918
- ...field,
12919
- onValueChange: (value) => onChange(value),
12920
- symbol: getNativeSymbol(currencyCode),
12921
- code: currencyCode
13003
+ width: "12",
13004
+ height: "12",
13005
+ fill: "white",
13006
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12922
13007
  }
12923
- ) })
12924
- ] });
12925
- }
12926
- }
12927
- );
12928
- };
12929
- const SalesChannel = () => {
12930
- const { id } = reactRouterDom.useParams();
12931
- const { draft_order, isPending, isError, error } = useDraftOrder(
12932
- id,
12933
- {
12934
- fields: "+sales_channel_id"
12935
- },
12936
- {
12937
- enabled: !!id
12938
- }
12939
- );
12940
- if (isError) {
12941
- throw error;
12942
- }
12943
- const ISrEADY = !!draft_order && !isPending;
12944
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12945
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
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" }) })
12948
- ] }),
12949
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12950
- ] });
12951
- };
12952
- const SalesChannelForm = ({ order }) => {
12953
- const form = reactHookForm.useForm({
12954
- defaultValues: {
12955
- sales_channel_id: order.sales_channel_id || ""
12956
- },
12957
- resolver: zod.zodResolver(schema)
12958
- });
12959
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12960
- const { handleSuccess } = useRouteModal();
12961
- const onSubmit = form.handleSubmit(async (data) => {
12962
- await mutateAsync(
12963
- {
12964
- sales_channel_id: data.sales_channel_id
12965
- },
12966
- {
12967
- onSuccess: () => {
12968
- ui.toast.success("Sales channel updated");
12969
- handleSuccess();
12970
- },
12971
- onError: (error) => {
12972
- ui.toast.error(error.message);
12973
- }
12974
- }
12975
- );
12976
- });
12977
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12978
- KeyboundForm,
12979
- {
12980
- className: "flex flex-1 flex-col overflow-hidden",
12981
- onSubmit,
12982
- children: [
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 }) }),
12984
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12985
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12986
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12987
- ] }) })
12988
- ]
12989
- }
12990
- ) });
12991
- };
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,
13008
+ ) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13010
+ "rect",
13016
13011
  {
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
13012
+ width: "12",
13013
+ height: "12",
13014
+ fill: "white",
13015
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13024
13016
  }
13025
13017
  ) }),
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13027
- ] });
13028
- }
13018
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13019
+ "rect",
13020
+ {
13021
+ width: "12",
13022
+ height: "12",
13023
+ fill: "white",
13024
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13025
+ }
13026
+ ) })
13027
+ ] })
13028
+ ]
13029
13029
  }
13030
13030
  );
13031
13031
  };
13032
13032
  const schema = objectType({
13033
- sales_channel_id: stringType().min(1)
13033
+ customer_id: stringType().min(1)
13034
13034
  });
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
@@ -13068,29 +13068,29 @@ const routeModule = {
13068
13068
  Component: Items,
13069
13069
  path: "/draft-orders/:id/items"
13070
13070
  },
13071
- {
13072
- Component: Promotions,
13073
- path: "/draft-orders/:id/promotions"
13074
- },
13075
13071
  {
13076
13072
  Component: Metadata,
13077
13073
  path: "/draft-orders/:id/metadata"
13078
13074
  },
13079
13075
  {
13080
- Component: ShippingAddress,
13081
- path: "/draft-orders/:id/shipping-address"
13076
+ Component: Promotions,
13077
+ path: "/draft-orders/:id/promotions"
13082
13078
  },
13083
13079
  {
13084
- Component: TransferOwnership,
13085
- path: "/draft-orders/:id/transfer-ownership"
13080
+ Component: SalesChannel,
13081
+ path: "/draft-orders/:id/sales-channel"
13086
13082
  },
13087
13083
  {
13088
13084
  Component: Shipping,
13089
13085
  path: "/draft-orders/:id/shipping"
13090
13086
  },
13091
13087
  {
13092
- Component: SalesChannel,
13093
- path: "/draft-orders/:id/sales-channel"
13088
+ Component: ShippingAddress,
13089
+ path: "/draft-orders/:id/shipping-address"
13090
+ },
13091
+ {
13092
+ Component: TransferOwnership,
13093
+ path: "/draft-orders/:id/transfer-ownership"
13094
13094
  }
13095
13095
  ]
13096
13096
  }