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

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