@medusajs/draft-order 2.12.0 → 2.12.1

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.
@@ -9762,6 +9762,95 @@ const BillingAddressForm = ({ order }) => {
9762
9762
  ) });
9763
9763
  };
9764
9764
  const schema$5 = addressSchema;
9765
+ const CustomItems = () => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
+ ] });
9770
+ };
9771
+ const CustomItemsForm = () => {
9772
+ const form = reactHookForm.useForm({
9773
+ resolver: zod.zodResolver(schema$4)
9774
+ });
9775
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
+ ] }) })
9781
+ ] }) });
9782
+ };
9783
+ const schema$4 = objectType({
9784
+ email: stringType().email()
9785
+ });
9786
+ const Email = () => {
9787
+ const { id } = reactRouterDom.useParams();
9788
+ const { order, isPending, isError, error } = useOrder(id, {
9789
+ fields: "+email"
9790
+ });
9791
+ if (isError) {
9792
+ throw error;
9793
+ }
9794
+ const isReady = !isPending && !!order;
9795
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9796
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9799
+ ] }),
9800
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9801
+ ] });
9802
+ };
9803
+ const EmailForm = ({ order }) => {
9804
+ const form = reactHookForm.useForm({
9805
+ defaultValues: {
9806
+ email: order.email ?? ""
9807
+ },
9808
+ resolver: zod.zodResolver(schema$3)
9809
+ });
9810
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
+ const { handleSuccess } = useRouteModal();
9812
+ const onSubmit = form.handleSubmit(async (data) => {
9813
+ await mutateAsync(
9814
+ { email: data.email },
9815
+ {
9816
+ onSuccess: () => {
9817
+ handleSuccess();
9818
+ },
9819
+ onError: (error) => {
9820
+ ui.toast.error(error.message);
9821
+ }
9822
+ }
9823
+ );
9824
+ });
9825
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9826
+ KeyboundForm,
9827
+ {
9828
+ className: "flex flex-1 flex-col overflow-hidden",
9829
+ onSubmit,
9830
+ children: [
9831
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9832
+ Form$2.Field,
9833
+ {
9834
+ control: form.control,
9835
+ name: "email",
9836
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
+ ] })
9841
+ }
9842
+ ) }),
9843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9845
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9846
+ ] }) })
9847
+ ]
9848
+ }
9849
+ ) });
9850
+ };
9851
+ const schema$3 = objectType({
9852
+ email: stringType().email()
9853
+ });
9765
9854
  const NumberInput = React.forwardRef(
9766
9855
  ({
9767
9856
  value,
@@ -11013,114 +11102,88 @@ function getPromotionIds(items, shippingMethods) {
11013
11102
  }
11014
11103
  return Array.from(promotionIds);
11015
11104
  }
11016
- const Email = () => {
11017
- const { id } = reactRouterDom.useParams();
11018
- const { order, isPending, isError, error } = useOrder(id, {
11019
- fields: "+email"
11020
- });
11021
- if (isError) {
11022
- throw error;
11023
- }
11024
- const isReady = !isPending && !!order;
11025
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11026
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11027
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
11028
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11029
- ] }),
11030
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
11031
- ] });
11032
- };
11033
- const EmailForm = ({ order }) => {
11034
- const form = reactHookForm.useForm({
11035
- defaultValues: {
11036
- email: order.email ?? ""
11037
- },
11038
- resolver: zod.zodResolver(schema$4)
11039
- });
11040
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11041
- const { handleSuccess } = useRouteModal();
11042
- const onSubmit = form.handleSubmit(async (data) => {
11043
- await mutateAsync(
11044
- { email: data.email },
11105
+ const InlineTip = React.forwardRef(
11106
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11107
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11108
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11109
+ "div",
11045
11110
  {
11046
- onSuccess: () => {
11047
- handleSuccess();
11048
- },
11049
- onError: (error) => {
11050
- ui.toast.error(error.message);
11051
- }
11111
+ ref,
11112
+ className: ui.clx(
11113
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11114
+ className
11115
+ ),
11116
+ ...props,
11117
+ children: [
11118
+ /* @__PURE__ */ jsxRuntime.jsx(
11119
+ "div",
11120
+ {
11121
+ role: "presentation",
11122
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11123
+ "bg-ui-tag-orange-icon": variant === "warning"
11124
+ })
11125
+ }
11126
+ ),
11127
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11128
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11129
+ labelValue,
11130
+ ":"
11131
+ ] }),
11132
+ " ",
11133
+ children
11134
+ ] })
11135
+ ]
11052
11136
  }
11053
11137
  );
11054
- });
11055
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11056
- KeyboundForm,
11057
- {
11058
- className: "flex flex-1 flex-col overflow-hidden",
11059
- onSubmit,
11060
- children: [
11061
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
11062
- Form$2.Field,
11063
- {
11064
- control: form.control,
11065
- name: "email",
11066
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11067
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
11068
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11069
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11070
- ] })
11071
- }
11072
- ) }),
11073
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11074
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11075
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
- ] }) })
11077
- ]
11078
- }
11079
- ) });
11080
- };
11081
- const schema$4 = objectType({
11082
- email: stringType().email()
11138
+ }
11139
+ );
11140
+ InlineTip.displayName = "InlineTip";
11141
+ const MetadataFieldSchema = objectType({
11142
+ key: stringType(),
11143
+ disabled: booleanType().optional(),
11144
+ value: anyType()
11083
11145
  });
11084
- const SalesChannel = () => {
11146
+ const MetadataSchema = objectType({
11147
+ metadata: arrayType(MetadataFieldSchema)
11148
+ });
11149
+ const Metadata = () => {
11085
11150
  const { id } = reactRouterDom.useParams();
11086
- const { draft_order, isPending, isError, error } = useDraftOrder(
11087
- id,
11088
- {
11089
- fields: "+sales_channel_id"
11090
- },
11091
- {
11092
- enabled: !!id
11093
- }
11094
- );
11151
+ const { order, isPending, isError, error } = useOrder(id, {
11152
+ fields: "metadata"
11153
+ });
11095
11154
  if (isError) {
11096
11155
  throw error;
11097
11156
  }
11098
- const ISrEADY = !!draft_order && !isPending;
11157
+ const isReady = !isPending && !!order;
11099
11158
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11100
11159
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11101
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11102
- /* @__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" }) })
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11161
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11103
11162
  ] }),
11104
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11163
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11105
11164
  ] });
11106
11165
  };
11107
- const SalesChannelForm = ({ order }) => {
11166
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11167
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11168
+ const MetadataForm = ({ orderId, metadata }) => {
11169
+ const { handleSuccess } = useRouteModal();
11170
+ const hasUneditableRows = getHasUneditableRows(metadata);
11171
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11108
11172
  const form = reactHookForm.useForm({
11109
11173
  defaultValues: {
11110
- sales_channel_id: order.sales_channel_id || ""
11174
+ metadata: getDefaultValues(metadata)
11111
11175
  },
11112
- resolver: zod.zodResolver(schema$3)
11176
+ resolver: zod.zodResolver(MetadataSchema)
11113
11177
  });
11114
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11115
- const { handleSuccess } = useRouteModal();
11116
- const onSubmit = form.handleSubmit(async (data) => {
11178
+ const handleSubmit = form.handleSubmit(async (data) => {
11179
+ const parsedData = parseValues(data);
11117
11180
  await mutateAsync(
11118
11181
  {
11119
- sales_channel_id: data.sales_channel_id
11182
+ metadata: parsedData
11120
11183
  },
11121
11184
  {
11122
11185
  onSuccess: () => {
11123
- ui.toast.success("Sales channel updated");
11186
+ ui.toast.success("Metadata updated");
11124
11187
  handleSuccess();
11125
11188
  },
11126
11189
  onError: (error) => {
@@ -11129,258 +11192,321 @@ const SalesChannelForm = ({ order }) => {
11129
11192
  }
11130
11193
  );
11131
11194
  });
11195
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11196
+ control: form.control,
11197
+ name: "metadata"
11198
+ });
11199
+ function deleteRow(index) {
11200
+ remove(index);
11201
+ if (fields.length === 1) {
11202
+ insert(0, {
11203
+ key: "",
11204
+ value: "",
11205
+ disabled: false
11206
+ });
11207
+ }
11208
+ }
11209
+ function insertRow(index, position) {
11210
+ insert(index + (position === "above" ? 0 : 1), {
11211
+ key: "",
11212
+ value: "",
11213
+ disabled: false
11214
+ });
11215
+ }
11132
11216
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11133
11217
  KeyboundForm,
11134
11218
  {
11219
+ onSubmit: handleSubmit,
11135
11220
  className: "flex flex-1 flex-col overflow-hidden",
11136
- onSubmit,
11137
11221
  children: [
11138
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11139
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11140
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11222
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11224
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11225
+ /* @__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" }) }),
11226
+ /* @__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" }) })
11227
+ ] }),
11228
+ fields.map((field, index) => {
11229
+ const isDisabled = field.disabled || false;
11230
+ let placeholder = "-";
11231
+ if (typeof field.value === "object") {
11232
+ placeholder = "{ ... }";
11233
+ }
11234
+ if (Array.isArray(field.value)) {
11235
+ placeholder = "[ ... ]";
11236
+ }
11237
+ return /* @__PURE__ */ jsxRuntime.jsx(
11238
+ ConditionalTooltip,
11239
+ {
11240
+ showTooltip: isDisabled,
11241
+ content: "This row is disabled because it contains non-primitive data.",
11242
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11243
+ /* @__PURE__ */ jsxRuntime.jsxs(
11244
+ "div",
11245
+ {
11246
+ className: ui.clx("grid grid-cols-2 divide-x", {
11247
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11248
+ }),
11249
+ children: [
11250
+ /* @__PURE__ */ jsxRuntime.jsx(
11251
+ Form$2.Field,
11252
+ {
11253
+ control: form.control,
11254
+ name: `metadata.${index}.key`,
11255
+ render: ({ field: field2 }) => {
11256
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11257
+ GridInput,
11258
+ {
11259
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11260
+ ...field2,
11261
+ disabled: isDisabled,
11262
+ placeholder: "Key"
11263
+ }
11264
+ ) }) });
11265
+ }
11266
+ }
11267
+ ),
11268
+ /* @__PURE__ */ jsxRuntime.jsx(
11269
+ Form$2.Field,
11270
+ {
11271
+ control: form.control,
11272
+ name: `metadata.${index}.value`,
11273
+ render: ({ field: { value, ...field2 } }) => {
11274
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11275
+ GridInput,
11276
+ {
11277
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11278
+ ...field2,
11279
+ value: isDisabled ? placeholder : value,
11280
+ disabled: isDisabled,
11281
+ placeholder: "Value"
11282
+ }
11283
+ ) }) });
11284
+ }
11285
+ }
11286
+ )
11287
+ ]
11288
+ }
11289
+ ),
11290
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11291
+ /* @__PURE__ */ jsxRuntime.jsx(
11292
+ ui.DropdownMenu.Trigger,
11293
+ {
11294
+ className: ui.clx(
11295
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11296
+ {
11297
+ hidden: isDisabled
11298
+ }
11299
+ ),
11300
+ disabled: isDisabled,
11301
+ asChild: true,
11302
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11303
+ }
11304
+ ),
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsxs(
11307
+ ui.DropdownMenu.Item,
11308
+ {
11309
+ className: "gap-x-2",
11310
+ onClick: () => insertRow(index, "above"),
11311
+ children: [
11312
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11313
+ "Insert row above"
11314
+ ]
11315
+ }
11316
+ ),
11317
+ /* @__PURE__ */ jsxRuntime.jsxs(
11318
+ ui.DropdownMenu.Item,
11319
+ {
11320
+ className: "gap-x-2",
11321
+ onClick: () => insertRow(index, "below"),
11322
+ children: [
11323
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11324
+ "Insert row below"
11325
+ ]
11326
+ }
11327
+ ),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11329
+ /* @__PURE__ */ jsxRuntime.jsxs(
11330
+ ui.DropdownMenu.Item,
11331
+ {
11332
+ className: "gap-x-2",
11333
+ onClick: () => deleteRow(index),
11334
+ children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11336
+ "Delete row"
11337
+ ]
11338
+ }
11339
+ )
11340
+ ] })
11341
+ ] })
11342
+ ] })
11343
+ },
11344
+ field.id
11345
+ );
11346
+ })
11347
+ ] }),
11348
+ 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." })
11349
+ ] }),
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11351
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11141
11352
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11142
11353
  ] }) })
11143
11354
  ]
11144
11355
  }
11145
11356
  ) });
11146
11357
  };
11147
- const SalesChannelField = ({ control, order }) => {
11148
- const salesChannels = useComboboxData({
11149
- queryFn: async (params) => {
11150
- return await sdk.admin.salesChannel.list(params);
11151
- },
11152
- queryKey: ["sales-channels"],
11153
- getOptions: (data) => {
11154
- return data.sales_channels.map((salesChannel) => ({
11155
- label: salesChannel.name,
11156
- value: salesChannel.id
11157
- }));
11158
- },
11159
- defaultValue: order.sales_channel_id || void 0
11160
- });
11358
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11161
11359
  return /* @__PURE__ */ jsxRuntime.jsx(
11162
- Form$2.Field,
11360
+ "input",
11163
11361
  {
11164
- control,
11165
- name: "sales_channel_id",
11166
- render: ({ field }) => {
11167
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11168
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11169
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11170
- Combobox,
11171
- {
11172
- options: salesChannels.options,
11173
- fetchNextPage: salesChannels.fetchNextPage,
11174
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11175
- searchValue: salesChannels.searchValue,
11176
- onSearchValueChange: salesChannels.onSearchValueChange,
11177
- placeholder: "Select sales channel",
11178
- ...field
11179
- }
11180
- ) }),
11181
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11182
- ] });
11183
- }
11362
+ ref,
11363
+ ...props,
11364
+ autoComplete: "off",
11365
+ className: ui.clx(
11366
+ "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",
11367
+ className
11368
+ )
11184
11369
  }
11185
11370
  );
11186
- };
11187
- const schema$3 = objectType({
11188
- sales_channel_id: stringType().min(1)
11189
11371
  });
11190
- const ShippingAddress = () => {
11191
- const { id } = reactRouterDom.useParams();
11192
- const { order, isPending, isError, error } = useOrder(id, {
11193
- fields: "+shipping_address"
11194
- });
11195
- if (isError) {
11196
- throw error;
11197
- }
11198
- const isReady = !isPending && !!order;
11199
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11200
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11201
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11202
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11203
- ] }),
11204
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11372
+ GridInput.displayName = "MetadataForm.GridInput";
11373
+ const PlaceholderInner = () => {
11374
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11376
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11378
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11379
+ ] }) })
11205
11380
  ] });
11206
11381
  };
11207
- const ShippingAddressForm = ({ order }) => {
11208
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11209
- const form = reactHookForm.useForm({
11210
- defaultValues: {
11211
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11212
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11213
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11214
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11215
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11216
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11217
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11218
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11219
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11220
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11221
- },
11222
- resolver: zod.zodResolver(schema$2)
11223
- });
11224
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11225
- const { handleSuccess } = useRouteModal();
11226
- const onSubmit = form.handleSubmit(async (data) => {
11227
- await mutateAsync(
11228
- {
11229
- shipping_address: {
11230
- first_name: data.first_name,
11231
- last_name: data.last_name,
11232
- company: data.company,
11233
- address_1: data.address_1,
11234
- address_2: data.address_2,
11235
- city: data.city,
11236
- province: data.province,
11237
- country_code: data.country_code,
11238
- postal_code: data.postal_code,
11239
- phone: data.phone
11240
- }
11241
- },
11382
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11383
+ function getDefaultValues(metadata) {
11384
+ if (!metadata || !Object.keys(metadata).length) {
11385
+ return [
11242
11386
  {
11243
- onSuccess: () => {
11244
- handleSuccess();
11245
- },
11246
- onError: (error) => {
11247
- ui.toast.error(error.message);
11248
- }
11387
+ key: "",
11388
+ value: "",
11389
+ disabled: false
11249
11390
  }
11250
- );
11251
- });
11252
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11391
+ ];
11392
+ }
11393
+ return Object.entries(metadata).map(([key, value]) => {
11394
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11395
+ return {
11396
+ key,
11397
+ value,
11398
+ disabled: true
11399
+ };
11400
+ }
11401
+ let stringValue = value;
11402
+ if (typeof value !== "string") {
11403
+ stringValue = JSON.stringify(value);
11404
+ }
11405
+ return {
11406
+ key,
11407
+ value: stringValue,
11408
+ original_key: key
11409
+ };
11410
+ });
11411
+ }
11412
+ function parseValues(values) {
11413
+ const metadata = values.metadata;
11414
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11415
+ if (isEmpty) {
11416
+ return null;
11417
+ }
11418
+ const update = {};
11419
+ metadata.forEach((field) => {
11420
+ let key = field.key;
11421
+ let value = field.value;
11422
+ const disabled = field.disabled;
11423
+ if (!key || !value) {
11424
+ return;
11425
+ }
11426
+ if (disabled) {
11427
+ update[key] = value;
11428
+ return;
11429
+ }
11430
+ key = key.trim();
11431
+ value = value.trim();
11432
+ if (value === "true") {
11433
+ update[key] = true;
11434
+ } else if (value === "false") {
11435
+ update[key] = false;
11436
+ } else {
11437
+ const parsedNumber = parseFloat(value);
11438
+ if (!isNaN(parsedNumber)) {
11439
+ update[key] = parsedNumber;
11440
+ } else {
11441
+ update[key] = value;
11442
+ }
11443
+ }
11444
+ });
11445
+ return update;
11446
+ }
11447
+ function getHasUneditableRows(metadata) {
11448
+ if (!metadata) {
11449
+ return false;
11450
+ }
11451
+ return Object.values(metadata).some(
11452
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11453
+ );
11454
+ }
11455
+ const SalesChannel = () => {
11456
+ const { id } = reactRouterDom.useParams();
11457
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11458
+ id,
11459
+ {
11460
+ fields: "+sales_channel_id"
11461
+ },
11462
+ {
11463
+ enabled: !!id
11464
+ }
11465
+ );
11466
+ if (isError) {
11467
+ throw error;
11468
+ }
11469
+ const ISrEADY = !!draft_order && !isPending;
11470
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
+ /* @__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" }) })
11474
+ ] }),
11475
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
+ ] });
11477
+ };
11478
+ const SalesChannelForm = ({ order }) => {
11479
+ const form = reactHookForm.useForm({
11480
+ defaultValues: {
11481
+ sales_channel_id: order.sales_channel_id || ""
11482
+ },
11483
+ resolver: zod.zodResolver(schema$2)
11484
+ });
11485
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
+ const { handleSuccess } = useRouteModal();
11487
+ const onSubmit = form.handleSubmit(async (data) => {
11488
+ await mutateAsync(
11489
+ {
11490
+ sales_channel_id: data.sales_channel_id
11491
+ },
11492
+ {
11493
+ onSuccess: () => {
11494
+ ui.toast.success("Sales channel updated");
11495
+ handleSuccess();
11496
+ },
11497
+ onError: (error) => {
11498
+ ui.toast.error(error.message);
11499
+ }
11500
+ }
11501
+ );
11502
+ });
11503
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11253
11504
  KeyboundForm,
11254
11505
  {
11255
11506
  className: "flex flex-1 flex-col overflow-hidden",
11256
11507
  onSubmit,
11257
11508
  children: [
11258
- /* @__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: [
11259
- /* @__PURE__ */ jsxRuntime.jsx(
11260
- Form$2.Field,
11261
- {
11262
- control: form.control,
11263
- name: "country_code",
11264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11268
- ] })
11269
- }
11270
- ),
11271
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11272
- /* @__PURE__ */ jsxRuntime.jsx(
11273
- Form$2.Field,
11274
- {
11275
- control: form.control,
11276
- name: "first_name",
11277
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11281
- ] })
11282
- }
11283
- ),
11284
- /* @__PURE__ */ jsxRuntime.jsx(
11285
- Form$2.Field,
11286
- {
11287
- control: form.control,
11288
- name: "last_name",
11289
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11290
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11293
- ] })
11294
- }
11295
- )
11296
- ] }),
11297
- /* @__PURE__ */ jsxRuntime.jsx(
11298
- Form$2.Field,
11299
- {
11300
- control: form.control,
11301
- name: "company",
11302
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11305
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11306
- ] })
11307
- }
11308
- ),
11309
- /* @__PURE__ */ jsxRuntime.jsx(
11310
- Form$2.Field,
11311
- {
11312
- control: form.control,
11313
- name: "address_1",
11314
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11318
- ] })
11319
- }
11320
- ),
11321
- /* @__PURE__ */ jsxRuntime.jsx(
11322
- Form$2.Field,
11323
- {
11324
- control: form.control,
11325
- name: "address_2",
11326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
- ] })
11331
- }
11332
- ),
11333
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11334
- /* @__PURE__ */ jsxRuntime.jsx(
11335
- Form$2.Field,
11336
- {
11337
- control: form.control,
11338
- name: "postal_code",
11339
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
- ] })
11344
- }
11345
- ),
11346
- /* @__PURE__ */ jsxRuntime.jsx(
11347
- Form$2.Field,
11348
- {
11349
- control: form.control,
11350
- name: "city",
11351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
- ] })
11356
- }
11357
- )
11358
- ] }),
11359
- /* @__PURE__ */ jsxRuntime.jsx(
11360
- Form$2.Field,
11361
- {
11362
- control: form.control,
11363
- name: "province",
11364
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
- ] })
11369
- }
11370
- ),
11371
- /* @__PURE__ */ jsxRuntime.jsx(
11372
- Form$2.Field,
11373
- {
11374
- control: form.control,
11375
- name: "phone",
11376
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
- ] })
11381
- }
11382
- )
11383
- ] }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11384
11510
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11385
11511
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11386
11512
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11389,1293 +11515,157 @@ const ShippingAddressForm = ({ order }) => {
11389
11515
  }
11390
11516
  ) });
11391
11517
  };
11392
- const schema$2 = addressSchema;
11393
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11394
- const Shipping = () => {
11395
- var _a;
11396
- const { id } = reactRouterDom.useParams();
11397
- const { order, isPending, isError, error } = useOrder(id, {
11398
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11399
- });
11400
- const {
11401
- order: preview,
11402
- isPending: isPreviewPending,
11403
- isError: isPreviewError,
11404
- error: previewError
11405
- } = useOrderPreview(id);
11406
- useInitiateOrderEdit({ preview });
11407
- const { onCancel } = useCancelOrderEdit({ preview });
11408
- if (isError) {
11409
- throw error;
11410
- }
11411
- if (isPreviewError) {
11412
- throw previewError;
11413
- }
11414
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11415
- const isReady = preview && !isPreviewPending && order && !isPending;
11416
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11417
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11418
- /* @__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: [
11419
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11420
- /* @__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." }) })
11421
- ] }) }) }),
11422
- /* @__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" }) }) })
11423
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11424
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11425
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11426
- ] }) });
11427
- };
11428
- const ShippingForm = ({ preview, order }) => {
11429
- var _a;
11430
- const { setIsOpen } = useStackedModal();
11431
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11432
- const [data, setData] = React.useState(null);
11433
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11434
- const { shipping_options } = useShippingOptions(
11435
- {
11436
- id: appliedShippingOptionIds,
11437
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11518
+ const SalesChannelField = ({ control, order }) => {
11519
+ const salesChannels = useComboboxData({
11520
+ queryFn: async (params) => {
11521
+ return await sdk.admin.salesChannel.list(params);
11522
+ },
11523
+ queryKey: ["sales-channels"],
11524
+ getOptions: (data) => {
11525
+ return data.sales_channels.map((salesChannel) => ({
11526
+ label: salesChannel.name,
11527
+ value: salesChannel.id
11528
+ }));
11438
11529
  },
11530
+ defaultValue: order.sales_channel_id || void 0
11531
+ });
11532
+ return /* @__PURE__ */ jsxRuntime.jsx(
11533
+ Form$2.Field,
11439
11534
  {
11440
- enabled: appliedShippingOptionIds.length > 0
11535
+ control,
11536
+ name: "sales_channel_id",
11537
+ render: ({ field }) => {
11538
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11541
+ Combobox,
11542
+ {
11543
+ options: salesChannels.options,
11544
+ fetchNextPage: salesChannels.fetchNextPage,
11545
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
+ searchValue: salesChannels.searchValue,
11547
+ onSearchValueChange: salesChannels.onSearchValueChange,
11548
+ placeholder: "Select sales channel",
11549
+ ...field
11550
+ }
11551
+ ) }),
11552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
+ ] });
11554
+ }
11441
11555
  }
11442
11556
  );
11443
- const uniqueShippingProfiles = React.useMemo(() => {
11444
- const profiles = /* @__PURE__ */ new Map();
11445
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11446
- profiles.set(profile.id, profile);
11447
- });
11448
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11449
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11450
- });
11451
- return Array.from(profiles.values());
11452
- }, [order.items, shipping_options]);
11557
+ };
11558
+ const schema$2 = objectType({
11559
+ sales_channel_id: stringType().min(1)
11560
+ });
11561
+ const TransferOwnership = () => {
11562
+ const { id } = reactRouterDom.useParams();
11563
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11564
+ fields: "id,customer_id,customer.*"
11565
+ });
11566
+ if (isError) {
11567
+ throw error;
11568
+ }
11569
+ const isReady = !isPending && !!draft_order;
11570
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11573
+ /* @__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" }) })
11574
+ ] }),
11575
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11576
+ ] });
11577
+ };
11578
+ const TransferOwnershipForm = ({ order }) => {
11579
+ var _a, _b;
11580
+ const form = reactHookForm.useForm({
11581
+ defaultValues: {
11582
+ customer_id: order.customer_id || ""
11583
+ },
11584
+ resolver: zod.zodResolver(schema$1)
11585
+ });
11586
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11453
11587
  const { handleSuccess } = useRouteModal();
11454
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11455
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11456
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11457
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11458
- const onSubmit = async () => {
11459
- setIsSubmitting(true);
11460
- let requestSucceeded = false;
11461
- await requestOrderEdit(void 0, {
11462
- onError: (e) => {
11463
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11464
- },
11465
- onSuccess: () => {
11466
- requestSucceeded = true;
11467
- }
11468
- });
11469
- if (!requestSucceeded) {
11470
- setIsSubmitting(false);
11471
- return;
11472
- }
11473
- await confirmOrderEdit(void 0, {
11474
- onError: (e) => {
11475
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11476
- },
11477
- onSuccess: () => {
11478
- handleSuccess();
11479
- },
11480
- onSettled: () => {
11481
- setIsSubmitting(false);
11482
- }
11483
- });
11484
- };
11485
- const onKeydown = React.useCallback(
11486
- (e) => {
11487
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11488
- if (data || isSubmitting) {
11489
- return;
11588
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11589
+ const currentCustomer = order.customer ? {
11590
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11591
+ value: order.customer.id
11592
+ } : null;
11593
+ const onSubmit = form.handleSubmit(async (data) => {
11594
+ await mutateAsync(
11595
+ { customer_id: data.customer_id },
11596
+ {
11597
+ onSuccess: () => {
11598
+ ui.toast.success("Customer updated");
11599
+ handleSuccess();
11600
+ },
11601
+ onError: (error) => {
11602
+ ui.toast.error(error.message);
11490
11603
  }
11491
- onSubmit();
11492
11604
  }
11605
+ );
11606
+ });
11607
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11608
+ KeyboundForm,
11609
+ {
11610
+ className: "flex flex-1 flex-col overflow-hidden",
11611
+ onSubmit,
11612
+ children: [
11613
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11614
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11615
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11616
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11617
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11618
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11619
+ ] }),
11620
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11621
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11622
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11623
+ ] })
11624
+ ] }),
11625
+ /* @__PURE__ */ jsxRuntime.jsx(
11626
+ CustomerField,
11627
+ {
11628
+ control: form.control,
11629
+ currentCustomerId: order.customer_id
11630
+ }
11631
+ )
11632
+ ] }),
11633
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11634
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11635
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11636
+ ] }) })
11637
+ ]
11638
+ }
11639
+ ) });
11640
+ };
11641
+ const CustomerField = ({ control, currentCustomerId }) => {
11642
+ const customers = useComboboxData({
11643
+ queryFn: async (params) => {
11644
+ return await sdk.admin.customer.list({
11645
+ ...params,
11646
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11647
+ });
11493
11648
  },
11494
- [data, isSubmitting, onSubmit]
11495
- );
11496
- React.useEffect(() => {
11497
- document.addEventListener("keydown", onKeydown);
11498
- return () => {
11499
- document.removeEventListener("keydown", onKeydown);
11500
- };
11501
- }, [onKeydown]);
11502
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11503
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11504
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11505
- /* @__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: [
11506
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11507
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11508
- /* @__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." }) })
11509
- ] }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11511
- /* @__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: [
11512
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11513
- /* @__PURE__ */ jsxRuntime.jsx(
11514
- ui.Text,
11515
- {
11516
- size: "xsmall",
11517
- weight: "plus",
11518
- className: "text-ui-fg-muted",
11519
- children: "Shipping profile"
11520
- }
11521
- ),
11522
- /* @__PURE__ */ jsxRuntime.jsx(
11523
- ui.Text,
11524
- {
11525
- size: "xsmall",
11526
- weight: "plus",
11527
- className: "text-ui-fg-muted",
11528
- children: "Action"
11529
- }
11530
- )
11531
- ] }),
11532
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11533
- var _a2, _b, _c, _d, _e, _f, _g;
11534
- const items = getItemsWithShippingProfile(
11535
- profile.id,
11536
- order.items
11537
- );
11538
- const hasItems = items.length > 0;
11539
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11540
- (option) => option.shipping_profile_id === profile.id
11541
- );
11542
- const shippingMethod = preview.shipping_methods.find(
11543
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11544
- );
11545
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11546
- (action) => action.action === "SHIPPING_ADD"
11547
- );
11548
- return /* @__PURE__ */ jsxRuntime.jsxs(
11549
- radixUi.Accordion.Item,
11550
- {
11551
- value: profile.id,
11552
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11553
- children: [
11554
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11555
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11556
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11557
- ui.IconButton,
11558
- {
11559
- size: "2xsmall",
11560
- variant: "transparent",
11561
- className: "group/trigger",
11562
- disabled: !hasItems,
11563
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11564
- }
11565
- ) }),
11566
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11567
- /* @__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" }) }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11569
- /* @__PURE__ */ jsxRuntime.jsx(
11570
- ui.Text,
11571
- {
11572
- size: "small",
11573
- weight: "plus",
11574
- leading: "compact",
11575
- children: profile.name
11576
- }
11577
- ),
11578
- /* @__PURE__ */ jsxRuntime.jsxs(
11579
- ui.Text,
11580
- {
11581
- size: "small",
11582
- leading: "compact",
11583
- className: "text-ui-fg-subtle",
11584
- children: [
11585
- items.length,
11586
- " ",
11587
- pluralize(items.length, "items", "item")
11588
- ]
11589
- }
11590
- )
11591
- ] })
11592
- ] }) : /* @__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: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(
11594
- ui.Tooltip,
11595
- {
11596
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11597
- var _a3, _b2, _c2;
11598
- return /* @__PURE__ */ jsxRuntime.jsx(
11599
- "li",
11600
- {
11601
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11602
- },
11603
- item.id
11604
- );
11605
- }) }),
11606
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11607
- ui.Badge,
11608
- {
11609
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11610
- size: "xsmall",
11611
- children: [
11612
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11613
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11614
- items.reduce(
11615
- (acc, item) => acc + item.quantity,
11616
- 0
11617
- ),
11618
- "x",
11619
- " ",
11620
- pluralize(items.length, "items", "item")
11621
- ] })
11622
- ]
11623
- }
11624
- )
11625
- }
11626
- ),
11627
- /* @__PURE__ */ jsxRuntime.jsx(
11628
- ui.Tooltip,
11629
- {
11630
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11631
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11632
- ui.Badge,
11633
- {
11634
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11635
- size: "xsmall",
11636
- children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11638
- /* @__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 })
11639
- ]
11640
- }
11641
- )
11642
- }
11643
- ),
11644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11645
- ui.Badge,
11646
- {
11647
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11648
- size: "xsmall",
11649
- children: [
11650
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11651
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11652
- ]
11653
- }
11654
- ) })
11655
- ] })
11656
- ] }),
11657
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11658
- ActionMenu,
11659
- {
11660
- groups: [
11661
- {
11662
- actions: [
11663
- hasItems ? {
11664
- label: "Edit shipping option",
11665
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11666
- onClick: () => {
11667
- setIsOpen(
11668
- STACKED_FOCUS_MODAL_ID,
11669
- true
11670
- );
11671
- setData({
11672
- shippingProfileId: profile.id,
11673
- shippingOption,
11674
- shippingMethod
11675
- });
11676
- }
11677
- } : void 0,
11678
- {
11679
- label: "Remove shipping option",
11680
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11681
- onClick: () => {
11682
- if (shippingMethod) {
11683
- if (addShippingMethodAction) {
11684
- removeActionShippingMethod(
11685
- addShippingMethodAction.id
11686
- );
11687
- } else {
11688
- removeShippingMethod(
11689
- shippingMethod.id
11690
- );
11691
- }
11692
- }
11693
- }
11694
- }
11695
- ].filter(Boolean)
11696
- }
11697
- ]
11698
- }
11699
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11700
- StackedModalTrigger,
11701
- {
11702
- shippingProfileId: profile.id,
11703
- shippingOption,
11704
- shippingMethod,
11705
- setData,
11706
- children: "Add shipping option"
11707
- }
11708
- )
11709
- ] }),
11710
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11712
- items.map((item, idx) => {
11713
- var _a3, _b2, _c2, _d2, _e2;
11714
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11715
- /* @__PURE__ */ jsxRuntime.jsxs(
11716
- "div",
11717
- {
11718
- className: "flex items-center gap-x-3 px-3",
11719
- children: [
11720
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11721
- ui.Divider,
11722
- {
11723
- variant: "dashed",
11724
- orientation: "vertical"
11725
- }
11726
- ) }),
11727
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11728
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11729
- ui.Text,
11730
- {
11731
- size: "small",
11732
- leading: "compact",
11733
- className: "text-ui-fg-subtle",
11734
- children: [
11735
- item.quantity,
11736
- "x"
11737
- ]
11738
- }
11739
- ) }),
11740
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11741
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11742
- /* @__PURE__ */ jsxRuntime.jsxs(
11743
- ui.Text,
11744
- {
11745
- size: "small",
11746
- leading: "compact",
11747
- weight: "plus",
11748
- children: [
11749
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11750
- " (",
11751
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11752
- ")"
11753
- ]
11754
- }
11755
- ),
11756
- /* @__PURE__ */ jsxRuntime.jsx(
11757
- ui.Text,
11758
- {
11759
- size: "small",
11760
- leading: "compact",
11761
- className: "text-ui-fg-subtle",
11762
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11763
- }
11764
- )
11765
- ] })
11766
- ] })
11767
- ]
11768
- },
11769
- item.id
11770
- ),
11771
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11772
- ] }, item.id);
11773
- })
11774
- ] })
11775
- ]
11776
- },
11777
- profile.id
11778
- );
11779
- }) })
11780
- ] }) })
11781
- ] }) }),
11782
- /* @__PURE__ */ jsxRuntime.jsx(
11783
- StackedFocusModal,
11784
- {
11785
- id: STACKED_FOCUS_MODAL_ID,
11786
- onOpenChangeCallback: (open) => {
11787
- if (!open) {
11788
- setData(null);
11789
- }
11790
- return open;
11791
- },
11792
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11793
- }
11794
- )
11795
- ] }),
11796
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11797
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11798
- /* @__PURE__ */ jsxRuntime.jsx(
11799
- ui.Button,
11800
- {
11801
- size: "small",
11802
- type: "button",
11803
- isLoading: isSubmitting,
11804
- onClick: onSubmit,
11805
- children: "Save"
11806
- }
11807
- )
11808
- ] }) })
11809
- ] });
11810
- };
11811
- const StackedModalTrigger = ({
11812
- shippingProfileId,
11813
- shippingOption,
11814
- shippingMethod,
11815
- setData,
11816
- children
11817
- }) => {
11818
- const { setIsOpen, getIsOpen } = useStackedModal();
11819
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11820
- const onToggle = () => {
11821
- if (isOpen) {
11822
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11823
- setData(null);
11824
- } else {
11825
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11826
- setData({
11827
- shippingProfileId,
11828
- shippingOption,
11829
- shippingMethod
11830
- });
11831
- }
11832
- };
11833
- return /* @__PURE__ */ jsxRuntime.jsx(
11834
- ui.Button,
11835
- {
11836
- size: "small",
11837
- variant: "secondary",
11838
- onClick: onToggle,
11839
- className: "text-ui-fg-primary shrink-0",
11840
- children
11841
- }
11842
- );
11843
- };
11844
- const ShippingProfileForm = ({
11845
- data,
11846
- order,
11847
- preview
11848
- }) => {
11849
- var _a, _b, _c, _d, _e, _f;
11850
- const { setIsOpen } = useStackedModal();
11851
- const form = reactHookForm.useForm({
11852
- resolver: zod.zodResolver(shippingMethodSchema),
11853
- defaultValues: {
11854
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11855
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11856
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11857
- }
11858
- });
11859
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11860
- const {
11861
- mutateAsync: updateShippingMethod,
11862
- isPending: isUpdatingShippingMethod
11863
- } = useDraftOrderUpdateShippingMethod(order.id);
11864
- const onSubmit = form.handleSubmit(async (values) => {
11865
- if (isEqual__default.default(values, form.formState.defaultValues)) {
11866
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11867
- return;
11868
- }
11869
- if (data.shippingMethod) {
11870
- await updateShippingMethod(
11871
- {
11872
- method_id: data.shippingMethod.id,
11873
- shipping_option_id: values.shipping_option_id,
11874
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11875
- },
11876
- {
11877
- onError: (e) => {
11878
- ui.toast.error(e.message);
11879
- },
11880
- onSuccess: () => {
11881
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11882
- }
11883
- }
11884
- );
11885
- return;
11886
- }
11887
- await addShippingMethod(
11888
- {
11889
- shipping_option_id: values.shipping_option_id,
11890
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11891
- },
11892
- {
11893
- onError: (e) => {
11894
- ui.toast.error(e.message);
11895
- },
11896
- onSuccess: () => {
11897
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11898
- }
11899
- }
11900
- );
11901
- });
11902
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11903
- KeyboundForm,
11904
- {
11905
- className: "flex h-full flex-col overflow-hidden",
11906
- onSubmit,
11907
- children: [
11908
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11909
- /* @__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: [
11910
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11911
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11912
- /* @__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." }) })
11913
- ] }),
11914
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11915
- /* @__PURE__ */ jsxRuntime.jsx(
11916
- LocationField,
11917
- {
11918
- control: form.control,
11919
- setValue: form.setValue
11920
- }
11921
- ),
11922
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11923
- /* @__PURE__ */ jsxRuntime.jsx(
11924
- ShippingOptionField,
11925
- {
11926
- shippingProfileId: data.shippingProfileId,
11927
- preview,
11928
- control: form.control
11929
- }
11930
- ),
11931
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11932
- /* @__PURE__ */ jsxRuntime.jsx(
11933
- CustomAmountField,
11934
- {
11935
- control: form.control,
11936
- currencyCode: order.currency_code
11937
- }
11938
- ),
11939
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11940
- /* @__PURE__ */ jsxRuntime.jsx(
11941
- ItemsPreview,
11942
- {
11943
- order,
11944
- shippingProfileId: data.shippingProfileId
11945
- }
11946
- )
11947
- ] }) }) }),
11948
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11949
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11950
- /* @__PURE__ */ jsxRuntime.jsx(
11951
- ui.Button,
11952
- {
11953
- size: "small",
11954
- type: "submit",
11955
- isLoading: isPending || isUpdatingShippingMethod,
11956
- children: data.shippingMethod ? "Update" : "Add"
11957
- }
11958
- )
11959
- ] }) })
11960
- ]
11961
- }
11962
- ) }) });
11963
- };
11964
- const shippingMethodSchema = objectType({
11965
- location_id: stringType(),
11966
- shipping_option_id: stringType(),
11967
- custom_amount: unionType([numberType(), stringType()]).optional()
11968
- });
11969
- const ItemsPreview = ({ order, shippingProfileId }) => {
11970
- const matches = order.items.filter(
11971
- (item) => {
11972
- var _a, _b, _c;
11973
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11974
- }
11975
- );
11976
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11977
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11978
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11980
- ] }) }),
11981
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11982
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11983
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11984
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11985
- ] }),
11986
- /* @__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(
11987
- "div",
11988
- {
11989
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11990
- children: [
11991
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11992
- /* @__PURE__ */ jsxRuntime.jsx(
11993
- Thumbnail,
11994
- {
11995
- thumbnail: item.thumbnail,
11996
- alt: item.product_title ?? void 0
11997
- }
11998
- ),
11999
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12000
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12001
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12002
- /* @__PURE__ */ jsxRuntime.jsxs(
12003
- ui.Text,
12004
- {
12005
- size: "small",
12006
- leading: "compact",
12007
- className: "text-ui-fg-subtle",
12008
- children: [
12009
- "(",
12010
- item.variant_title,
12011
- ")"
12012
- ]
12013
- }
12014
- )
12015
- ] }),
12016
- /* @__PURE__ */ jsxRuntime.jsx(
12017
- ui.Text,
12018
- {
12019
- size: "small",
12020
- leading: "compact",
12021
- className: "text-ui-fg-subtle",
12022
- children: item.variant_sku
12023
- }
12024
- )
12025
- ] })
12026
- ] }),
12027
- /* @__PURE__ */ jsxRuntime.jsxs(
12028
- ui.Text,
12029
- {
12030
- size: "small",
12031
- leading: "compact",
12032
- className: "text-ui-fg-subtle",
12033
- children: [
12034
- item.quantity,
12035
- "x"
12036
- ]
12037
- }
12038
- )
12039
- ]
12040
- },
12041
- item.id
12042
- )) : /* @__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: [
12043
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12044
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12045
- 'No items found for "',
12046
- query,
12047
- '".'
12048
- ] })
12049
- ] }) })
12050
- ] })
12051
- ] });
12052
- };
12053
- const LocationField = ({ control, setValue }) => {
12054
- const locations = useComboboxData({
12055
- queryKey: ["locations"],
12056
- queryFn: async (params) => {
12057
- return await sdk.admin.stockLocation.list(params);
12058
- },
12059
- getOptions: (data) => {
12060
- return data.stock_locations.map((location) => ({
12061
- label: location.name,
12062
- value: location.id
12063
- }));
12064
- }
12065
- });
12066
- return /* @__PURE__ */ jsxRuntime.jsx(
12067
- Form$2.Field,
12068
- {
12069
- control,
12070
- name: "location_id",
12071
- render: ({ field: { onChange, ...field } }) => {
12072
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12073
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12074
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12075
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12076
- ] }),
12077
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12078
- Combobox,
12079
- {
12080
- options: locations.options,
12081
- fetchNextPage: locations.fetchNextPage,
12082
- isFetchingNextPage: locations.isFetchingNextPage,
12083
- searchValue: locations.searchValue,
12084
- onSearchValueChange: locations.onSearchValueChange,
12085
- placeholder: "Select location",
12086
- onChange: (value) => {
12087
- setValue("shipping_option_id", "", {
12088
- shouldDirty: true,
12089
- shouldTouch: true
12090
- });
12091
- onChange(value);
12092
- },
12093
- ...field
12094
- }
12095
- ) })
12096
- ] }) });
12097
- }
12098
- }
12099
- );
12100
- };
12101
- const ShippingOptionField = ({
12102
- shippingProfileId,
12103
- preview,
12104
- control
12105
- }) => {
12106
- var _a;
12107
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12108
- const shippingOptions = useComboboxData({
12109
- queryKey: ["shipping_options", locationId, shippingProfileId],
12110
- queryFn: async (params) => {
12111
- return await sdk.admin.shippingOption.list({
12112
- ...params,
12113
- stock_location_id: locationId,
12114
- shipping_profile_id: shippingProfileId
12115
- });
12116
- },
12117
- getOptions: (data) => {
12118
- return data.shipping_options.map((option) => {
12119
- var _a2;
12120
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12121
- (r) => r.attribute === "is_return" && r.value === "true"
12122
- )) {
12123
- return void 0;
12124
- }
12125
- return {
12126
- label: option.name,
12127
- value: option.id
12128
- };
12129
- }).filter(Boolean);
12130
- },
12131
- enabled: !!locationId && !!shippingProfileId,
12132
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12133
- });
12134
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12135
- return /* @__PURE__ */ jsxRuntime.jsx(
12136
- Form$2.Field,
12137
- {
12138
- control,
12139
- name: "shipping_option_id",
12140
- render: ({ field }) => {
12141
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12142
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12143
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12144
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12145
- ] }),
12146
- /* @__PURE__ */ jsxRuntime.jsx(
12147
- ConditionalTooltip,
12148
- {
12149
- content: tooltipContent,
12150
- showTooltip: !locationId || !shippingProfileId,
12151
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12152
- Combobox,
12153
- {
12154
- options: shippingOptions.options,
12155
- fetchNextPage: shippingOptions.fetchNextPage,
12156
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12157
- searchValue: shippingOptions.searchValue,
12158
- onSearchValueChange: shippingOptions.onSearchValueChange,
12159
- placeholder: "Select shipping option",
12160
- ...field,
12161
- disabled: !locationId || !shippingProfileId
12162
- }
12163
- ) }) })
12164
- }
12165
- )
12166
- ] }) });
12167
- }
12168
- }
12169
- );
12170
- };
12171
- const CustomAmountField = ({
12172
- control,
12173
- currencyCode
12174
- }) => {
12175
- return /* @__PURE__ */ jsxRuntime.jsx(
12176
- Form$2.Field,
12177
- {
12178
- control,
12179
- name: "custom_amount",
12180
- render: ({ field: { onChange, ...field } }) => {
12181
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12182
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12183
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12184
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12185
- ] }),
12186
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12187
- ui.CurrencyInput,
12188
- {
12189
- ...field,
12190
- onValueChange: (value) => onChange(value),
12191
- symbol: getNativeSymbol(currencyCode),
12192
- code: currencyCode
12193
- }
12194
- ) })
12195
- ] });
12196
- }
12197
- }
12198
- );
12199
- };
12200
- const InlineTip = React.forwardRef(
12201
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12202
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12203
- return /* @__PURE__ */ jsxRuntime.jsxs(
12204
- "div",
12205
- {
12206
- ref,
12207
- className: ui.clx(
12208
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12209
- className
12210
- ),
12211
- ...props,
12212
- children: [
12213
- /* @__PURE__ */ jsxRuntime.jsx(
12214
- "div",
12215
- {
12216
- role: "presentation",
12217
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12218
- "bg-ui-tag-orange-icon": variant === "warning"
12219
- })
12220
- }
12221
- ),
12222
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12223
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12224
- labelValue,
12225
- ":"
12226
- ] }),
12227
- " ",
12228
- children
12229
- ] })
12230
- ]
12231
- }
12232
- );
12233
- }
12234
- );
12235
- InlineTip.displayName = "InlineTip";
12236
- const MetadataFieldSchema = objectType({
12237
- key: stringType(),
12238
- disabled: booleanType().optional(),
12239
- value: anyType()
12240
- });
12241
- const MetadataSchema = objectType({
12242
- metadata: arrayType(MetadataFieldSchema)
12243
- });
12244
- const Metadata = () => {
12245
- const { id } = reactRouterDom.useParams();
12246
- const { order, isPending, isError, error } = useOrder(id, {
12247
- fields: "metadata"
12248
- });
12249
- if (isError) {
12250
- throw error;
12251
- }
12252
- const isReady = !isPending && !!order;
12253
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12254
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12255
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12256
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12257
- ] }),
12258
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12259
- ] });
12260
- };
12261
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12262
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12263
- const MetadataForm = ({ orderId, metadata }) => {
12264
- const { handleSuccess } = useRouteModal();
12265
- const hasUneditableRows = getHasUneditableRows(metadata);
12266
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12267
- const form = reactHookForm.useForm({
12268
- defaultValues: {
12269
- metadata: getDefaultValues(metadata)
12270
- },
12271
- resolver: zod.zodResolver(MetadataSchema)
12272
- });
12273
- const handleSubmit = form.handleSubmit(async (data) => {
12274
- const parsedData = parseValues(data);
12275
- await mutateAsync(
12276
- {
12277
- metadata: parsedData
12278
- },
12279
- {
12280
- onSuccess: () => {
12281
- ui.toast.success("Metadata updated");
12282
- handleSuccess();
12283
- },
12284
- onError: (error) => {
12285
- ui.toast.error(error.message);
12286
- }
12287
- }
12288
- );
12289
- });
12290
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12291
- control: form.control,
12292
- name: "metadata"
12293
- });
12294
- function deleteRow(index) {
12295
- remove(index);
12296
- if (fields.length === 1) {
12297
- insert(0, {
12298
- key: "",
12299
- value: "",
12300
- disabled: false
12301
- });
12302
- }
12303
- }
12304
- function insertRow(index, position) {
12305
- insert(index + (position === "above" ? 0 : 1), {
12306
- key: "",
12307
- value: "",
12308
- disabled: false
12309
- });
12310
- }
12311
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12312
- KeyboundForm,
12313
- {
12314
- onSubmit: handleSubmit,
12315
- className: "flex flex-1 flex-col overflow-hidden",
12316
- children: [
12317
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12318
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12319
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12320
- /* @__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" }) }),
12321
- /* @__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" }) })
12322
- ] }),
12323
- fields.map((field, index) => {
12324
- const isDisabled = field.disabled || false;
12325
- let placeholder = "-";
12326
- if (typeof field.value === "object") {
12327
- placeholder = "{ ... }";
12328
- }
12329
- if (Array.isArray(field.value)) {
12330
- placeholder = "[ ... ]";
12331
- }
12332
- return /* @__PURE__ */ jsxRuntime.jsx(
12333
- ConditionalTooltip,
12334
- {
12335
- showTooltip: isDisabled,
12336
- content: "This row is disabled because it contains non-primitive data.",
12337
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12338
- /* @__PURE__ */ jsxRuntime.jsxs(
12339
- "div",
12340
- {
12341
- className: ui.clx("grid grid-cols-2 divide-x", {
12342
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12343
- }),
12344
- children: [
12345
- /* @__PURE__ */ jsxRuntime.jsx(
12346
- Form$2.Field,
12347
- {
12348
- control: form.control,
12349
- name: `metadata.${index}.key`,
12350
- render: ({ field: field2 }) => {
12351
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12352
- GridInput,
12353
- {
12354
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12355
- ...field2,
12356
- disabled: isDisabled,
12357
- placeholder: "Key"
12358
- }
12359
- ) }) });
12360
- }
12361
- }
12362
- ),
12363
- /* @__PURE__ */ jsxRuntime.jsx(
12364
- Form$2.Field,
12365
- {
12366
- control: form.control,
12367
- name: `metadata.${index}.value`,
12368
- render: ({ field: { value, ...field2 } }) => {
12369
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12370
- GridInput,
12371
- {
12372
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12373
- ...field2,
12374
- value: isDisabled ? placeholder : value,
12375
- disabled: isDisabled,
12376
- placeholder: "Value"
12377
- }
12378
- ) }) });
12379
- }
12380
- }
12381
- )
12382
- ]
12383
- }
12384
- ),
12385
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12386
- /* @__PURE__ */ jsxRuntime.jsx(
12387
- ui.DropdownMenu.Trigger,
12388
- {
12389
- className: ui.clx(
12390
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12391
- {
12392
- hidden: isDisabled
12393
- }
12394
- ),
12395
- disabled: isDisabled,
12396
- asChild: true,
12397
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12398
- }
12399
- ),
12400
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12401
- /* @__PURE__ */ jsxRuntime.jsxs(
12402
- ui.DropdownMenu.Item,
12403
- {
12404
- className: "gap-x-2",
12405
- onClick: () => insertRow(index, "above"),
12406
- children: [
12407
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12408
- "Insert row above"
12409
- ]
12410
- }
12411
- ),
12412
- /* @__PURE__ */ jsxRuntime.jsxs(
12413
- ui.DropdownMenu.Item,
12414
- {
12415
- className: "gap-x-2",
12416
- onClick: () => insertRow(index, "below"),
12417
- children: [
12418
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12419
- "Insert row below"
12420
- ]
12421
- }
12422
- ),
12423
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12424
- /* @__PURE__ */ jsxRuntime.jsxs(
12425
- ui.DropdownMenu.Item,
12426
- {
12427
- className: "gap-x-2",
12428
- onClick: () => deleteRow(index),
12429
- children: [
12430
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12431
- "Delete row"
12432
- ]
12433
- }
12434
- )
12435
- ] })
12436
- ] })
12437
- ] })
12438
- },
12439
- field.id
12440
- );
12441
- })
12442
- ] }),
12443
- 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." })
12444
- ] }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12446
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12447
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12448
- ] }) })
12449
- ]
12450
- }
12451
- ) });
12452
- };
12453
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12454
- return /* @__PURE__ */ jsxRuntime.jsx(
12455
- "input",
12456
- {
12457
- ref,
12458
- ...props,
12459
- autoComplete: "off",
12460
- className: ui.clx(
12461
- "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",
12462
- className
12463
- )
12464
- }
12465
- );
12466
- });
12467
- GridInput.displayName = "MetadataForm.GridInput";
12468
- const PlaceholderInner = () => {
12469
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12470
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12472
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12473
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12474
- ] }) })
12475
- ] });
12476
- };
12477
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12478
- function getDefaultValues(metadata) {
12479
- if (!metadata || !Object.keys(metadata).length) {
12480
- return [
12481
- {
12482
- key: "",
12483
- value: "",
12484
- disabled: false
12485
- }
12486
- ];
12487
- }
12488
- return Object.entries(metadata).map(([key, value]) => {
12489
- if (!EDITABLE_TYPES.includes(typeof value)) {
12490
- return {
12491
- key,
12492
- value,
12493
- disabled: true
12494
- };
12495
- }
12496
- let stringValue = value;
12497
- if (typeof value !== "string") {
12498
- stringValue = JSON.stringify(value);
12499
- }
12500
- return {
12501
- key,
12502
- value: stringValue,
12503
- original_key: key
12504
- };
12505
- });
12506
- }
12507
- function parseValues(values) {
12508
- const metadata = values.metadata;
12509
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
12510
- if (isEmpty) {
12511
- return null;
12512
- }
12513
- const update = {};
12514
- metadata.forEach((field) => {
12515
- let key = field.key;
12516
- let value = field.value;
12517
- const disabled = field.disabled;
12518
- if (!key || !value) {
12519
- return;
12520
- }
12521
- if (disabled) {
12522
- update[key] = value;
12523
- return;
12524
- }
12525
- key = key.trim();
12526
- value = value.trim();
12527
- if (value === "true") {
12528
- update[key] = true;
12529
- } else if (value === "false") {
12530
- update[key] = false;
12531
- } else {
12532
- const parsedNumber = parseFloat(value);
12533
- if (!isNaN(parsedNumber)) {
12534
- update[key] = parsedNumber;
12535
- } else {
12536
- update[key] = value;
12537
- }
12538
- }
12539
- });
12540
- return update;
12541
- }
12542
- function getHasUneditableRows(metadata) {
12543
- if (!metadata) {
12544
- return false;
12545
- }
12546
- return Object.values(metadata).some(
12547
- (value) => !EDITABLE_TYPES.includes(typeof value)
12548
- );
12549
- }
12550
- const CustomItems = () => {
12551
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12552
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
12553
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12554
- ] });
12555
- };
12556
- const CustomItemsForm = () => {
12557
- const form = reactHookForm.useForm({
12558
- resolver: zod.zodResolver(schema$1)
12559
- });
12560
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
12565
- ] }) })
12566
- ] }) });
12567
- };
12568
- const schema$1 = objectType({
12569
- email: stringType().email()
12570
- });
12571
- const TransferOwnership = () => {
12572
- const { id } = reactRouterDom.useParams();
12573
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
- fields: "id,customer_id,customer.*"
12575
- });
12576
- if (isError) {
12577
- throw error;
12578
- }
12579
- const isReady = !isPending && !!draft_order;
12580
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12581
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
- /* @__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" }) })
12584
- ] }),
12585
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12586
- ] });
12587
- };
12588
- const TransferOwnershipForm = ({ order }) => {
12589
- var _a, _b;
12590
- const form = reactHookForm.useForm({
12591
- defaultValues: {
12592
- customer_id: order.customer_id || ""
12593
- },
12594
- resolver: zod.zodResolver(schema)
12595
- });
12596
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
- const { handleSuccess } = useRouteModal();
12598
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12599
- const currentCustomer = order.customer ? {
12600
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12601
- value: order.customer.id
12602
- } : null;
12603
- const onSubmit = form.handleSubmit(async (data) => {
12604
- await mutateAsync(
12605
- { customer_id: data.customer_id },
12606
- {
12607
- onSuccess: () => {
12608
- ui.toast.success("Customer updated");
12609
- handleSuccess();
12610
- },
12611
- onError: (error) => {
12612
- ui.toast.error(error.message);
12613
- }
12614
- }
12615
- );
12616
- });
12617
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12618
- KeyboundForm,
12619
- {
12620
- className: "flex flex-1 flex-col overflow-hidden",
12621
- onSubmit,
12622
- children: [
12623
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12624
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12625
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12626
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12627
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12629
- ] }),
12630
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12633
- ] })
12634
- ] }),
12635
- /* @__PURE__ */ jsxRuntime.jsx(
12636
- CustomerField,
12637
- {
12638
- control: form.control,
12639
- currentCustomerId: order.customer_id
12640
- }
12641
- )
12642
- ] }),
12643
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12644
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12645
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12646
- ] }) })
12647
- ]
12648
- }
12649
- ) });
12650
- };
12651
- const CustomerField = ({ control, currentCustomerId }) => {
12652
- const customers = useComboboxData({
12653
- queryFn: async (params) => {
12654
- return await sdk.admin.customer.list({
12655
- ...params,
12656
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12657
- });
12658
- },
12659
- queryKey: ["customers"],
12660
- getOptions: (data) => {
12661
- return data.customers.map((customer) => {
12662
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12663
- return {
12664
- label: name ? `${name} (${customer.email})` : customer.email,
12665
- value: customer.id
12666
- };
12667
- });
12668
- }
12669
- });
12670
- return /* @__PURE__ */ jsxRuntime.jsx(
12671
- Form$2.Field,
12672
- {
12673
- name: "customer_id",
12674
- control,
12675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12676
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11649
+ queryKey: ["customers"],
11650
+ getOptions: (data) => {
11651
+ return data.customers.map((customer) => {
11652
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11653
+ return {
11654
+ label: name ? `${name} (${customer.email})` : customer.email,
11655
+ value: customer.id
11656
+ };
11657
+ });
11658
+ }
11659
+ });
11660
+ return /* @__PURE__ */ jsxRuntime.jsx(
11661
+ Form$2.Field,
11662
+ {
11663
+ name: "customer_id",
11664
+ control,
11665
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11666
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11667
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11668
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12679
11669
  ] }),
12680
11670
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12681
11671
  Combobox,
@@ -12980,70 +11970,1080 @@ const Illustration = () => {
12980
11970
  strokeLinecap: "round",
12981
11971
  strokeLinejoin: "round"
12982
11972
  }
12983
- ) }),
12984
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12985
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12986
- "rect",
11973
+ ) }),
11974
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11975
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11976
+ "rect",
11977
+ {
11978
+ width: "12",
11979
+ height: "12",
11980
+ fill: "white",
11981
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11982
+ }
11983
+ ) }),
11984
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11985
+ "rect",
11986
+ {
11987
+ width: "12",
11988
+ height: "12",
11989
+ fill: "white",
11990
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11991
+ }
11992
+ ) }),
11993
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11994
+ "rect",
11995
+ {
11996
+ width: "12",
11997
+ height: "12",
11998
+ fill: "white",
11999
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12000
+ }
12001
+ ) }),
12002
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12003
+ "rect",
12004
+ {
12005
+ width: "12",
12006
+ height: "12",
12007
+ fill: "white",
12008
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12009
+ }
12010
+ ) }),
12011
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12012
+ "rect",
12013
+ {
12014
+ width: "12",
12015
+ height: "12",
12016
+ fill: "white",
12017
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12018
+ }
12019
+ ) }),
12020
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12021
+ "rect",
12022
+ {
12023
+ width: "12",
12024
+ height: "12",
12025
+ fill: "white",
12026
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12027
+ }
12028
+ ) })
12029
+ ] })
12030
+ ]
12031
+ }
12032
+ );
12033
+ };
12034
+ const schema$1 = objectType({
12035
+ customer_id: stringType().min(1)
12036
+ });
12037
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12038
+ const Shipping = () => {
12039
+ var _a;
12040
+ const { id } = reactRouterDom.useParams();
12041
+ const { order, isPending, isError, error } = useOrder(id, {
12042
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12043
+ });
12044
+ const {
12045
+ order: preview,
12046
+ isPending: isPreviewPending,
12047
+ isError: isPreviewError,
12048
+ error: previewError
12049
+ } = useOrderPreview(id);
12050
+ useInitiateOrderEdit({ preview });
12051
+ const { onCancel } = useCancelOrderEdit({ preview });
12052
+ if (isError) {
12053
+ throw error;
12054
+ }
12055
+ if (isPreviewError) {
12056
+ throw previewError;
12057
+ }
12058
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12059
+ const isReady = preview && !isPreviewPending && order && !isPending;
12060
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12061
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12062
+ /* @__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: [
12063
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12064
+ /* @__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." }) })
12065
+ ] }) }) }),
12066
+ /* @__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" }) }) })
12067
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12068
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12069
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12070
+ ] }) });
12071
+ };
12072
+ const ShippingForm = ({ preview, order }) => {
12073
+ var _a;
12074
+ const { setIsOpen } = useStackedModal();
12075
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12076
+ const [data, setData] = React.useState(null);
12077
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12078
+ const { shipping_options } = useShippingOptions(
12079
+ {
12080
+ id: appliedShippingOptionIds,
12081
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12082
+ },
12083
+ {
12084
+ enabled: appliedShippingOptionIds.length > 0
12085
+ }
12086
+ );
12087
+ const uniqueShippingProfiles = React.useMemo(() => {
12088
+ const profiles = /* @__PURE__ */ new Map();
12089
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12090
+ profiles.set(profile.id, profile);
12091
+ });
12092
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12093
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12094
+ });
12095
+ return Array.from(profiles.values());
12096
+ }, [order.items, shipping_options]);
12097
+ const { handleSuccess } = useRouteModal();
12098
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12099
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12100
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12101
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12102
+ const onSubmit = async () => {
12103
+ setIsSubmitting(true);
12104
+ let requestSucceeded = false;
12105
+ await requestOrderEdit(void 0, {
12106
+ onError: (e) => {
12107
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12108
+ },
12109
+ onSuccess: () => {
12110
+ requestSucceeded = true;
12111
+ }
12112
+ });
12113
+ if (!requestSucceeded) {
12114
+ setIsSubmitting(false);
12115
+ return;
12116
+ }
12117
+ await confirmOrderEdit(void 0, {
12118
+ onError: (e) => {
12119
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12120
+ },
12121
+ onSuccess: () => {
12122
+ handleSuccess();
12123
+ },
12124
+ onSettled: () => {
12125
+ setIsSubmitting(false);
12126
+ }
12127
+ });
12128
+ };
12129
+ const onKeydown = React.useCallback(
12130
+ (e) => {
12131
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12132
+ if (data || isSubmitting) {
12133
+ return;
12134
+ }
12135
+ onSubmit();
12136
+ }
12137
+ },
12138
+ [data, isSubmitting, onSubmit]
12139
+ );
12140
+ React.useEffect(() => {
12141
+ document.addEventListener("keydown", onKeydown);
12142
+ return () => {
12143
+ document.removeEventListener("keydown", onKeydown);
12144
+ };
12145
+ }, [onKeydown]);
12146
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12148
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12149
+ /* @__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: [
12150
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12151
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12152
+ /* @__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." }) })
12153
+ ] }),
12154
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12155
+ /* @__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: [
12156
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
12157
+ /* @__PURE__ */ jsxRuntime.jsx(
12158
+ ui.Text,
12159
+ {
12160
+ size: "xsmall",
12161
+ weight: "plus",
12162
+ className: "text-ui-fg-muted",
12163
+ children: "Shipping profile"
12164
+ }
12165
+ ),
12166
+ /* @__PURE__ */ jsxRuntime.jsx(
12167
+ ui.Text,
12168
+ {
12169
+ size: "xsmall",
12170
+ weight: "plus",
12171
+ className: "text-ui-fg-muted",
12172
+ children: "Action"
12173
+ }
12174
+ )
12175
+ ] }),
12176
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12177
+ var _a2, _b, _c, _d, _e, _f, _g;
12178
+ const items = getItemsWithShippingProfile(
12179
+ profile.id,
12180
+ order.items
12181
+ );
12182
+ const hasItems = items.length > 0;
12183
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12184
+ (option) => option.shipping_profile_id === profile.id
12185
+ );
12186
+ const shippingMethod = preview.shipping_methods.find(
12187
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12188
+ );
12189
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12190
+ (action) => action.action === "SHIPPING_ADD"
12191
+ );
12192
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12193
+ radixUi.Accordion.Item,
12194
+ {
12195
+ value: profile.id,
12196
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12197
+ children: [
12198
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
12199
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
12200
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12201
+ ui.IconButton,
12202
+ {
12203
+ size: "2xsmall",
12204
+ variant: "transparent",
12205
+ className: "group/trigger",
12206
+ disabled: !hasItems,
12207
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
12208
+ }
12209
+ ) }),
12210
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12211
+ /* @__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" }) }) }),
12212
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
12213
+ /* @__PURE__ */ jsxRuntime.jsx(
12214
+ ui.Text,
12215
+ {
12216
+ size: "small",
12217
+ weight: "plus",
12218
+ leading: "compact",
12219
+ children: profile.name
12220
+ }
12221
+ ),
12222
+ /* @__PURE__ */ jsxRuntime.jsxs(
12223
+ ui.Text,
12224
+ {
12225
+ size: "small",
12226
+ leading: "compact",
12227
+ className: "text-ui-fg-subtle",
12228
+ children: [
12229
+ items.length,
12230
+ " ",
12231
+ pluralize(items.length, "items", "item")
12232
+ ]
12233
+ }
12234
+ )
12235
+ ] })
12236
+ ] }) : /* @__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: [
12237
+ /* @__PURE__ */ jsxRuntime.jsx(
12238
+ ui.Tooltip,
12239
+ {
12240
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12241
+ var _a3, _b2, _c2;
12242
+ return /* @__PURE__ */ jsxRuntime.jsx(
12243
+ "li",
12244
+ {
12245
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12246
+ },
12247
+ item.id
12248
+ );
12249
+ }) }),
12250
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12251
+ ui.Badge,
12252
+ {
12253
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12254
+ size: "xsmall",
12255
+ children: [
12256
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12257
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12258
+ items.reduce(
12259
+ (acc, item) => acc + item.quantity,
12260
+ 0
12261
+ ),
12262
+ "x",
12263
+ " ",
12264
+ pluralize(items.length, "items", "item")
12265
+ ] })
12266
+ ]
12267
+ }
12268
+ )
12269
+ }
12270
+ ),
12271
+ /* @__PURE__ */ jsxRuntime.jsx(
12272
+ ui.Tooltip,
12273
+ {
12274
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12275
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12276
+ ui.Badge,
12277
+ {
12278
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12279
+ size: "xsmall",
12280
+ children: [
12281
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12282
+ /* @__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 })
12283
+ ]
12284
+ }
12285
+ )
12286
+ }
12287
+ ),
12288
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12289
+ ui.Badge,
12290
+ {
12291
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12292
+ size: "xsmall",
12293
+ children: [
12294
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12295
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12296
+ ]
12297
+ }
12298
+ ) })
12299
+ ] })
12300
+ ] }),
12301
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12302
+ ActionMenu,
12303
+ {
12304
+ groups: [
12305
+ {
12306
+ actions: [
12307
+ hasItems ? {
12308
+ label: "Edit shipping option",
12309
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12310
+ onClick: () => {
12311
+ setIsOpen(
12312
+ STACKED_FOCUS_MODAL_ID,
12313
+ true
12314
+ );
12315
+ setData({
12316
+ shippingProfileId: profile.id,
12317
+ shippingOption,
12318
+ shippingMethod
12319
+ });
12320
+ }
12321
+ } : void 0,
12322
+ {
12323
+ label: "Remove shipping option",
12324
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12325
+ onClick: () => {
12326
+ if (shippingMethod) {
12327
+ if (addShippingMethodAction) {
12328
+ removeActionShippingMethod(
12329
+ addShippingMethodAction.id
12330
+ );
12331
+ } else {
12332
+ removeShippingMethod(
12333
+ shippingMethod.id
12334
+ );
12335
+ }
12336
+ }
12337
+ }
12338
+ }
12339
+ ].filter(Boolean)
12340
+ }
12341
+ ]
12342
+ }
12343
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12344
+ StackedModalTrigger,
12345
+ {
12346
+ shippingProfileId: profile.id,
12347
+ shippingOption,
12348
+ shippingMethod,
12349
+ setData,
12350
+ children: "Add shipping option"
12351
+ }
12352
+ )
12353
+ ] }),
12354
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12355
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12356
+ items.map((item, idx) => {
12357
+ var _a3, _b2, _c2, _d2, _e2;
12358
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12359
+ /* @__PURE__ */ jsxRuntime.jsxs(
12360
+ "div",
12361
+ {
12362
+ className: "flex items-center gap-x-3 px-3",
12363
+ children: [
12364
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12365
+ ui.Divider,
12366
+ {
12367
+ variant: "dashed",
12368
+ orientation: "vertical"
12369
+ }
12370
+ ) }),
12371
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12372
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12373
+ ui.Text,
12374
+ {
12375
+ size: "small",
12376
+ leading: "compact",
12377
+ className: "text-ui-fg-subtle",
12378
+ children: [
12379
+ item.quantity,
12380
+ "x"
12381
+ ]
12382
+ }
12383
+ ) }),
12384
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12385
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12386
+ /* @__PURE__ */ jsxRuntime.jsxs(
12387
+ ui.Text,
12388
+ {
12389
+ size: "small",
12390
+ leading: "compact",
12391
+ weight: "plus",
12392
+ children: [
12393
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12394
+ " (",
12395
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12396
+ ")"
12397
+ ]
12398
+ }
12399
+ ),
12400
+ /* @__PURE__ */ jsxRuntime.jsx(
12401
+ ui.Text,
12402
+ {
12403
+ size: "small",
12404
+ leading: "compact",
12405
+ className: "text-ui-fg-subtle",
12406
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12407
+ }
12408
+ )
12409
+ ] })
12410
+ ] })
12411
+ ]
12412
+ },
12413
+ item.id
12414
+ ),
12415
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12416
+ ] }, item.id);
12417
+ })
12418
+ ] })
12419
+ ]
12420
+ },
12421
+ profile.id
12422
+ );
12423
+ }) })
12424
+ ] }) })
12425
+ ] }) }),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(
12427
+ StackedFocusModal,
12428
+ {
12429
+ id: STACKED_FOCUS_MODAL_ID,
12430
+ onOpenChangeCallback: (open) => {
12431
+ if (!open) {
12432
+ setData(null);
12433
+ }
12434
+ return open;
12435
+ },
12436
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12437
+ }
12438
+ )
12439
+ ] }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12441
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12442
+ /* @__PURE__ */ jsxRuntime.jsx(
12443
+ ui.Button,
12444
+ {
12445
+ size: "small",
12446
+ type: "button",
12447
+ isLoading: isSubmitting,
12448
+ onClick: onSubmit,
12449
+ children: "Save"
12450
+ }
12451
+ )
12452
+ ] }) })
12453
+ ] });
12454
+ };
12455
+ const StackedModalTrigger = ({
12456
+ shippingProfileId,
12457
+ shippingOption,
12458
+ shippingMethod,
12459
+ setData,
12460
+ children
12461
+ }) => {
12462
+ const { setIsOpen, getIsOpen } = useStackedModal();
12463
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12464
+ const onToggle = () => {
12465
+ if (isOpen) {
12466
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12467
+ setData(null);
12468
+ } else {
12469
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12470
+ setData({
12471
+ shippingProfileId,
12472
+ shippingOption,
12473
+ shippingMethod
12474
+ });
12475
+ }
12476
+ };
12477
+ return /* @__PURE__ */ jsxRuntime.jsx(
12478
+ ui.Button,
12479
+ {
12480
+ size: "small",
12481
+ variant: "secondary",
12482
+ onClick: onToggle,
12483
+ className: "text-ui-fg-primary shrink-0",
12484
+ children
12485
+ }
12486
+ );
12487
+ };
12488
+ const ShippingProfileForm = ({
12489
+ data,
12490
+ order,
12491
+ preview
12492
+ }) => {
12493
+ var _a, _b, _c, _d, _e, _f;
12494
+ const { setIsOpen } = useStackedModal();
12495
+ const form = reactHookForm.useForm({
12496
+ resolver: zod.zodResolver(shippingMethodSchema),
12497
+ defaultValues: {
12498
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12499
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12500
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12501
+ }
12502
+ });
12503
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12504
+ const {
12505
+ mutateAsync: updateShippingMethod,
12506
+ isPending: isUpdatingShippingMethod
12507
+ } = useDraftOrderUpdateShippingMethod(order.id);
12508
+ const onSubmit = form.handleSubmit(async (values) => {
12509
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
12510
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12511
+ return;
12512
+ }
12513
+ if (data.shippingMethod) {
12514
+ await updateShippingMethod(
12515
+ {
12516
+ method_id: data.shippingMethod.id,
12517
+ shipping_option_id: values.shipping_option_id,
12518
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12519
+ },
12520
+ {
12521
+ onError: (e) => {
12522
+ ui.toast.error(e.message);
12523
+ },
12524
+ onSuccess: () => {
12525
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12526
+ }
12527
+ }
12528
+ );
12529
+ return;
12530
+ }
12531
+ await addShippingMethod(
12532
+ {
12533
+ shipping_option_id: values.shipping_option_id,
12534
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12535
+ },
12536
+ {
12537
+ onError: (e) => {
12538
+ ui.toast.error(e.message);
12539
+ },
12540
+ onSuccess: () => {
12541
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12542
+ }
12543
+ }
12544
+ );
12545
+ });
12546
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12547
+ KeyboundForm,
12548
+ {
12549
+ className: "flex h-full flex-col overflow-hidden",
12550
+ onSubmit,
12551
+ children: [
12552
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12553
+ /* @__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: [
12554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12555
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12556
+ /* @__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." }) })
12557
+ ] }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12559
+ /* @__PURE__ */ jsxRuntime.jsx(
12560
+ LocationField,
12561
+ {
12562
+ control: form.control,
12563
+ setValue: form.setValue
12564
+ }
12565
+ ),
12566
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12567
+ /* @__PURE__ */ jsxRuntime.jsx(
12568
+ ShippingOptionField,
12569
+ {
12570
+ shippingProfileId: data.shippingProfileId,
12571
+ preview,
12572
+ control: form.control
12573
+ }
12574
+ ),
12575
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12576
+ /* @__PURE__ */ jsxRuntime.jsx(
12577
+ CustomAmountField,
12578
+ {
12579
+ control: form.control,
12580
+ currencyCode: order.currency_code
12581
+ }
12582
+ ),
12583
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12584
+ /* @__PURE__ */ jsxRuntime.jsx(
12585
+ ItemsPreview,
12586
+ {
12587
+ order,
12588
+ shippingProfileId: data.shippingProfileId
12589
+ }
12590
+ )
12591
+ ] }) }) }),
12592
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12593
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12594
+ /* @__PURE__ */ jsxRuntime.jsx(
12595
+ ui.Button,
12596
+ {
12597
+ size: "small",
12598
+ type: "submit",
12599
+ isLoading: isPending || isUpdatingShippingMethod,
12600
+ children: data.shippingMethod ? "Update" : "Add"
12601
+ }
12602
+ )
12603
+ ] }) })
12604
+ ]
12605
+ }
12606
+ ) }) });
12607
+ };
12608
+ const shippingMethodSchema = objectType({
12609
+ location_id: stringType(),
12610
+ shipping_option_id: stringType(),
12611
+ custom_amount: unionType([numberType(), stringType()]).optional()
12612
+ });
12613
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12614
+ const matches = order.items.filter(
12615
+ (item) => {
12616
+ var _a, _b, _c;
12617
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12618
+ }
12619
+ );
12620
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12621
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12623
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12624
+ ] }) }),
12625
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12626
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12627
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12628
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12629
+ ] }),
12630
+ /* @__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(
12631
+ "div",
12632
+ {
12633
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12634
+ children: [
12635
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12636
+ /* @__PURE__ */ jsxRuntime.jsx(
12637
+ Thumbnail,
12638
+ {
12639
+ thumbnail: item.thumbnail,
12640
+ alt: item.product_title ?? void 0
12641
+ }
12642
+ ),
12643
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12645
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12646
+ /* @__PURE__ */ jsxRuntime.jsxs(
12647
+ ui.Text,
12648
+ {
12649
+ size: "small",
12650
+ leading: "compact",
12651
+ className: "text-ui-fg-subtle",
12652
+ children: [
12653
+ "(",
12654
+ item.variant_title,
12655
+ ")"
12656
+ ]
12657
+ }
12658
+ )
12659
+ ] }),
12660
+ /* @__PURE__ */ jsxRuntime.jsx(
12661
+ ui.Text,
12662
+ {
12663
+ size: "small",
12664
+ leading: "compact",
12665
+ className: "text-ui-fg-subtle",
12666
+ children: item.variant_sku
12667
+ }
12668
+ )
12669
+ ] })
12670
+ ] }),
12671
+ /* @__PURE__ */ jsxRuntime.jsxs(
12672
+ ui.Text,
12673
+ {
12674
+ size: "small",
12675
+ leading: "compact",
12676
+ className: "text-ui-fg-subtle",
12677
+ children: [
12678
+ item.quantity,
12679
+ "x"
12680
+ ]
12681
+ }
12682
+ )
12683
+ ]
12684
+ },
12685
+ item.id
12686
+ )) : /* @__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: [
12687
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12688
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12689
+ 'No items found for "',
12690
+ query,
12691
+ '".'
12692
+ ] })
12693
+ ] }) })
12694
+ ] })
12695
+ ] });
12696
+ };
12697
+ const LocationField = ({ control, setValue }) => {
12698
+ const locations = useComboboxData({
12699
+ queryKey: ["locations"],
12700
+ queryFn: async (params) => {
12701
+ return await sdk.admin.stockLocation.list(params);
12702
+ },
12703
+ getOptions: (data) => {
12704
+ return data.stock_locations.map((location) => ({
12705
+ label: location.name,
12706
+ value: location.id
12707
+ }));
12708
+ }
12709
+ });
12710
+ return /* @__PURE__ */ jsxRuntime.jsx(
12711
+ Form$2.Field,
12712
+ {
12713
+ control,
12714
+ name: "location_id",
12715
+ render: ({ field: { onChange, ...field } }) => {
12716
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12717
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12718
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12719
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12720
+ ] }),
12721
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12722
+ Combobox,
12723
+ {
12724
+ options: locations.options,
12725
+ fetchNextPage: locations.fetchNextPage,
12726
+ isFetchingNextPage: locations.isFetchingNextPage,
12727
+ searchValue: locations.searchValue,
12728
+ onSearchValueChange: locations.onSearchValueChange,
12729
+ placeholder: "Select location",
12730
+ onChange: (value) => {
12731
+ setValue("shipping_option_id", "", {
12732
+ shouldDirty: true,
12733
+ shouldTouch: true
12734
+ });
12735
+ onChange(value);
12736
+ },
12737
+ ...field
12738
+ }
12739
+ ) })
12740
+ ] }) });
12741
+ }
12742
+ }
12743
+ );
12744
+ };
12745
+ const ShippingOptionField = ({
12746
+ shippingProfileId,
12747
+ preview,
12748
+ control
12749
+ }) => {
12750
+ var _a;
12751
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12752
+ const shippingOptions = useComboboxData({
12753
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12754
+ queryFn: async (params) => {
12755
+ return await sdk.admin.shippingOption.list({
12756
+ ...params,
12757
+ stock_location_id: locationId,
12758
+ shipping_profile_id: shippingProfileId
12759
+ });
12760
+ },
12761
+ getOptions: (data) => {
12762
+ return data.shipping_options.map((option) => {
12763
+ var _a2;
12764
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12765
+ (r) => r.attribute === "is_return" && r.value === "true"
12766
+ )) {
12767
+ return void 0;
12768
+ }
12769
+ return {
12770
+ label: option.name,
12771
+ value: option.id
12772
+ };
12773
+ }).filter(Boolean);
12774
+ },
12775
+ enabled: !!locationId && !!shippingProfileId,
12776
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12777
+ });
12778
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12779
+ return /* @__PURE__ */ jsxRuntime.jsx(
12780
+ Form$2.Field,
12781
+ {
12782
+ control,
12783
+ name: "shipping_option_id",
12784
+ render: ({ field }) => {
12785
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12786
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12787
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12788
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12789
+ ] }),
12790
+ /* @__PURE__ */ jsxRuntime.jsx(
12791
+ ConditionalTooltip,
12792
+ {
12793
+ content: tooltipContent,
12794
+ showTooltip: !locationId || !shippingProfileId,
12795
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12796
+ Combobox,
12797
+ {
12798
+ options: shippingOptions.options,
12799
+ fetchNextPage: shippingOptions.fetchNextPage,
12800
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12801
+ searchValue: shippingOptions.searchValue,
12802
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12803
+ placeholder: "Select shipping option",
12804
+ ...field,
12805
+ disabled: !locationId || !shippingProfileId
12806
+ }
12807
+ ) }) })
12808
+ }
12809
+ )
12810
+ ] }) });
12811
+ }
12812
+ }
12813
+ );
12814
+ };
12815
+ const CustomAmountField = ({
12816
+ control,
12817
+ currencyCode
12818
+ }) => {
12819
+ return /* @__PURE__ */ jsxRuntime.jsx(
12820
+ Form$2.Field,
12821
+ {
12822
+ control,
12823
+ name: "custom_amount",
12824
+ render: ({ field: { onChange, ...field } }) => {
12825
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12826
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12827
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12828
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12829
+ ] }),
12830
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12831
+ ui.CurrencyInput,
12832
+ {
12833
+ ...field,
12834
+ onValueChange: (value) => onChange(value),
12835
+ symbol: getNativeSymbol(currencyCode),
12836
+ code: currencyCode
12837
+ }
12838
+ ) })
12839
+ ] });
12840
+ }
12841
+ }
12842
+ );
12843
+ };
12844
+ const ShippingAddress = () => {
12845
+ const { id } = reactRouterDom.useParams();
12846
+ const { order, isPending, isError, error } = useOrder(id, {
12847
+ fields: "+shipping_address"
12848
+ });
12849
+ if (isError) {
12850
+ throw error;
12851
+ }
12852
+ const isReady = !isPending && !!order;
12853
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12854
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12857
+ ] }),
12858
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12859
+ ] });
12860
+ };
12861
+ const ShippingAddressForm = ({ order }) => {
12862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12863
+ const form = reactHookForm.useForm({
12864
+ defaultValues: {
12865
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12866
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12867
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12868
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12869
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12870
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12871
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12872
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12873
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12874
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12875
+ },
12876
+ resolver: zod.zodResolver(schema)
12877
+ });
12878
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12879
+ const { handleSuccess } = useRouteModal();
12880
+ const onSubmit = form.handleSubmit(async (data) => {
12881
+ await mutateAsync(
12882
+ {
12883
+ shipping_address: {
12884
+ first_name: data.first_name,
12885
+ last_name: data.last_name,
12886
+ company: data.company,
12887
+ address_1: data.address_1,
12888
+ address_2: data.address_2,
12889
+ city: data.city,
12890
+ province: data.province,
12891
+ country_code: data.country_code,
12892
+ postal_code: data.postal_code,
12893
+ phone: data.phone
12894
+ }
12895
+ },
12896
+ {
12897
+ onSuccess: () => {
12898
+ handleSuccess();
12899
+ },
12900
+ onError: (error) => {
12901
+ ui.toast.error(error.message);
12902
+ }
12903
+ }
12904
+ );
12905
+ });
12906
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12907
+ KeyboundForm,
12908
+ {
12909
+ className: "flex flex-1 flex-col overflow-hidden",
12910
+ onSubmit,
12911
+ children: [
12912
+ /* @__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: [
12913
+ /* @__PURE__ */ jsxRuntime.jsx(
12914
+ Form$2.Field,
12987
12915
  {
12988
- width: "12",
12989
- height: "12",
12990
- fill: "white",
12991
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12916
+ control: form.control,
12917
+ name: "country_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12992
12923
  }
12993
- ) }),
12994
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12995
- "rect",
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "first_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ ),
12938
+ /* @__PURE__ */ jsxRuntime.jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "last_name",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ )
12950
+ ] }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12996
12953
  {
12997
- width: "12",
12998
- height: "12",
12999
- fill: "white",
13000
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12954
+ control: form.control,
12955
+ name: "company",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
13001
12961
  }
13002
- ) }),
13003
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13004
- "rect",
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
13005
12965
  {
13006
- width: "12",
13007
- height: "12",
13008
- fill: "white",
13009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12966
+ control: form.control,
12967
+ name: "address_1",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
13010
12973
  }
13011
- ) }),
13012
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13013
- "rect",
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(
12976
+ Form$2.Field,
13014
12977
  {
13015
- width: "12",
13016
- height: "12",
13017
- fill: "white",
13018
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12978
+ control: form.control,
12979
+ name: "address_2",
12980
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
+ ] })
13019
12985
  }
13020
- ) }),
13021
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13022
- "rect",
12986
+ ),
12987
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "postal_code",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ ),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "city",
13005
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
+ ] })
13010
+ }
13011
+ )
13012
+ ] }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13023
13015
  {
13024
- width: "12",
13025
- height: "12",
13026
- fill: "white",
13027
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13016
+ control: form.control,
13017
+ name: "province",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13028
13023
  }
13029
- ) }),
13030
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13031
- "rect",
13024
+ ),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13032
13027
  {
13033
- width: "12",
13034
- height: "12",
13035
- fill: "white",
13036
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13028
+ control: form.control,
13029
+ name: "phone",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13037
13035
  }
13038
- ) })
13039
- ] })
13036
+ )
13037
+ ] }) }),
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13040
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13041
+ ] }) })
13040
13042
  ]
13041
13043
  }
13042
- );
13044
+ ) });
13043
13045
  };
13044
- const schema = objectType({
13045
- customer_id: stringType().min(1)
13046
- });
13046
+ const schema = addressSchema;
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13068,6 +13068,14 @@ const routeModule = {
13068
13068
  Component: BillingAddress,
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
+ {
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
+ },
13075
+ {
13076
+ Component: Email,
13077
+ path: "/draft-orders/:id/email"
13078
+ },
13071
13079
  {
13072
13080
  Component: Items,
13073
13081
  path: "/draft-orders/:id/items"
@@ -13077,32 +13085,24 @@ const routeModule = {
13077
13085
  path: "/draft-orders/:id/promotions"
13078
13086
  },
13079
13087
  {
13080
- Component: Email,
13081
- path: "/draft-orders/:id/email"
13088
+ Component: Metadata,
13089
+ path: "/draft-orders/:id/metadata"
13082
13090
  },
13083
13091
  {
13084
13092
  Component: SalesChannel,
13085
13093
  path: "/draft-orders/:id/sales-channel"
13086
13094
  },
13087
13095
  {
13088
- Component: ShippingAddress,
13089
- path: "/draft-orders/:id/shipping-address"
13096
+ Component: TransferOwnership,
13097
+ path: "/draft-orders/:id/transfer-ownership"
13090
13098
  },
13091
13099
  {
13092
13100
  Component: Shipping,
13093
13101
  path: "/draft-orders/:id/shipping"
13094
13102
  },
13095
13103
  {
13096
- Component: Metadata,
13097
- path: "/draft-orders/:id/metadata"
13098
- },
13099
- {
13100
- Component: CustomItems,
13101
- path: "/draft-orders/:id/custom-items"
13102
- },
13103
- {
13104
- Component: TransferOwnership,
13105
- path: "/draft-orders/:id/transfer-ownership"
13104
+ Component: ShippingAddress,
13105
+ path: "/draft-orders/:id/shipping-address"
13106
13106
  }
13107
13107
  ]
13108
13108
  }