@medusajs/draft-order 2.20.1 → 2.20.2-preview-20260904091918

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.
@@ -5979,6 +5979,195 @@ const ID = () => {
5979
5979
  }
5980
5980
  );
5981
5981
  };
5982
+ const BillingAddress = () => {
5983
+ const { id } = reactRouterDom.useParams();
5984
+ const { order, isPending, isError, error } = useOrder(id, {
5985
+ fields: "+billing_address"
5986
+ });
5987
+ if (isError) {
5988
+ throw error;
5989
+ }
5990
+ const isReady = !isPending && !!order;
5991
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
5992
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
5993
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
5994
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
5995
+ ] }),
5996
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
5997
+ ] });
5998
+ };
5999
+ const BillingAddressForm = ({ order }) => {
6000
+ const form = reactHookForm.useForm({
6001
+ defaultValues: {
6002
+ first_name: order.billing_address?.first_name ?? "",
6003
+ last_name: order.billing_address?.last_name ?? "",
6004
+ company: order.billing_address?.company ?? "",
6005
+ address_1: order.billing_address?.address_1 ?? "",
6006
+ address_2: order.billing_address?.address_2 ?? "",
6007
+ city: order.billing_address?.city ?? "",
6008
+ province: order.billing_address?.province ?? "",
6009
+ country_code: order.billing_address?.country_code ?? "",
6010
+ postal_code: order.billing_address?.postal_code ?? "",
6011
+ phone: order.billing_address?.phone ?? ""
6012
+ },
6013
+ resolver: zod$1.zodResolver(schema$5)
6014
+ });
6015
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6016
+ const { handleSuccess } = useRouteModal();
6017
+ const onSubmit = form.handleSubmit(async (data) => {
6018
+ await mutateAsync(
6019
+ { billing_address: data },
6020
+ {
6021
+ onSuccess: () => {
6022
+ handleSuccess();
6023
+ },
6024
+ onError: (error) => {
6025
+ ui.toast.error(error.message);
6026
+ }
6027
+ }
6028
+ );
6029
+ });
6030
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
6031
+ KeyboundForm,
6032
+ {
6033
+ className: "flex flex-1 flex-col overflow-hidden",
6034
+ onSubmit,
6035
+ children: [
6036
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
6037
+ /* @__PURE__ */ jsxRuntime.jsx(
6038
+ Form$2.Field,
6039
+ {
6040
+ control: form.control,
6041
+ name: "country_code",
6042
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6043
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
6044
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
6045
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6046
+ ] })
6047
+ }
6048
+ ),
6049
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6050
+ /* @__PURE__ */ jsxRuntime.jsx(
6051
+ Form$2.Field,
6052
+ {
6053
+ control: form.control,
6054
+ name: "first_name",
6055
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6056
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
6057
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6058
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6059
+ ] })
6060
+ }
6061
+ ),
6062
+ /* @__PURE__ */ jsxRuntime.jsx(
6063
+ Form$2.Field,
6064
+ {
6065
+ control: form.control,
6066
+ name: "last_name",
6067
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6068
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
6069
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6070
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6071
+ ] })
6072
+ }
6073
+ )
6074
+ ] }),
6075
+ /* @__PURE__ */ jsxRuntime.jsx(
6076
+ Form$2.Field,
6077
+ {
6078
+ control: form.control,
6079
+ name: "company",
6080
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6081
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
6082
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6083
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6084
+ ] })
6085
+ }
6086
+ ),
6087
+ /* @__PURE__ */ jsxRuntime.jsx(
6088
+ Form$2.Field,
6089
+ {
6090
+ control: form.control,
6091
+ name: "address_1",
6092
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6093
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
6094
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6095
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6096
+ ] })
6097
+ }
6098
+ ),
6099
+ /* @__PURE__ */ jsxRuntime.jsx(
6100
+ Form$2.Field,
6101
+ {
6102
+ control: form.control,
6103
+ name: "address_2",
6104
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6105
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
6106
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6107
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6108
+ ] })
6109
+ }
6110
+ ),
6111
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6112
+ /* @__PURE__ */ jsxRuntime.jsx(
6113
+ Form$2.Field,
6114
+ {
6115
+ control: form.control,
6116
+ name: "postal_code",
6117
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6118
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
6119
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6120
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6121
+ ] })
6122
+ }
6123
+ ),
6124
+ /* @__PURE__ */ jsxRuntime.jsx(
6125
+ Form$2.Field,
6126
+ {
6127
+ control: form.control,
6128
+ name: "city",
6129
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6130
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
6131
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6132
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6133
+ ] })
6134
+ }
6135
+ )
6136
+ ] }),
6137
+ /* @__PURE__ */ jsxRuntime.jsx(
6138
+ Form$2.Field,
6139
+ {
6140
+ control: form.control,
6141
+ name: "province",
6142
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6143
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
6144
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6145
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6146
+ ] })
6147
+ }
6148
+ ),
6149
+ /* @__PURE__ */ jsxRuntime.jsx(
6150
+ Form$2.Field,
6151
+ {
6152
+ control: form.control,
6153
+ name: "phone",
6154
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
6155
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
6156
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
6157
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
6158
+ ] })
6159
+ }
6160
+ )
6161
+ ] }) }),
6162
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
6163
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6164
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
6165
+ ] }) })
6166
+ ]
6167
+ }
6168
+ ) });
6169
+ };
6170
+ const schema$5 = addressSchema;
5982
6171
  const CustomItems = () => {
5983
6172
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
5984
6173
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -5987,7 +6176,7 @@ const CustomItems = () => {
5987
6176
  };
5988
6177
  const CustomItemsForm = () => {
5989
6178
  const form = reactHookForm.useForm({
5990
- resolver: zod$1.zodResolver(schema$5)
6179
+ resolver: zod$1.zodResolver(schema$4)
5991
6180
  });
5992
6181
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
5993
6182
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -5997,7 +6186,7 @@ const CustomItemsForm = () => {
5997
6186
  ] }) })
5998
6187
  ] }) });
5999
6188
  };
6000
- const schema$5 = zod.z.object({
6189
+ const schema$4 = zod.z.object({
6001
6190
  email: zod.z.string().email()
6002
6191
  });
6003
6192
  const Email = () => {
@@ -6022,7 +6211,7 @@ const EmailForm = ({ order }) => {
6022
6211
  defaultValues: {
6023
6212
  email: order.email ?? ""
6024
6213
  },
6025
- resolver: zod$1.zodResolver(schema$4)
6214
+ resolver: zod$1.zodResolver(schema$3)
6026
6215
  });
6027
6216
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6028
6217
  const { handleSuccess } = useRouteModal();
@@ -6065,7 +6254,7 @@ const EmailForm = ({ order }) => {
6065
6254
  }
6066
6255
  ) });
6067
6256
  };
6068
- const schema$4 = zod.z.object({
6257
+ const schema$3 = zod.z.object({
6069
6258
  email: zod.z.string().email()
6070
6259
  });
6071
6260
  const NumberInput = React.forwardRef(
@@ -7087,844 +7276,336 @@ const customItemSchema = zod.z.object({
7087
7276
  quantity: zod.z.number(),
7088
7277
  unit_price: zod.z.union([zod.z.number(), zod.z.string()])
7089
7278
  });
7090
- const BillingAddress = () => {
7091
- const { id } = reactRouterDom.useParams();
7092
- const { order, isPending, isError, error } = useOrder(id, {
7093
- fields: "+billing_address"
7279
+ const PROMOTION_QUERY_KEY = "promotions";
7280
+ const promotionsQueryKeys = {
7281
+ list: (query2) => [
7282
+ PROMOTION_QUERY_KEY,
7283
+ query2 ? query2 : void 0
7284
+ ],
7285
+ detail: (id, query2) => [
7286
+ PROMOTION_QUERY_KEY,
7287
+ id,
7288
+ query2 ? query2 : void 0
7289
+ ]
7290
+ };
7291
+ const usePromotions = (query2, options) => {
7292
+ const { data, ...rest } = reactQuery.useQuery({
7293
+ queryKey: promotionsQueryKeys.list(query2),
7294
+ queryFn: async () => sdk.admin.promotion.list(query2),
7295
+ ...options
7094
7296
  });
7095
- if (isError) {
7096
- throw error;
7297
+ return { ...data, ...rest };
7298
+ };
7299
+ const Promotions = () => {
7300
+ const { id } = reactRouterDom.useParams();
7301
+ const {
7302
+ order: preview,
7303
+ isError: isPreviewError,
7304
+ error: previewError
7305
+ } = useOrderPreview(id, void 0);
7306
+ useInitiateOrderEdit({ preview });
7307
+ const { onCancel } = useCancelOrderEdit({ preview });
7308
+ if (isPreviewError) {
7309
+ throw previewError;
7097
7310
  }
7098
- const isReady = !isPending && !!order;
7099
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7100
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7101
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
7102
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
7103
- ] }),
7104
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
7311
+ const isReady = !!preview;
7312
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
7313
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
7314
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
7105
7315
  ] });
7106
7316
  };
7107
- const BillingAddressForm = ({ order }) => {
7108
- const form = reactHookForm.useForm({
7109
- defaultValues: {
7110
- first_name: order.billing_address?.first_name ?? "",
7111
- last_name: order.billing_address?.last_name ?? "",
7112
- company: order.billing_address?.company ?? "",
7113
- address_1: order.billing_address?.address_1 ?? "",
7114
- address_2: order.billing_address?.address_2 ?? "",
7115
- city: order.billing_address?.city ?? "",
7116
- province: order.billing_address?.province ?? "",
7117
- country_code: order.billing_address?.country_code ?? "",
7118
- postal_code: order.billing_address?.postal_code ?? "",
7119
- phone: order.billing_address?.phone ?? ""
7120
- },
7121
- resolver: zod$1.zodResolver(schema$3)
7122
- });
7123
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7317
+ const PromotionForm = ({ preview }) => {
7318
+ const { items, shipping_methods } = preview;
7319
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
7320
+ const [comboboxValue, setComboboxValue] = React.useState("");
7124
7321
  const { handleSuccess } = useRouteModal();
7125
- const onSubmit = form.handleSubmit(async (data) => {
7126
- await mutateAsync(
7127
- { billing_address: data },
7128
- {
7129
- onSuccess: () => {
7130
- handleSuccess();
7131
- },
7132
- onError: (error) => {
7133
- ui.toast.error(error.message);
7134
- }
7135
- }
7136
- );
7137
- });
7138
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7139
- KeyboundForm,
7322
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
7323
+ const promoIds = getPromotionIds(items, shipping_methods);
7324
+ const { promotions, isPending, isError, error } = usePromotions(
7140
7325
  {
7141
- className: "flex flex-1 flex-col overflow-hidden",
7142
- onSubmit,
7143
- children: [
7144
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
7145
- /* @__PURE__ */ jsxRuntime.jsx(
7146
- Form$2.Field,
7147
- {
7148
- control: form.control,
7149
- name: "country_code",
7150
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7151
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
7152
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
7153
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7154
- ] })
7155
- }
7156
- ),
7157
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7158
- /* @__PURE__ */ jsxRuntime.jsx(
7159
- Form$2.Field,
7160
- {
7161
- control: form.control,
7162
- name: "first_name",
7163
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7164
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
7165
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7166
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7167
- ] })
7168
- }
7169
- ),
7170
- /* @__PURE__ */ jsxRuntime.jsx(
7171
- Form$2.Field,
7172
- {
7173
- control: form.control,
7174
- name: "last_name",
7175
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7176
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
7177
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7178
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7179
- ] })
7180
- }
7181
- )
7182
- ] }),
7183
- /* @__PURE__ */ jsxRuntime.jsx(
7184
- Form$2.Field,
7185
- {
7186
- control: form.control,
7187
- name: "company",
7188
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7189
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
7190
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7191
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7192
- ] })
7193
- }
7194
- ),
7195
- /* @__PURE__ */ jsxRuntime.jsx(
7196
- Form$2.Field,
7197
- {
7198
- control: form.control,
7199
- name: "address_1",
7200
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7201
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
7202
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7203
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7204
- ] })
7205
- }
7206
- ),
7207
- /* @__PURE__ */ jsxRuntime.jsx(
7208
- Form$2.Field,
7209
- {
7210
- control: form.control,
7211
- name: "address_2",
7212
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7213
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
7214
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7215
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7216
- ] })
7217
- }
7218
- ),
7219
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7220
- /* @__PURE__ */ jsxRuntime.jsx(
7221
- Form$2.Field,
7222
- {
7223
- control: form.control,
7224
- name: "postal_code",
7225
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7226
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
7227
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7228
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7229
- ] })
7230
- }
7231
- ),
7232
- /* @__PURE__ */ jsxRuntime.jsx(
7233
- Form$2.Field,
7234
- {
7235
- control: form.control,
7236
- name: "city",
7237
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7238
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
7239
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7240
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7241
- ] })
7242
- }
7243
- )
7244
- ] }),
7245
- /* @__PURE__ */ jsxRuntime.jsx(
7246
- Form$2.Field,
7247
- {
7248
- control: form.control,
7249
- name: "province",
7250
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7251
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
7252
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7254
- ] })
7255
- }
7256
- ),
7257
- /* @__PURE__ */ jsxRuntime.jsx(
7258
- Form$2.Field,
7259
- {
7260
- control: form.control,
7261
- name: "phone",
7262
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7263
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
7264
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7266
- ] })
7267
- }
7268
- )
7269
- ] }) }),
7270
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
7271
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7272
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7273
- ] }) })
7274
- ]
7275
- }
7276
- ) });
7277
- };
7278
- const schema$3 = addressSchema;
7279
- const InlineTip = React.forwardRef(
7280
- ({ variant = "tip", label, className, children, ...props }, ref) => {
7281
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
7282
- return /* @__PURE__ */ jsxRuntime.jsxs(
7283
- "div",
7284
- {
7285
- ref,
7286
- className: ui.clx(
7287
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
7288
- className
7289
- ),
7290
- ...props,
7291
- children: [
7292
- /* @__PURE__ */ jsxRuntime.jsx(
7293
- "div",
7294
- {
7295
- role: "presentation",
7296
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
7297
- "bg-ui-tag-orange-icon": variant === "warning"
7298
- })
7299
- }
7300
- ),
7301
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
7302
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
7303
- labelValue,
7304
- ":"
7305
- ] }),
7306
- " ",
7307
- children
7308
- ] })
7309
- ]
7310
- }
7311
- );
7312
- }
7313
- );
7314
- InlineTip.displayName = "InlineTip";
7315
- const MetadataFieldSchema = zod.z.object({
7316
- key: zod.z.string(),
7317
- disabled: zod.z.boolean().optional(),
7318
- value: zod.z.any()
7319
- });
7320
- const MetadataSchema = zod.z.object({
7321
- metadata: zod.z.array(MetadataFieldSchema)
7322
- });
7323
- const Metadata = () => {
7324
- const { id } = reactRouterDom.useParams();
7325
- const { order, isPending, isError, error } = useOrder(id, {
7326
- fields: "metadata"
7327
- });
7328
- if (isError) {
7329
- throw error;
7330
- }
7331
- const isReady = !isPending && !!order;
7332
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7333
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7334
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
7335
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
7336
- ] }),
7337
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
7338
- ] });
7339
- };
7340
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
7341
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
7342
- const MetadataForm = ({ orderId, metadata }) => {
7343
- const { handleSuccess } = useRouteModal();
7344
- const hasUneditableRows = getHasUneditableRows(metadata);
7345
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
7346
- const form = reactHookForm.useForm({
7347
- defaultValues: {
7348
- metadata: getDefaultValues(metadata)
7326
+ id: promoIds
7349
7327
  },
7350
- resolver: zod$1.zodResolver(MetadataSchema)
7351
- });
7352
- const handleSubmit = form.handleSubmit(async (data) => {
7353
- const parsedData = parseValues(data);
7354
- await mutateAsync(
7355
- {
7356
- metadata: parsedData
7357
- },
7358
- {
7359
- onSuccess: () => {
7360
- ui.toast.success("Metadata updated");
7361
- handleSuccess();
7362
- },
7363
- onError: (error) => {
7364
- ui.toast.error(error.message);
7365
- }
7366
- }
7367
- );
7368
- });
7369
- const { fields, insert, remove } = reactHookForm.useFieldArray({
7370
- control: form.control,
7371
- name: "metadata"
7372
- });
7373
- function deleteRow(index) {
7374
- remove(index);
7375
- if (fields.length === 1) {
7376
- insert(0, {
7377
- key: "",
7378
- value: "",
7379
- disabled: false
7380
- });
7381
- }
7382
- }
7383
- function insertRow(index, position) {
7384
- insert(index + (position === "above" ? 0 : 1), {
7385
- key: "",
7386
- value: "",
7387
- disabled: false
7388
- });
7389
- }
7390
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7391
- KeyboundForm,
7392
- {
7393
- onSubmit: handleSubmit,
7394
- className: "flex flex-1 flex-col overflow-hidden",
7395
- children: [
7396
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
7397
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
7398
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
7399
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
7400
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
7401
- ] }),
7402
- fields.map((field, index) => {
7403
- const isDisabled = field.disabled || false;
7404
- let placeholder = "-";
7405
- if (typeof field.value === "object") {
7406
- placeholder = "{ ... }";
7407
- }
7408
- if (Array.isArray(field.value)) {
7409
- placeholder = "[ ... ]";
7410
- }
7411
- return /* @__PURE__ */ jsxRuntime.jsx(
7412
- ConditionalTooltip,
7413
- {
7414
- showTooltip: isDisabled,
7415
- content: "This row is disabled because it contains non-primitive data.",
7416
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
7417
- /* @__PURE__ */ jsxRuntime.jsxs(
7418
- "div",
7419
- {
7420
- className: ui.clx("grid grid-cols-2 divide-x", {
7421
- "overflow-hidden rounded-b-lg": index === fields.length - 1
7422
- }),
7423
- children: [
7424
- /* @__PURE__ */ jsxRuntime.jsx(
7425
- Form$2.Field,
7426
- {
7427
- control: form.control,
7428
- name: `metadata.${index}.key`,
7429
- render: ({ field: field2 }) => {
7430
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7431
- GridInput,
7432
- {
7433
- "aria-labelledby": METADATA_KEY_LABEL_ID,
7434
- ...field2,
7435
- disabled: isDisabled,
7436
- placeholder: "Key"
7437
- }
7438
- ) }) });
7439
- }
7440
- }
7441
- ),
7442
- /* @__PURE__ */ jsxRuntime.jsx(
7443
- Form$2.Field,
7444
- {
7445
- control: form.control,
7446
- name: `metadata.${index}.value`,
7447
- render: ({ field: { value, ...field2 } }) => {
7448
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7449
- GridInput,
7450
- {
7451
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
7452
- ...field2,
7453
- value: isDisabled ? placeholder : value,
7454
- disabled: isDisabled,
7455
- placeholder: "Value"
7456
- }
7457
- ) }) });
7458
- }
7459
- }
7460
- )
7461
- ]
7462
- }
7463
- ),
7464
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
7465
- /* @__PURE__ */ jsxRuntime.jsx(
7466
- ui.DropdownMenu.Trigger,
7467
- {
7468
- className: ui.clx(
7469
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
7470
- {
7471
- hidden: isDisabled
7472
- }
7473
- ),
7474
- disabled: isDisabled,
7475
- asChild: true,
7476
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
7477
- }
7478
- ),
7479
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
7480
- /* @__PURE__ */ jsxRuntime.jsxs(
7481
- ui.DropdownMenu.Item,
7482
- {
7483
- className: "gap-x-2",
7484
- onClick: () => insertRow(index, "above"),
7485
- children: [
7486
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
7487
- "Insert row above"
7488
- ]
7489
- }
7490
- ),
7491
- /* @__PURE__ */ jsxRuntime.jsxs(
7492
- ui.DropdownMenu.Item,
7493
- {
7494
- className: "gap-x-2",
7495
- onClick: () => insertRow(index, "below"),
7496
- children: [
7497
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
7498
- "Insert row below"
7499
- ]
7500
- }
7501
- ),
7502
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
7503
- /* @__PURE__ */ jsxRuntime.jsxs(
7504
- ui.DropdownMenu.Item,
7505
- {
7506
- className: "gap-x-2",
7507
- onClick: () => deleteRow(index),
7508
- children: [
7509
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
7510
- "Delete row"
7511
- ]
7512
- }
7513
- )
7514
- ] })
7515
- ] })
7516
- ] })
7517
- },
7518
- field.id
7519
- );
7520
- })
7521
- ] }),
7522
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
7523
- ] }),
7524
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7525
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
7526
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7527
- ] }) })
7528
- ]
7529
- }
7530
- ) });
7531
- };
7532
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
7533
- return /* @__PURE__ */ jsxRuntime.jsx(
7534
- "input",
7535
7328
  {
7536
- ref,
7537
- ...props,
7538
- autoComplete: "off",
7539
- className: ui.clx(
7540
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
7541
- className
7542
- )
7543
- }
7544
- );
7545
- });
7546
- GridInput.displayName = "MetadataForm.GridInput";
7547
- const PlaceholderInner = () => {
7548
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
7549
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
7550
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7551
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
7552
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
7553
- ] }) })
7554
- ] });
7555
- };
7556
- const EDITABLE_TYPES = ["string", "number", "boolean"];
7557
- function getDefaultValues(metadata) {
7558
- if (!metadata || !Object.keys(metadata).length) {
7559
- return [
7560
- {
7561
- key: "",
7562
- value: "",
7563
- disabled: false
7564
- }
7565
- ];
7566
- }
7567
- return Object.entries(metadata).map(([key, value]) => {
7568
- if (!EDITABLE_TYPES.includes(typeof value)) {
7569
- return {
7570
- key,
7571
- value,
7572
- disabled: true
7573
- };
7329
+ enabled: !!promoIds.length
7574
7330
  }
7575
- let stringValue = value;
7576
- if (typeof value !== "string") {
7577
- stringValue = JSON.stringify(value);
7331
+ );
7332
+ const comboboxData = useComboboxData({
7333
+ queryKey: ["promotions", "combobox", promoIds],
7334
+ queryFn: async (params) => {
7335
+ return await sdk.admin.promotion.list({
7336
+ ...params,
7337
+ id: {
7338
+ $nin: promoIds
7339
+ }
7340
+ });
7341
+ },
7342
+ getOptions: (data) => {
7343
+ return data.promotions.map((promotion) => ({
7344
+ label: promotion.code,
7345
+ value: promotion.code
7346
+ }));
7578
7347
  }
7579
- return {
7580
- key,
7581
- value: stringValue,
7582
- original_key: key
7583
- };
7584
7348
  });
7585
- }
7586
- function parseValues(values) {
7587
- const metadata = values.metadata;
7588
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
7589
- if (isEmpty) {
7590
- return null;
7591
- }
7592
- const update = {};
7593
- metadata.forEach((field) => {
7594
- let key = field.key;
7595
- let value = field.value;
7596
- const disabled = field.disabled;
7597
- if (!key || !value) {
7349
+ const add = async (value) => {
7350
+ if (!value) {
7598
7351
  return;
7599
7352
  }
7600
- if (disabled) {
7601
- update[key] = value;
7353
+ addPromotions(
7354
+ {
7355
+ promo_codes: [value]
7356
+ },
7357
+ {
7358
+ onError: (e) => {
7359
+ ui.toast.error(e.message);
7360
+ comboboxData.onSearchValueChange("");
7361
+ setComboboxValue("");
7362
+ },
7363
+ onSuccess: () => {
7364
+ comboboxData.onSearchValueChange("");
7365
+ setComboboxValue("");
7366
+ }
7367
+ }
7368
+ );
7369
+ };
7370
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
7371
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
7372
+ const onSubmit = async () => {
7373
+ setIsSubmitting(true);
7374
+ let requestSucceeded = false;
7375
+ await requestOrderEdit(void 0, {
7376
+ onError: (e) => {
7377
+ ui.toast.error(e.message);
7378
+ },
7379
+ onSuccess: () => {
7380
+ requestSucceeded = true;
7381
+ }
7382
+ });
7383
+ if (!requestSucceeded) {
7384
+ setIsSubmitting(false);
7602
7385
  return;
7603
7386
  }
7604
- key = key.trim();
7605
- value = value.trim();
7606
- if (value === "true") {
7607
- update[key] = true;
7608
- } else if (value === "false") {
7609
- update[key] = false;
7610
- } else {
7611
- const parsedNumber = parseFloat(value);
7612
- if (!isNaN(parsedNumber)) {
7613
- update[key] = parsedNumber;
7614
- } else {
7615
- update[key] = value;
7387
+ await confirmOrderEdit(void 0, {
7388
+ onError: (e) => {
7389
+ ui.toast.error(e.message);
7390
+ },
7391
+ onSuccess: () => {
7392
+ handleSuccess();
7393
+ },
7394
+ onSettled: () => {
7395
+ setIsSubmitting(false);
7616
7396
  }
7617
- }
7618
- });
7619
- return update;
7620
- }
7621
- function getHasUneditableRows(metadata) {
7622
- if (!metadata) {
7623
- return false;
7624
- }
7625
- return Object.values(metadata).some(
7626
- (value) => !EDITABLE_TYPES.includes(typeof value)
7627
- );
7628
- }
7629
- const SalesChannel = () => {
7630
- const { id } = reactRouterDom.useParams();
7631
- const { draft_order, isPending, isError, error } = useDraftOrder(
7632
- id,
7633
- {
7634
- fields: "+sales_channel_id"
7635
- },
7636
- {
7637
- enabled: !!id
7638
- }
7639
- );
7397
+ });
7398
+ };
7640
7399
  if (isError) {
7641
7400
  throw error;
7642
7401
  }
7643
- const ISrEADY = !!draft_order && !isPending;
7644
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7645
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7646
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
7647
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7648
- ] }),
7649
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
7402
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
7403
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
7404
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
7405
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
7406
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
7407
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
7408
+ ] }),
7409
+ /* @__PURE__ */ jsxRuntime.jsx(
7410
+ Combobox,
7411
+ {
7412
+ id: "promotion-combobox",
7413
+ "aria-describedby": "promotion-combobox-hint",
7414
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
7415
+ fetchNextPage: comboboxData.fetchNextPage,
7416
+ options: comboboxData.options,
7417
+ onSearchValueChange: comboboxData.onSearchValueChange,
7418
+ searchValue: comboboxData.searchValue,
7419
+ disabled: comboboxData.disabled || isAddingPromotions,
7420
+ onChange: add,
7421
+ value: comboboxValue
7422
+ }
7423
+ )
7424
+ ] }),
7425
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
7426
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
7427
+ PromotionItem,
7428
+ {
7429
+ promotion,
7430
+ orderId: preview.id,
7431
+ isLoading: isPending
7432
+ },
7433
+ promotion.id
7434
+ )) })
7435
+ ] }) }),
7436
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
7437
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7438
+ /* @__PURE__ */ jsxRuntime.jsx(
7439
+ ui.Button,
7440
+ {
7441
+ size: "small",
7442
+ type: "submit",
7443
+ isLoading: isSubmitting || isAddingPromotions,
7444
+ children: "Save"
7445
+ }
7446
+ )
7447
+ ] }) })
7650
7448
  ] });
7651
7449
  };
7652
- const SalesChannelForm = ({ order }) => {
7653
- const form = reactHookForm.useForm({
7654
- defaultValues: {
7655
- sales_channel_id: order.sales_channel_id || ""
7656
- },
7657
- resolver: zod$1.zodResolver(schema$2)
7658
- });
7659
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7660
- const { handleSuccess } = useRouteModal();
7661
- const onSubmit = form.handleSubmit(async (data) => {
7662
- await mutateAsync(
7450
+ const PromotionItem = ({
7451
+ promotion,
7452
+ orderId,
7453
+ isLoading
7454
+ }) => {
7455
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
7456
+ const onRemove = async () => {
7457
+ removePromotions(
7663
7458
  {
7664
- sales_channel_id: data.sales_channel_id
7459
+ promo_codes: [promotion.code]
7665
7460
  },
7666
7461
  {
7667
- onSuccess: () => {
7668
- ui.toast.success("Sales channel updated");
7669
- handleSuccess();
7670
- },
7671
- onError: (error) => {
7672
- ui.toast.error(error.message);
7462
+ onError: (e) => {
7463
+ ui.toast.error(e.message);
7673
7464
  }
7674
7465
  }
7675
7466
  );
7676
- });
7677
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7678
- KeyboundForm,
7467
+ };
7468
+ const displayValue = getDisplayValue(promotion);
7469
+ return /* @__PURE__ */ jsxRuntime.jsxs(
7470
+ "div",
7679
7471
  {
7680
- className: "flex flex-1 flex-col overflow-hidden",
7681
- onSubmit,
7472
+ className: ui.clx(
7473
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
7474
+ {
7475
+ "animate-pulse": isLoading
7476
+ }
7477
+ ),
7682
7478
  children: [
7683
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
7684
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
7685
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7686
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7687
- ] }) })
7479
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7480
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
7481
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
7482
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
7483
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
7484
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
7485
+ ] }),
7486
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
7487
+ ] })
7488
+ ] }),
7489
+ /* @__PURE__ */ jsxRuntime.jsx(
7490
+ ui.IconButton,
7491
+ {
7492
+ size: "small",
7493
+ type: "button",
7494
+ variant: "transparent",
7495
+ onClick: onRemove,
7496
+ isLoading: isPending || isLoading,
7497
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
7498
+ }
7499
+ )
7688
7500
  ]
7689
- }
7690
- ) });
7691
- };
7692
- const SalesChannelField = ({ control, order }) => {
7693
- const salesChannels = useComboboxData({
7694
- queryFn: async (params) => {
7695
- return await sdk.admin.salesChannel.list(params);
7696
- },
7697
- queryKey: ["sales-channels"],
7698
- getOptions: (data) => {
7699
- return data.sales_channels.map((salesChannel) => ({
7700
- label: salesChannel.name,
7701
- value: salesChannel.id
7702
- }));
7703
7501
  },
7704
- defaultValue: order.sales_channel_id || void 0
7705
- });
7706
- return /* @__PURE__ */ jsxRuntime.jsx(
7707
- Form$2.Field,
7708
- {
7709
- control,
7710
- name: "sales_channel_id",
7711
- render: ({ field }) => {
7712
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
7714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7715
- Combobox,
7716
- {
7717
- options: salesChannels.options,
7718
- fetchNextPage: salesChannels.fetchNextPage,
7719
- isFetchingNextPage: salesChannels.isFetchingNextPage,
7720
- searchValue: salesChannels.searchValue,
7721
- onSearchValueChange: salesChannels.onSearchValueChange,
7722
- placeholder: "Select sales channel",
7723
- ...field
7724
- }
7725
- ) }),
7726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7727
- ] });
7728
- }
7729
- }
7502
+ promotion.id
7730
7503
  );
7731
7504
  };
7732
- const schema$2 = zod.z.object({
7733
- sales_channel_id: zod.z.string().min(1)
7505
+ function getDisplayValue(promotion) {
7506
+ const value = promotion.application_method?.value;
7507
+ if (!value) {
7508
+ return null;
7509
+ }
7510
+ if (promotion.application_method?.type === "fixed") {
7511
+ const currency = promotion.application_method?.currency_code;
7512
+ if (!currency) {
7513
+ return null;
7514
+ }
7515
+ return getLocaleAmount(value, currency);
7516
+ } else if (promotion.application_method?.type === "percentage") {
7517
+ return formatPercentage(value);
7518
+ }
7519
+ return null;
7520
+ }
7521
+ const formatter = new Intl.NumberFormat([], {
7522
+ style: "percent",
7523
+ minimumFractionDigits: 2
7734
7524
  });
7735
- const ShippingAddress = () => {
7736
- const { id } = reactRouterDom.useParams();
7737
- const { order, isPending, isError, error } = useOrder(id, {
7738
- fields: "+shipping_address"
7739
- });
7740
- if (isError) {
7741
- throw error;
7525
+ const formatPercentage = (value, isPercentageValue = false) => {
7526
+ let val = value || 0;
7527
+ if (!isPercentageValue) {
7528
+ val = val / 100;
7742
7529
  }
7743
- const isReady = !isPending && !!order;
7744
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7745
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7746
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
7747
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
7748
- ] }),
7749
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
7750
- ] });
7530
+ return formatter.format(val);
7751
7531
  };
7752
- const ShippingAddressForm = ({ order }) => {
7753
- const form = reactHookForm.useForm({
7754
- defaultValues: {
7755
- first_name: order.shipping_address?.first_name ?? "",
7756
- last_name: order.shipping_address?.last_name ?? "",
7757
- company: order.shipping_address?.company ?? "",
7758
- address_1: order.shipping_address?.address_1 ?? "",
7759
- address_2: order.shipping_address?.address_2 ?? "",
7760
- city: order.shipping_address?.city ?? "",
7761
- province: order.shipping_address?.province ?? "",
7762
- country_code: order.shipping_address?.country_code ?? "",
7763
- postal_code: order.shipping_address?.postal_code ?? "",
7764
- phone: order.shipping_address?.phone ?? ""
7765
- },
7766
- resolver: zod$1.zodResolver(schema$1)
7767
- });
7768
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7769
- const { handleSuccess } = useRouteModal();
7770
- const onSubmit = form.handleSubmit(async (data) => {
7771
- await mutateAsync(
7772
- {
7773
- shipping_address: {
7774
- first_name: data.first_name,
7775
- last_name: data.last_name,
7776
- company: data.company,
7777
- address_1: data.address_1,
7778
- address_2: data.address_2,
7779
- city: data.city,
7780
- province: data.province,
7781
- country_code: data.country_code,
7782
- postal_code: data.postal_code,
7783
- phone: data.phone
7532
+ function getPromotionIds(items, shippingMethods) {
7533
+ const promotionIds = /* @__PURE__ */ new Set();
7534
+ for (const item of items) {
7535
+ if (item.adjustments) {
7536
+ for (const adjustment of item.adjustments) {
7537
+ if (adjustment.promotion_id) {
7538
+ promotionIds.add(adjustment.promotion_id);
7784
7539
  }
7785
- },
7786
- {
7787
- onSuccess: () => {
7788
- handleSuccess();
7789
- },
7790
- onError: (error) => {
7791
- ui.toast.error(error.message);
7540
+ }
7541
+ }
7542
+ }
7543
+ for (const shippingMethod of shippingMethods) {
7544
+ if (shippingMethod.adjustments) {
7545
+ for (const adjustment of shippingMethod.adjustments) {
7546
+ if (adjustment.promotion_id) {
7547
+ promotionIds.add(adjustment.promotion_id);
7792
7548
  }
7793
7549
  }
7794
- );
7795
- });
7796
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7797
- KeyboundForm,
7798
- {
7799
- className: "flex flex-1 flex-col overflow-hidden",
7800
- onSubmit,
7801
- children: [
7802
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
7803
- /* @__PURE__ */ jsxRuntime.jsx(
7804
- Form$2.Field,
7805
- {
7806
- control: form.control,
7807
- name: "country_code",
7808
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7809
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
7810
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
7811
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7812
- ] })
7813
- }
7814
- ),
7815
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7816
- /* @__PURE__ */ jsxRuntime.jsx(
7817
- Form$2.Field,
7818
- {
7819
- control: form.control,
7820
- name: "first_name",
7821
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7822
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
7823
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7824
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7825
- ] })
7826
- }
7827
- ),
7828
- /* @__PURE__ */ jsxRuntime.jsx(
7829
- Form$2.Field,
7830
- {
7831
- control: form.control,
7832
- name: "last_name",
7833
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7834
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
7835
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7836
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7837
- ] })
7838
- }
7839
- )
7840
- ] }),
7841
- /* @__PURE__ */ jsxRuntime.jsx(
7842
- Form$2.Field,
7843
- {
7844
- control: form.control,
7845
- name: "company",
7846
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7847
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
7848
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7849
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7850
- ] })
7851
- }
7852
- ),
7853
- /* @__PURE__ */ jsxRuntime.jsx(
7854
- Form$2.Field,
7855
- {
7856
- control: form.control,
7857
- name: "address_1",
7858
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7859
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
7860
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7861
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7862
- ] })
7863
- }
7864
- ),
7865
- /* @__PURE__ */ jsxRuntime.jsx(
7866
- Form$2.Field,
7867
- {
7868
- control: form.control,
7869
- name: "address_2",
7870
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7871
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
7872
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7873
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7874
- ] })
7875
- }
7876
- ),
7877
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7878
- /* @__PURE__ */ jsxRuntime.jsx(
7879
- Form$2.Field,
7880
- {
7881
- control: form.control,
7882
- name: "postal_code",
7883
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7884
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
7885
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7886
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7887
- ] })
7888
- }
7889
- ),
7890
- /* @__PURE__ */ jsxRuntime.jsx(
7891
- Form$2.Field,
7892
- {
7893
- control: form.control,
7894
- name: "city",
7895
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7896
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
7897
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7898
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7899
- ] })
7900
- }
7901
- )
7902
- ] }),
7903
- /* @__PURE__ */ jsxRuntime.jsx(
7904
- Form$2.Field,
7905
- {
7906
- control: form.control,
7907
- name: "province",
7908
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7909
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
7910
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7911
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7912
- ] })
7913
- }
7914
- ),
7915
- /* @__PURE__ */ jsxRuntime.jsx(
7916
- Form$2.Field,
7917
- {
7918
- control: form.control,
7919
- name: "phone",
7920
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
7922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
7923
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7924
- ] })
7925
- }
7926
- )
7927
- ] }) }),
7550
+ }
7551
+ }
7552
+ return Array.from(promotionIds);
7553
+ }
7554
+ const SalesChannel = () => {
7555
+ const { id } = reactRouterDom.useParams();
7556
+ const { draft_order, isPending, isError, error } = useDraftOrder(
7557
+ id,
7558
+ {
7559
+ fields: "+sales_channel_id"
7560
+ },
7561
+ {
7562
+ enabled: !!id
7563
+ }
7564
+ );
7565
+ if (isError) {
7566
+ throw error;
7567
+ }
7568
+ const ISrEADY = !!draft_order && !isPending;
7569
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
7570
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
7571
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
7572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7573
+ ] }),
7574
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
7575
+ ] });
7576
+ };
7577
+ const SalesChannelForm = ({ order }) => {
7578
+ const form = reactHookForm.useForm({
7579
+ defaultValues: {
7580
+ sales_channel_id: order.sales_channel_id || ""
7581
+ },
7582
+ resolver: zod$1.zodResolver(schema$2)
7583
+ });
7584
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7585
+ const { handleSuccess } = useRouteModal();
7586
+ const onSubmit = form.handleSubmit(async (data) => {
7587
+ await mutateAsync(
7588
+ {
7589
+ sales_channel_id: data.sales_channel_id
7590
+ },
7591
+ {
7592
+ onSuccess: () => {
7593
+ ui.toast.success("Sales channel updated");
7594
+ handleSuccess();
7595
+ },
7596
+ onError: (error) => {
7597
+ ui.toast.error(error.message);
7598
+ }
7599
+ }
7600
+ );
7601
+ });
7602
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
7603
+ KeyboundForm,
7604
+ {
7605
+ className: "flex flex-1 flex-col overflow-hidden",
7606
+ onSubmit,
7607
+ children: [
7608
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
7928
7609
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
7929
7610
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7930
7611
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -7933,7 +7614,49 @@ const ShippingAddressForm = ({ order }) => {
7933
7614
  }
7934
7615
  ) });
7935
7616
  };
7936
- const schema$1 = addressSchema;
7617
+ const SalesChannelField = ({ control, order }) => {
7618
+ const salesChannels = useComboboxData({
7619
+ queryFn: async (params) => {
7620
+ return await sdk.admin.salesChannel.list(params);
7621
+ },
7622
+ queryKey: ["sales-channels"],
7623
+ getOptions: (data) => {
7624
+ return data.sales_channels.map((salesChannel) => ({
7625
+ label: salesChannel.name,
7626
+ value: salesChannel.id
7627
+ }));
7628
+ },
7629
+ defaultValue: order.sales_channel_id || void 0
7630
+ });
7631
+ return /* @__PURE__ */ jsxRuntime.jsx(
7632
+ Form$2.Field,
7633
+ {
7634
+ control,
7635
+ name: "sales_channel_id",
7636
+ render: ({ field }) => {
7637
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
7638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
7639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
7640
+ Combobox,
7641
+ {
7642
+ options: salesChannels.options,
7643
+ fetchNextPage: salesChannels.fetchNextPage,
7644
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
7645
+ searchValue: salesChannels.searchValue,
7646
+ onSearchValueChange: salesChannels.onSearchValueChange,
7647
+ placeholder: "Select sales channel",
7648
+ ...field
7649
+ }
7650
+ ) }),
7651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
7652
+ ] });
7653
+ }
7654
+ }
7655
+ );
7656
+ };
7657
+ const schema$2 = zod.z.object({
7658
+ sales_channel_id: zod.z.string().min(1)
7659
+ });
7937
7660
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
7938
7661
  const Shipping = () => {
7939
7662
  const { id } = reactRouterDom.useParams();
@@ -8677,332 +8400,259 @@ const ShippingOptionField = ({
8677
8400
  /* @__PURE__ */ jsxRuntime.jsx(
8678
8401
  ConditionalTooltip,
8679
8402
  {
8680
- content: tooltipContent,
8681
- showTooltip: !locationId || !shippingProfileId,
8682
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8683
- Combobox,
8684
- {
8685
- options: shippingOptions.options,
8686
- fetchNextPage: shippingOptions.fetchNextPage,
8687
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
8688
- searchValue: shippingOptions.searchValue,
8689
- onSearchValueChange: shippingOptions.onSearchValueChange,
8690
- placeholder: "Select shipping option",
8691
- ...field,
8692
- disabled: !locationId || !shippingProfileId
8693
- }
8694
- ) }) })
8695
- }
8696
- )
8697
- ] }) });
8698
- }
8699
- }
8700
- );
8701
- };
8702
- const CustomAmountField = ({
8703
- control,
8704
- currencyCode
8705
- }) => {
8706
- return /* @__PURE__ */ jsxRuntime.jsx(
8707
- Form$2.Field,
8708
- {
8709
- control,
8710
- name: "custom_amount",
8711
- render: ({ field: { onChange, ...field } }) => {
8712
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8713
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
8715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
8716
- ] }),
8717
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8718
- ui.CurrencyInput,
8719
- {
8720
- ...field,
8721
- onValueChange: (value) => onChange(value),
8722
- symbol: getNativeSymbol(currencyCode),
8723
- code: currencyCode
8724
- }
8725
- ) })
8726
- ] });
8727
- }
8728
- }
8729
- );
8730
- };
8731
- const PROMOTION_QUERY_KEY = "promotions";
8732
- const promotionsQueryKeys = {
8733
- list: (query2) => [
8734
- PROMOTION_QUERY_KEY,
8735
- query2 ? query2 : void 0
8736
- ],
8737
- detail: (id, query2) => [
8738
- PROMOTION_QUERY_KEY,
8739
- id,
8740
- query2 ? query2 : void 0
8741
- ]
8742
- };
8743
- const usePromotions = (query2, options) => {
8744
- const { data, ...rest } = reactQuery.useQuery({
8745
- queryKey: promotionsQueryKeys.list(query2),
8746
- queryFn: async () => sdk.admin.promotion.list(query2),
8747
- ...options
8748
- });
8749
- return { ...data, ...rest };
8750
- };
8751
- const Promotions = () => {
8752
- const { id } = reactRouterDom.useParams();
8753
- const {
8754
- order: preview,
8755
- isError: isPreviewError,
8756
- error: previewError
8757
- } = useOrderPreview(id, void 0);
8758
- useInitiateOrderEdit({ preview });
8759
- const { onCancel } = useCancelOrderEdit({ preview });
8760
- if (isPreviewError) {
8761
- throw previewError;
8762
- }
8763
- const isReady = !!preview;
8764
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
8765
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
8766
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
8767
- ] });
8768
- };
8769
- const PromotionForm = ({ preview }) => {
8770
- const { items, shipping_methods } = preview;
8771
- const [isSubmitting, setIsSubmitting] = React.useState(false);
8772
- const [comboboxValue, setComboboxValue] = React.useState("");
8773
- const { handleSuccess } = useRouteModal();
8774
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
8775
- const promoIds = getPromotionIds(items, shipping_methods);
8776
- const { promotions, isPending, isError, error } = usePromotions(
8777
- {
8778
- id: promoIds
8779
- },
8780
- {
8781
- enabled: !!promoIds.length
8782
- }
8783
- );
8784
- const comboboxData = useComboboxData({
8785
- queryKey: ["promotions", "combobox", promoIds],
8786
- queryFn: async (params) => {
8787
- return await sdk.admin.promotion.list({
8788
- ...params,
8789
- id: {
8790
- $nin: promoIds
8791
- }
8792
- });
8793
- },
8794
- getOptions: (data) => {
8795
- return data.promotions.map((promotion) => ({
8796
- label: promotion.code,
8797
- value: promotion.code
8798
- }));
8799
- }
8800
- });
8801
- const add = async (value) => {
8802
- if (!value) {
8803
- return;
8804
- }
8805
- addPromotions(
8806
- {
8807
- promo_codes: [value]
8808
- },
8809
- {
8810
- onError: (e) => {
8811
- ui.toast.error(e.message);
8812
- comboboxData.onSearchValueChange("");
8813
- setComboboxValue("");
8814
- },
8815
- onSuccess: () => {
8816
- comboboxData.onSearchValueChange("");
8817
- setComboboxValue("");
8818
- }
8819
- }
8820
- );
8821
- };
8822
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
8823
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
8824
- const onSubmit = async () => {
8825
- setIsSubmitting(true);
8826
- let requestSucceeded = false;
8827
- await requestOrderEdit(void 0, {
8828
- onError: (e) => {
8829
- ui.toast.error(e.message);
8830
- },
8831
- onSuccess: () => {
8832
- requestSucceeded = true;
8403
+ content: tooltipContent,
8404
+ showTooltip: !locationId || !shippingProfileId,
8405
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8406
+ Combobox,
8407
+ {
8408
+ options: shippingOptions.options,
8409
+ fetchNextPage: shippingOptions.fetchNextPage,
8410
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
8411
+ searchValue: shippingOptions.searchValue,
8412
+ onSearchValueChange: shippingOptions.onSearchValueChange,
8413
+ placeholder: "Select shipping option",
8414
+ ...field,
8415
+ disabled: !locationId || !shippingProfileId
8416
+ }
8417
+ ) }) })
8418
+ }
8419
+ )
8420
+ ] }) });
8833
8421
  }
8834
- });
8835
- if (!requestSucceeded) {
8836
- setIsSubmitting(false);
8837
- return;
8838
8422
  }
8839
- await confirmOrderEdit(void 0, {
8840
- onError: (e) => {
8841
- ui.toast.error(e.message);
8842
- },
8843
- onSuccess: () => {
8844
- handleSuccess();
8845
- },
8846
- onSettled: () => {
8847
- setIsSubmitting(false);
8423
+ );
8424
+ };
8425
+ const CustomAmountField = ({
8426
+ control,
8427
+ currencyCode
8428
+ }) => {
8429
+ return /* @__PURE__ */ jsxRuntime.jsx(
8430
+ Form$2.Field,
8431
+ {
8432
+ control,
8433
+ name: "custom_amount",
8434
+ render: ({ field: { onChange, ...field } }) => {
8435
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8436
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8437
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
8438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
8439
+ ] }),
8440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8441
+ ui.CurrencyInput,
8442
+ {
8443
+ ...field,
8444
+ onValueChange: (value) => onChange(value),
8445
+ symbol: getNativeSymbol(currencyCode),
8446
+ code: currencyCode
8447
+ }
8448
+ ) })
8449
+ ] });
8848
8450
  }
8849
- });
8850
- };
8451
+ }
8452
+ );
8453
+ };
8454
+ const ShippingAddress = () => {
8455
+ const { id } = reactRouterDom.useParams();
8456
+ const { order, isPending, isError, error } = useOrder(id, {
8457
+ fields: "+shipping_address"
8458
+ });
8851
8459
  if (isError) {
8852
8460
  throw error;
8853
8461
  }
8854
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
8855
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
8856
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
8857
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8858
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
8859
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
8860
- ] }),
8861
- /* @__PURE__ */ jsxRuntime.jsx(
8862
- Combobox,
8863
- {
8864
- id: "promotion-combobox",
8865
- "aria-describedby": "promotion-combobox-hint",
8866
- isFetchingNextPage: comboboxData.isFetchingNextPage,
8867
- fetchNextPage: comboboxData.fetchNextPage,
8868
- options: comboboxData.options,
8869
- onSearchValueChange: comboboxData.onSearchValueChange,
8870
- searchValue: comboboxData.searchValue,
8871
- disabled: comboboxData.disabled || isAddingPromotions,
8872
- onChange: add,
8873
- value: comboboxValue
8874
- }
8875
- )
8876
- ] }),
8877
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8878
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
8879
- PromotionItem,
8880
- {
8881
- promotion,
8882
- orderId: preview.id,
8883
- isLoading: isPending
8884
- },
8885
- promotion.id
8886
- )) })
8887
- ] }) }),
8888
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8889
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8890
- /* @__PURE__ */ jsxRuntime.jsx(
8891
- ui.Button,
8892
- {
8893
- size: "small",
8894
- type: "submit",
8895
- isLoading: isSubmitting || isAddingPromotions,
8896
- children: "Save"
8897
- }
8898
- )
8899
- ] }) })
8462
+ const isReady = !isPending && !!order;
8463
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8464
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8465
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
8466
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
8467
+ ] }),
8468
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
8900
8469
  ] });
8901
8470
  };
8902
- const PromotionItem = ({
8903
- promotion,
8904
- orderId,
8905
- isLoading
8906
- }) => {
8907
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
8908
- const onRemove = async () => {
8909
- removePromotions(
8471
+ const ShippingAddressForm = ({ order }) => {
8472
+ const form = reactHookForm.useForm({
8473
+ defaultValues: {
8474
+ first_name: order.shipping_address?.first_name ?? "",
8475
+ last_name: order.shipping_address?.last_name ?? "",
8476
+ company: order.shipping_address?.company ?? "",
8477
+ address_1: order.shipping_address?.address_1 ?? "",
8478
+ address_2: order.shipping_address?.address_2 ?? "",
8479
+ city: order.shipping_address?.city ?? "",
8480
+ province: order.shipping_address?.province ?? "",
8481
+ country_code: order.shipping_address?.country_code ?? "",
8482
+ postal_code: order.shipping_address?.postal_code ?? "",
8483
+ phone: order.shipping_address?.phone ?? ""
8484
+ },
8485
+ resolver: zod$1.zodResolver(schema$1)
8486
+ });
8487
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8488
+ const { handleSuccess } = useRouteModal();
8489
+ const onSubmit = form.handleSubmit(async (data) => {
8490
+ await mutateAsync(
8910
8491
  {
8911
- promo_codes: [promotion.code]
8492
+ shipping_address: {
8493
+ first_name: data.first_name,
8494
+ last_name: data.last_name,
8495
+ company: data.company,
8496
+ address_1: data.address_1,
8497
+ address_2: data.address_2,
8498
+ city: data.city,
8499
+ province: data.province,
8500
+ country_code: data.country_code,
8501
+ postal_code: data.postal_code,
8502
+ phone: data.phone
8503
+ }
8912
8504
  },
8913
8505
  {
8914
- onError: (e) => {
8915
- ui.toast.error(e.message);
8506
+ onSuccess: () => {
8507
+ handleSuccess();
8508
+ },
8509
+ onError: (error) => {
8510
+ ui.toast.error(error.message);
8916
8511
  }
8917
8512
  }
8918
8513
  );
8919
- };
8920
- const displayValue = getDisplayValue(promotion);
8921
- return /* @__PURE__ */ jsxRuntime.jsxs(
8922
- "div",
8514
+ });
8515
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8516
+ KeyboundForm,
8923
8517
  {
8924
- className: ui.clx(
8925
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
8926
- {
8927
- "animate-pulse": isLoading
8928
- }
8929
- ),
8518
+ className: "flex flex-1 flex-col overflow-hidden",
8519
+ onSubmit,
8930
8520
  children: [
8931
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8932
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
8933
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
8934
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
8935
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
8936
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
8937
- ] }),
8938
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
8939
- ] })
8940
- ] }),
8941
- /* @__PURE__ */ jsxRuntime.jsx(
8942
- ui.IconButton,
8943
- {
8944
- size: "small",
8945
- type: "button",
8946
- variant: "transparent",
8947
- onClick: onRemove,
8948
- isLoading: isPending || isLoading,
8949
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
8950
- }
8951
- )
8521
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
8522
+ /* @__PURE__ */ jsxRuntime.jsx(
8523
+ Form$2.Field,
8524
+ {
8525
+ control: form.control,
8526
+ name: "country_code",
8527
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8528
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
8529
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
8530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8531
+ ] })
8532
+ }
8533
+ ),
8534
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8535
+ /* @__PURE__ */ jsxRuntime.jsx(
8536
+ Form$2.Field,
8537
+ {
8538
+ control: form.control,
8539
+ name: "first_name",
8540
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
8542
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8544
+ ] })
8545
+ }
8546
+ ),
8547
+ /* @__PURE__ */ jsxRuntime.jsx(
8548
+ Form$2.Field,
8549
+ {
8550
+ control: form.control,
8551
+ name: "last_name",
8552
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
8554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8556
+ ] })
8557
+ }
8558
+ )
8559
+ ] }),
8560
+ /* @__PURE__ */ jsxRuntime.jsx(
8561
+ Form$2.Field,
8562
+ {
8563
+ control: form.control,
8564
+ name: "company",
8565
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8566
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
8567
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8568
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8569
+ ] })
8570
+ }
8571
+ ),
8572
+ /* @__PURE__ */ jsxRuntime.jsx(
8573
+ Form$2.Field,
8574
+ {
8575
+ control: form.control,
8576
+ name: "address_1",
8577
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8578
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
8579
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8580
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8581
+ ] })
8582
+ }
8583
+ ),
8584
+ /* @__PURE__ */ jsxRuntime.jsx(
8585
+ Form$2.Field,
8586
+ {
8587
+ control: form.control,
8588
+ name: "address_2",
8589
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8590
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
8591
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8592
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8593
+ ] })
8594
+ }
8595
+ ),
8596
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8597
+ /* @__PURE__ */ jsxRuntime.jsx(
8598
+ Form$2.Field,
8599
+ {
8600
+ control: form.control,
8601
+ name: "postal_code",
8602
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8603
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
8604
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8605
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8606
+ ] })
8607
+ }
8608
+ ),
8609
+ /* @__PURE__ */ jsxRuntime.jsx(
8610
+ Form$2.Field,
8611
+ {
8612
+ control: form.control,
8613
+ name: "city",
8614
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8615
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
8616
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8617
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8618
+ ] })
8619
+ }
8620
+ )
8621
+ ] }),
8622
+ /* @__PURE__ */ jsxRuntime.jsx(
8623
+ Form$2.Field,
8624
+ {
8625
+ control: form.control,
8626
+ name: "province",
8627
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8628
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
8629
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8630
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8631
+ ] })
8632
+ }
8633
+ ),
8634
+ /* @__PURE__ */ jsxRuntime.jsx(
8635
+ Form$2.Field,
8636
+ {
8637
+ control: form.control,
8638
+ name: "phone",
8639
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8640
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
8641
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8642
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8643
+ ] })
8644
+ }
8645
+ )
8646
+ ] }) }),
8647
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8648
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8649
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8650
+ ] }) })
8952
8651
  ]
8953
- },
8954
- promotion.id
8955
- );
8956
- };
8957
- function getDisplayValue(promotion) {
8958
- const value = promotion.application_method?.value;
8959
- if (!value) {
8960
- return null;
8961
- }
8962
- if (promotion.application_method?.type === "fixed") {
8963
- const currency = promotion.application_method?.currency_code;
8964
- if (!currency) {
8965
- return null;
8966
8652
  }
8967
- return getLocaleAmount(value, currency);
8968
- } else if (promotion.application_method?.type === "percentage") {
8969
- return formatPercentage(value);
8970
- }
8971
- return null;
8972
- }
8973
- const formatter = new Intl.NumberFormat([], {
8974
- style: "percent",
8975
- minimumFractionDigits: 2
8976
- });
8977
- const formatPercentage = (value, isPercentageValue = false) => {
8978
- let val = value || 0;
8979
- if (!isPercentageValue) {
8980
- val = val / 100;
8981
- }
8982
- return formatter.format(val);
8653
+ ) });
8983
8654
  };
8984
- function getPromotionIds(items, shippingMethods) {
8985
- const promotionIds = /* @__PURE__ */ new Set();
8986
- for (const item of items) {
8987
- if (item.adjustments) {
8988
- for (const adjustment of item.adjustments) {
8989
- if (adjustment.promotion_id) {
8990
- promotionIds.add(adjustment.promotion_id);
8991
- }
8992
- }
8993
- }
8994
- }
8995
- for (const shippingMethod of shippingMethods) {
8996
- if (shippingMethod.adjustments) {
8997
- for (const adjustment of shippingMethod.adjustments) {
8998
- if (adjustment.promotion_id) {
8999
- promotionIds.add(adjustment.promotion_id);
9000
- }
9001
- }
9002
- }
9003
- }
9004
- return Array.from(promotionIds);
9005
- }
8655
+ const schema$1 = addressSchema;
9006
8656
  const TransferOwnership = () => {
9007
8657
  const { id } = reactRouterDom.useParams();
9008
8658
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -9473,11 +9123,361 @@ const Illustration = () => {
9473
9123
  ] })
9474
9124
  ]
9475
9125
  }
9476
- );
9126
+ );
9127
+ };
9128
+ const schema = zod.z.object({
9129
+ customer_id: zod.z.string().min(1)
9130
+ });
9131
+ const InlineTip = React.forwardRef(
9132
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9133
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9134
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9135
+ "div",
9136
+ {
9137
+ ref,
9138
+ className: ui.clx(
9139
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9140
+ className
9141
+ ),
9142
+ ...props,
9143
+ children: [
9144
+ /* @__PURE__ */ jsxRuntime.jsx(
9145
+ "div",
9146
+ {
9147
+ role: "presentation",
9148
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9149
+ "bg-ui-tag-orange-icon": variant === "warning"
9150
+ })
9151
+ }
9152
+ ),
9153
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9154
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9155
+ labelValue,
9156
+ ":"
9157
+ ] }),
9158
+ " ",
9159
+ children
9160
+ ] })
9161
+ ]
9162
+ }
9163
+ );
9164
+ }
9165
+ );
9166
+ InlineTip.displayName = "InlineTip";
9167
+ const MetadataFieldSchema = zod.z.object({
9168
+ key: zod.z.string(),
9169
+ disabled: zod.z.boolean().optional(),
9170
+ value: zod.z.any()
9171
+ });
9172
+ const MetadataSchema = zod.z.object({
9173
+ metadata: zod.z.array(MetadataFieldSchema)
9174
+ });
9175
+ const Metadata = () => {
9176
+ const { id } = reactRouterDom.useParams();
9177
+ const { order, isPending, isError, error } = useOrder(id, {
9178
+ fields: "metadata"
9179
+ });
9180
+ if (isError) {
9181
+ throw error;
9182
+ }
9183
+ const isReady = !isPending && !!order;
9184
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9185
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9186
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9187
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9188
+ ] }),
9189
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
9190
+ ] });
9191
+ };
9192
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9193
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9194
+ const MetadataForm = ({ orderId, metadata }) => {
9195
+ const { handleSuccess } = useRouteModal();
9196
+ const hasUneditableRows = getHasUneditableRows(metadata);
9197
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9198
+ const form = reactHookForm.useForm({
9199
+ defaultValues: {
9200
+ metadata: getDefaultValues(metadata)
9201
+ },
9202
+ resolver: zod$1.zodResolver(MetadataSchema)
9203
+ });
9204
+ const handleSubmit = form.handleSubmit(async (data) => {
9205
+ const parsedData = parseValues(data);
9206
+ await mutateAsync(
9207
+ {
9208
+ metadata: parsedData
9209
+ },
9210
+ {
9211
+ onSuccess: () => {
9212
+ ui.toast.success("Metadata updated");
9213
+ handleSuccess();
9214
+ },
9215
+ onError: (error) => {
9216
+ ui.toast.error(error.message);
9217
+ }
9218
+ }
9219
+ );
9220
+ });
9221
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9222
+ control: form.control,
9223
+ name: "metadata"
9224
+ });
9225
+ function deleteRow(index) {
9226
+ remove(index);
9227
+ if (fields.length === 1) {
9228
+ insert(0, {
9229
+ key: "",
9230
+ value: "",
9231
+ disabled: false
9232
+ });
9233
+ }
9234
+ }
9235
+ function insertRow(index, position) {
9236
+ insert(index + (position === "above" ? 0 : 1), {
9237
+ key: "",
9238
+ value: "",
9239
+ disabled: false
9240
+ });
9241
+ }
9242
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9243
+ KeyboundForm,
9244
+ {
9245
+ onSubmit: handleSubmit,
9246
+ className: "flex flex-1 flex-col overflow-hidden",
9247
+ children: [
9248
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9249
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9250
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9251
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9252
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9253
+ ] }),
9254
+ fields.map((field, index) => {
9255
+ const isDisabled = field.disabled || false;
9256
+ let placeholder = "-";
9257
+ if (typeof field.value === "object") {
9258
+ placeholder = "{ ... }";
9259
+ }
9260
+ if (Array.isArray(field.value)) {
9261
+ placeholder = "[ ... ]";
9262
+ }
9263
+ return /* @__PURE__ */ jsxRuntime.jsx(
9264
+ ConditionalTooltip,
9265
+ {
9266
+ showTooltip: isDisabled,
9267
+ content: "This row is disabled because it contains non-primitive data.",
9268
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9269
+ /* @__PURE__ */ jsxRuntime.jsxs(
9270
+ "div",
9271
+ {
9272
+ className: ui.clx("grid grid-cols-2 divide-x", {
9273
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9274
+ }),
9275
+ children: [
9276
+ /* @__PURE__ */ jsxRuntime.jsx(
9277
+ Form$2.Field,
9278
+ {
9279
+ control: form.control,
9280
+ name: `metadata.${index}.key`,
9281
+ render: ({ field: field2 }) => {
9282
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9283
+ GridInput,
9284
+ {
9285
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9286
+ ...field2,
9287
+ disabled: isDisabled,
9288
+ placeholder: "Key"
9289
+ }
9290
+ ) }) });
9291
+ }
9292
+ }
9293
+ ),
9294
+ /* @__PURE__ */ jsxRuntime.jsx(
9295
+ Form$2.Field,
9296
+ {
9297
+ control: form.control,
9298
+ name: `metadata.${index}.value`,
9299
+ render: ({ field: { value, ...field2 } }) => {
9300
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9301
+ GridInput,
9302
+ {
9303
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9304
+ ...field2,
9305
+ value: isDisabled ? placeholder : value,
9306
+ disabled: isDisabled,
9307
+ placeholder: "Value"
9308
+ }
9309
+ ) }) });
9310
+ }
9311
+ }
9312
+ )
9313
+ ]
9314
+ }
9315
+ ),
9316
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9317
+ /* @__PURE__ */ jsxRuntime.jsx(
9318
+ ui.DropdownMenu.Trigger,
9319
+ {
9320
+ className: ui.clx(
9321
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9322
+ {
9323
+ hidden: isDisabled
9324
+ }
9325
+ ),
9326
+ disabled: isDisabled,
9327
+ asChild: true,
9328
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9329
+ }
9330
+ ),
9331
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9332
+ /* @__PURE__ */ jsxRuntime.jsxs(
9333
+ ui.DropdownMenu.Item,
9334
+ {
9335
+ className: "gap-x-2",
9336
+ onClick: () => insertRow(index, "above"),
9337
+ children: [
9338
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9339
+ "Insert row above"
9340
+ ]
9341
+ }
9342
+ ),
9343
+ /* @__PURE__ */ jsxRuntime.jsxs(
9344
+ ui.DropdownMenu.Item,
9345
+ {
9346
+ className: "gap-x-2",
9347
+ onClick: () => insertRow(index, "below"),
9348
+ children: [
9349
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9350
+ "Insert row below"
9351
+ ]
9352
+ }
9353
+ ),
9354
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9355
+ /* @__PURE__ */ jsxRuntime.jsxs(
9356
+ ui.DropdownMenu.Item,
9357
+ {
9358
+ className: "gap-x-2",
9359
+ onClick: () => deleteRow(index),
9360
+ children: [
9361
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9362
+ "Delete row"
9363
+ ]
9364
+ }
9365
+ )
9366
+ ] })
9367
+ ] })
9368
+ ] })
9369
+ },
9370
+ field.id
9371
+ );
9372
+ })
9373
+ ] }),
9374
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
9375
+ ] }),
9376
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9377
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9378
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9379
+ ] }) })
9380
+ ]
9381
+ }
9382
+ ) });
9477
9383
  };
9478
- const schema = zod.z.object({
9479
- customer_id: zod.z.string().min(1)
9384
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9385
+ return /* @__PURE__ */ jsxRuntime.jsx(
9386
+ "input",
9387
+ {
9388
+ ref,
9389
+ ...props,
9390
+ autoComplete: "off",
9391
+ className: ui.clx(
9392
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
9393
+ className
9394
+ )
9395
+ }
9396
+ );
9480
9397
  });
9398
+ GridInput.displayName = "MetadataForm.GridInput";
9399
+ const PlaceholderInner = () => {
9400
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9401
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9402
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9403
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9404
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9405
+ ] }) })
9406
+ ] });
9407
+ };
9408
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9409
+ function getDefaultValues(metadata) {
9410
+ if (!metadata || !Object.keys(metadata).length) {
9411
+ return [
9412
+ {
9413
+ key: "",
9414
+ value: "",
9415
+ disabled: false
9416
+ }
9417
+ ];
9418
+ }
9419
+ return Object.entries(metadata).map(([key, value]) => {
9420
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9421
+ return {
9422
+ key,
9423
+ value,
9424
+ disabled: true
9425
+ };
9426
+ }
9427
+ let stringValue = value;
9428
+ if (typeof value !== "string") {
9429
+ stringValue = JSON.stringify(value);
9430
+ }
9431
+ return {
9432
+ key,
9433
+ value: stringValue,
9434
+ original_key: key
9435
+ };
9436
+ });
9437
+ }
9438
+ function parseValues(values) {
9439
+ const metadata = values.metadata;
9440
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9441
+ if (isEmpty) {
9442
+ return null;
9443
+ }
9444
+ const update = {};
9445
+ metadata.forEach((field) => {
9446
+ let key = field.key;
9447
+ let value = field.value;
9448
+ const disabled = field.disabled;
9449
+ if (!key || !value) {
9450
+ return;
9451
+ }
9452
+ if (disabled) {
9453
+ update[key] = value;
9454
+ return;
9455
+ }
9456
+ key = key.trim();
9457
+ value = value.trim();
9458
+ if (value === "true") {
9459
+ update[key] = true;
9460
+ } else if (value === "false") {
9461
+ update[key] = false;
9462
+ } else {
9463
+ const parsedNumber = parseFloat(value);
9464
+ if (!isNaN(parsedNumber)) {
9465
+ update[key] = parsedNumber;
9466
+ } else {
9467
+ update[key] = value;
9468
+ }
9469
+ }
9470
+ });
9471
+ return update;
9472
+ }
9473
+ function getHasUneditableRows(metadata) {
9474
+ if (!metadata) {
9475
+ return false;
9476
+ }
9477
+ return Object.values(metadata).some(
9478
+ (value) => !EDITABLE_TYPES.includes(typeof value)
9479
+ );
9480
+ }
9481
9481
  const widgetModule = { widgets: [] };
9482
9482
  const routeModule = {
9483
9483
  routes: [
@@ -9498,6 +9498,10 @@ const routeModule = {
9498
9498
  handle,
9499
9499
  loader,
9500
9500
  children: [
9501
+ {
9502
+ Component: BillingAddress,
9503
+ path: "/draft-orders/:id/billing-address"
9504
+ },
9501
9505
  {
9502
9506
  Component: CustomItems,
9503
9507
  path: "/draft-orders/:id/custom-items"
@@ -9511,32 +9515,28 @@ const routeModule = {
9511
9515
  path: "/draft-orders/:id/items"
9512
9516
  },
9513
9517
  {
9514
- Component: BillingAddress,
9515
- path: "/draft-orders/:id/billing-address"
9516
- },
9517
- {
9518
- Component: Metadata,
9519
- path: "/draft-orders/:id/metadata"
9518
+ Component: Promotions,
9519
+ path: "/draft-orders/:id/promotions"
9520
9520
  },
9521
9521
  {
9522
9522
  Component: SalesChannel,
9523
9523
  path: "/draft-orders/:id/sales-channel"
9524
9524
  },
9525
- {
9526
- Component: ShippingAddress,
9527
- path: "/draft-orders/:id/shipping-address"
9528
- },
9529
9525
  {
9530
9526
  Component: Shipping,
9531
9527
  path: "/draft-orders/:id/shipping"
9532
9528
  },
9533
9529
  {
9534
- Component: Promotions,
9535
- path: "/draft-orders/:id/promotions"
9530
+ Component: ShippingAddress,
9531
+ path: "/draft-orders/:id/shipping-address"
9536
9532
  },
9537
9533
  {
9538
9534
  Component: TransferOwnership,
9539
9535
  path: "/draft-orders/:id/transfer-ownership"
9536
+ },
9537
+ {
9538
+ Component: Metadata,
9539
+ path: "/draft-orders/:id/metadata"
9540
9540
  }
9541
9541
  ]
9542
9542
  }