@medusajs/draft-order 2.15.3 → 2.15.4-preview-20260521212902

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.
@@ -9899,217 +9899,6 @@ const ID = () => {
9899
9899
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9900
9900
  ] });
9901
9901
  };
9902
- const BillingAddress = () => {
9903
- const { id } = reactRouterDom.useParams();
9904
- const { order, isPending, isError, error } = useOrder(id, {
9905
- fields: "+billing_address"
9906
- });
9907
- if (isError) {
9908
- throw error;
9909
- }
9910
- const isReady = !isPending && !!order;
9911
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9912
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9913
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9914
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9915
- ] }),
9916
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9917
- ] });
9918
- };
9919
- const BillingAddressForm = ({ order }) => {
9920
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9921
- const form = reactHookForm.useForm({
9922
- defaultValues: {
9923
- first_name: ((_a2 = order.billing_address) == null ? void 0 : _a2.first_name) ?? "",
9924
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9925
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9926
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9927
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9928
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9929
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9930
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9931
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9932
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9933
- },
9934
- resolver: zod.zodResolver(schema$5)
9935
- });
9936
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9937
- const { handleSuccess } = useRouteModal();
9938
- const onSubmit = form.handleSubmit(async (data) => {
9939
- await mutateAsync(
9940
- { billing_address: data },
9941
- {
9942
- onSuccess: () => {
9943
- handleSuccess();
9944
- },
9945
- onError: (error) => {
9946
- ui.toast.error(error.message);
9947
- }
9948
- }
9949
- );
9950
- });
9951
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9952
- KeyboundForm,
9953
- {
9954
- className: "flex flex-1 flex-col overflow-hidden",
9955
- onSubmit,
9956
- children: [
9957
- /* @__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: [
9958
- /* @__PURE__ */ jsxRuntime.jsx(
9959
- Form$2.Field,
9960
- {
9961
- control: form.control,
9962
- name: "country_code",
9963
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9964
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9966
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9967
- ] })
9968
- }
9969
- ),
9970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9971
- /* @__PURE__ */ jsxRuntime.jsx(
9972
- Form$2.Field,
9973
- {
9974
- control: form.control,
9975
- name: "first_name",
9976
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9977
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9980
- ] })
9981
- }
9982
- ),
9983
- /* @__PURE__ */ jsxRuntime.jsx(
9984
- Form$2.Field,
9985
- {
9986
- control: form.control,
9987
- name: "last_name",
9988
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9989
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9990
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9992
- ] })
9993
- }
9994
- )
9995
- ] }),
9996
- /* @__PURE__ */ jsxRuntime.jsx(
9997
- Form$2.Field,
9998
- {
9999
- control: form.control,
10000
- name: "company",
10001
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
10003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10005
- ] })
10006
- }
10007
- ),
10008
- /* @__PURE__ */ jsxRuntime.jsx(
10009
- Form$2.Field,
10010
- {
10011
- control: form.control,
10012
- name: "address_1",
10013
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10014
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
10015
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10016
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10017
- ] })
10018
- }
10019
- ),
10020
- /* @__PURE__ */ jsxRuntime.jsx(
10021
- Form$2.Field,
10022
- {
10023
- control: form.control,
10024
- name: "address_2",
10025
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10028
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10029
- ] })
10030
- }
10031
- ),
10032
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10033
- /* @__PURE__ */ jsxRuntime.jsx(
10034
- Form$2.Field,
10035
- {
10036
- control: form.control,
10037
- name: "postal_code",
10038
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
10040
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10041
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10042
- ] })
10043
- }
10044
- ),
10045
- /* @__PURE__ */ jsxRuntime.jsx(
10046
- Form$2.Field,
10047
- {
10048
- control: form.control,
10049
- name: "city",
10050
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10051
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
10052
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10053
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10054
- ] })
10055
- }
10056
- )
10057
- ] }),
10058
- /* @__PURE__ */ jsxRuntime.jsx(
10059
- Form$2.Field,
10060
- {
10061
- control: form.control,
10062
- name: "province",
10063
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10064
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10065
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10066
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10067
- ] })
10068
- }
10069
- ),
10070
- /* @__PURE__ */ jsxRuntime.jsx(
10071
- Form$2.Field,
10072
- {
10073
- control: form.control,
10074
- name: "phone",
10075
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10076
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
10077
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10078
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10079
- ] })
10080
- }
10081
- )
10082
- ] }) }),
10083
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10084
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10085
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10086
- ] }) })
10087
- ]
10088
- }
10089
- ) });
10090
- };
10091
- const schema$5 = addressSchema;
10092
- const CustomItems = () => {
10093
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10094
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10095
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10096
- ] });
10097
- };
10098
- const CustomItemsForm = () => {
10099
- const form = reactHookForm.useForm({
10100
- resolver: zod.zodResolver(schema$4)
10101
- });
10102
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10103
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10104
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10105
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10107
- ] }) })
10108
- ] }) });
10109
- };
10110
- const schema$4 = object({
10111
- email: string().email()
10112
- });
10113
9902
  const Email = () => {
10114
9903
  const { id } = reactRouterDom.useParams();
10115
9904
  const { order, isPending, isError, error } = useOrder(id, {
@@ -10132,7 +9921,7 @@ const EmailForm = ({ order }) => {
10132
9921
  defaultValues: {
10133
9922
  email: order.email ?? ""
10134
9923
  },
10135
- resolver: zod.zodResolver(schema$3)
9924
+ resolver: zod.zodResolver(schema$5)
10136
9925
  });
10137
9926
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10138
9927
  const { handleSuccess } = useRouteModal();
@@ -10175,7 +9964,28 @@ const EmailForm = ({ order }) => {
10175
9964
  }
10176
9965
  ) });
10177
9966
  };
10178
- const schema$3 = object({
9967
+ const schema$5 = object({
9968
+ email: string().email()
9969
+ });
9970
+ const CustomItems = () => {
9971
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9972
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9973
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9974
+ ] });
9975
+ };
9976
+ const CustomItemsForm = () => {
9977
+ const form = reactHookForm.useForm({
9978
+ resolver: zod.zodResolver(schema$4)
9979
+ });
9980
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9981
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9982
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9983
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9984
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9985
+ ] }) })
9986
+ ] }) });
9987
+ };
9988
+ const schema$4 = object({
10179
9989
  email: string().email()
10180
9990
  });
10181
9991
  const NumberInput = React.forwardRef(
@@ -11152,54 +10962,10 @@ const customItemSchema = object({
11152
10962
  quantity: number(),
11153
10963
  unit_price: union([number(), string()])
11154
10964
  });
11155
- const InlineTip = React.forwardRef(
11156
- ({ variant = "tip", label, className, children, ...props }, ref) => {
11157
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11158
- return /* @__PURE__ */ jsxRuntime.jsxs(
11159
- "div",
11160
- {
11161
- ref,
11162
- className: ui.clx(
11163
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11164
- className
11165
- ),
11166
- ...props,
11167
- children: [
11168
- /* @__PURE__ */ jsxRuntime.jsx(
11169
- "div",
11170
- {
11171
- role: "presentation",
11172
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11173
- "bg-ui-tag-orange-icon": variant === "warning"
11174
- })
11175
- }
11176
- ),
11177
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11178
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11179
- labelValue,
11180
- ":"
11181
- ] }),
11182
- " ",
11183
- children
11184
- ] })
11185
- ]
11186
- }
11187
- );
11188
- }
11189
- );
11190
- InlineTip.displayName = "InlineTip";
11191
- const MetadataFieldSchema = object({
11192
- key: string(),
11193
- disabled: boolean().optional(),
11194
- value: any()
11195
- });
11196
- const MetadataSchema = object({
11197
- metadata: array(MetadataFieldSchema)
11198
- });
11199
- const Metadata = () => {
10965
+ const BillingAddress = () => {
11200
10966
  const { id } = reactRouterDom.useParams();
11201
10967
  const { order, isPending, isError, error } = useOrder(id, {
11202
- fields: "metadata"
10968
+ fields: "+billing_address"
11203
10969
  });
11204
10970
  if (isError) {
11205
10971
  throw error;
@@ -11207,33 +10973,36 @@ const Metadata = () => {
11207
10973
  const isReady = !isPending && !!order;
11208
10974
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11209
10975
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11210
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11211
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10976
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
10977
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11212
10978
  ] }),
11213
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10979
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11214
10980
  ] });
11215
10981
  };
11216
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11217
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11218
- const MetadataForm = ({ orderId, metadata }) => {
11219
- const { handleSuccess } = useRouteModal();
11220
- const hasUneditableRows = getHasUneditableRows(metadata);
11221
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10982
+ const BillingAddressForm = ({ order }) => {
10983
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11222
10984
  const form = reactHookForm.useForm({
11223
10985
  defaultValues: {
11224
- metadata: getDefaultValues(metadata)
10986
+ first_name: ((_a2 = order.billing_address) == null ? void 0 : _a2.first_name) ?? "",
10987
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10988
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10989
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10990
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10991
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10992
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10993
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10994
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10995
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11225
10996
  },
11226
- resolver: zod.zodResolver(MetadataSchema)
10997
+ resolver: zod.zodResolver(schema$3)
11227
10998
  });
11228
- const handleSubmit = form.handleSubmit(async (data) => {
11229
- const parsedData = parseValues(data);
10999
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11000
+ const { handleSuccess } = useRouteModal();
11001
+ const onSubmit = form.handleSubmit(async (data) => {
11230
11002
  await mutateAsync(
11231
- {
11232
- metadata: parsedData
11233
- },
11003
+ { billing_address: data },
11234
11004
  {
11235
11005
  onSuccess: () => {
11236
- ui.toast.success("Metadata updated");
11237
11006
  handleSuccess();
11238
11007
  },
11239
11008
  onError: (error) => {
@@ -11242,266 +11011,147 @@ const MetadataForm = ({ orderId, metadata }) => {
11242
11011
  }
11243
11012
  );
11244
11013
  });
11245
- const { fields, insert, remove } = reactHookForm.useFieldArray({
11246
- control: form.control,
11247
- name: "metadata"
11248
- });
11249
- function deleteRow(index) {
11250
- remove(index);
11251
- if (fields.length === 1) {
11252
- insert(0, {
11253
- key: "",
11254
- value: "",
11255
- disabled: false
11256
- });
11257
- }
11258
- }
11259
- function insertRow(index, position) {
11260
- insert(index + (position === "above" ? 0 : 1), {
11261
- key: "",
11262
- value: "",
11263
- disabled: false
11264
- });
11265
- }
11266
11014
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11267
11015
  KeyboundForm,
11268
11016
  {
11269
- onSubmit: handleSubmit,
11270
11017
  className: "flex flex-1 flex-col overflow-hidden",
11018
+ onSubmit,
11271
11019
  children: [
11272
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11273
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11274
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11275
- /* @__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" }) }),
11276
- /* @__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" }) })
11277
- ] }),
11278
- fields.map((field, index) => {
11279
- const isDisabled = field.disabled || false;
11280
- let placeholder = "-";
11281
- if (typeof field.value === "object") {
11282
- placeholder = "{ ... }";
11020
+ /* @__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: [
11021
+ /* @__PURE__ */ jsxRuntime.jsx(
11022
+ Form$2.Field,
11023
+ {
11024
+ control: form.control,
11025
+ name: "country_code",
11026
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11028
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11029
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11030
+ ] })
11031
+ }
11032
+ ),
11033
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(
11035
+ Form$2.Field,
11036
+ {
11037
+ control: form.control,
11038
+ name: "first_name",
11039
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11040
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11041
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11042
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11043
+ ] })
11283
11044
  }
11284
- if (Array.isArray(field.value)) {
11285
- placeholder = "[ ... ]";
11045
+ ),
11046
+ /* @__PURE__ */ jsxRuntime.jsx(
11047
+ Form$2.Field,
11048
+ {
11049
+ control: form.control,
11050
+ name: "last_name",
11051
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11052
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11053
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11054
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11055
+ ] })
11286
11056
  }
11287
- return /* @__PURE__ */ jsxRuntime.jsx(
11288
- ConditionalTooltip,
11289
- {
11290
- showTooltip: isDisabled,
11291
- content: "This row is disabled because it contains non-primitive data.",
11292
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11293
- /* @__PURE__ */ jsxRuntime.jsxs(
11294
- "div",
11295
- {
11296
- className: ui.clx("grid grid-cols-2 divide-x", {
11297
- "overflow-hidden rounded-b-lg": index === fields.length - 1
11298
- }),
11299
- children: [
11300
- /* @__PURE__ */ jsxRuntime.jsx(
11301
- Form$2.Field,
11302
- {
11303
- control: form.control,
11304
- name: `metadata.${index}.key`,
11305
- render: ({ field: field2 }) => {
11306
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11307
- GridInput,
11308
- {
11309
- "aria-labelledby": METADATA_KEY_LABEL_ID,
11310
- ...field2,
11311
- disabled: isDisabled,
11312
- placeholder: "Key"
11313
- }
11314
- ) }) });
11315
- }
11316
- }
11317
- ),
11318
- /* @__PURE__ */ jsxRuntime.jsx(
11319
- Form$2.Field,
11320
- {
11321
- control: form.control,
11322
- name: `metadata.${index}.value`,
11323
- render: ({ field: { value, ...field2 } }) => {
11324
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11325
- GridInput,
11326
- {
11327
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11328
- ...field2,
11329
- value: isDisabled ? placeholder : value,
11330
- disabled: isDisabled,
11331
- placeholder: "Value"
11332
- }
11333
- ) }) });
11334
- }
11335
- }
11336
- )
11337
- ]
11338
- }
11339
- ),
11340
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11341
- /* @__PURE__ */ jsxRuntime.jsx(
11342
- ui.DropdownMenu.Trigger,
11343
- {
11344
- className: ui.clx(
11345
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11346
- {
11347
- hidden: isDisabled
11348
- }
11349
- ),
11350
- disabled: isDisabled,
11351
- asChild: true,
11352
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11353
- }
11354
- ),
11355
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11356
- /* @__PURE__ */ jsxRuntime.jsxs(
11357
- ui.DropdownMenu.Item,
11358
- {
11359
- className: "gap-x-2",
11360
- onClick: () => insertRow(index, "above"),
11361
- children: [
11362
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11363
- "Insert row above"
11364
- ]
11365
- }
11366
- ),
11367
- /* @__PURE__ */ jsxRuntime.jsxs(
11368
- ui.DropdownMenu.Item,
11369
- {
11370
- className: "gap-x-2",
11371
- onClick: () => insertRow(index, "below"),
11372
- children: [
11373
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11374
- "Insert row below"
11375
- ]
11376
- }
11377
- ),
11378
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11379
- /* @__PURE__ */ jsxRuntime.jsxs(
11380
- ui.DropdownMenu.Item,
11381
- {
11382
- className: "gap-x-2",
11383
- onClick: () => deleteRow(index),
11384
- children: [
11385
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11386
- "Delete row"
11387
- ]
11388
- }
11389
- )
11390
- ] })
11391
- ] })
11392
- ] })
11393
- },
11394
- field.id
11395
- );
11396
- })
11057
+ )
11397
11058
  ] }),
11398
- 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." })
11399
- ] }),
11400
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11401
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11402
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11403
- ] }) })
11404
- ]
11405
- }
11406
- ) });
11407
- };
11408
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11409
- return /* @__PURE__ */ jsxRuntime.jsx(
11410
- "input",
11411
- {
11412
- ref,
11413
- ...props,
11414
- autoComplete: "off",
11415
- className: ui.clx(
11416
- "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",
11417
- className
11418
- )
11059
+ /* @__PURE__ */ jsxRuntime.jsx(
11060
+ Form$2.Field,
11061
+ {
11062
+ control: form.control,
11063
+ name: "company",
11064
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11065
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11066
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11067
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11068
+ ] })
11069
+ }
11070
+ ),
11071
+ /* @__PURE__ */ jsxRuntime.jsx(
11072
+ Form$2.Field,
11073
+ {
11074
+ control: form.control,
11075
+ name: "address_1",
11076
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11077
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11078
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11079
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11080
+ ] })
11081
+ }
11082
+ ),
11083
+ /* @__PURE__ */ jsxRuntime.jsx(
11084
+ Form$2.Field,
11085
+ {
11086
+ control: form.control,
11087
+ name: "address_2",
11088
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11089
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11090
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11091
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11092
+ ] })
11093
+ }
11094
+ ),
11095
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11096
+ /* @__PURE__ */ jsxRuntime.jsx(
11097
+ Form$2.Field,
11098
+ {
11099
+ control: form.control,
11100
+ name: "postal_code",
11101
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11102
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11103
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11104
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11105
+ ] })
11106
+ }
11107
+ ),
11108
+ /* @__PURE__ */ jsxRuntime.jsx(
11109
+ Form$2.Field,
11110
+ {
11111
+ control: form.control,
11112
+ name: "city",
11113
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11115
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11116
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11117
+ ] })
11118
+ }
11119
+ )
11120
+ ] }),
11121
+ /* @__PURE__ */ jsxRuntime.jsx(
11122
+ Form$2.Field,
11123
+ {
11124
+ control: form.control,
11125
+ name: "province",
11126
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11127
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11128
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11129
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11130
+ ] })
11131
+ }
11132
+ ),
11133
+ /* @__PURE__ */ jsxRuntime.jsx(
11134
+ Form$2.Field,
11135
+ {
11136
+ control: form.control,
11137
+ name: "phone",
11138
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11139
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11140
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11141
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11142
+ ] })
11143
+ }
11144
+ )
11145
+ ] }) }),
11146
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11147
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11149
+ ] }) })
11150
+ ]
11419
11151
  }
11420
- );
11421
- });
11422
- GridInput.displayName = "MetadataForm.GridInput";
11423
- const PlaceholderInner = () => {
11424
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11425
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11426
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11427
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11428
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11429
- ] }) })
11430
- ] });
11152
+ ) });
11431
11153
  };
11432
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11433
- function getDefaultValues(metadata) {
11434
- if (!metadata || !Object.keys(metadata).length) {
11435
- return [
11436
- {
11437
- key: "",
11438
- value: "",
11439
- disabled: false
11440
- }
11441
- ];
11442
- }
11443
- return Object.entries(metadata).map(([key, value]) => {
11444
- if (!EDITABLE_TYPES.includes(typeof value)) {
11445
- return {
11446
- key,
11447
- value,
11448
- disabled: true
11449
- };
11450
- }
11451
- let stringValue = value;
11452
- if (typeof value !== "string") {
11453
- stringValue = JSON.stringify(value);
11454
- }
11455
- return {
11456
- key,
11457
- value: stringValue,
11458
- original_key: key
11459
- };
11460
- });
11461
- }
11462
- function parseValues(values) {
11463
- const metadata = values.metadata;
11464
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11465
- if (isEmpty) {
11466
- return null;
11467
- }
11468
- const update = {};
11469
- metadata.forEach((field) => {
11470
- let key = field.key;
11471
- let value = field.value;
11472
- const disabled = field.disabled;
11473
- if (!key || !value) {
11474
- return;
11475
- }
11476
- if (disabled) {
11477
- update[key] = value;
11478
- return;
11479
- }
11480
- key = key.trim();
11481
- value = value.trim();
11482
- if (value === "true") {
11483
- update[key] = true;
11484
- } else if (value === "false") {
11485
- update[key] = false;
11486
- } else {
11487
- const parsedNumber = parseFloat(value);
11488
- if (!isNaN(parsedNumber)) {
11489
- update[key] = parsedNumber;
11490
- } else {
11491
- update[key] = value;
11492
- }
11493
- }
11494
- });
11495
- return update;
11496
- }
11497
- function getHasUneditableRows(metadata) {
11498
- if (!metadata) {
11499
- return false;
11500
- }
11501
- return Object.values(metadata).some(
11502
- (value) => !EDITABLE_TYPES.includes(typeof value)
11503
- );
11504
- }
11154
+ const schema$3 = addressSchema;
11505
11155
  const PROMOTION_QUERY_KEY = "promotions";
11506
11156
  const promotionsQueryKeys = {
11507
11157
  list: (query2) => [
@@ -11779,46 +11429,88 @@ function getPromotionIds(items, shippingMethods) {
11779
11429
  }
11780
11430
  return Array.from(promotionIds);
11781
11431
  }
11782
- const SalesChannel = () => {
11432
+ const InlineTip = React.forwardRef(
11433
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11434
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11435
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11436
+ "div",
11437
+ {
11438
+ ref,
11439
+ className: ui.clx(
11440
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11441
+ className
11442
+ ),
11443
+ ...props,
11444
+ children: [
11445
+ /* @__PURE__ */ jsxRuntime.jsx(
11446
+ "div",
11447
+ {
11448
+ role: "presentation",
11449
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11450
+ "bg-ui-tag-orange-icon": variant === "warning"
11451
+ })
11452
+ }
11453
+ ),
11454
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11455
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11456
+ labelValue,
11457
+ ":"
11458
+ ] }),
11459
+ " ",
11460
+ children
11461
+ ] })
11462
+ ]
11463
+ }
11464
+ );
11465
+ }
11466
+ );
11467
+ InlineTip.displayName = "InlineTip";
11468
+ const MetadataFieldSchema = object({
11469
+ key: string(),
11470
+ disabled: boolean().optional(),
11471
+ value: any()
11472
+ });
11473
+ const MetadataSchema = object({
11474
+ metadata: array(MetadataFieldSchema)
11475
+ });
11476
+ const Metadata = () => {
11783
11477
  const { id } = reactRouterDom.useParams();
11784
- const { draft_order, isPending, isError, error } = useDraftOrder(
11785
- id,
11786
- {
11787
- fields: "+sales_channel_id"
11788
- },
11789
- {
11790
- enabled: !!id
11791
- }
11792
- );
11478
+ const { order, isPending, isError, error } = useOrder(id, {
11479
+ fields: "metadata"
11480
+ });
11793
11481
  if (isError) {
11794
11482
  throw error;
11795
11483
  }
11796
- const ISrEADY = !!draft_order && !isPending;
11484
+ const isReady = !isPending && !!order;
11797
11485
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11798
11486
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11800
- /* @__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" }) })
11487
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11488
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11801
11489
  ] }),
11802
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11490
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11803
11491
  ] });
11804
11492
  };
11805
- const SalesChannelForm = ({ order }) => {
11806
- const form = reactHookForm.useForm({
11807
- defaultValues: {
11808
- sales_channel_id: order.sales_channel_id || ""
11493
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11494
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11495
+ const MetadataForm = ({ orderId, metadata }) => {
11496
+ const { handleSuccess } = useRouteModal();
11497
+ const hasUneditableRows = getHasUneditableRows(metadata);
11498
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11499
+ const form = reactHookForm.useForm({
11500
+ defaultValues: {
11501
+ metadata: getDefaultValues(metadata)
11809
11502
  },
11810
- resolver: zod.zodResolver(schema$2)
11503
+ resolver: zod.zodResolver(MetadataSchema)
11811
11504
  });
11812
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11813
- const { handleSuccess } = useRouteModal();
11814
- const onSubmit = form.handleSubmit(async (data) => {
11505
+ const handleSubmit = form.handleSubmit(async (data) => {
11506
+ const parsedData = parseValues(data);
11815
11507
  await mutateAsync(
11816
11508
  {
11817
- sales_channel_id: data.sales_channel_id
11509
+ metadata: parsedData
11818
11510
  },
11819
11511
  {
11820
11512
  onSuccess: () => {
11821
- ui.toast.success("Sales channel updated");
11513
+ ui.toast.success("Metadata updated");
11822
11514
  handleSuccess();
11823
11515
  },
11824
11516
  onError: (error) => {
@@ -11827,91 +11519,399 @@ const SalesChannelForm = ({ order }) => {
11827
11519
  }
11828
11520
  );
11829
11521
  });
11522
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11523
+ control: form.control,
11524
+ name: "metadata"
11525
+ });
11526
+ function deleteRow(index) {
11527
+ remove(index);
11528
+ if (fields.length === 1) {
11529
+ insert(0, {
11530
+ key: "",
11531
+ value: "",
11532
+ disabled: false
11533
+ });
11534
+ }
11535
+ }
11536
+ function insertRow(index, position) {
11537
+ insert(index + (position === "above" ? 0 : 1), {
11538
+ key: "",
11539
+ value: "",
11540
+ disabled: false
11541
+ });
11542
+ }
11830
11543
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11831
11544
  KeyboundForm,
11832
11545
  {
11546
+ onSubmit: handleSubmit,
11833
11547
  className: "flex flex-1 flex-col overflow-hidden",
11834
- onSubmit,
11835
11548
  children: [
11836
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11837
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11838
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11549
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11550
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11551
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11552
+ /* @__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" }) }),
11553
+ /* @__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" }) })
11554
+ ] }),
11555
+ fields.map((field, index) => {
11556
+ const isDisabled = field.disabled || false;
11557
+ let placeholder = "-";
11558
+ if (typeof field.value === "object") {
11559
+ placeholder = "{ ... }";
11560
+ }
11561
+ if (Array.isArray(field.value)) {
11562
+ placeholder = "[ ... ]";
11563
+ }
11564
+ return /* @__PURE__ */ jsxRuntime.jsx(
11565
+ ConditionalTooltip,
11566
+ {
11567
+ showTooltip: isDisabled,
11568
+ content: "This row is disabled because it contains non-primitive data.",
11569
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11570
+ /* @__PURE__ */ jsxRuntime.jsxs(
11571
+ "div",
11572
+ {
11573
+ className: ui.clx("grid grid-cols-2 divide-x", {
11574
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11575
+ }),
11576
+ children: [
11577
+ /* @__PURE__ */ jsxRuntime.jsx(
11578
+ Form$2.Field,
11579
+ {
11580
+ control: form.control,
11581
+ name: `metadata.${index}.key`,
11582
+ render: ({ field: field2 }) => {
11583
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11584
+ GridInput,
11585
+ {
11586
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11587
+ ...field2,
11588
+ disabled: isDisabled,
11589
+ placeholder: "Key"
11590
+ }
11591
+ ) }) });
11592
+ }
11593
+ }
11594
+ ),
11595
+ /* @__PURE__ */ jsxRuntime.jsx(
11596
+ Form$2.Field,
11597
+ {
11598
+ control: form.control,
11599
+ name: `metadata.${index}.value`,
11600
+ render: ({ field: { value, ...field2 } }) => {
11601
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11602
+ GridInput,
11603
+ {
11604
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11605
+ ...field2,
11606
+ value: isDisabled ? placeholder : value,
11607
+ disabled: isDisabled,
11608
+ placeholder: "Value"
11609
+ }
11610
+ ) }) });
11611
+ }
11612
+ }
11613
+ )
11614
+ ]
11615
+ }
11616
+ ),
11617
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11618
+ /* @__PURE__ */ jsxRuntime.jsx(
11619
+ ui.DropdownMenu.Trigger,
11620
+ {
11621
+ className: ui.clx(
11622
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11623
+ {
11624
+ hidden: isDisabled
11625
+ }
11626
+ ),
11627
+ disabled: isDisabled,
11628
+ asChild: true,
11629
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11630
+ }
11631
+ ),
11632
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11633
+ /* @__PURE__ */ jsxRuntime.jsxs(
11634
+ ui.DropdownMenu.Item,
11635
+ {
11636
+ className: "gap-x-2",
11637
+ onClick: () => insertRow(index, "above"),
11638
+ children: [
11639
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11640
+ "Insert row above"
11641
+ ]
11642
+ }
11643
+ ),
11644
+ /* @__PURE__ */ jsxRuntime.jsxs(
11645
+ ui.DropdownMenu.Item,
11646
+ {
11647
+ className: "gap-x-2",
11648
+ onClick: () => insertRow(index, "below"),
11649
+ children: [
11650
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11651
+ "Insert row below"
11652
+ ]
11653
+ }
11654
+ ),
11655
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11656
+ /* @__PURE__ */ jsxRuntime.jsxs(
11657
+ ui.DropdownMenu.Item,
11658
+ {
11659
+ className: "gap-x-2",
11660
+ onClick: () => deleteRow(index),
11661
+ children: [
11662
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11663
+ "Delete row"
11664
+ ]
11665
+ }
11666
+ )
11667
+ ] })
11668
+ ] })
11669
+ ] })
11670
+ },
11671
+ field.id
11672
+ );
11673
+ })
11674
+ ] }),
11675
+ 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." })
11676
+ ] }),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11678
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11839
11679
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11840
11680
  ] }) })
11841
11681
  ]
11842
11682
  }
11843
11683
  ) });
11844
11684
  };
11845
- const SalesChannelField = ({ control, order }) => {
11846
- const salesChannels = useComboboxData({
11847
- queryFn: async (params) => {
11848
- return await sdk.admin.salesChannel.list(params);
11849
- },
11850
- queryKey: ["sales-channels"],
11851
- getOptions: (data) => {
11852
- return data.sales_channels.map((salesChannel) => ({
11853
- label: salesChannel.name,
11854
- value: salesChannel.id
11855
- }));
11856
- },
11857
- defaultValue: order.sales_channel_id || void 0
11858
- });
11685
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11859
11686
  return /* @__PURE__ */ jsxRuntime.jsx(
11860
- Form$2.Field,
11687
+ "input",
11861
11688
  {
11862
- control,
11863
- name: "sales_channel_id",
11864
- render: ({ field }) => {
11865
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11866
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11867
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11868
- Combobox,
11869
- {
11870
- options: salesChannels.options,
11871
- fetchNextPage: salesChannels.fetchNextPage,
11872
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11873
- searchValue: salesChannels.searchValue,
11874
- onSearchValueChange: salesChannels.onSearchValueChange,
11875
- placeholder: "Select sales channel",
11876
- ...field
11877
- }
11878
- ) }),
11879
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11880
- ] });
11881
- }
11689
+ ref,
11690
+ ...props,
11691
+ autoComplete: "off",
11692
+ className: ui.clx(
11693
+ "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",
11694
+ className
11695
+ )
11882
11696
  }
11883
11697
  );
11884
- };
11885
- const schema$2 = object({
11886
- sales_channel_id: string().min(1)
11887
11698
  });
11888
- const ShippingAddress = () => {
11889
- const { id } = reactRouterDom.useParams();
11890
- const { order, isPending, isError, error } = useOrder(id, {
11891
- fields: "+shipping_address"
11892
- });
11893
- if (isError) {
11894
- throw error;
11895
- }
11896
- const isReady = !isPending && !!order;
11897
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11898
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11899
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11900
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11901
- ] }),
11902
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11699
+ GridInput.displayName = "MetadataForm.GridInput";
11700
+ const PlaceholderInner = () => {
11701
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11702
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11703
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11704
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11705
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11706
+ ] }) })
11903
11707
  ] });
11904
11708
  };
11905
- const ShippingAddressForm = ({ order }) => {
11906
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11907
- const form = reactHookForm.useForm({
11908
- defaultValues: {
11909
- first_name: ((_a2 = order.shipping_address) == null ? void 0 : _a2.first_name) ?? "",
11910
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11911
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11912
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11913
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11914
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11709
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11710
+ function getDefaultValues(metadata) {
11711
+ if (!metadata || !Object.keys(metadata).length) {
11712
+ return [
11713
+ {
11714
+ key: "",
11715
+ value: "",
11716
+ disabled: false
11717
+ }
11718
+ ];
11719
+ }
11720
+ return Object.entries(metadata).map(([key, value]) => {
11721
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11722
+ return {
11723
+ key,
11724
+ value,
11725
+ disabled: true
11726
+ };
11727
+ }
11728
+ let stringValue = value;
11729
+ if (typeof value !== "string") {
11730
+ stringValue = JSON.stringify(value);
11731
+ }
11732
+ return {
11733
+ key,
11734
+ value: stringValue,
11735
+ original_key: key
11736
+ };
11737
+ });
11738
+ }
11739
+ function parseValues(values) {
11740
+ const metadata = values.metadata;
11741
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11742
+ if (isEmpty) {
11743
+ return null;
11744
+ }
11745
+ const update = {};
11746
+ metadata.forEach((field) => {
11747
+ let key = field.key;
11748
+ let value = field.value;
11749
+ const disabled = field.disabled;
11750
+ if (!key || !value) {
11751
+ return;
11752
+ }
11753
+ if (disabled) {
11754
+ update[key] = value;
11755
+ return;
11756
+ }
11757
+ key = key.trim();
11758
+ value = value.trim();
11759
+ if (value === "true") {
11760
+ update[key] = true;
11761
+ } else if (value === "false") {
11762
+ update[key] = false;
11763
+ } else {
11764
+ const parsedNumber = parseFloat(value);
11765
+ if (!isNaN(parsedNumber)) {
11766
+ update[key] = parsedNumber;
11767
+ } else {
11768
+ update[key] = value;
11769
+ }
11770
+ }
11771
+ });
11772
+ return update;
11773
+ }
11774
+ function getHasUneditableRows(metadata) {
11775
+ if (!metadata) {
11776
+ return false;
11777
+ }
11778
+ return Object.values(metadata).some(
11779
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11780
+ );
11781
+ }
11782
+ const SalesChannel = () => {
11783
+ const { id } = reactRouterDom.useParams();
11784
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11785
+ id,
11786
+ {
11787
+ fields: "+sales_channel_id"
11788
+ },
11789
+ {
11790
+ enabled: !!id
11791
+ }
11792
+ );
11793
+ if (isError) {
11794
+ throw error;
11795
+ }
11796
+ const ISrEADY = !!draft_order && !isPending;
11797
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11798
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11799
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11800
+ /* @__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" }) })
11801
+ ] }),
11802
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11803
+ ] });
11804
+ };
11805
+ const SalesChannelForm = ({ order }) => {
11806
+ const form = reactHookForm.useForm({
11807
+ defaultValues: {
11808
+ sales_channel_id: order.sales_channel_id || ""
11809
+ },
11810
+ resolver: zod.zodResolver(schema$2)
11811
+ });
11812
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11813
+ const { handleSuccess } = useRouteModal();
11814
+ const onSubmit = form.handleSubmit(async (data) => {
11815
+ await mutateAsync(
11816
+ {
11817
+ sales_channel_id: data.sales_channel_id
11818
+ },
11819
+ {
11820
+ onSuccess: () => {
11821
+ ui.toast.success("Sales channel updated");
11822
+ handleSuccess();
11823
+ },
11824
+ onError: (error) => {
11825
+ ui.toast.error(error.message);
11826
+ }
11827
+ }
11828
+ );
11829
+ });
11830
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11831
+ KeyboundForm,
11832
+ {
11833
+ className: "flex flex-1 flex-col overflow-hidden",
11834
+ onSubmit,
11835
+ children: [
11836
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11837
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11838
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11839
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11840
+ ] }) })
11841
+ ]
11842
+ }
11843
+ ) });
11844
+ };
11845
+ const SalesChannelField = ({ control, order }) => {
11846
+ const salesChannels = useComboboxData({
11847
+ queryFn: async (params) => {
11848
+ return await sdk.admin.salesChannel.list(params);
11849
+ },
11850
+ queryKey: ["sales-channels"],
11851
+ getOptions: (data) => {
11852
+ return data.sales_channels.map((salesChannel) => ({
11853
+ label: salesChannel.name,
11854
+ value: salesChannel.id
11855
+ }));
11856
+ },
11857
+ defaultValue: order.sales_channel_id || void 0
11858
+ });
11859
+ return /* @__PURE__ */ jsxRuntime.jsx(
11860
+ Form$2.Field,
11861
+ {
11862
+ control,
11863
+ name: "sales_channel_id",
11864
+ render: ({ field }) => {
11865
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11866
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11867
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11868
+ Combobox,
11869
+ {
11870
+ options: salesChannels.options,
11871
+ fetchNextPage: salesChannels.fetchNextPage,
11872
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11873
+ searchValue: salesChannels.searchValue,
11874
+ onSearchValueChange: salesChannels.onSearchValueChange,
11875
+ placeholder: "Select sales channel",
11876
+ ...field
11877
+ }
11878
+ ) }),
11879
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11880
+ ] });
11881
+ }
11882
+ }
11883
+ );
11884
+ };
11885
+ const schema$2 = object({
11886
+ sales_channel_id: string().min(1)
11887
+ });
11888
+ const ShippingAddress = () => {
11889
+ const { id } = reactRouterDom.useParams();
11890
+ const { order, isPending, isError, error } = useOrder(id, {
11891
+ fields: "+shipping_address"
11892
+ });
11893
+ if (isError) {
11894
+ throw error;
11895
+ }
11896
+ const isReady = !isPending && !!order;
11897
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11898
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11899
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11900
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11901
+ ] }),
11902
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11903
+ ] });
11904
+ };
11905
+ const ShippingAddressForm = ({ order }) => {
11906
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11907
+ const form = reactHookForm.useForm({
11908
+ defaultValues: {
11909
+ first_name: ((_a2 = order.shipping_address) == null ? void 0 : _a2.first_name) ?? "",
11910
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11911
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11912
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11913
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11914
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11915
11915
  province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11916
11916
  country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11917
11917
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
@@ -12088,948 +12088,141 @@ const ShippingAddressForm = ({ order }) => {
12088
12088
  ) });
12089
12089
  };
12090
12090
  const schema$1 = addressSchema;
12091
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12092
- const Shipping = () => {
12093
- var _a2;
12091
+ const TransferOwnership = () => {
12094
12092
  const { id } = reactRouterDom.useParams();
12095
- const { order, isPending, isError, error } = useOrder(id, {
12096
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12093
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12094
+ fields: "id,customer_id,customer.*"
12097
12095
  });
12098
- const {
12099
- order: preview,
12100
- isPending: isPreviewPending,
12101
- isError: isPreviewError,
12102
- error: previewError
12103
- } = useOrderPreview(id);
12104
- useInitiateOrderEdit({ preview });
12105
- const { onCancel } = useCancelOrderEdit({ preview });
12106
12096
  if (isError) {
12107
12097
  throw error;
12108
12098
  }
12109
- if (isPreviewError) {
12110
- throw previewError;
12111
- }
12112
- const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
12113
- const isReady = preview && !isPreviewPending && order && !isPending;
12114
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12115
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12116
- /* @__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: [
12117
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12118
- /* @__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." }) })
12119
- ] }) }) }),
12120
- /* @__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" }) }) })
12121
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12122
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12123
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12124
- ] }) });
12099
+ const isReady = !isPending && !!draft_order;
12100
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12101
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12102
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12103
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12104
+ ] }),
12105
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12106
+ ] });
12125
12107
  };
12126
- const ShippingForm = ({ preview, order }) => {
12127
- var _a2;
12128
- const { setIsOpen } = useStackedModal();
12129
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12130
- const [data, setData] = React.useState(null);
12131
- const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
12132
- const { shipping_options } = useShippingOptions(
12133
- {
12134
- id: appliedShippingOptionIds,
12135
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12108
+ const TransferOwnershipForm = ({ order }) => {
12109
+ var _a2, _b;
12110
+ const form = reactHookForm.useForm({
12111
+ defaultValues: {
12112
+ customer_id: order.customer_id || ""
12136
12113
  },
12137
- {
12138
- enabled: appliedShippingOptionIds.length > 0
12139
- }
12140
- );
12141
- const uniqueShippingProfiles = React.useMemo(() => {
12142
- const profiles = /* @__PURE__ */ new Map();
12143
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12144
- profiles.set(profile.id, profile);
12145
- });
12146
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12147
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12148
- });
12149
- return Array.from(profiles.values());
12150
- }, [order.items, shipping_options]);
12114
+ resolver: zod.zodResolver(schema)
12115
+ });
12116
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12151
12117
  const { handleSuccess } = useRouteModal();
12152
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12153
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12154
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12155
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12156
- const onSubmit = async () => {
12157
- setIsSubmitting(true);
12158
- let requestSucceeded = false;
12159
- await requestOrderEdit(void 0, {
12160
- onError: (e) => {
12161
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12162
- },
12163
- onSuccess: () => {
12164
- requestSucceeded = true;
12165
- }
12166
- });
12167
- if (!requestSucceeded) {
12168
- setIsSubmitting(false);
12169
- return;
12170
- }
12171
- await confirmOrderEdit(void 0, {
12172
- onError: (e) => {
12173
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12174
- },
12175
- onSuccess: () => {
12176
- handleSuccess();
12177
- },
12178
- onSettled: () => {
12179
- setIsSubmitting(false);
12180
- }
12181
- });
12182
- };
12183
- const onKeydown = React.useCallback(
12184
- (e) => {
12185
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12186
- if (data || isSubmitting) {
12187
- return;
12118
+ const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12119
+ const currentCustomer = order.customer ? {
12120
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12121
+ value: order.customer.id
12122
+ } : null;
12123
+ const onSubmit = form.handleSubmit(async (data) => {
12124
+ await mutateAsync(
12125
+ { customer_id: data.customer_id },
12126
+ {
12127
+ onSuccess: () => {
12128
+ ui.toast.success("Customer updated");
12129
+ handleSuccess();
12130
+ },
12131
+ onError: (error) => {
12132
+ ui.toast.error(error.message);
12188
12133
  }
12189
- onSubmit();
12190
12134
  }
12135
+ );
12136
+ });
12137
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12138
+ KeyboundForm,
12139
+ {
12140
+ className: "flex flex-1 flex-col overflow-hidden",
12141
+ onSubmit,
12142
+ children: [
12143
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12144
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12145
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12146
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12149
+ ] }),
12150
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12151
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12152
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12153
+ ] })
12154
+ ] }),
12155
+ /* @__PURE__ */ jsxRuntime.jsx(
12156
+ CustomerField,
12157
+ {
12158
+ control: form.control,
12159
+ currentCustomerId: order.customer_id
12160
+ }
12161
+ )
12162
+ ] }),
12163
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12164
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12165
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12166
+ ] }) })
12167
+ ]
12168
+ }
12169
+ ) });
12170
+ };
12171
+ const CustomerField = ({ control, currentCustomerId }) => {
12172
+ const customers = useComboboxData({
12173
+ queryFn: async (params) => {
12174
+ return await sdk.admin.customer.list({
12175
+ ...params,
12176
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12177
+ });
12191
12178
  },
12192
- [data, isSubmitting, onSubmit]
12193
- );
12194
- React.useEffect(() => {
12195
- document.addEventListener("keydown", onKeydown);
12196
- return () => {
12197
- document.removeEventListener("keydown", onKeydown);
12198
- };
12199
- }, [onKeydown]);
12200
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12201
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12202
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12203
- /* @__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: [
12204
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12205
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12206
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12179
+ queryKey: ["customers"],
12180
+ getOptions: (data) => {
12181
+ return data.customers.map((customer) => {
12182
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12183
+ return {
12184
+ label: name ? `${name} (${customer.email})` : customer.email,
12185
+ value: customer.id
12186
+ };
12187
+ });
12188
+ }
12189
+ });
12190
+ return /* @__PURE__ */ jsxRuntime.jsx(
12191
+ Form$2.Field,
12192
+ {
12193
+ name: "customer_id",
12194
+ control,
12195
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12196
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12197
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12198
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12207
12199
  ] }),
12208
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12209
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12210
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
12211
- /* @__PURE__ */ jsxRuntime.jsx(
12212
- ui.Text,
12213
- {
12214
- size: "xsmall",
12215
- weight: "plus",
12216
- className: "text-ui-fg-muted",
12217
- children: "Shipping profile"
12218
- }
12219
- ),
12220
- /* @__PURE__ */ jsxRuntime.jsx(
12221
- ui.Text,
12222
- {
12223
- size: "xsmall",
12224
- weight: "plus",
12225
- className: "text-ui-fg-muted",
12226
- children: "Action"
12227
- }
12228
- )
12229
- ] }),
12230
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12231
- var _a3, _b, _c, _d, _e, _f, _g;
12232
- const items = getItemsWithShippingProfile(
12233
- profile.id,
12234
- order.items
12235
- );
12236
- const hasItems = items.length > 0;
12237
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12238
- (option) => option.shipping_profile_id === profile.id
12239
- );
12240
- const shippingMethod = preview.shipping_methods.find(
12241
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12242
- );
12243
- const addShippingMethodAction = (_a3 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a3.find(
12244
- (action) => action.action === "SHIPPING_ADD"
12245
- );
12246
- return /* @__PURE__ */ jsxRuntime.jsxs(
12247
- radixUi.Accordion.Item,
12248
- {
12249
- value: profile.id,
12250
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12251
- children: [
12252
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
12253
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12255
- ui.IconButton,
12256
- {
12257
- size: "2xsmall",
12258
- variant: "transparent",
12259
- className: "group/trigger",
12260
- disabled: !hasItems,
12261
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
12262
- }
12263
- ) }),
12264
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12266
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(
12268
- ui.Text,
12269
- {
12270
- size: "small",
12271
- weight: "plus",
12272
- leading: "compact",
12273
- children: profile.name
12274
- }
12275
- ),
12276
- /* @__PURE__ */ jsxRuntime.jsxs(
12277
- ui.Text,
12278
- {
12279
- size: "small",
12280
- leading: "compact",
12281
- className: "text-ui-fg-subtle",
12282
- children: [
12283
- items.length,
12284
- " ",
12285
- pluralize(items.length, "items", "item")
12286
- ]
12287
- }
12288
- )
12289
- ] })
12290
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
12291
- /* @__PURE__ */ jsxRuntime.jsx(
12292
- ui.Tooltip,
12293
- {
12294
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12295
- var _a4, _b2, _c2;
12296
- return /* @__PURE__ */ jsxRuntime.jsx(
12297
- "li",
12298
- {
12299
- children: `${item.quantity}x ${(_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12300
- },
12301
- item.id
12302
- );
12303
- }) }),
12304
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12305
- ui.Badge,
12306
- {
12307
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12308
- size: "xsmall",
12309
- children: [
12310
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12311
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12312
- items.reduce(
12313
- (acc, item) => acc + item.quantity,
12314
- 0
12315
- ),
12316
- "x",
12317
- " ",
12318
- pluralize(items.length, "items", "item")
12319
- ] })
12320
- ]
12321
- }
12322
- )
12323
- }
12324
- ),
12325
- /* @__PURE__ */ jsxRuntime.jsx(
12326
- ui.Tooltip,
12327
- {
12328
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12329
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12330
- ui.Badge,
12331
- {
12332
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12333
- size: "xsmall",
12334
- children: [
12335
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12336
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12337
- ]
12338
- }
12339
- )
12340
- }
12341
- ),
12342
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12343
- ui.Badge,
12344
- {
12345
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12346
- size: "xsmall",
12347
- children: [
12348
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12349
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12350
- ]
12351
- }
12352
- ) })
12353
- ] })
12354
- ] }),
12355
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12356
- ActionMenu,
12357
- {
12358
- groups: [
12359
- {
12360
- actions: [
12361
- hasItems ? {
12362
- label: "Edit shipping option",
12363
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12364
- onClick: () => {
12365
- setIsOpen(
12366
- STACKED_FOCUS_MODAL_ID,
12367
- true
12368
- );
12369
- setData({
12370
- shippingProfileId: profile.id,
12371
- shippingOption,
12372
- shippingMethod
12373
- });
12374
- }
12375
- } : void 0,
12376
- {
12377
- label: "Remove shipping option",
12378
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12379
- onClick: () => {
12380
- if (shippingMethod) {
12381
- if (addShippingMethodAction) {
12382
- removeActionShippingMethod(
12383
- addShippingMethodAction.id
12384
- );
12385
- } else {
12386
- removeShippingMethod(
12387
- shippingMethod.id
12388
- );
12389
- }
12390
- }
12391
- }
12392
- }
12393
- ].filter(Boolean)
12394
- }
12395
- ]
12396
- }
12397
- ) : /* @__PURE__ */ jsxRuntime.jsx(
12398
- StackedModalTrigger,
12399
- {
12400
- shippingProfileId: profile.id,
12401
- shippingOption,
12402
- shippingMethod,
12403
- setData,
12404
- children: "Add shipping option"
12405
- }
12406
- )
12407
- ] }),
12408
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12409
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12410
- items.map((item, idx) => {
12411
- var _a4, _b2, _c2, _d2, _e2;
12412
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12413
- /* @__PURE__ */ jsxRuntime.jsxs(
12414
- "div",
12415
- {
12416
- className: "flex items-center gap-x-3 px-3",
12417
- children: [
12418
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12419
- ui.Divider,
12420
- {
12421
- variant: "dashed",
12422
- orientation: "vertical"
12423
- }
12424
- ) }),
12425
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12426
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12427
- ui.Text,
12428
- {
12429
- size: "small",
12430
- leading: "compact",
12431
- className: "text-ui-fg-subtle",
12432
- children: [
12433
- item.quantity,
12434
- "x"
12435
- ]
12436
- }
12437
- ) }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12439
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12440
- /* @__PURE__ */ jsxRuntime.jsxs(
12441
- ui.Text,
12442
- {
12443
- size: "small",
12444
- leading: "compact",
12445
- weight: "plus",
12446
- children: [
12447
- (_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title,
12448
- " (",
12449
- (_c2 = item.variant) == null ? void 0 : _c2.title,
12450
- ")"
12451
- ]
12452
- }
12453
- ),
12454
- /* @__PURE__ */ jsxRuntime.jsx(
12455
- ui.Text,
12456
- {
12457
- size: "small",
12458
- leading: "compact",
12459
- className: "text-ui-fg-subtle",
12460
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12461
- }
12462
- )
12463
- ] })
12464
- ] })
12465
- ]
12466
- },
12467
- item.id
12468
- ),
12469
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12470
- ] }, item.id);
12471
- })
12472
- ] })
12473
- ]
12474
- },
12475
- profile.id
12476
- );
12477
- }) })
12478
- ] }) })
12479
- ] }) }),
12480
- /* @__PURE__ */ jsxRuntime.jsx(
12481
- StackedFocusModal,
12482
- {
12483
- id: STACKED_FOCUS_MODAL_ID,
12484
- onOpenChangeCallback: (open) => {
12485
- if (!open) {
12486
- setData(null);
12487
- }
12488
- return open;
12489
- },
12490
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12491
- }
12492
- )
12493
- ] }),
12494
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12495
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12496
- /* @__PURE__ */ jsxRuntime.jsx(
12497
- ui.Button,
12498
- {
12499
- size: "small",
12500
- type: "button",
12501
- isLoading: isSubmitting,
12502
- onClick: onSubmit,
12503
- children: "Save"
12504
- }
12505
- )
12506
- ] }) })
12507
- ] });
12508
- };
12509
- const StackedModalTrigger = ({
12510
- shippingProfileId,
12511
- shippingOption,
12512
- shippingMethod,
12513
- setData,
12514
- children
12515
- }) => {
12516
- const { setIsOpen, getIsOpen } = useStackedModal();
12517
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12518
- const onToggle = () => {
12519
- if (isOpen) {
12520
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12521
- setData(null);
12522
- } else {
12523
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12524
- setData({
12525
- shippingProfileId,
12526
- shippingOption,
12527
- shippingMethod
12528
- });
12529
- }
12530
- };
12531
- return /* @__PURE__ */ jsxRuntime.jsx(
12532
- ui.Button,
12533
- {
12534
- size: "small",
12535
- variant: "secondary",
12536
- onClick: onToggle,
12537
- className: "text-ui-fg-primary shrink-0",
12538
- children
12200
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12201
+ Combobox,
12202
+ {
12203
+ options: customers.options,
12204
+ fetchNextPage: customers.fetchNextPage,
12205
+ isFetchingNextPage: customers.isFetchingNextPage,
12206
+ searchValue: customers.searchValue,
12207
+ onSearchValueChange: customers.onSearchValueChange,
12208
+ placeholder: "Select customer",
12209
+ ...field
12210
+ }
12211
+ ) }),
12212
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12213
+ ] })
12539
12214
  }
12540
12215
  );
12541
12216
  };
12542
- const ShippingProfileForm = ({
12543
- data,
12544
- order,
12545
- preview
12546
- }) => {
12547
- var _a2, _b, _c, _d, _e, _f;
12548
- const { setIsOpen } = useStackedModal();
12549
- const form = reactHookForm.useForm({
12550
- resolver: zod.zodResolver(shippingMethodSchema),
12551
- defaultValues: {
12552
- location_id: (_d = (_c = (_b = (_a2 = data.shippingOption) == null ? void 0 : _a2.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12553
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12554
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12555
- }
12556
- });
12557
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12558
- const {
12559
- mutateAsync: updateShippingMethod,
12560
- isPending: isUpdatingShippingMethod
12561
- } = useDraftOrderUpdateShippingMethod(order.id);
12562
- const onSubmit = form.handleSubmit(async (values) => {
12563
- if (isEqual__default.default(values, form.formState.defaultValues)) {
12564
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12565
- return;
12566
- }
12567
- if (data.shippingMethod) {
12568
- await updateShippingMethod(
12569
- {
12570
- method_id: data.shippingMethod.id,
12571
- shipping_option_id: values.shipping_option_id,
12572
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12573
- },
12574
- {
12575
- onError: (e) => {
12576
- ui.toast.error(e.message);
12577
- },
12578
- onSuccess: () => {
12579
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12580
- }
12581
- }
12582
- );
12583
- return;
12584
- }
12585
- await addShippingMethod(
12586
- {
12587
- shipping_option_id: values.shipping_option_id,
12588
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12589
- },
12590
- {
12591
- onError: (e) => {
12592
- ui.toast.error(e.message);
12593
- },
12594
- onSuccess: () => {
12595
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12596
- }
12597
- }
12598
- );
12599
- });
12600
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12601
- KeyboundForm,
12217
+ const Illustration = () => {
12218
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12219
+ "svg",
12602
12220
  {
12603
- className: "flex h-full flex-col overflow-hidden",
12604
- onSubmit,
12605
- children: [
12606
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12607
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12608
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12609
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12610
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12611
- ] }),
12612
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12613
- /* @__PURE__ */ jsxRuntime.jsx(
12614
- LocationField,
12615
- {
12616
- control: form.control,
12617
- setValue: form.setValue
12618
- }
12619
- ),
12620
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12621
- /* @__PURE__ */ jsxRuntime.jsx(
12622
- ShippingOptionField,
12623
- {
12624
- shippingProfileId: data.shippingProfileId,
12625
- preview,
12626
- control: form.control
12627
- }
12628
- ),
12629
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12630
- /* @__PURE__ */ jsxRuntime.jsx(
12631
- CustomAmountField,
12632
- {
12633
- control: form.control,
12634
- currencyCode: order.currency_code
12635
- }
12636
- ),
12637
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12638
- /* @__PURE__ */ jsxRuntime.jsx(
12639
- ItemsPreview,
12640
- {
12641
- order,
12642
- shippingProfileId: data.shippingProfileId
12643
- }
12644
- )
12645
- ] }) }) }),
12646
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12647
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12648
- /* @__PURE__ */ jsxRuntime.jsx(
12649
- ui.Button,
12650
- {
12651
- size: "small",
12652
- type: "submit",
12653
- isLoading: isPending || isUpdatingShippingMethod,
12654
- children: data.shippingMethod ? "Update" : "Add"
12655
- }
12656
- )
12657
- ] }) })
12658
- ]
12659
- }
12660
- ) }) });
12661
- };
12662
- const shippingMethodSchema = object({
12663
- location_id: string(),
12664
- shipping_option_id: string(),
12665
- custom_amount: union([number(), string()]).optional()
12666
- });
12667
- const ItemsPreview = ({ order, shippingProfileId }) => {
12668
- const matches = order.items.filter(
12669
- (item) => {
12670
- var _a2, _b, _c;
12671
- return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12672
- }
12673
- );
12674
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12675
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12676
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12677
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12678
- ] }) }),
12679
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12680
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12681
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12682
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12683
- ] }),
12684
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12685
- "div",
12686
- {
12687
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12688
- children: [
12689
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12690
- /* @__PURE__ */ jsxRuntime.jsx(
12691
- Thumbnail,
12692
- {
12693
- thumbnail: item.thumbnail,
12694
- alt: item.product_title ?? void 0
12695
- }
12696
- ),
12697
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12698
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12699
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12700
- /* @__PURE__ */ jsxRuntime.jsxs(
12701
- ui.Text,
12702
- {
12703
- size: "small",
12704
- leading: "compact",
12705
- className: "text-ui-fg-subtle",
12706
- children: [
12707
- "(",
12708
- item.variant_title,
12709
- ")"
12710
- ]
12711
- }
12712
- )
12713
- ] }),
12714
- /* @__PURE__ */ jsxRuntime.jsx(
12715
- ui.Text,
12716
- {
12717
- size: "small",
12718
- leading: "compact",
12719
- className: "text-ui-fg-subtle",
12720
- children: item.variant_sku
12721
- }
12722
- )
12723
- ] })
12724
- ] }),
12725
- /* @__PURE__ */ jsxRuntime.jsxs(
12726
- ui.Text,
12727
- {
12728
- size: "small",
12729
- leading: "compact",
12730
- className: "text-ui-fg-subtle",
12731
- children: [
12732
- item.quantity,
12733
- "x"
12734
- ]
12735
- }
12736
- )
12737
- ]
12738
- },
12739
- item.id
12740
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12741
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12742
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12743
- 'No items found for "',
12744
- query,
12745
- '".'
12746
- ] })
12747
- ] }) })
12748
- ] })
12749
- ] });
12750
- };
12751
- const LocationField = ({ control, setValue }) => {
12752
- const locations = useComboboxData({
12753
- queryKey: ["locations"],
12754
- queryFn: async (params) => {
12755
- return await sdk.admin.stockLocation.list(params);
12756
- },
12757
- getOptions: (data) => {
12758
- return data.stock_locations.map((location) => ({
12759
- label: location.name,
12760
- value: location.id
12761
- }));
12762
- }
12763
- });
12764
- return /* @__PURE__ */ jsxRuntime.jsx(
12765
- Form$2.Field,
12766
- {
12767
- control,
12768
- name: "location_id",
12769
- render: ({ field: { onChange, ...field } }) => {
12770
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12771
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12772
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12773
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12774
- ] }),
12775
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12776
- Combobox,
12777
- {
12778
- options: locations.options,
12779
- fetchNextPage: locations.fetchNextPage,
12780
- isFetchingNextPage: locations.isFetchingNextPage,
12781
- searchValue: locations.searchValue,
12782
- onSearchValueChange: locations.onSearchValueChange,
12783
- placeholder: "Select location",
12784
- onChange: (value) => {
12785
- setValue("shipping_option_id", "", {
12786
- shouldDirty: true,
12787
- shouldTouch: true
12788
- });
12789
- onChange(value);
12790
- },
12791
- ...field
12792
- }
12793
- ) })
12794
- ] }) });
12795
- }
12796
- }
12797
- );
12798
- };
12799
- const ShippingOptionField = ({
12800
- shippingProfileId,
12801
- preview,
12802
- control
12803
- }) => {
12804
- var _a2;
12805
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12806
- const shippingOptions = useComboboxData({
12807
- queryKey: ["shipping_options", locationId, shippingProfileId],
12808
- queryFn: async (params) => {
12809
- return await sdk.admin.shippingOption.list({
12810
- ...params,
12811
- stock_location_id: locationId,
12812
- shipping_profile_id: shippingProfileId
12813
- });
12814
- },
12815
- getOptions: (data) => {
12816
- return data.shipping_options.map((option) => {
12817
- var _a3;
12818
- if ((_a3 = option.rules) == null ? void 0 : _a3.find(
12819
- (r) => r.attribute === "is_return" && r.value === "true"
12820
- )) {
12821
- return void 0;
12822
- }
12823
- return {
12824
- label: option.name,
12825
- value: option.id
12826
- };
12827
- }).filter(Boolean);
12828
- },
12829
- enabled: !!locationId && !!shippingProfileId,
12830
- defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
12831
- });
12832
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12833
- return /* @__PURE__ */ jsxRuntime.jsx(
12834
- Form$2.Field,
12835
- {
12836
- control,
12837
- name: "shipping_option_id",
12838
- render: ({ field }) => {
12839
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12840
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12841
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12842
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12843
- ] }),
12844
- /* @__PURE__ */ jsxRuntime.jsx(
12845
- ConditionalTooltip,
12846
- {
12847
- content: tooltipContent,
12848
- showTooltip: !locationId || !shippingProfileId,
12849
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12850
- Combobox,
12851
- {
12852
- options: shippingOptions.options,
12853
- fetchNextPage: shippingOptions.fetchNextPage,
12854
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12855
- searchValue: shippingOptions.searchValue,
12856
- onSearchValueChange: shippingOptions.onSearchValueChange,
12857
- placeholder: "Select shipping option",
12858
- ...field,
12859
- disabled: !locationId || !shippingProfileId
12860
- }
12861
- ) }) })
12862
- }
12863
- )
12864
- ] }) });
12865
- }
12866
- }
12867
- );
12868
- };
12869
- const CustomAmountField = ({
12870
- control,
12871
- currencyCode
12872
- }) => {
12873
- return /* @__PURE__ */ jsxRuntime.jsx(
12874
- Form$2.Field,
12875
- {
12876
- control,
12877
- name: "custom_amount",
12878
- render: ({ field: { onChange, ...field } }) => {
12879
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12880
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12881
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12882
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12883
- ] }),
12884
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12885
- ui.CurrencyInput,
12886
- {
12887
- ...field,
12888
- onValueChange: (value) => onChange(value),
12889
- symbol: getNativeSymbol(currencyCode),
12890
- code: currencyCode
12891
- }
12892
- ) })
12893
- ] });
12894
- }
12895
- }
12896
- );
12897
- };
12898
- const TransferOwnership = () => {
12899
- const { id } = reactRouterDom.useParams();
12900
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12901
- fields: "id,customer_id,customer.*"
12902
- });
12903
- if (isError) {
12904
- throw error;
12905
- }
12906
- const isReady = !isPending && !!draft_order;
12907
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12908
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12909
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12910
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12911
- ] }),
12912
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12913
- ] });
12914
- };
12915
- const TransferOwnershipForm = ({ order }) => {
12916
- var _a2, _b;
12917
- const form = reactHookForm.useForm({
12918
- defaultValues: {
12919
- customer_id: order.customer_id || ""
12920
- },
12921
- resolver: zod.zodResolver(schema)
12922
- });
12923
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12924
- const { handleSuccess } = useRouteModal();
12925
- const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12926
- const currentCustomer = order.customer ? {
12927
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12928
- value: order.customer.id
12929
- } : null;
12930
- const onSubmit = form.handleSubmit(async (data) => {
12931
- await mutateAsync(
12932
- { customer_id: data.customer_id },
12933
- {
12934
- onSuccess: () => {
12935
- ui.toast.success("Customer updated");
12936
- handleSuccess();
12937
- },
12938
- onError: (error) => {
12939
- ui.toast.error(error.message);
12940
- }
12941
- }
12942
- );
12943
- });
12944
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12945
- KeyboundForm,
12946
- {
12947
- className: "flex flex-1 flex-col overflow-hidden",
12948
- onSubmit,
12949
- children: [
12950
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12951
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12952
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12953
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12954
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12956
- ] }),
12957
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12960
- ] })
12961
- ] }),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- CustomerField,
12964
- {
12965
- control: form.control,
12966
- currentCustomerId: order.customer_id
12967
- }
12968
- )
12969
- ] }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12971
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12973
- ] }) })
12974
- ]
12975
- }
12976
- ) });
12977
- };
12978
- const CustomerField = ({ control, currentCustomerId }) => {
12979
- const customers = useComboboxData({
12980
- queryFn: async (params) => {
12981
- return await sdk.admin.customer.list({
12982
- ...params,
12983
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12984
- });
12985
- },
12986
- queryKey: ["customers"],
12987
- getOptions: (data) => {
12988
- return data.customers.map((customer) => {
12989
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12990
- return {
12991
- label: name ? `${name} (${customer.email})` : customer.email,
12992
- value: customer.id
12993
- };
12994
- });
12995
- }
12996
- });
12997
- return /* @__PURE__ */ jsxRuntime.jsx(
12998
- Form$2.Field,
12999
- {
13000
- name: "customer_id",
13001
- control,
13002
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
13003
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
13005
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
13006
- ] }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13008
- Combobox,
13009
- {
13010
- options: customers.options,
13011
- fetchNextPage: customers.fetchNextPage,
13012
- isFetchingNextPage: customers.isFetchingNextPage,
13013
- searchValue: customers.searchValue,
13014
- onSearchValueChange: customers.onSearchValueChange,
13015
- placeholder: "Select customer",
13016
- ...field
13017
- }
13018
- ) }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13020
- ] })
13021
- }
13022
- );
13023
- };
13024
- const Illustration = () => {
13025
- return /* @__PURE__ */ jsxRuntime.jsxs(
13026
- "svg",
13027
- {
13028
- width: "280",
13029
- height: "180",
13030
- viewBox: "0 0 280 180",
13031
- fill: "none",
13032
- xmlns: "http://www.w3.org/2000/svg",
12221
+ width: "280",
12222
+ height: "180",
12223
+ viewBox: "0 0 280 180",
12224
+ fill: "none",
12225
+ xmlns: "http://www.w3.org/2000/svg",
13033
12226
  children: [
13034
12227
  /* @__PURE__ */ jsxRuntime.jsx(
13035
12228
  "rect",
@@ -13307,70 +12500,877 @@ const Illustration = () => {
13307
12500
  strokeLinecap: "round",
13308
12501
  strokeLinejoin: "round"
13309
12502
  }
13310
- ) }),
13311
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
13312
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13313
- "rect",
12503
+ ) }),
12504
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12505
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12506
+ "rect",
12507
+ {
12508
+ width: "12",
12509
+ height: "12",
12510
+ fill: "white",
12511
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12512
+ }
12513
+ ) }),
12514
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12515
+ "rect",
12516
+ {
12517
+ width: "12",
12518
+ height: "12",
12519
+ fill: "white",
12520
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12521
+ }
12522
+ ) }),
12523
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12524
+ "rect",
12525
+ {
12526
+ width: "12",
12527
+ height: "12",
12528
+ fill: "white",
12529
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12530
+ }
12531
+ ) }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12533
+ "rect",
12534
+ {
12535
+ width: "12",
12536
+ height: "12",
12537
+ fill: "white",
12538
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12539
+ }
12540
+ ) }),
12541
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12542
+ "rect",
12543
+ {
12544
+ width: "12",
12545
+ height: "12",
12546
+ fill: "white",
12547
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12548
+ }
12549
+ ) }),
12550
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12551
+ "rect",
12552
+ {
12553
+ width: "12",
12554
+ height: "12",
12555
+ fill: "white",
12556
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12557
+ }
12558
+ ) })
12559
+ ] })
12560
+ ]
12561
+ }
12562
+ );
12563
+ };
12564
+ const schema = object({
12565
+ customer_id: string().min(1)
12566
+ });
12567
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12568
+ const Shipping = () => {
12569
+ var _a2;
12570
+ const { id } = reactRouterDom.useParams();
12571
+ const { order, isPending, isError, error } = useOrder(id, {
12572
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12573
+ });
12574
+ const {
12575
+ order: preview,
12576
+ isPending: isPreviewPending,
12577
+ isError: isPreviewError,
12578
+ error: previewError
12579
+ } = useOrderPreview(id);
12580
+ useInitiateOrderEdit({ preview });
12581
+ const { onCancel } = useCancelOrderEdit({ preview });
12582
+ if (isError) {
12583
+ throw error;
12584
+ }
12585
+ if (isPreviewError) {
12586
+ throw previewError;
12587
+ }
12588
+ const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
12589
+ const isReady = preview && !isPreviewPending && order && !isPending;
12590
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12592
+ /* @__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: [
12593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12594
+ /* @__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." }) })
12595
+ ] }) }) }),
12596
+ /* @__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" }) }) })
12597
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12598
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12599
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12600
+ ] }) });
12601
+ };
12602
+ const ShippingForm = ({ preview, order }) => {
12603
+ var _a2;
12604
+ const { setIsOpen } = useStackedModal();
12605
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12606
+ const [data, setData] = React.useState(null);
12607
+ const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
12608
+ const { shipping_options } = useShippingOptions(
12609
+ {
12610
+ id: appliedShippingOptionIds,
12611
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12612
+ },
12613
+ {
12614
+ enabled: appliedShippingOptionIds.length > 0
12615
+ }
12616
+ );
12617
+ const uniqueShippingProfiles = React.useMemo(() => {
12618
+ const profiles = /* @__PURE__ */ new Map();
12619
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12620
+ profiles.set(profile.id, profile);
12621
+ });
12622
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12623
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12624
+ });
12625
+ return Array.from(profiles.values());
12626
+ }, [order.items, shipping_options]);
12627
+ const { handleSuccess } = useRouteModal();
12628
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12629
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12630
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12631
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12632
+ const onSubmit = async () => {
12633
+ setIsSubmitting(true);
12634
+ let requestSucceeded = false;
12635
+ await requestOrderEdit(void 0, {
12636
+ onError: (e) => {
12637
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12638
+ },
12639
+ onSuccess: () => {
12640
+ requestSucceeded = true;
12641
+ }
12642
+ });
12643
+ if (!requestSucceeded) {
12644
+ setIsSubmitting(false);
12645
+ return;
12646
+ }
12647
+ await confirmOrderEdit(void 0, {
12648
+ onError: (e) => {
12649
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12650
+ },
12651
+ onSuccess: () => {
12652
+ handleSuccess();
12653
+ },
12654
+ onSettled: () => {
12655
+ setIsSubmitting(false);
12656
+ }
12657
+ });
12658
+ };
12659
+ const onKeydown = React.useCallback(
12660
+ (e) => {
12661
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12662
+ if (data || isSubmitting) {
12663
+ return;
12664
+ }
12665
+ onSubmit();
12666
+ }
12667
+ },
12668
+ [data, isSubmitting, onSubmit]
12669
+ );
12670
+ React.useEffect(() => {
12671
+ document.addEventListener("keydown", onKeydown);
12672
+ return () => {
12673
+ document.removeEventListener("keydown", onKeydown);
12674
+ };
12675
+ }, [onKeydown]);
12676
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12677
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12678
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12679
+ /* @__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: [
12680
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12681
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12682
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12683
+ ] }),
12684
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12685
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12686
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
12687
+ /* @__PURE__ */ jsxRuntime.jsx(
12688
+ ui.Text,
12689
+ {
12690
+ size: "xsmall",
12691
+ weight: "plus",
12692
+ className: "text-ui-fg-muted",
12693
+ children: "Shipping profile"
12694
+ }
12695
+ ),
12696
+ /* @__PURE__ */ jsxRuntime.jsx(
12697
+ ui.Text,
12698
+ {
12699
+ size: "xsmall",
12700
+ weight: "plus",
12701
+ className: "text-ui-fg-muted",
12702
+ children: "Action"
12703
+ }
12704
+ )
12705
+ ] }),
12706
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12707
+ var _a3, _b, _c, _d, _e, _f, _g;
12708
+ const items = getItemsWithShippingProfile(
12709
+ profile.id,
12710
+ order.items
12711
+ );
12712
+ const hasItems = items.length > 0;
12713
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12714
+ (option) => option.shipping_profile_id === profile.id
12715
+ );
12716
+ const shippingMethod = preview.shipping_methods.find(
12717
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12718
+ );
12719
+ const addShippingMethodAction = (_a3 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a3.find(
12720
+ (action) => action.action === "SHIPPING_ADD"
12721
+ );
12722
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12723
+ radixUi.Accordion.Item,
12724
+ {
12725
+ value: profile.id,
12726
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12727
+ children: [
12728
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
12729
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
12730
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12731
+ ui.IconButton,
12732
+ {
12733
+ size: "2xsmall",
12734
+ variant: "transparent",
12735
+ className: "group/trigger",
12736
+ disabled: !hasItems,
12737
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
12738
+ }
12739
+ ) }),
12740
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12741
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12742
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
12743
+ /* @__PURE__ */ jsxRuntime.jsx(
12744
+ ui.Text,
12745
+ {
12746
+ size: "small",
12747
+ weight: "plus",
12748
+ leading: "compact",
12749
+ children: profile.name
12750
+ }
12751
+ ),
12752
+ /* @__PURE__ */ jsxRuntime.jsxs(
12753
+ ui.Text,
12754
+ {
12755
+ size: "small",
12756
+ leading: "compact",
12757
+ className: "text-ui-fg-subtle",
12758
+ children: [
12759
+ items.length,
12760
+ " ",
12761
+ pluralize(items.length, "items", "item")
12762
+ ]
12763
+ }
12764
+ )
12765
+ ] })
12766
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
12767
+ /* @__PURE__ */ jsxRuntime.jsx(
12768
+ ui.Tooltip,
12769
+ {
12770
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12771
+ var _a4, _b2, _c2;
12772
+ return /* @__PURE__ */ jsxRuntime.jsx(
12773
+ "li",
12774
+ {
12775
+ children: `${item.quantity}x ${(_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12776
+ },
12777
+ item.id
12778
+ );
12779
+ }) }),
12780
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12781
+ ui.Badge,
12782
+ {
12783
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12784
+ size: "xsmall",
12785
+ children: [
12786
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12787
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12788
+ items.reduce(
12789
+ (acc, item) => acc + item.quantity,
12790
+ 0
12791
+ ),
12792
+ "x",
12793
+ " ",
12794
+ pluralize(items.length, "items", "item")
12795
+ ] })
12796
+ ]
12797
+ }
12798
+ )
12799
+ }
12800
+ ),
12801
+ /* @__PURE__ */ jsxRuntime.jsx(
12802
+ ui.Tooltip,
12803
+ {
12804
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12805
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12806
+ ui.Badge,
12807
+ {
12808
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12809
+ size: "xsmall",
12810
+ children: [
12811
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12812
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12813
+ ]
12814
+ }
12815
+ )
12816
+ }
12817
+ ),
12818
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12819
+ ui.Badge,
12820
+ {
12821
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12822
+ size: "xsmall",
12823
+ children: [
12824
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12825
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12826
+ ]
12827
+ }
12828
+ ) })
12829
+ ] })
12830
+ ] }),
12831
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12832
+ ActionMenu,
12833
+ {
12834
+ groups: [
12835
+ {
12836
+ actions: [
12837
+ hasItems ? {
12838
+ label: "Edit shipping option",
12839
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12840
+ onClick: () => {
12841
+ setIsOpen(
12842
+ STACKED_FOCUS_MODAL_ID,
12843
+ true
12844
+ );
12845
+ setData({
12846
+ shippingProfileId: profile.id,
12847
+ shippingOption,
12848
+ shippingMethod
12849
+ });
12850
+ }
12851
+ } : void 0,
12852
+ {
12853
+ label: "Remove shipping option",
12854
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12855
+ onClick: () => {
12856
+ if (shippingMethod) {
12857
+ if (addShippingMethodAction) {
12858
+ removeActionShippingMethod(
12859
+ addShippingMethodAction.id
12860
+ );
12861
+ } else {
12862
+ removeShippingMethod(
12863
+ shippingMethod.id
12864
+ );
12865
+ }
12866
+ }
12867
+ }
12868
+ }
12869
+ ].filter(Boolean)
12870
+ }
12871
+ ]
12872
+ }
12873
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12874
+ StackedModalTrigger,
12875
+ {
12876
+ shippingProfileId: profile.id,
12877
+ shippingOption,
12878
+ shippingMethod,
12879
+ setData,
12880
+ children: "Add shipping option"
12881
+ }
12882
+ )
12883
+ ] }),
12884
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12885
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12886
+ items.map((item, idx) => {
12887
+ var _a4, _b2, _c2, _d2, _e2;
12888
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12889
+ /* @__PURE__ */ jsxRuntime.jsxs(
12890
+ "div",
12891
+ {
12892
+ className: "flex items-center gap-x-3 px-3",
12893
+ children: [
12894
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12895
+ ui.Divider,
12896
+ {
12897
+ variant: "dashed",
12898
+ orientation: "vertical"
12899
+ }
12900
+ ) }),
12901
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12902
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
+ ui.Text,
12904
+ {
12905
+ size: "small",
12906
+ leading: "compact",
12907
+ className: "text-ui-fg-subtle",
12908
+ children: [
12909
+ item.quantity,
12910
+ "x"
12911
+ ]
12912
+ }
12913
+ ) }),
12914
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12915
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12916
+ /* @__PURE__ */ jsxRuntime.jsxs(
12917
+ ui.Text,
12918
+ {
12919
+ size: "small",
12920
+ leading: "compact",
12921
+ weight: "plus",
12922
+ children: [
12923
+ (_b2 = (_a4 = item.variant) == null ? void 0 : _a4.product) == null ? void 0 : _b2.title,
12924
+ " (",
12925
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12926
+ ")"
12927
+ ]
12928
+ }
12929
+ ),
12930
+ /* @__PURE__ */ jsxRuntime.jsx(
12931
+ ui.Text,
12932
+ {
12933
+ size: "small",
12934
+ leading: "compact",
12935
+ className: "text-ui-fg-subtle",
12936
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12937
+ }
12938
+ )
12939
+ ] })
12940
+ ] })
12941
+ ]
12942
+ },
12943
+ item.id
12944
+ ),
12945
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12946
+ ] }, item.id);
12947
+ })
12948
+ ] })
12949
+ ]
12950
+ },
12951
+ profile.id
12952
+ );
12953
+ }) })
12954
+ ] }) })
12955
+ ] }) }),
12956
+ /* @__PURE__ */ jsxRuntime.jsx(
12957
+ StackedFocusModal,
12958
+ {
12959
+ id: STACKED_FOCUS_MODAL_ID,
12960
+ onOpenChangeCallback: (open) => {
12961
+ if (!open) {
12962
+ setData(null);
12963
+ }
12964
+ return open;
12965
+ },
12966
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12967
+ }
12968
+ )
12969
+ ] }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12971
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(
12973
+ ui.Button,
12974
+ {
12975
+ size: "small",
12976
+ type: "button",
12977
+ isLoading: isSubmitting,
12978
+ onClick: onSubmit,
12979
+ children: "Save"
12980
+ }
12981
+ )
12982
+ ] }) })
12983
+ ] });
12984
+ };
12985
+ const StackedModalTrigger = ({
12986
+ shippingProfileId,
12987
+ shippingOption,
12988
+ shippingMethod,
12989
+ setData,
12990
+ children
12991
+ }) => {
12992
+ const { setIsOpen, getIsOpen } = useStackedModal();
12993
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12994
+ const onToggle = () => {
12995
+ if (isOpen) {
12996
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12997
+ setData(null);
12998
+ } else {
12999
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
13000
+ setData({
13001
+ shippingProfileId,
13002
+ shippingOption,
13003
+ shippingMethod
13004
+ });
13005
+ }
13006
+ };
13007
+ return /* @__PURE__ */ jsxRuntime.jsx(
13008
+ ui.Button,
13009
+ {
13010
+ size: "small",
13011
+ variant: "secondary",
13012
+ onClick: onToggle,
13013
+ className: "text-ui-fg-primary shrink-0",
13014
+ children
13015
+ }
13016
+ );
13017
+ };
13018
+ const ShippingProfileForm = ({
13019
+ data,
13020
+ order,
13021
+ preview
13022
+ }) => {
13023
+ var _a2, _b, _c, _d, _e, _f;
13024
+ const { setIsOpen } = useStackedModal();
13025
+ const form = reactHookForm.useForm({
13026
+ resolver: zod.zodResolver(shippingMethodSchema),
13027
+ defaultValues: {
13028
+ location_id: (_d = (_c = (_b = (_a2 = data.shippingOption) == null ? void 0 : _a2.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
13029
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
13030
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
13031
+ }
13032
+ });
13033
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
13034
+ const {
13035
+ mutateAsync: updateShippingMethod,
13036
+ isPending: isUpdatingShippingMethod
13037
+ } = useDraftOrderUpdateShippingMethod(order.id);
13038
+ const onSubmit = form.handleSubmit(async (values) => {
13039
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
13040
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
13041
+ return;
13042
+ }
13043
+ if (data.shippingMethod) {
13044
+ await updateShippingMethod(
13045
+ {
13046
+ method_id: data.shippingMethod.id,
13047
+ shipping_option_id: values.shipping_option_id,
13048
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
13049
+ },
13050
+ {
13051
+ onError: (e) => {
13052
+ ui.toast.error(e.message);
13053
+ },
13054
+ onSuccess: () => {
13055
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
13056
+ }
13057
+ }
13058
+ );
13059
+ return;
13060
+ }
13061
+ await addShippingMethod(
13062
+ {
13063
+ shipping_option_id: values.shipping_option_id,
13064
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
13065
+ },
13066
+ {
13067
+ onError: (e) => {
13068
+ ui.toast.error(e.message);
13069
+ },
13070
+ onSuccess: () => {
13071
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
13072
+ }
13073
+ }
13074
+ );
13075
+ });
13076
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13077
+ KeyboundForm,
13078
+ {
13079
+ className: "flex h-full flex-col overflow-hidden",
13080
+ onSubmit,
13081
+ children: [
13082
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
13083
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
13084
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13085
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
13086
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
13087
+ ] }),
13088
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13089
+ /* @__PURE__ */ jsxRuntime.jsx(
13090
+ LocationField,
13314
13091
  {
13315
- width: "12",
13316
- height: "12",
13317
- fill: "white",
13318
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
13092
+ control: form.control,
13093
+ setValue: form.setValue
13319
13094
  }
13320
- ) }),
13321
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13322
- "rect",
13095
+ ),
13096
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13097
+ /* @__PURE__ */ jsxRuntime.jsx(
13098
+ ShippingOptionField,
13323
13099
  {
13324
- width: "12",
13325
- height: "12",
13326
- fill: "white",
13327
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13100
+ shippingProfileId: data.shippingProfileId,
13101
+ preview,
13102
+ control: form.control
13328
13103
  }
13329
- ) }),
13330
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13331
- "rect",
13104
+ ),
13105
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13106
+ /* @__PURE__ */ jsxRuntime.jsx(
13107
+ CustomAmountField,
13332
13108
  {
13333
- width: "12",
13334
- height: "12",
13335
- fill: "white",
13336
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13109
+ control: form.control,
13110
+ currencyCode: order.currency_code
13337
13111
  }
13338
- ) }),
13339
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13340
- "rect",
13112
+ ),
13113
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13114
+ /* @__PURE__ */ jsxRuntime.jsx(
13115
+ ItemsPreview,
13116
+ {
13117
+ order,
13118
+ shippingProfileId: data.shippingProfileId
13119
+ }
13120
+ )
13121
+ ] }) }) }),
13122
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
13123
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13124
+ /* @__PURE__ */ jsxRuntime.jsx(
13125
+ ui.Button,
13126
+ {
13127
+ size: "small",
13128
+ type: "submit",
13129
+ isLoading: isPending || isUpdatingShippingMethod,
13130
+ children: data.shippingMethod ? "Update" : "Add"
13131
+ }
13132
+ )
13133
+ ] }) })
13134
+ ]
13135
+ }
13136
+ ) }) });
13137
+ };
13138
+ const shippingMethodSchema = object({
13139
+ location_id: string(),
13140
+ shipping_option_id: string(),
13141
+ custom_amount: union([number(), string()]).optional()
13142
+ });
13143
+ const ItemsPreview = ({ order, shippingProfileId }) => {
13144
+ const matches = order.items.filter(
13145
+ (item) => {
13146
+ var _a2, _b, _c;
13147
+ return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
13148
+ }
13149
+ );
13150
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
13151
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13152
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
13153
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
13154
+ ] }) }),
13155
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
13156
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
13157
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
13158
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
13159
+ ] }),
13160
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
13161
+ "div",
13162
+ {
13163
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
13164
+ children: [
13165
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
13166
+ /* @__PURE__ */ jsxRuntime.jsx(
13167
+ Thumbnail,
13168
+ {
13169
+ thumbnail: item.thumbnail,
13170
+ alt: item.product_title ?? void 0
13171
+ }
13172
+ ),
13173
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13174
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
13175
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
13176
+ /* @__PURE__ */ jsxRuntime.jsxs(
13177
+ ui.Text,
13178
+ {
13179
+ size: "small",
13180
+ leading: "compact",
13181
+ className: "text-ui-fg-subtle",
13182
+ children: [
13183
+ "(",
13184
+ item.variant_title,
13185
+ ")"
13186
+ ]
13187
+ }
13188
+ )
13189
+ ] }),
13190
+ /* @__PURE__ */ jsxRuntime.jsx(
13191
+ ui.Text,
13192
+ {
13193
+ size: "small",
13194
+ leading: "compact",
13195
+ className: "text-ui-fg-subtle",
13196
+ children: item.variant_sku
13197
+ }
13198
+ )
13199
+ ] })
13200
+ ] }),
13201
+ /* @__PURE__ */ jsxRuntime.jsxs(
13202
+ ui.Text,
13203
+ {
13204
+ size: "small",
13205
+ leading: "compact",
13206
+ className: "text-ui-fg-subtle",
13207
+ children: [
13208
+ item.quantity,
13209
+ "x"
13210
+ ]
13211
+ }
13212
+ )
13213
+ ]
13214
+ },
13215
+ item.id
13216
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
13217
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
13218
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
13219
+ 'No items found for "',
13220
+ query,
13221
+ '".'
13222
+ ] })
13223
+ ] }) })
13224
+ ] })
13225
+ ] });
13226
+ };
13227
+ const LocationField = ({ control, setValue }) => {
13228
+ const locations = useComboboxData({
13229
+ queryKey: ["locations"],
13230
+ queryFn: async (params) => {
13231
+ return await sdk.admin.stockLocation.list(params);
13232
+ },
13233
+ getOptions: (data) => {
13234
+ return data.stock_locations.map((location) => ({
13235
+ label: location.name,
13236
+ value: location.id
13237
+ }));
13238
+ }
13239
+ });
13240
+ return /* @__PURE__ */ jsxRuntime.jsx(
13241
+ Form$2.Field,
13242
+ {
13243
+ control,
13244
+ name: "location_id",
13245
+ render: ({ field: { onChange, ...field } }) => {
13246
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13247
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13248
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
13249
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
13250
+ ] }),
13251
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13252
+ Combobox,
13341
13253
  {
13342
- width: "12",
13343
- height: "12",
13344
- fill: "white",
13345
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13254
+ options: locations.options,
13255
+ fetchNextPage: locations.fetchNextPage,
13256
+ isFetchingNextPage: locations.isFetchingNextPage,
13257
+ searchValue: locations.searchValue,
13258
+ onSearchValueChange: locations.onSearchValueChange,
13259
+ placeholder: "Select location",
13260
+ onChange: (value) => {
13261
+ setValue("shipping_option_id", "", {
13262
+ shouldDirty: true,
13263
+ shouldTouch: true
13264
+ });
13265
+ onChange(value);
13266
+ },
13267
+ ...field
13346
13268
  }
13347
- ) }),
13348
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13349
- "rect",
13269
+ ) })
13270
+ ] }) });
13271
+ }
13272
+ }
13273
+ );
13274
+ };
13275
+ const ShippingOptionField = ({
13276
+ shippingProfileId,
13277
+ preview,
13278
+ control
13279
+ }) => {
13280
+ var _a2;
13281
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
13282
+ const shippingOptions = useComboboxData({
13283
+ queryKey: ["shipping_options", locationId, shippingProfileId],
13284
+ queryFn: async (params) => {
13285
+ return await sdk.admin.shippingOption.list({
13286
+ ...params,
13287
+ stock_location_id: locationId,
13288
+ shipping_profile_id: shippingProfileId
13289
+ });
13290
+ },
13291
+ getOptions: (data) => {
13292
+ return data.shipping_options.map((option) => {
13293
+ var _a3;
13294
+ if ((_a3 = option.rules) == null ? void 0 : _a3.find(
13295
+ (r) => r.attribute === "is_return" && r.value === "true"
13296
+ )) {
13297
+ return void 0;
13298
+ }
13299
+ return {
13300
+ label: option.name,
13301
+ value: option.id
13302
+ };
13303
+ }).filter(Boolean);
13304
+ },
13305
+ enabled: !!locationId && !!shippingProfileId,
13306
+ defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
13307
+ });
13308
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
13309
+ return /* @__PURE__ */ jsxRuntime.jsx(
13310
+ Form$2.Field,
13311
+ {
13312
+ control,
13313
+ name: "shipping_option_id",
13314
+ render: ({ field }) => {
13315
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13316
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13317
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
13318
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
13319
+ ] }),
13320
+ /* @__PURE__ */ jsxRuntime.jsx(
13321
+ ConditionalTooltip,
13350
13322
  {
13351
- width: "12",
13352
- height: "12",
13353
- fill: "white",
13354
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13323
+ content: tooltipContent,
13324
+ showTooltip: !locationId || !shippingProfileId,
13325
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13326
+ Combobox,
13327
+ {
13328
+ options: shippingOptions.options,
13329
+ fetchNextPage: shippingOptions.fetchNextPage,
13330
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
13331
+ searchValue: shippingOptions.searchValue,
13332
+ onSearchValueChange: shippingOptions.onSearchValueChange,
13333
+ placeholder: "Select shipping option",
13334
+ ...field,
13335
+ disabled: !locationId || !shippingProfileId
13336
+ }
13337
+ ) }) })
13355
13338
  }
13356
- ) }),
13357
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13358
- "rect",
13339
+ )
13340
+ ] }) });
13341
+ }
13342
+ }
13343
+ );
13344
+ };
13345
+ const CustomAmountField = ({
13346
+ control,
13347
+ currencyCode
13348
+ }) => {
13349
+ return /* @__PURE__ */ jsxRuntime.jsx(
13350
+ Form$2.Field,
13351
+ {
13352
+ control,
13353
+ name: "custom_amount",
13354
+ render: ({ field: { onChange, ...field } }) => {
13355
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13356
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13357
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13358
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13359
+ ] }),
13360
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13361
+ ui.CurrencyInput,
13359
13362
  {
13360
- width: "12",
13361
- height: "12",
13362
- fill: "white",
13363
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13363
+ ...field,
13364
+ onValueChange: (value) => onChange(value),
13365
+ symbol: getNativeSymbol(currencyCode),
13366
+ code: currencyCode
13364
13367
  }
13365
13368
  ) })
13366
- ] })
13367
- ]
13369
+ ] });
13370
+ }
13368
13371
  }
13369
13372
  );
13370
13373
  };
13371
- const schema = object({
13372
- customer_id: string().min(1)
13373
- });
13374
13374
  const widgetModule = { widgets: [] };
13375
13375
  const routeModule = {
13376
13376
  routes: [
@@ -13392,29 +13392,29 @@ const routeModule = {
13392
13392
  loader,
13393
13393
  children: [
13394
13394
  {
13395
- Component: BillingAddress,
13396
- path: "/draft-orders/:id/billing-address"
13395
+ Component: Email,
13396
+ path: "/draft-orders/:id/email"
13397
13397
  },
13398
13398
  {
13399
13399
  Component: CustomItems,
13400
13400
  path: "/draft-orders/:id/custom-items"
13401
13401
  },
13402
- {
13403
- Component: Email,
13404
- path: "/draft-orders/:id/email"
13405
- },
13406
13402
  {
13407
13403
  Component: Items,
13408
13404
  path: "/draft-orders/:id/items"
13409
13405
  },
13410
13406
  {
13411
- Component: Metadata,
13412
- path: "/draft-orders/:id/metadata"
13407
+ Component: BillingAddress,
13408
+ path: "/draft-orders/:id/billing-address"
13413
13409
  },
13414
13410
  {
13415
13411
  Component: Promotions,
13416
13412
  path: "/draft-orders/:id/promotions"
13417
13413
  },
13414
+ {
13415
+ Component: Metadata,
13416
+ path: "/draft-orders/:id/metadata"
13417
+ },
13418
13418
  {
13419
13419
  Component: SalesChannel,
13420
13420
  path: "/draft-orders/:id/sales-channel"
@@ -13423,13 +13423,13 @@ const routeModule = {
13423
13423
  Component: ShippingAddress,
13424
13424
  path: "/draft-orders/:id/shipping-address"
13425
13425
  },
13426
- {
13427
- Component: Shipping,
13428
- path: "/draft-orders/:id/shipping"
13429
- },
13430
13426
  {
13431
13427
  Component: TransferOwnership,
13432
13428
  path: "/draft-orders/:id/transfer-ownership"
13429
+ },
13430
+ {
13431
+ Component: Shipping,
13432
+ path: "/draft-orders/:id/shipping"
13433
13433
  }
13434
13434
  ]
13435
13435
  }