@medusajs/draft-order 2.19.0 → 2.19.1-preview-20260813144737

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.
@@ -5972,195 +5972,27 @@ const ID = () => {
5972
5972
  }
5973
5973
  );
5974
5974
  };
5975
- const BillingAddress = () => {
5976
- const { id } = useParams();
5977
- const { order, isPending, isError, error } = useOrder(id, {
5978
- fields: "+billing_address"
5979
- });
5980
- if (isError) {
5981
- throw error;
5982
- }
5983
- const isReady = !isPending && !!order;
5975
+ const CustomItems = () => {
5984
5976
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
5985
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
5986
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
5987
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
5988
- ] }),
5989
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
5977
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
5978
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
5990
5979
  ] });
5991
5980
  };
5992
- const BillingAddressForm = ({ order }) => {
5981
+ const CustomItemsForm = () => {
5993
5982
  const form = useForm({
5994
- defaultValues: {
5995
- first_name: order.billing_address?.first_name ?? "",
5996
- last_name: order.billing_address?.last_name ?? "",
5997
- company: order.billing_address?.company ?? "",
5998
- address_1: order.billing_address?.address_1 ?? "",
5999
- address_2: order.billing_address?.address_2 ?? "",
6000
- city: order.billing_address?.city ?? "",
6001
- province: order.billing_address?.province ?? "",
6002
- country_code: order.billing_address?.country_code ?? "",
6003
- postal_code: order.billing_address?.postal_code ?? "",
6004
- phone: order.billing_address?.phone ?? ""
6005
- },
6006
5983
  resolver: zodResolver(schema$5)
6007
5984
  });
6008
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6009
- const { handleSuccess } = useRouteModal();
6010
- const onSubmit = form.handleSubmit(async (data) => {
6011
- await mutateAsync(
6012
- { billing_address: data },
6013
- {
6014
- onSuccess: () => {
6015
- handleSuccess();
6016
- },
6017
- onError: (error) => {
6018
- toast.error(error.message);
6019
- }
6020
- }
6021
- );
6022
- });
6023
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
6024
- KeyboundForm,
6025
- {
6026
- className: "flex flex-1 flex-col overflow-hidden",
6027
- onSubmit,
6028
- children: [
6029
- /* @__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: [
6030
- /* @__PURE__ */ jsx(
6031
- Form$2.Field,
6032
- {
6033
- control: form.control,
6034
- name: "country_code",
6035
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6036
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
6037
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
6038
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6039
- ] })
6040
- }
6041
- ),
6042
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6043
- /* @__PURE__ */ jsx(
6044
- Form$2.Field,
6045
- {
6046
- control: form.control,
6047
- name: "first_name",
6048
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6049
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
6050
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6051
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6052
- ] })
6053
- }
6054
- ),
6055
- /* @__PURE__ */ jsx(
6056
- Form$2.Field,
6057
- {
6058
- control: form.control,
6059
- name: "last_name",
6060
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6061
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
6062
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6063
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6064
- ] })
6065
- }
6066
- )
6067
- ] }),
6068
- /* @__PURE__ */ jsx(
6069
- Form$2.Field,
6070
- {
6071
- control: form.control,
6072
- name: "company",
6073
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6074
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
6075
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6076
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6077
- ] })
6078
- }
6079
- ),
6080
- /* @__PURE__ */ jsx(
6081
- Form$2.Field,
6082
- {
6083
- control: form.control,
6084
- name: "address_1",
6085
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6086
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
6087
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6088
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6089
- ] })
6090
- }
6091
- ),
6092
- /* @__PURE__ */ jsx(
6093
- Form$2.Field,
6094
- {
6095
- control: form.control,
6096
- name: "address_2",
6097
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6098
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
6099
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6100
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6101
- ] })
6102
- }
6103
- ),
6104
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6105
- /* @__PURE__ */ jsx(
6106
- Form$2.Field,
6107
- {
6108
- control: form.control,
6109
- name: "postal_code",
6110
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6111
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
6112
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6113
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6114
- ] })
6115
- }
6116
- ),
6117
- /* @__PURE__ */ jsx(
6118
- Form$2.Field,
6119
- {
6120
- control: form.control,
6121
- name: "city",
6122
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6123
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
6124
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6125
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6126
- ] })
6127
- }
6128
- )
6129
- ] }),
6130
- /* @__PURE__ */ jsx(
6131
- Form$2.Field,
6132
- {
6133
- control: form.control,
6134
- name: "province",
6135
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6136
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
6137
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6138
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6139
- ] })
6140
- }
6141
- ),
6142
- /* @__PURE__ */ jsx(
6143
- Form$2.Field,
6144
- {
6145
- control: form.control,
6146
- name: "phone",
6147
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6148
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
6149
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6150
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6151
- ] })
6152
- }
6153
- )
6154
- ] }) }),
6155
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6156
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6157
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
6158
- ] }) })
6159
- ]
6160
- }
6161
- ) });
5985
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
5986
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
5987
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
5988
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
5989
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
5990
+ ] }) })
5991
+ ] }) });
6162
5992
  };
6163
- const schema$5 = addressSchema;
5993
+ const schema$5 = z.object({
5994
+ email: z.string().email()
5995
+ });
6164
5996
  const Email = () => {
6165
5997
  const { id } = useParams();
6166
5998
  const { order, isPending, isError, error } = useOrder(id, {
@@ -7199,44 +7031,212 @@ const customItemSchema = z.object({
7199
7031
  quantity: z.number(),
7200
7032
  unit_price: z.union([z.number(), z.string()])
7201
7033
  });
7202
- const CustomItems = () => {
7034
+ const BillingAddress = () => {
7035
+ const { id } = useParams();
7036
+ const { order, isPending, isError, error } = useOrder(id, {
7037
+ fields: "+billing_address"
7038
+ });
7039
+ if (isError) {
7040
+ throw error;
7041
+ }
7042
+ const isReady = !isPending && !!order;
7203
7043
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7204
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
7205
- /* @__PURE__ */ jsx(CustomItemsForm, {})
7044
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7045
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
7046
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
7047
+ ] }),
7048
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
7206
7049
  ] });
7207
7050
  };
7208
- const CustomItemsForm = () => {
7051
+ const BillingAddressForm = ({ order }) => {
7209
7052
  const form = useForm({
7053
+ defaultValues: {
7054
+ first_name: order.billing_address?.first_name ?? "",
7055
+ last_name: order.billing_address?.last_name ?? "",
7056
+ company: order.billing_address?.company ?? "",
7057
+ address_1: order.billing_address?.address_1 ?? "",
7058
+ address_2: order.billing_address?.address_2 ?? "",
7059
+ city: order.billing_address?.city ?? "",
7060
+ province: order.billing_address?.province ?? "",
7061
+ country_code: order.billing_address?.country_code ?? "",
7062
+ postal_code: order.billing_address?.postal_code ?? "",
7063
+ phone: order.billing_address?.phone ?? ""
7064
+ },
7210
7065
  resolver: zodResolver(schema$3)
7211
7066
  });
7212
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
7213
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
7214
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7215
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7216
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
7217
- ] }) })
7218
- ] }) });
7219
- };
7220
- const schema$3 = z.object({
7221
- email: z.string().email()
7222
- });
7223
- const InlineTip = forwardRef(
7224
- ({ variant = "tip", label, className, children, ...props }, ref) => {
7225
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
7226
- return /* @__PURE__ */ jsxs(
7227
- "div",
7067
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7068
+ const { handleSuccess } = useRouteModal();
7069
+ const onSubmit = form.handleSubmit(async (data) => {
7070
+ await mutateAsync(
7071
+ { billing_address: data },
7228
7072
  {
7229
- ref,
7230
- className: clx(
7231
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
7232
- className
7233
- ),
7234
- ...props,
7235
- children: [
7236
- /* @__PURE__ */ jsx(
7237
- "div",
7238
- {
7239
- role: "presentation",
7073
+ onSuccess: () => {
7074
+ handleSuccess();
7075
+ },
7076
+ onError: (error) => {
7077
+ toast.error(error.message);
7078
+ }
7079
+ }
7080
+ );
7081
+ });
7082
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7083
+ KeyboundForm,
7084
+ {
7085
+ className: "flex flex-1 flex-col overflow-hidden",
7086
+ onSubmit,
7087
+ children: [
7088
+ /* @__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: [
7089
+ /* @__PURE__ */ jsx(
7090
+ Form$2.Field,
7091
+ {
7092
+ control: form.control,
7093
+ name: "country_code",
7094
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7095
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
7096
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
7097
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7098
+ ] })
7099
+ }
7100
+ ),
7101
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7102
+ /* @__PURE__ */ jsx(
7103
+ Form$2.Field,
7104
+ {
7105
+ control: form.control,
7106
+ name: "first_name",
7107
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7108
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
7109
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7110
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7111
+ ] })
7112
+ }
7113
+ ),
7114
+ /* @__PURE__ */ jsx(
7115
+ Form$2.Field,
7116
+ {
7117
+ control: form.control,
7118
+ name: "last_name",
7119
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7120
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
7121
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7122
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7123
+ ] })
7124
+ }
7125
+ )
7126
+ ] }),
7127
+ /* @__PURE__ */ jsx(
7128
+ Form$2.Field,
7129
+ {
7130
+ control: form.control,
7131
+ name: "company",
7132
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7133
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
7134
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7135
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7136
+ ] })
7137
+ }
7138
+ ),
7139
+ /* @__PURE__ */ jsx(
7140
+ Form$2.Field,
7141
+ {
7142
+ control: form.control,
7143
+ name: "address_1",
7144
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7145
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
7146
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7147
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7148
+ ] })
7149
+ }
7150
+ ),
7151
+ /* @__PURE__ */ jsx(
7152
+ Form$2.Field,
7153
+ {
7154
+ control: form.control,
7155
+ name: "address_2",
7156
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7157
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
7158
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7159
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7160
+ ] })
7161
+ }
7162
+ ),
7163
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7164
+ /* @__PURE__ */ jsx(
7165
+ Form$2.Field,
7166
+ {
7167
+ control: form.control,
7168
+ name: "postal_code",
7169
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7170
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
7171
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7172
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7173
+ ] })
7174
+ }
7175
+ ),
7176
+ /* @__PURE__ */ jsx(
7177
+ Form$2.Field,
7178
+ {
7179
+ control: form.control,
7180
+ name: "city",
7181
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7182
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
7183
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7184
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7185
+ ] })
7186
+ }
7187
+ )
7188
+ ] }),
7189
+ /* @__PURE__ */ jsx(
7190
+ Form$2.Field,
7191
+ {
7192
+ control: form.control,
7193
+ name: "province",
7194
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7195
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
7196
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7197
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7198
+ ] })
7199
+ }
7200
+ ),
7201
+ /* @__PURE__ */ jsx(
7202
+ Form$2.Field,
7203
+ {
7204
+ control: form.control,
7205
+ name: "phone",
7206
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7207
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
7208
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7209
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7210
+ ] })
7211
+ }
7212
+ )
7213
+ ] }) }),
7214
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7215
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7216
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7217
+ ] }) })
7218
+ ]
7219
+ }
7220
+ ) });
7221
+ };
7222
+ const schema$3 = addressSchema;
7223
+ const InlineTip = forwardRef(
7224
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
7225
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
7226
+ return /* @__PURE__ */ jsxs(
7227
+ "div",
7228
+ {
7229
+ ref,
7230
+ className: clx(
7231
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
7232
+ className
7233
+ ),
7234
+ ...props,
7235
+ children: [
7236
+ /* @__PURE__ */ jsx(
7237
+ "div",
7238
+ {
7239
+ role: "presentation",
7240
7240
  className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
7241
7241
  "bg-ui-tag-orange-icon": variant === "warning"
7242
7242
  })
@@ -7570,433 +7570,52 @@ function getHasUneditableRows(metadata) {
7570
7570
  (value) => !EDITABLE_TYPES.includes(typeof value)
7571
7571
  );
7572
7572
  }
7573
- const PROMOTION_QUERY_KEY = "promotions";
7574
- const promotionsQueryKeys = {
7575
- list: (query2) => [
7576
- PROMOTION_QUERY_KEY,
7577
- query2 ? query2 : void 0
7578
- ],
7579
- detail: (id, query2) => [
7580
- PROMOTION_QUERY_KEY,
7581
- id,
7582
- query2 ? query2 : void 0
7583
- ]
7584
- };
7585
- const usePromotions = (query2, options) => {
7586
- const { data, ...rest } = useQuery({
7587
- queryKey: promotionsQueryKeys.list(query2),
7588
- queryFn: async () => sdk.admin.promotion.list(query2),
7589
- ...options
7590
- });
7591
- return { ...data, ...rest };
7592
- };
7593
- const Promotions = () => {
7573
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
7574
+ const Shipping = () => {
7594
7575
  const { id } = useParams();
7576
+ const { order, isPending, isError, error } = useOrder(id, {
7577
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
7578
+ });
7595
7579
  const {
7596
7580
  order: preview,
7581
+ isPending: isPreviewPending,
7597
7582
  isError: isPreviewError,
7598
7583
  error: previewError
7599
- } = useOrderPreview(id, void 0);
7584
+ } = useOrderPreview(id);
7600
7585
  useInitiateOrderEdit({ preview });
7601
7586
  const { onCancel } = useCancelOrderEdit({ preview });
7587
+ if (isError) {
7588
+ throw error;
7589
+ }
7602
7590
  if (isPreviewError) {
7603
7591
  throw previewError;
7604
7592
  }
7605
- const isReady = !!preview;
7606
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
7607
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
7608
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
7609
- ] });
7593
+ const orderHasItems = (order?.items?.length || 0) > 0;
7594
+ const isReady = preview && !isPreviewPending && order && !isPending;
7595
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
7596
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
7597
+ /* @__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 px-6 py-16", children: [
7598
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
7599
+ /* @__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." }) })
7600
+ ] }) }) }),
7601
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
7602
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
7603
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
7604
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
7605
+ ] }) });
7610
7606
  };
7611
- const PromotionForm = ({ preview }) => {
7612
- const { items, shipping_methods } = preview;
7607
+ const ShippingForm = ({ preview, order }) => {
7608
+ const { setIsOpen } = useStackedModal();
7613
7609
  const [isSubmitting, setIsSubmitting] = useState(false);
7614
- const [comboboxValue, setComboboxValue] = useState("");
7615
- const { handleSuccess } = useRouteModal();
7616
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
7617
- const promoIds = getPromotionIds(items, shipping_methods);
7618
- const { promotions, isPending, isError, error } = usePromotions(
7610
+ const [data, setData] = useState(null);
7611
+ const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
7612
+ const { shipping_options } = useShippingOptions(
7619
7613
  {
7620
- id: promoIds
7614
+ id: appliedShippingOptionIds,
7615
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
7621
7616
  },
7622
7617
  {
7623
- enabled: !!promoIds.length
7624
- }
7625
- );
7626
- const comboboxData = useComboboxData({
7627
- queryKey: ["promotions", "combobox", promoIds],
7628
- queryFn: async (params) => {
7629
- return await sdk.admin.promotion.list({
7630
- ...params,
7631
- id: {
7632
- $nin: promoIds
7633
- }
7634
- });
7635
- },
7636
- getOptions: (data) => {
7637
- return data.promotions.map((promotion) => ({
7638
- label: promotion.code,
7639
- value: promotion.code
7640
- }));
7641
- }
7642
- });
7643
- const add = async (value) => {
7644
- if (!value) {
7645
- return;
7646
- }
7647
- addPromotions(
7648
- {
7649
- promo_codes: [value]
7650
- },
7651
- {
7652
- onError: (e) => {
7653
- toast.error(e.message);
7654
- comboboxData.onSearchValueChange("");
7655
- setComboboxValue("");
7656
- },
7657
- onSuccess: () => {
7658
- comboboxData.onSearchValueChange("");
7659
- setComboboxValue("");
7660
- }
7661
- }
7662
- );
7663
- };
7664
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
7665
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
7666
- const onSubmit = async () => {
7667
- setIsSubmitting(true);
7668
- let requestSucceeded = false;
7669
- await requestOrderEdit(void 0, {
7670
- onError: (e) => {
7671
- toast.error(e.message);
7672
- },
7673
- onSuccess: () => {
7674
- requestSucceeded = true;
7675
- }
7676
- });
7677
- if (!requestSucceeded) {
7678
- setIsSubmitting(false);
7679
- return;
7680
- }
7681
- await confirmOrderEdit(void 0, {
7682
- onError: (e) => {
7683
- toast.error(e.message);
7684
- },
7685
- onSuccess: () => {
7686
- handleSuccess();
7687
- },
7688
- onSettled: () => {
7689
- setIsSubmitting(false);
7690
- }
7691
- });
7692
- };
7693
- if (isError) {
7694
- throw error;
7695
- }
7696
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
7697
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
7698
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
7699
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
7700
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
7701
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
7702
- ] }),
7703
- /* @__PURE__ */ jsx(
7704
- Combobox,
7705
- {
7706
- id: "promotion-combobox",
7707
- "aria-describedby": "promotion-combobox-hint",
7708
- isFetchingNextPage: comboboxData.isFetchingNextPage,
7709
- fetchNextPage: comboboxData.fetchNextPage,
7710
- options: comboboxData.options,
7711
- onSearchValueChange: comboboxData.onSearchValueChange,
7712
- searchValue: comboboxData.searchValue,
7713
- disabled: comboboxData.disabled || isAddingPromotions,
7714
- onChange: add,
7715
- value: comboboxValue
7716
- }
7717
- )
7718
- ] }),
7719
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
7720
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
7721
- PromotionItem,
7722
- {
7723
- promotion,
7724
- orderId: preview.id,
7725
- isLoading: isPending
7726
- },
7727
- promotion.id
7728
- )) })
7729
- ] }) }),
7730
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7731
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7732
- /* @__PURE__ */ jsx(
7733
- Button,
7734
- {
7735
- size: "small",
7736
- type: "submit",
7737
- isLoading: isSubmitting || isAddingPromotions,
7738
- children: "Save"
7739
- }
7740
- )
7741
- ] }) })
7742
- ] });
7743
- };
7744
- const PromotionItem = ({
7745
- promotion,
7746
- orderId,
7747
- isLoading
7748
- }) => {
7749
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
7750
- const onRemove = async () => {
7751
- removePromotions(
7752
- {
7753
- promo_codes: [promotion.code]
7754
- },
7755
- {
7756
- onError: (e) => {
7757
- toast.error(e.message);
7758
- }
7759
- }
7760
- );
7761
- };
7762
- const displayValue = getDisplayValue(promotion);
7763
- return /* @__PURE__ */ jsxs(
7764
- "div",
7765
- {
7766
- className: clx(
7767
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
7768
- {
7769
- "animate-pulse": isLoading
7770
- }
7771
- ),
7772
- children: [
7773
- /* @__PURE__ */ jsxs("div", { children: [
7774
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
7775
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
7776
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
7777
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
7778
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
7779
- ] }),
7780
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
7781
- ] })
7782
- ] }),
7783
- /* @__PURE__ */ jsx(
7784
- IconButton,
7785
- {
7786
- size: "small",
7787
- type: "button",
7788
- variant: "transparent",
7789
- onClick: onRemove,
7790
- isLoading: isPending || isLoading,
7791
- children: /* @__PURE__ */ jsx(XMark, {})
7792
- }
7793
- )
7794
- ]
7795
- },
7796
- promotion.id
7797
- );
7798
- };
7799
- function getDisplayValue(promotion) {
7800
- const value = promotion.application_method?.value;
7801
- if (!value) {
7802
- return null;
7803
- }
7804
- if (promotion.application_method?.type === "fixed") {
7805
- const currency = promotion.application_method?.currency_code;
7806
- if (!currency) {
7807
- return null;
7808
- }
7809
- return getLocaleAmount(value, currency);
7810
- } else if (promotion.application_method?.type === "percentage") {
7811
- return formatPercentage(value);
7812
- }
7813
- return null;
7814
- }
7815
- const formatter = new Intl.NumberFormat([], {
7816
- style: "percent",
7817
- minimumFractionDigits: 2
7818
- });
7819
- const formatPercentage = (value, isPercentageValue = false) => {
7820
- let val = value || 0;
7821
- if (!isPercentageValue) {
7822
- val = val / 100;
7823
- }
7824
- return formatter.format(val);
7825
- };
7826
- function getPromotionIds(items, shippingMethods) {
7827
- const promotionIds = /* @__PURE__ */ new Set();
7828
- for (const item of items) {
7829
- if (item.adjustments) {
7830
- for (const adjustment of item.adjustments) {
7831
- if (adjustment.promotion_id) {
7832
- promotionIds.add(adjustment.promotion_id);
7833
- }
7834
- }
7835
- }
7836
- }
7837
- for (const shippingMethod of shippingMethods) {
7838
- if (shippingMethod.adjustments) {
7839
- for (const adjustment of shippingMethod.adjustments) {
7840
- if (adjustment.promotion_id) {
7841
- promotionIds.add(adjustment.promotion_id);
7842
- }
7843
- }
7844
- }
7845
- }
7846
- return Array.from(promotionIds);
7847
- }
7848
- const SalesChannel = () => {
7849
- const { id } = useParams();
7850
- const { draft_order, isPending, isError, error } = useDraftOrder(
7851
- id,
7852
- {
7853
- fields: "+sales_channel_id"
7854
- },
7855
- {
7856
- enabled: !!id
7857
- }
7858
- );
7859
- if (isError) {
7860
- throw error;
7861
- }
7862
- const ISrEADY = !!draft_order && !isPending;
7863
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7864
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7865
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
7866
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7867
- ] }),
7868
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
7869
- ] });
7870
- };
7871
- const SalesChannelForm = ({ order }) => {
7872
- const form = useForm({
7873
- defaultValues: {
7874
- sales_channel_id: order.sales_channel_id || ""
7875
- },
7876
- resolver: zodResolver(schema$2)
7877
- });
7878
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7879
- const { handleSuccess } = useRouteModal();
7880
- const onSubmit = form.handleSubmit(async (data) => {
7881
- await mutateAsync(
7882
- {
7883
- sales_channel_id: data.sales_channel_id
7884
- },
7885
- {
7886
- onSuccess: () => {
7887
- toast.success("Sales channel updated");
7888
- handleSuccess();
7889
- },
7890
- onError: (error) => {
7891
- toast.error(error.message);
7892
- }
7893
- }
7894
- );
7895
- });
7896
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7897
- KeyboundForm,
7898
- {
7899
- className: "flex flex-1 flex-col overflow-hidden",
7900
- onSubmit,
7901
- children: [
7902
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
7903
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7904
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7905
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7906
- ] }) })
7907
- ]
7908
- }
7909
- ) });
7910
- };
7911
- const SalesChannelField = ({ control, order }) => {
7912
- const salesChannels = useComboboxData({
7913
- queryFn: async (params) => {
7914
- return await sdk.admin.salesChannel.list(params);
7915
- },
7916
- queryKey: ["sales-channels"],
7917
- getOptions: (data) => {
7918
- return data.sales_channels.map((salesChannel) => ({
7919
- label: salesChannel.name,
7920
- value: salesChannel.id
7921
- }));
7922
- },
7923
- defaultValue: order.sales_channel_id || void 0
7924
- });
7925
- return /* @__PURE__ */ jsx(
7926
- Form$2.Field,
7927
- {
7928
- control,
7929
- name: "sales_channel_id",
7930
- render: ({ field }) => {
7931
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7932
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
7933
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
7934
- Combobox,
7935
- {
7936
- options: salesChannels.options,
7937
- fetchNextPage: salesChannels.fetchNextPage,
7938
- isFetchingNextPage: salesChannels.isFetchingNextPage,
7939
- searchValue: salesChannels.searchValue,
7940
- onSearchValueChange: salesChannels.onSearchValueChange,
7941
- placeholder: "Select sales channel",
7942
- ...field
7943
- }
7944
- ) }),
7945
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7946
- ] });
7947
- }
7948
- }
7949
- );
7950
- };
7951
- const schema$2 = z.object({
7952
- sales_channel_id: z.string().min(1)
7953
- });
7954
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
7955
- const Shipping = () => {
7956
- const { id } = useParams();
7957
- const { order, isPending, isError, error } = useOrder(id, {
7958
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
7959
- });
7960
- const {
7961
- order: preview,
7962
- isPending: isPreviewPending,
7963
- isError: isPreviewError,
7964
- error: previewError
7965
- } = useOrderPreview(id);
7966
- useInitiateOrderEdit({ preview });
7967
- const { onCancel } = useCancelOrderEdit({ preview });
7968
- if (isError) {
7969
- throw error;
7970
- }
7971
- if (isPreviewError) {
7972
- throw previewError;
7973
- }
7974
- const orderHasItems = (order?.items?.length || 0) > 0;
7975
- const isReady = preview && !isPreviewPending && order && !isPending;
7976
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
7977
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
7978
- /* @__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 px-6 py-16", children: [
7979
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
7980
- /* @__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." }) })
7981
- ] }) }) }),
7982
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
7983
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
7984
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
7985
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
7986
- ] }) });
7987
- };
7988
- const ShippingForm = ({ preview, order }) => {
7989
- const { setIsOpen } = useStackedModal();
7990
- const [isSubmitting, setIsSubmitting] = useState(false);
7991
- const [data, setData] = useState(null);
7992
- const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
7993
- const { shipping_options } = useShippingOptions(
7994
- {
7995
- id: appliedShippingOptionIds,
7996
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
7997
- },
7998
- {
7999
- enabled: appliedShippingOptionIds.length > 0
7618
+ enabled: appliedShippingOptionIds.length > 0
8000
7619
  }
8001
7620
  );
8002
7621
  const uniqueShippingProfiles = useMemo(() => {
@@ -8714,37 +8333,143 @@ const ShippingOptionField = ({
8714
8333
  ] }) });
8715
8334
  }
8716
8335
  }
8717
- );
8336
+ );
8337
+ };
8338
+ const CustomAmountField = ({
8339
+ control,
8340
+ currencyCode
8341
+ }) => {
8342
+ return /* @__PURE__ */ jsx(
8343
+ Form$2.Field,
8344
+ {
8345
+ control,
8346
+ name: "custom_amount",
8347
+ render: ({ field: { onChange, ...field } }) => {
8348
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8349
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
8350
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
8351
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
8352
+ ] }),
8353
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
8354
+ CurrencyInput,
8355
+ {
8356
+ ...field,
8357
+ onValueChange: (value) => onChange(value),
8358
+ symbol: getNativeSymbol(currencyCode),
8359
+ code: currencyCode
8360
+ }
8361
+ ) })
8362
+ ] });
8363
+ }
8364
+ }
8365
+ );
8366
+ };
8367
+ const SalesChannel = () => {
8368
+ const { id } = useParams();
8369
+ const { draft_order, isPending, isError, error } = useDraftOrder(
8370
+ id,
8371
+ {
8372
+ fields: "+sales_channel_id"
8373
+ },
8374
+ {
8375
+ enabled: !!id
8376
+ }
8377
+ );
8378
+ if (isError) {
8379
+ throw error;
8380
+ }
8381
+ const ISrEADY = !!draft_order && !isPending;
8382
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
8383
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
8384
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
8385
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
8386
+ ] }),
8387
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
8388
+ ] });
8389
+ };
8390
+ const SalesChannelForm = ({ order }) => {
8391
+ const form = useForm({
8392
+ defaultValues: {
8393
+ sales_channel_id: order.sales_channel_id || ""
8394
+ },
8395
+ resolver: zodResolver(schema$2)
8396
+ });
8397
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8398
+ const { handleSuccess } = useRouteModal();
8399
+ const onSubmit = form.handleSubmit(async (data) => {
8400
+ await mutateAsync(
8401
+ {
8402
+ sales_channel_id: data.sales_channel_id
8403
+ },
8404
+ {
8405
+ onSuccess: () => {
8406
+ toast.success("Sales channel updated");
8407
+ handleSuccess();
8408
+ },
8409
+ onError: (error) => {
8410
+ toast.error(error.message);
8411
+ }
8412
+ }
8413
+ );
8414
+ });
8415
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
8416
+ KeyboundForm,
8417
+ {
8418
+ className: "flex flex-1 flex-col overflow-hidden",
8419
+ onSubmit,
8420
+ children: [
8421
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
8422
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
8423
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8424
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8425
+ ] }) })
8426
+ ]
8427
+ }
8428
+ ) });
8718
8429
  };
8719
- const CustomAmountField = ({
8720
- control,
8721
- currencyCode
8722
- }) => {
8430
+ const SalesChannelField = ({ control, order }) => {
8431
+ const salesChannels = useComboboxData({
8432
+ queryFn: async (params) => {
8433
+ return await sdk.admin.salesChannel.list(params);
8434
+ },
8435
+ queryKey: ["sales-channels"],
8436
+ getOptions: (data) => {
8437
+ return data.sales_channels.map((salesChannel) => ({
8438
+ label: salesChannel.name,
8439
+ value: salesChannel.id
8440
+ }));
8441
+ },
8442
+ defaultValue: order.sales_channel_id || void 0
8443
+ });
8723
8444
  return /* @__PURE__ */ jsx(
8724
8445
  Form$2.Field,
8725
8446
  {
8726
8447
  control,
8727
- name: "custom_amount",
8728
- render: ({ field: { onChange, ...field } }) => {
8729
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8730
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
8731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
8732
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
8733
- ] }),
8448
+ name: "sales_channel_id",
8449
+ render: ({ field }) => {
8450
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
8734
8452
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
8735
- CurrencyInput,
8453
+ Combobox,
8736
8454
  {
8737
- ...field,
8738
- onValueChange: (value) => onChange(value),
8739
- symbol: getNativeSymbol(currencyCode),
8740
- code: currencyCode
8455
+ options: salesChannels.options,
8456
+ fetchNextPage: salesChannels.fetchNextPage,
8457
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
8458
+ searchValue: salesChannels.searchValue,
8459
+ onSearchValueChange: salesChannels.onSearchValueChange,
8460
+ placeholder: "Select sales channel",
8461
+ ...field
8741
8462
  }
8742
- ) })
8463
+ ) }),
8464
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8743
8465
  ] });
8744
8466
  }
8745
8467
  }
8746
8468
  );
8747
8469
  };
8470
+ const schema$2 = z.object({
8471
+ sales_channel_id: z.string().min(1)
8472
+ });
8748
8473
  const ShippingAddress = () => {
8749
8474
  const { id } = useParams();
8750
8475
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9342,86 +9067,361 @@ const Illustration = () => {
9342
9067
  /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
9343
9068
  "path",
9344
9069
  {
9345
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
9346
- stroke: "#A1A1AA",
9347
- strokeWidth: "1.5",
9348
- strokeLinecap: "round",
9349
- strokeLinejoin: "round"
9070
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
9071
+ stroke: "#A1A1AA",
9072
+ strokeWidth: "1.5",
9073
+ strokeLinecap: "round",
9074
+ strokeLinejoin: "round"
9075
+ }
9076
+ ) }),
9077
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
9078
+ "path",
9079
+ {
9080
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
9081
+ stroke: "#A1A1AA",
9082
+ strokeWidth: "1.5",
9083
+ strokeLinecap: "round",
9084
+ strokeLinejoin: "round"
9085
+ }
9086
+ ) }),
9087
+ /* @__PURE__ */ jsxs("defs", { children: [
9088
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
9089
+ "rect",
9090
+ {
9091
+ width: "12",
9092
+ height: "12",
9093
+ fill: "white",
9094
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
9095
+ }
9096
+ ) }),
9097
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
9098
+ "rect",
9099
+ {
9100
+ width: "12",
9101
+ height: "12",
9102
+ fill: "white",
9103
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
9104
+ }
9105
+ ) }),
9106
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
9107
+ "rect",
9108
+ {
9109
+ width: "12",
9110
+ height: "12",
9111
+ fill: "white",
9112
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
9113
+ }
9114
+ ) }),
9115
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
9116
+ "rect",
9117
+ {
9118
+ width: "12",
9119
+ height: "12",
9120
+ fill: "white",
9121
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
9122
+ }
9123
+ ) }),
9124
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
9125
+ "rect",
9126
+ {
9127
+ width: "12",
9128
+ height: "12",
9129
+ fill: "white",
9130
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
9131
+ }
9132
+ ) }),
9133
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
9134
+ "rect",
9135
+ {
9136
+ width: "12",
9137
+ height: "12",
9138
+ fill: "white",
9139
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
9140
+ }
9141
+ ) })
9142
+ ] })
9143
+ ]
9144
+ }
9145
+ );
9146
+ };
9147
+ const schema = z.object({
9148
+ customer_id: z.string().min(1)
9149
+ });
9150
+ const PROMOTION_QUERY_KEY = "promotions";
9151
+ const promotionsQueryKeys = {
9152
+ list: (query2) => [
9153
+ PROMOTION_QUERY_KEY,
9154
+ query2 ? query2 : void 0
9155
+ ],
9156
+ detail: (id, query2) => [
9157
+ PROMOTION_QUERY_KEY,
9158
+ id,
9159
+ query2 ? query2 : void 0
9160
+ ]
9161
+ };
9162
+ const usePromotions = (query2, options) => {
9163
+ const { data, ...rest } = useQuery({
9164
+ queryKey: promotionsQueryKeys.list(query2),
9165
+ queryFn: async () => sdk.admin.promotion.list(query2),
9166
+ ...options
9167
+ });
9168
+ return { ...data, ...rest };
9169
+ };
9170
+ const Promotions = () => {
9171
+ const { id } = useParams();
9172
+ const {
9173
+ order: preview,
9174
+ isError: isPreviewError,
9175
+ error: previewError
9176
+ } = useOrderPreview(id, void 0);
9177
+ useInitiateOrderEdit({ preview });
9178
+ const { onCancel } = useCancelOrderEdit({ preview });
9179
+ if (isPreviewError) {
9180
+ throw previewError;
9181
+ }
9182
+ const isReady = !!preview;
9183
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
9184
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
9185
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
9186
+ ] });
9187
+ };
9188
+ const PromotionForm = ({ preview }) => {
9189
+ const { items, shipping_methods } = preview;
9190
+ const [isSubmitting, setIsSubmitting] = useState(false);
9191
+ const [comboboxValue, setComboboxValue] = useState("");
9192
+ const { handleSuccess } = useRouteModal();
9193
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
9194
+ const promoIds = getPromotionIds(items, shipping_methods);
9195
+ const { promotions, isPending, isError, error } = usePromotions(
9196
+ {
9197
+ id: promoIds
9198
+ },
9199
+ {
9200
+ enabled: !!promoIds.length
9201
+ }
9202
+ );
9203
+ const comboboxData = useComboboxData({
9204
+ queryKey: ["promotions", "combobox", promoIds],
9205
+ queryFn: async (params) => {
9206
+ return await sdk.admin.promotion.list({
9207
+ ...params,
9208
+ id: {
9209
+ $nin: promoIds
9210
+ }
9211
+ });
9212
+ },
9213
+ getOptions: (data) => {
9214
+ return data.promotions.map((promotion) => ({
9215
+ label: promotion.code,
9216
+ value: promotion.code
9217
+ }));
9218
+ }
9219
+ });
9220
+ const add = async (value) => {
9221
+ if (!value) {
9222
+ return;
9223
+ }
9224
+ addPromotions(
9225
+ {
9226
+ promo_codes: [value]
9227
+ },
9228
+ {
9229
+ onError: (e) => {
9230
+ toast.error(e.message);
9231
+ comboboxData.onSearchValueChange("");
9232
+ setComboboxValue("");
9233
+ },
9234
+ onSuccess: () => {
9235
+ comboboxData.onSearchValueChange("");
9236
+ setComboboxValue("");
9237
+ }
9238
+ }
9239
+ );
9240
+ };
9241
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9242
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
9243
+ const onSubmit = async () => {
9244
+ setIsSubmitting(true);
9245
+ let requestSucceeded = false;
9246
+ await requestOrderEdit(void 0, {
9247
+ onError: (e) => {
9248
+ toast.error(e.message);
9249
+ },
9250
+ onSuccess: () => {
9251
+ requestSucceeded = true;
9252
+ }
9253
+ });
9254
+ if (!requestSucceeded) {
9255
+ setIsSubmitting(false);
9256
+ return;
9257
+ }
9258
+ await confirmOrderEdit(void 0, {
9259
+ onError: (e) => {
9260
+ toast.error(e.message);
9261
+ },
9262
+ onSuccess: () => {
9263
+ handleSuccess();
9264
+ },
9265
+ onSettled: () => {
9266
+ setIsSubmitting(false);
9267
+ }
9268
+ });
9269
+ };
9270
+ if (isError) {
9271
+ throw error;
9272
+ }
9273
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
9274
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
9275
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
9276
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
9277
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
9278
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
9279
+ ] }),
9280
+ /* @__PURE__ */ jsx(
9281
+ Combobox,
9282
+ {
9283
+ id: "promotion-combobox",
9284
+ "aria-describedby": "promotion-combobox-hint",
9285
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
9286
+ fetchNextPage: comboboxData.fetchNextPage,
9287
+ options: comboboxData.options,
9288
+ onSearchValueChange: comboboxData.onSearchValueChange,
9289
+ searchValue: comboboxData.searchValue,
9290
+ disabled: comboboxData.disabled || isAddingPromotions,
9291
+ onChange: add,
9292
+ value: comboboxValue
9350
9293
  }
9351
- ) }),
9352
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
9353
- "path",
9294
+ )
9295
+ ] }),
9296
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
9297
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
9298
+ PromotionItem,
9299
+ {
9300
+ promotion,
9301
+ orderId: preview.id,
9302
+ isLoading: isPending
9303
+ },
9304
+ promotion.id
9305
+ )) })
9306
+ ] }) }),
9307
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9308
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9309
+ /* @__PURE__ */ jsx(
9310
+ Button,
9311
+ {
9312
+ size: "small",
9313
+ type: "submit",
9314
+ isLoading: isSubmitting || isAddingPromotions,
9315
+ children: "Save"
9316
+ }
9317
+ )
9318
+ ] }) })
9319
+ ] });
9320
+ };
9321
+ const PromotionItem = ({
9322
+ promotion,
9323
+ orderId,
9324
+ isLoading
9325
+ }) => {
9326
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
9327
+ const onRemove = async () => {
9328
+ removePromotions(
9329
+ {
9330
+ promo_codes: [promotion.code]
9331
+ },
9332
+ {
9333
+ onError: (e) => {
9334
+ toast.error(e.message);
9335
+ }
9336
+ }
9337
+ );
9338
+ };
9339
+ const displayValue = getDisplayValue(promotion);
9340
+ return /* @__PURE__ */ jsxs(
9341
+ "div",
9342
+ {
9343
+ className: clx(
9344
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
9345
+ {
9346
+ "animate-pulse": isLoading
9347
+ }
9348
+ ),
9349
+ children: [
9350
+ /* @__PURE__ */ jsxs("div", { children: [
9351
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
9352
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
9353
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
9354
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
9355
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
9356
+ ] }),
9357
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
9358
+ ] })
9359
+ ] }),
9360
+ /* @__PURE__ */ jsx(
9361
+ IconButton,
9354
9362
  {
9355
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
9356
- stroke: "#A1A1AA",
9357
- strokeWidth: "1.5",
9358
- strokeLinecap: "round",
9359
- strokeLinejoin: "round"
9363
+ size: "small",
9364
+ type: "button",
9365
+ variant: "transparent",
9366
+ onClick: onRemove,
9367
+ isLoading: isPending || isLoading,
9368
+ children: /* @__PURE__ */ jsx(XMark, {})
9360
9369
  }
9361
- ) }),
9362
- /* @__PURE__ */ jsxs("defs", { children: [
9363
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
9364
- "rect",
9365
- {
9366
- width: "12",
9367
- height: "12",
9368
- fill: "white",
9369
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
9370
- }
9371
- ) }),
9372
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
9373
- "rect",
9374
- {
9375
- width: "12",
9376
- height: "12",
9377
- fill: "white",
9378
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
9379
- }
9380
- ) }),
9381
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
9382
- "rect",
9383
- {
9384
- width: "12",
9385
- height: "12",
9386
- fill: "white",
9387
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
9388
- }
9389
- ) }),
9390
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
9391
- "rect",
9392
- {
9393
- width: "12",
9394
- height: "12",
9395
- fill: "white",
9396
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
9397
- }
9398
- ) }),
9399
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
9400
- "rect",
9401
- {
9402
- width: "12",
9403
- height: "12",
9404
- fill: "white",
9405
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
9406
- }
9407
- ) }),
9408
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
9409
- "rect",
9410
- {
9411
- width: "12",
9412
- height: "12",
9413
- fill: "white",
9414
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
9415
- }
9416
- ) })
9417
- ] })
9370
+ )
9418
9371
  ]
9419
- }
9372
+ },
9373
+ promotion.id
9420
9374
  );
9421
9375
  };
9422
- const schema = z.object({
9423
- customer_id: z.string().min(1)
9376
+ function getDisplayValue(promotion) {
9377
+ const value = promotion.application_method?.value;
9378
+ if (!value) {
9379
+ return null;
9380
+ }
9381
+ if (promotion.application_method?.type === "fixed") {
9382
+ const currency = promotion.application_method?.currency_code;
9383
+ if (!currency) {
9384
+ return null;
9385
+ }
9386
+ return getLocaleAmount(value, currency);
9387
+ } else if (promotion.application_method?.type === "percentage") {
9388
+ return formatPercentage(value);
9389
+ }
9390
+ return null;
9391
+ }
9392
+ const formatter = new Intl.NumberFormat([], {
9393
+ style: "percent",
9394
+ minimumFractionDigits: 2
9424
9395
  });
9396
+ const formatPercentage = (value, isPercentageValue = false) => {
9397
+ let val = value || 0;
9398
+ if (!isPercentageValue) {
9399
+ val = val / 100;
9400
+ }
9401
+ return formatter.format(val);
9402
+ };
9403
+ function getPromotionIds(items, shippingMethods) {
9404
+ const promotionIds = /* @__PURE__ */ new Set();
9405
+ for (const item of items) {
9406
+ if (item.adjustments) {
9407
+ for (const adjustment of item.adjustments) {
9408
+ if (adjustment.promotion_id) {
9409
+ promotionIds.add(adjustment.promotion_id);
9410
+ }
9411
+ }
9412
+ }
9413
+ }
9414
+ for (const shippingMethod of shippingMethods) {
9415
+ if (shippingMethod.adjustments) {
9416
+ for (const adjustment of shippingMethod.adjustments) {
9417
+ if (adjustment.promotion_id) {
9418
+ promotionIds.add(adjustment.promotion_id);
9419
+ }
9420
+ }
9421
+ }
9422
+ }
9423
+ return Array.from(promotionIds);
9424
+ }
9425
9425
  const widgetModule = { widgets: [] };
9426
9426
  const routeModule = {
9427
9427
  routes: [
@@ -9443,8 +9443,8 @@ const routeModule = {
9443
9443
  loader,
9444
9444
  children: [
9445
9445
  {
9446
- Component: BillingAddress,
9447
- path: "/draft-orders/:id/billing-address"
9446
+ Component: CustomItems,
9447
+ path: "/draft-orders/:id/custom-items"
9448
9448
  },
9449
9449
  {
9450
9450
  Component: Email,
@@ -9455,25 +9455,21 @@ const routeModule = {
9455
9455
  path: "/draft-orders/:id/items"
9456
9456
  },
9457
9457
  {
9458
- Component: CustomItems,
9459
- path: "/draft-orders/:id/custom-items"
9458
+ Component: BillingAddress,
9459
+ path: "/draft-orders/:id/billing-address"
9460
9460
  },
9461
9461
  {
9462
9462
  Component: Metadata,
9463
9463
  path: "/draft-orders/:id/metadata"
9464
9464
  },
9465
9465
  {
9466
- Component: Promotions,
9467
- path: "/draft-orders/:id/promotions"
9466
+ Component: Shipping,
9467
+ path: "/draft-orders/:id/shipping"
9468
9468
  },
9469
9469
  {
9470
9470
  Component: SalesChannel,
9471
9471
  path: "/draft-orders/:id/sales-channel"
9472
9472
  },
9473
- {
9474
- Component: Shipping,
9475
- path: "/draft-orders/:id/shipping"
9476
- },
9477
9473
  {
9478
9474
  Component: ShippingAddress,
9479
9475
  path: "/draft-orders/:id/shipping-address"
@@ -9481,6 +9477,10 @@ const routeModule = {
9481
9477
  {
9482
9478
  Component: TransferOwnership,
9483
9479
  path: "/draft-orders/:id/transfer-ownership"
9480
+ },
9481
+ {
9482
+ Component: Promotions,
9483
+ path: "/draft-orders/:id/promotions"
9484
9484
  }
9485
9485
  ]
9486
9486
  }
@@ -9505,6 +9505,7 @@ const displayModule = {
9505
9505
  const i18nModule = { resources: {} };
9506
9506
  const cellRendererModule = {};
9507
9507
  const layoutModule = { layouts: [] };
9508
+ const searchEntityModule = {};
9508
9509
  const plugin = {
9509
9510
  widgetModule,
9510
9511
  routeModule,
@@ -9513,7 +9514,8 @@ const plugin = {
9513
9514
  displayModule,
9514
9515
  i18nModule,
9515
9516
  cellRendererModule,
9516
- layoutModule
9517
+ layoutModule,
9518
+ searchEntityModule
9517
9519
  };
9518
9520
  export {
9519
9521
  plugin as default