@medusajs/draft-order 2.11.1-snapshot-20251022143349 → 2.11.1-snapshot-20251025141132

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