@medusajs/draft-order 2.22.7 → 2.22.8-preview-20261118094528

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.
@@ -8149,1144 +8149,347 @@ const schema$2 = zod.z.object({
8149
8149
  const handle$3 = {
8150
8150
  permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
8151
8151
  };
8152
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
8153
- const Shipping = () => {
8152
+ const ShippingAddress = () => {
8154
8153
  const { id } = reactRouterDom.useParams();
8155
8154
  const { order, isPending, isError, error } = useOrder(id, {
8156
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
8155
+ fields: "+shipping_address"
8157
8156
  });
8158
- const {
8159
- order: preview,
8160
- isPending: isPreviewPending,
8161
- isError: isPreviewError,
8162
- error: previewError
8163
- } = useOrderPreview(id);
8164
- useInitiateOrderEdit({ preview });
8165
- const { onCancel } = useCancelOrderEdit({ preview });
8166
8157
  if (isError) {
8167
8158
  throw error;
8168
8159
  }
8169
- if (isPreviewError) {
8170
- throw previewError;
8171
- }
8172
- const orderHasItems = (order?.items?.length || 0) > 0;
8173
- const isReady = preview && !isPreviewPending && order && !isPending;
8174
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
8175
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
8176
- /* @__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: [
8177
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
8178
- /* @__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." }) })
8179
- ] }) }) }),
8180
- /* @__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" }) }) })
8181
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8182
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
8183
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
8184
- ] }) });
8160
+ const isReady = !isPending && !!order;
8161
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8162
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8163
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
8164
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
8165
+ ] }),
8166
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
8167
+ ] });
8185
8168
  };
8186
- const ShippingForm = ({ preview, order }) => {
8187
- const { setIsOpen } = useStackedModal();
8188
- const [isSubmitting, setIsSubmitting] = React.useState(false);
8189
- const [data, setData] = React.useState(null);
8190
- const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
8191
- const { shipping_options } = useShippingOptions(
8192
- {
8193
- id: appliedShippingOptionIds,
8194
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
8169
+ const ShippingAddressForm = ({ order }) => {
8170
+ const form = reactHookForm.useForm({
8171
+ defaultValues: {
8172
+ first_name: order.shipping_address?.first_name ?? "",
8173
+ last_name: order.shipping_address?.last_name ?? "",
8174
+ company: order.shipping_address?.company ?? "",
8175
+ address_1: order.shipping_address?.address_1 ?? "",
8176
+ address_2: order.shipping_address?.address_2 ?? "",
8177
+ city: order.shipping_address?.city ?? "",
8178
+ province: order.shipping_address?.province ?? "",
8179
+ country_code: order.shipping_address?.country_code ?? "",
8180
+ postal_code: order.shipping_address?.postal_code ?? "",
8181
+ phone: order.shipping_address?.phone ?? ""
8195
8182
  },
8196
- {
8197
- enabled: appliedShippingOptionIds.length > 0
8198
- }
8199
- );
8200
- const uniqueShippingProfiles = React.useMemo(() => {
8201
- const profiles = /* @__PURE__ */ new Map();
8202
- getUniqueShippingProfiles(order.items).forEach((profile) => {
8203
- profiles.set(profile.id, profile);
8204
- });
8205
- shipping_options?.forEach((option) => {
8206
- profiles.set(option.shipping_profile_id, option.shipping_profile);
8207
- });
8208
- return Array.from(profiles.values());
8209
- }, [order.items, shipping_options]);
8183
+ resolver: zod$1.zodResolver(schema$1)
8184
+ });
8185
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8210
8186
  const { handleSuccess } = useRouteModal();
8211
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
8212
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
8213
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
8214
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
8215
- const onSubmit = async () => {
8216
- setIsSubmitting(true);
8217
- let requestSucceeded = false;
8218
- await requestOrderEdit(void 0, {
8219
- onError: (e) => {
8220
- ui.toast.error(`Failed to request order edit: ${e.message}`);
8221
- },
8222
- onSuccess: () => {
8223
- requestSucceeded = true;
8224
- }
8225
- });
8226
- if (!requestSucceeded) {
8227
- setIsSubmitting(false);
8228
- return;
8229
- }
8230
- await confirmOrderEdit(void 0, {
8231
- onError: (e) => {
8232
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
8233
- },
8234
- onSuccess: () => {
8235
- handleSuccess();
8187
+ const onSubmit = form.handleSubmit(async (data) => {
8188
+ await mutateAsync(
8189
+ {
8190
+ shipping_address: {
8191
+ first_name: data.first_name,
8192
+ last_name: data.last_name,
8193
+ company: data.company,
8194
+ address_1: data.address_1,
8195
+ address_2: data.address_2,
8196
+ city: data.city,
8197
+ province: data.province,
8198
+ country_code: data.country_code,
8199
+ postal_code: data.postal_code,
8200
+ phone: data.phone
8201
+ }
8236
8202
  },
8237
- onSettled: () => {
8238
- setIsSubmitting(false);
8239
- }
8240
- });
8241
- };
8242
- const onKeydown = React.useCallback(
8243
- (e) => {
8244
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
8245
- if (data || isSubmitting) {
8246
- return;
8203
+ {
8204
+ onSuccess: () => {
8205
+ handleSuccess();
8206
+ },
8207
+ onError: (error) => {
8208
+ ui.toast.error(error.message);
8247
8209
  }
8248
- onSubmit();
8249
8210
  }
8250
- },
8251
- [data, isSubmitting, onSubmit]
8252
- );
8253
- React.useEffect(() => {
8254
- document.addEventListener("keydown", onKeydown);
8255
- return () => {
8256
- document.removeEventListener("keydown", onKeydown);
8257
- };
8258
- }, [onKeydown]);
8259
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
8260
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
8261
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
8262
- /* @__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: [
8263
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8264
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
8265
- /* @__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." }) })
8266
- ] }),
8267
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8268
- /* @__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: [
8269
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
8211
+ );
8212
+ });
8213
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8214
+ KeyboundForm,
8215
+ {
8216
+ className: "flex flex-1 flex-col overflow-hidden",
8217
+ onSubmit,
8218
+ children: [
8219
+ /* @__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: [
8220
+ /* @__PURE__ */ jsxRuntime.jsx(
8221
+ Form$2.Field,
8222
+ {
8223
+ control: form.control,
8224
+ name: "country_code",
8225
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8226
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
8227
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
8228
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8229
+ ] })
8230
+ }
8231
+ ),
8232
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8270
8233
  /* @__PURE__ */ jsxRuntime.jsx(
8271
- ui.Text,
8234
+ Form$2.Field,
8272
8235
  {
8273
- size: "xsmall",
8274
- weight: "plus",
8275
- className: "text-ui-fg-muted",
8276
- children: "Shipping profile"
8236
+ control: form.control,
8237
+ name: "first_name",
8238
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8239
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
8240
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8241
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8242
+ ] })
8277
8243
  }
8278
8244
  ),
8279
8245
  /* @__PURE__ */ jsxRuntime.jsx(
8280
- ui.Text,
8246
+ Form$2.Field,
8281
8247
  {
8282
- size: "xsmall",
8283
- weight: "plus",
8284
- className: "text-ui-fg-muted",
8285
- children: "Action"
8248
+ control: form.control,
8249
+ name: "last_name",
8250
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8251
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
8252
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8253
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8254
+ ] })
8286
8255
  }
8287
8256
  )
8288
8257
  ] }),
8289
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
8290
- const items = getItemsWithShippingProfile(
8291
- profile.id,
8292
- order.items
8293
- );
8294
- const hasItems = items.length > 0;
8295
- const shippingOption = shipping_options?.find(
8296
- (option) => option.shipping_profile_id === profile.id
8297
- );
8298
- const shippingMethod = preview.shipping_methods.find(
8299
- (method) => method.shipping_option_id === shippingOption?.id
8300
- );
8301
- const addShippingMethodAction = shippingMethod?.actions?.find(
8302
- (action) => action.action === "SHIPPING_ADD"
8303
- );
8304
- return /* @__PURE__ */ jsxRuntime.jsxs(
8305
- radixUi.Accordion.Item,
8306
- {
8307
- value: profile.id,
8308
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
8309
- children: [
8310
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
8311
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
8312
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
8313
- ui.IconButton,
8314
- {
8315
- size: "2xsmall",
8316
- variant: "transparent",
8317
- className: "group/trigger",
8318
- disabled: !hasItems,
8319
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
8320
- }
8321
- ) }),
8322
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
8323
- /* @__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" }) }) }),
8324
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
8325
- /* @__PURE__ */ jsxRuntime.jsx(
8326
- ui.Text,
8327
- {
8328
- size: "small",
8329
- weight: "plus",
8330
- leading: "compact",
8331
- children: profile.name
8332
- }
8333
- ),
8334
- /* @__PURE__ */ jsxRuntime.jsxs(
8335
- ui.Text,
8336
- {
8337
- size: "small",
8338
- leading: "compact",
8339
- className: "text-ui-fg-subtle",
8340
- children: [
8341
- items.length,
8342
- " ",
8343
- pluralize(items.length, "items", "item")
8344
- ]
8345
- }
8346
- )
8347
- ] })
8348
- ] }) : /* @__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: [
8349
- /* @__PURE__ */ jsxRuntime.jsx(
8350
- ui.Tooltip,
8351
- {
8352
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
8353
- "li",
8354
- {
8355
- children: `${item.quantity}x ${item.variant?.product?.title} (${item.variant?.title})`
8356
- },
8357
- item.id
8358
- )) }),
8359
- children: /* @__PURE__ */ jsxRuntime.jsxs(
8360
- ui.Badge,
8361
- {
8362
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
8363
- size: "xsmall",
8364
- children: [
8365
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
8366
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
8367
- items.reduce(
8368
- (acc, item) => acc + item.quantity,
8369
- 0
8370
- ),
8371
- "x",
8372
- " ",
8373
- pluralize(items.length, "items", "item")
8374
- ] })
8375
- ]
8376
- }
8377
- )
8378
- }
8379
- ),
8380
- /* @__PURE__ */ jsxRuntime.jsx(
8381
- ui.Tooltip,
8382
- {
8383
- content: shippingOption.service_zone?.fulfillment_set?.location?.name,
8384
- children: /* @__PURE__ */ jsxRuntime.jsxs(
8385
- ui.Badge,
8386
- {
8387
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
8388
- size: "xsmall",
8389
- children: [
8390
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
8391
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.service_zone?.fulfillment_set?.location?.name })
8392
- ]
8393
- }
8394
- )
8395
- }
8396
- ),
8397
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
8398
- ui.Badge,
8399
- {
8400
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
8401
- size: "xsmall",
8402
- children: [
8403
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
8404
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
8405
- ]
8406
- }
8407
- ) })
8408
- ] })
8409
- ] }),
8410
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
8411
- ActionMenu,
8412
- {
8413
- groups: [
8414
- {
8415
- actions: [
8416
- hasItems ? {
8417
- label: "Edit shipping option",
8418
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
8419
- onClick: () => {
8420
- setIsOpen(
8421
- STACKED_FOCUS_MODAL_ID,
8422
- true
8423
- );
8424
- setData({
8425
- shippingProfileId: profile.id,
8426
- shippingOption,
8427
- shippingMethod
8428
- });
8429
- }
8430
- } : void 0,
8431
- {
8432
- label: "Remove shipping option",
8433
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
8434
- onClick: () => {
8435
- if (shippingMethod) {
8436
- if (addShippingMethodAction) {
8437
- removeActionShippingMethod(
8438
- addShippingMethodAction.id
8439
- );
8440
- } else {
8441
- removeShippingMethod(
8442
- shippingMethod.id
8443
- );
8444
- }
8445
- }
8446
- }
8447
- }
8448
- ].filter(Boolean)
8449
- }
8450
- ]
8451
- }
8452
- ) : /* @__PURE__ */ jsxRuntime.jsx(
8453
- StackedModalTrigger,
8454
- {
8455
- shippingProfileId: profile.id,
8456
- shippingOption,
8457
- shippingMethod,
8458
- setData,
8459
- children: "Add shipping option"
8460
- }
8461
- )
8462
- ] }),
8463
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
8464
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8465
- items.map((item, idx) => {
8466
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8467
- /* @__PURE__ */ jsxRuntime.jsxs(
8468
- "div",
8469
- {
8470
- className: "flex items-center gap-x-3 px-3",
8471
- children: [
8472
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
8473
- ui.Divider,
8474
- {
8475
- variant: "dashed",
8476
- orientation: "vertical"
8477
- }
8478
- ) }),
8479
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
8480
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
8481
- ui.Text,
8482
- {
8483
- size: "small",
8484
- leading: "compact",
8485
- className: "text-ui-fg-subtle",
8486
- children: [
8487
- item.quantity,
8488
- "x"
8489
- ]
8490
- }
8491
- ) }),
8492
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
8493
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8494
- /* @__PURE__ */ jsxRuntime.jsxs(
8495
- ui.Text,
8496
- {
8497
- size: "small",
8498
- leading: "compact",
8499
- weight: "plus",
8500
- children: [
8501
- item.variant?.product?.title,
8502
- " (",
8503
- item.variant?.title,
8504
- ")"
8505
- ]
8506
- }
8507
- ),
8508
- /* @__PURE__ */ jsxRuntime.jsx(
8509
- ui.Text,
8510
- {
8511
- size: "small",
8512
- leading: "compact",
8513
- className: "text-ui-fg-subtle",
8514
- children: item.variant?.options?.map((option) => option.value).join(" · ")
8515
- }
8516
- )
8517
- ] })
8518
- ] })
8519
- ]
8520
- },
8521
- item.id
8522
- ),
8523
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
8524
- ] }, item.id);
8525
- })
8526
- ] })
8527
- ]
8528
- },
8529
- profile.id
8530
- );
8531
- }) })
8532
- ] }) })
8533
- ] }) }),
8534
- /* @__PURE__ */ jsxRuntime.jsx(
8535
- StackedFocusModal,
8536
- {
8537
- id: STACKED_FOCUS_MODAL_ID,
8538
- onOpenChangeCallback: (open) => {
8539
- if (!open) {
8540
- setData(null);
8258
+ /* @__PURE__ */ jsxRuntime.jsx(
8259
+ Form$2.Field,
8260
+ {
8261
+ control: form.control,
8262
+ name: "company",
8263
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8264
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
8265
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8266
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8267
+ ] })
8541
8268
  }
8542
- return open;
8543
- },
8544
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
8545
- }
8546
- )
8547
- ] }),
8548
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
8549
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
8550
- /* @__PURE__ */ jsxRuntime.jsx(
8551
- ui.Button,
8552
- {
8553
- size: "small",
8554
- type: "button",
8555
- isLoading: isSubmitting,
8556
- onClick: onSubmit,
8557
- children: "Save"
8558
- }
8559
- )
8560
- ] }) })
8561
- ] });
8562
- };
8563
- const StackedModalTrigger = ({
8564
- shippingProfileId,
8565
- shippingOption,
8566
- shippingMethod,
8567
- setData,
8568
- children
8569
- }) => {
8570
- const { setIsOpen, getIsOpen } = useStackedModal();
8571
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
8572
- const onToggle = () => {
8573
- if (isOpen) {
8574
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
8575
- setData(null);
8576
- } else {
8577
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
8578
- setData({
8579
- shippingProfileId,
8580
- shippingOption,
8581
- shippingMethod
8582
- });
8583
- }
8584
- };
8585
- return /* @__PURE__ */ jsxRuntime.jsx(
8586
- ui.Button,
8587
- {
8588
- size: "small",
8589
- variant: "secondary",
8590
- onClick: onToggle,
8591
- className: "text-ui-fg-primary shrink-0",
8592
- children
8593
- }
8594
- );
8595
- };
8596
- const ShippingProfileForm = ({
8597
- data,
8598
- order,
8599
- preview
8600
- }) => {
8601
- const { setIsOpen } = useStackedModal();
8602
- const form = reactHookForm.useForm({
8603
- resolver: zod$1.zodResolver(shippingMethodSchema),
8604
- defaultValues: {
8605
- location_id: data.shippingOption?.service_zone?.fulfillment_set?.location?.id,
8606
- shipping_option_id: data.shippingOption?.id,
8607
- custom_amount: data.shippingMethod?.amount
8608
- }
8609
- });
8610
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
8611
- const {
8612
- mutateAsync: updateShippingMethod,
8613
- isPending: isUpdatingShippingMethod
8614
- } = useDraftOrderUpdateShippingMethod(order.id);
8615
- const onSubmit = form.handleSubmit(async (values) => {
8616
- if (dequal.dequal(values, form.formState.defaultValues)) {
8617
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
8618
- return;
8619
- }
8620
- if (data.shippingMethod) {
8621
- await updateShippingMethod(
8622
- {
8623
- method_id: data.shippingMethod.id,
8624
- shipping_option_id: values.shipping_option_id,
8625
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
8626
- },
8627
- {
8628
- onError: (e) => {
8629
- ui.toast.error(e.message);
8630
- },
8631
- onSuccess: () => {
8632
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
8633
- }
8634
- }
8635
- );
8636
- return;
8637
- }
8638
- await addShippingMethod(
8639
- {
8640
- shipping_option_id: values.shipping_option_id,
8641
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
8642
- },
8643
- {
8644
- onError: (e) => {
8645
- ui.toast.error(e.message);
8646
- },
8647
- onSuccess: () => {
8648
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
8649
- }
8650
- }
8651
- );
8652
- });
8653
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8654
- KeyboundForm,
8655
- {
8656
- className: "flex h-full flex-col overflow-hidden",
8657
- onSubmit,
8658
- children: [
8659
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
8660
- /* @__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: [
8661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8662
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
8663
- /* @__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." }) })
8664
- ] }),
8665
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8269
+ ),
8666
8270
  /* @__PURE__ */ jsxRuntime.jsx(
8667
- LocationField,
8271
+ Form$2.Field,
8668
8272
  {
8669
8273
  control: form.control,
8670
- setValue: form.setValue
8274
+ name: "address_1",
8275
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8276
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
8277
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8278
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8279
+ ] })
8671
8280
  }
8672
8281
  ),
8673
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8674
8282
  /* @__PURE__ */ jsxRuntime.jsx(
8675
- ShippingOptionField,
8283
+ Form$2.Field,
8676
8284
  {
8677
- shippingProfileId: data.shippingProfileId,
8678
- preview,
8679
- control: form.control
8285
+ control: form.control,
8286
+ name: "address_2",
8287
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8288
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
8289
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8290
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8291
+ ] })
8680
8292
  }
8681
8293
  ),
8682
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8294
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8295
+ /* @__PURE__ */ jsxRuntime.jsx(
8296
+ Form$2.Field,
8297
+ {
8298
+ control: form.control,
8299
+ name: "postal_code",
8300
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8301
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
8302
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8303
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8304
+ ] })
8305
+ }
8306
+ ),
8307
+ /* @__PURE__ */ jsxRuntime.jsx(
8308
+ Form$2.Field,
8309
+ {
8310
+ control: form.control,
8311
+ name: "city",
8312
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8313
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
8314
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8315
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8316
+ ] })
8317
+ }
8318
+ )
8319
+ ] }),
8683
8320
  /* @__PURE__ */ jsxRuntime.jsx(
8684
- CustomAmountField,
8321
+ Form$2.Field,
8685
8322
  {
8686
8323
  control: form.control,
8687
- currencyCode: order.currency_code
8324
+ name: "province",
8325
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8326
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
8327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8328
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8329
+ ] })
8688
8330
  }
8689
8331
  ),
8690
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8691
8332
  /* @__PURE__ */ jsxRuntime.jsx(
8692
- ItemsPreview,
8333
+ Form$2.Field,
8693
8334
  {
8694
- order,
8695
- shippingProfileId: data.shippingProfileId
8335
+ control: form.control,
8336
+ name: "phone",
8337
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8338
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
8339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
8340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8341
+ ] })
8696
8342
  }
8697
8343
  )
8698
- ] }) }) }),
8699
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
8700
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
8344
+ ] }) }),
8345
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8346
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8347
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8348
+ ] }) })
8349
+ ]
8350
+ }
8351
+ ) });
8352
+ };
8353
+ const schema$1 = addressSchema;
8354
+ const handle$2 = {
8355
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
8356
+ };
8357
+ const TransferOwnership = () => {
8358
+ const { id } = reactRouterDom.useParams();
8359
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
8360
+ fields: "id,customer_id,customer.*"
8361
+ });
8362
+ if (isError) {
8363
+ throw error;
8364
+ }
8365
+ const isReady = !isPending && !!draft_order;
8366
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8367
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8368
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
8369
+ /* @__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" }) })
8370
+ ] }),
8371
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
8372
+ ] });
8373
+ };
8374
+ const TransferOwnershipForm = ({ order }) => {
8375
+ const form = reactHookForm.useForm({
8376
+ defaultValues: {
8377
+ customer_id: order.customer_id || ""
8378
+ },
8379
+ resolver: zod$1.zodResolver(schema)
8380
+ });
8381
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8382
+ const { handleSuccess } = useRouteModal();
8383
+ const name = [order.customer?.first_name, order.customer?.last_name].filter(Boolean).join(" ");
8384
+ const currentCustomer = order.customer ? {
8385
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
8386
+ value: order.customer.id
8387
+ } : null;
8388
+ const onSubmit = form.handleSubmit(async (data) => {
8389
+ await mutateAsync(
8390
+ { customer_id: data.customer_id },
8391
+ {
8392
+ onSuccess: () => {
8393
+ ui.toast.success("Customer updated");
8394
+ handleSuccess();
8395
+ },
8396
+ onError: (error) => {
8397
+ ui.toast.error(error.message);
8398
+ }
8399
+ }
8400
+ );
8401
+ });
8402
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8403
+ KeyboundForm,
8404
+ {
8405
+ className: "flex flex-1 flex-col overflow-hidden",
8406
+ onSubmit,
8407
+ children: [
8408
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
8409
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
8410
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
8411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
8413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
8414
+ ] }),
8415
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
8416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
8417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
8418
+ ] })
8419
+ ] }),
8701
8420
  /* @__PURE__ */ jsxRuntime.jsx(
8702
- ui.Button,
8421
+ CustomerField,
8703
8422
  {
8704
- size: "small",
8705
- type: "submit",
8706
- isLoading: isPending || isUpdatingShippingMethod,
8707
- children: data.shippingMethod ? "Update" : "Add"
8423
+ control: form.control,
8424
+ currentCustomerId: order.customer_id
8708
8425
  }
8709
8426
  )
8427
+ ] }),
8428
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
8429
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
8430
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8710
8431
  ] }) })
8711
8432
  ]
8712
8433
  }
8713
- ) }) });
8434
+ ) });
8714
8435
  };
8715
- const shippingMethodSchema = zod.z.object({
8716
- location_id: zod.z.string(),
8717
- shipping_option_id: zod.z.string(),
8718
- custom_amount: zod.z.union([zod.z.number(), zod.z.string()]).optional()
8719
- });
8720
- const ItemsPreview = ({ order, shippingProfileId }) => {
8721
- const matches = order.items.filter(
8722
- (item) => item.variant?.product?.shipping_profile?.id === shippingProfileId
8723
- );
8724
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
8725
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8726
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
8727
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
8728
- ] }) }),
8729
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
8730
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
8731
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
8732
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
8733
- ] }),
8734
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
8735
- "div",
8736
- {
8737
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
8738
- children: [
8739
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
8740
- /* @__PURE__ */ jsxRuntime.jsx(
8741
- Thumbnail,
8742
- {
8743
- thumbnail: item.thumbnail,
8744
- alt: item.product_title ?? void 0
8745
- }
8746
- ),
8747
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8748
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
8749
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
8750
- /* @__PURE__ */ jsxRuntime.jsxs(
8751
- ui.Text,
8752
- {
8753
- size: "small",
8754
- leading: "compact",
8755
- className: "text-ui-fg-subtle",
8756
- children: [
8757
- "(",
8758
- item.variant_title,
8759
- ")"
8760
- ]
8761
- }
8762
- )
8763
- ] }),
8764
- /* @__PURE__ */ jsxRuntime.jsx(
8765
- ui.Text,
8766
- {
8767
- size: "small",
8768
- leading: "compact",
8769
- className: "text-ui-fg-subtle",
8770
- children: item.variant_sku
8771
- }
8772
- )
8773
- ] })
8774
- ] }),
8775
- /* @__PURE__ */ jsxRuntime.jsxs(
8776
- ui.Text,
8777
- {
8778
- size: "small",
8779
- leading: "compact",
8780
- className: "text-ui-fg-subtle",
8781
- children: [
8782
- item.quantity,
8783
- "x"
8784
- ]
8785
- }
8786
- )
8787
- ]
8788
- },
8789
- item.id
8790
- )) : /* @__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: [
8791
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
8792
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
8793
- 'No items found for "',
8794
- query,
8795
- '".'
8796
- ] })
8797
- ] }) })
8798
- ] })
8799
- ] });
8800
- };
8801
- const LocationField = ({ control, setValue }) => {
8802
- const locations = useComboboxData({
8803
- queryKey: ["locations"],
8804
- queryFn: async (params) => {
8805
- return await sdk.admin.stockLocation.list(params);
8806
- },
8807
- getOptions: (data) => {
8808
- return data.stock_locations.map((location) => ({
8809
- label: location.name,
8810
- value: location.id
8811
- }));
8812
- }
8813
- });
8814
- return /* @__PURE__ */ jsxRuntime.jsx(
8815
- Form$2.Field,
8816
- {
8817
- control,
8818
- name: "location_id",
8819
- render: ({ field: { onChange, ...field } }) => {
8820
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8821
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8822
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
8823
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
8824
- ] }),
8825
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8826
- Combobox,
8827
- {
8828
- options: locations.options,
8829
- fetchNextPage: locations.fetchNextPage,
8830
- isFetchingNextPage: locations.isFetchingNextPage,
8831
- searchValue: locations.searchValue,
8832
- onSearchValueChange: locations.onSearchValueChange,
8833
- placeholder: "Select location",
8834
- onChange: (value) => {
8835
- setValue("shipping_option_id", "", {
8836
- shouldDirty: true,
8837
- shouldTouch: true
8838
- });
8839
- onChange(value);
8840
- },
8841
- ...field
8842
- }
8843
- ) })
8844
- ] }) });
8845
- }
8846
- }
8847
- );
8848
- };
8849
- const ShippingOptionField = ({
8850
- shippingProfileId,
8851
- preview,
8852
- control
8853
- }) => {
8854
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
8855
- const shippingOptions = useComboboxData({
8856
- queryKey: ["shipping_options", locationId, shippingProfileId],
8436
+ const CustomerField = ({ control, currentCustomerId }) => {
8437
+ const customers = useComboboxData({
8857
8438
  queryFn: async (params) => {
8858
- return await sdk.admin.shippingOption.list({
8439
+ return await sdk.admin.customer.list({
8859
8440
  ...params,
8860
- stock_location_id: locationId,
8861
- shipping_profile_id: shippingProfileId
8441
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
8862
8442
  });
8863
8443
  },
8444
+ queryKey: ["customers"],
8864
8445
  getOptions: (data) => {
8865
- return data.shipping_options.map((option) => {
8866
- if (option.rules?.find(
8867
- (r) => r.attribute === "is_return" && r.value === "true"
8868
- )) {
8869
- return void 0;
8870
- }
8446
+ return data.customers.filter(
8447
+ (customer) => customer !== null
8448
+ ).map((customer) => {
8449
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
8871
8450
  return {
8872
- label: option.name,
8873
- value: option.id
8451
+ label: name ? `${name} (${customer.email})` : customer.email,
8452
+ value: customer.id
8874
8453
  };
8875
- }).filter(Boolean);
8876
- },
8877
- enabled: !!locationId && !!shippingProfileId,
8878
- defaultValue: preview.shipping_methods[0]?.shipping_option_id || void 0
8454
+ });
8455
+ }
8879
8456
  });
8880
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
8881
8457
  return /* @__PURE__ */ jsxRuntime.jsx(
8882
8458
  Form$2.Field,
8883
8459
  {
8460
+ name: "customer_id",
8884
8461
  control,
8885
- name: "shipping_option_id",
8886
- render: ({ field }) => {
8887
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8888
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8889
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
8890
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
8891
- ] }),
8892
- /* @__PURE__ */ jsxRuntime.jsx(
8893
- ConditionalTooltip,
8894
- {
8895
- content: tooltipContent,
8896
- showTooltip: !locationId || !shippingProfileId,
8897
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8898
- Combobox,
8899
- {
8900
- options: shippingOptions.options,
8901
- fetchNextPage: shippingOptions.fetchNextPage,
8902
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
8903
- searchValue: shippingOptions.searchValue,
8904
- onSearchValueChange: shippingOptions.onSearchValueChange,
8905
- placeholder: "Select shipping option",
8906
- ...field,
8907
- disabled: !locationId || !shippingProfileId
8908
- }
8909
- ) }) })
8910
- }
8911
- )
8912
- ] }) });
8913
- }
8462
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
8463
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
8465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
8466
+ ] }),
8467
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8468
+ Combobox,
8469
+ {
8470
+ options: customers.options,
8471
+ fetchNextPage: customers.fetchNextPage,
8472
+ isFetchingNextPage: customers.isFetchingNextPage,
8473
+ searchValue: customers.searchValue,
8474
+ onSearchValueChange: customers.onSearchValueChange,
8475
+ placeholder: "Select customer",
8476
+ ...field
8477
+ }
8478
+ ) }),
8479
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8480
+ ] })
8914
8481
  }
8915
8482
  );
8916
8483
  };
8917
- const CustomAmountField = ({
8918
- control,
8919
- currencyCode
8920
- }) => {
8921
- return /* @__PURE__ */ jsxRuntime.jsx(
8922
- Form$2.Field,
8484
+ const Illustration = () => {
8485
+ return /* @__PURE__ */ jsxRuntime.jsxs(
8486
+ "svg",
8923
8487
  {
8924
- control,
8925
- name: "custom_amount",
8926
- render: ({ field: { onChange, ...field } }) => {
8927
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
8928
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
8929
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
8930
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
8931
- ] }),
8932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8933
- ui.CurrencyInput,
8934
- {
8935
- ...field,
8936
- onValueChange: (value) => onChange(value),
8937
- symbol: getNativeSymbol(currencyCode),
8938
- code: currencyCode
8939
- }
8940
- ) })
8941
- ] });
8942
- }
8943
- }
8944
- );
8945
- };
8946
- const handle$2 = {
8947
- permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
8948
- };
8949
- const ShippingAddress = () => {
8950
- const { id } = reactRouterDom.useParams();
8951
- const { order, isPending, isError, error } = useOrder(id, {
8952
- fields: "+shipping_address"
8953
- });
8954
- if (isError) {
8955
- throw error;
8956
- }
8957
- const isReady = !isPending && !!order;
8958
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8959
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8960
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
8961
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
8962
- ] }),
8963
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
8964
- ] });
8965
- };
8966
- const ShippingAddressForm = ({ order }) => {
8967
- const form = reactHookForm.useForm({
8968
- defaultValues: {
8969
- first_name: order.shipping_address?.first_name ?? "",
8970
- last_name: order.shipping_address?.last_name ?? "",
8971
- company: order.shipping_address?.company ?? "",
8972
- address_1: order.shipping_address?.address_1 ?? "",
8973
- address_2: order.shipping_address?.address_2 ?? "",
8974
- city: order.shipping_address?.city ?? "",
8975
- province: order.shipping_address?.province ?? "",
8976
- country_code: order.shipping_address?.country_code ?? "",
8977
- postal_code: order.shipping_address?.postal_code ?? "",
8978
- phone: order.shipping_address?.phone ?? ""
8979
- },
8980
- resolver: zod$1.zodResolver(schema$1)
8981
- });
8982
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8983
- const { handleSuccess } = useRouteModal();
8984
- const onSubmit = form.handleSubmit(async (data) => {
8985
- await mutateAsync(
8986
- {
8987
- shipping_address: {
8988
- first_name: data.first_name,
8989
- last_name: data.last_name,
8990
- company: data.company,
8991
- address_1: data.address_1,
8992
- address_2: data.address_2,
8993
- city: data.city,
8994
- province: data.province,
8995
- country_code: data.country_code,
8996
- postal_code: data.postal_code,
8997
- phone: data.phone
8998
- }
8999
- },
9000
- {
9001
- onSuccess: () => {
9002
- handleSuccess();
9003
- },
9004
- onError: (error) => {
9005
- ui.toast.error(error.message);
9006
- }
9007
- }
9008
- );
9009
- });
9010
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9011
- KeyboundForm,
9012
- {
9013
- className: "flex flex-1 flex-col overflow-hidden",
9014
- onSubmit,
9015
- children: [
9016
- /* @__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: [
9017
- /* @__PURE__ */ jsxRuntime.jsx(
9018
- Form$2.Field,
9019
- {
9020
- control: form.control,
9021
- name: "country_code",
9022
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9023
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9024
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9026
- ] })
9027
- }
9028
- ),
9029
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9030
- /* @__PURE__ */ jsxRuntime.jsx(
9031
- Form$2.Field,
9032
- {
9033
- control: form.control,
9034
- name: "first_name",
9035
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9036
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9037
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9038
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9039
- ] })
9040
- }
9041
- ),
9042
- /* @__PURE__ */ jsxRuntime.jsx(
9043
- Form$2.Field,
9044
- {
9045
- control: form.control,
9046
- name: "last_name",
9047
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9048
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9049
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9050
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9051
- ] })
9052
- }
9053
- )
9054
- ] }),
9055
- /* @__PURE__ */ jsxRuntime.jsx(
9056
- Form$2.Field,
9057
- {
9058
- control: form.control,
9059
- name: "company",
9060
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9061
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9062
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9063
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9064
- ] })
9065
- }
9066
- ),
9067
- /* @__PURE__ */ jsxRuntime.jsx(
9068
- Form$2.Field,
9069
- {
9070
- control: form.control,
9071
- name: "address_1",
9072
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9073
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9074
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9075
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9076
- ] })
9077
- }
9078
- ),
9079
- /* @__PURE__ */ jsxRuntime.jsx(
9080
- Form$2.Field,
9081
- {
9082
- control: form.control,
9083
- name: "address_2",
9084
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9085
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9086
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9087
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9088
- ] })
9089
- }
9090
- ),
9091
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9092
- /* @__PURE__ */ jsxRuntime.jsx(
9093
- Form$2.Field,
9094
- {
9095
- control: form.control,
9096
- name: "postal_code",
9097
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9098
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9099
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9100
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9101
- ] })
9102
- }
9103
- ),
9104
- /* @__PURE__ */ jsxRuntime.jsx(
9105
- Form$2.Field,
9106
- {
9107
- control: form.control,
9108
- name: "city",
9109
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9110
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9111
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9112
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9113
- ] })
9114
- }
9115
- )
9116
- ] }),
9117
- /* @__PURE__ */ jsxRuntime.jsx(
9118
- Form$2.Field,
9119
- {
9120
- control: form.control,
9121
- name: "province",
9122
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9123
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9124
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9125
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9126
- ] })
9127
- }
9128
- ),
9129
- /* @__PURE__ */ jsxRuntime.jsx(
9130
- Form$2.Field,
9131
- {
9132
- control: form.control,
9133
- name: "phone",
9134
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9135
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9136
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9138
- ] })
9139
- }
9140
- )
9141
- ] }) }),
9142
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9143
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9144
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9145
- ] }) })
9146
- ]
9147
- }
9148
- ) });
9149
- };
9150
- const schema$1 = addressSchema;
9151
- const handle$1 = {
9152
- permissions: EDIT_DRAFT_ORDER_PERMISSIONS
9153
- };
9154
- const TransferOwnership = () => {
9155
- const { id } = reactRouterDom.useParams();
9156
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
9157
- fields: "id,customer_id,customer.*"
9158
- });
9159
- if (isError) {
9160
- throw error;
9161
- }
9162
- const isReady = !isPending && !!draft_order;
9163
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9164
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9165
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
9166
- /* @__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" }) })
9167
- ] }),
9168
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
9169
- ] });
9170
- };
9171
- const TransferOwnershipForm = ({ order }) => {
9172
- const form = reactHookForm.useForm({
9173
- defaultValues: {
9174
- customer_id: order.customer_id || ""
9175
- },
9176
- resolver: zod$1.zodResolver(schema)
9177
- });
9178
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9179
- const { handleSuccess } = useRouteModal();
9180
- const name = [order.customer?.first_name, order.customer?.last_name].filter(Boolean).join(" ");
9181
- const currentCustomer = order.customer ? {
9182
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
9183
- value: order.customer.id
9184
- } : null;
9185
- const onSubmit = form.handleSubmit(async (data) => {
9186
- await mutateAsync(
9187
- { customer_id: data.customer_id },
9188
- {
9189
- onSuccess: () => {
9190
- ui.toast.success("Customer updated");
9191
- handleSuccess();
9192
- },
9193
- onError: (error) => {
9194
- ui.toast.error(error.message);
9195
- }
9196
- }
9197
- );
9198
- });
9199
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9200
- KeyboundForm,
9201
- {
9202
- className: "flex flex-1 flex-col overflow-hidden",
9203
- onSubmit,
9204
- children: [
9205
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
9206
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
9207
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
9208
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9209
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
9210
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
9211
- ] }),
9212
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
9213
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
9214
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
9215
- ] })
9216
- ] }),
9217
- /* @__PURE__ */ jsxRuntime.jsx(
9218
- CustomerField,
9219
- {
9220
- control: form.control,
9221
- currentCustomerId: order.customer_id
9222
- }
9223
- )
9224
- ] }),
9225
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9226
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
9227
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9228
- ] }) })
9229
- ]
9230
- }
9231
- ) });
9232
- };
9233
- const CustomerField = ({ control, currentCustomerId }) => {
9234
- const customers = useComboboxData({
9235
- queryFn: async (params) => {
9236
- return await sdk.admin.customer.list({
9237
- ...params,
9238
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
9239
- });
9240
- },
9241
- queryKey: ["customers"],
9242
- getOptions: (data) => {
9243
- return data.customers.filter(
9244
- (customer) => customer !== null
9245
- ).map((customer) => {
9246
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
9247
- return {
9248
- label: name ? `${name} (${customer.email})` : customer.email,
9249
- value: customer.id
9250
- };
9251
- });
9252
- }
9253
- });
9254
- return /* @__PURE__ */ jsxRuntime.jsx(
9255
- Form$2.Field,
9256
- {
9257
- name: "customer_id",
9258
- control,
9259
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
9260
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9261
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
9262
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
9263
- ] }),
9264
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9265
- Combobox,
9266
- {
9267
- options: customers.options,
9268
- fetchNextPage: customers.fetchNextPage,
9269
- isFetchingNextPage: customers.isFetchingNextPage,
9270
- searchValue: customers.searchValue,
9271
- onSearchValueChange: customers.onSearchValueChange,
9272
- placeholder: "Select customer",
9273
- ...field
9274
- }
9275
- ) }),
9276
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9277
- ] })
9278
- }
9279
- );
9280
- };
9281
- const Illustration = () => {
9282
- return /* @__PURE__ */ jsxRuntime.jsxs(
9283
- "svg",
9284
- {
9285
- width: "280",
9286
- height: "180",
9287
- viewBox: "0 0 280 180",
9288
- fill: "none",
9289
- xmlns: "http://www.w3.org/2000/svg",
8488
+ width: "280",
8489
+ height: "180",
8490
+ viewBox: "0 0 280 180",
8491
+ fill: "none",
8492
+ xmlns: "http://www.w3.org/2000/svg",
9290
8493
  children: [
9291
8494
  /* @__PURE__ */ jsxRuntime.jsx(
9292
8495
  "rect",
@@ -9564,72 +8767,869 @@ const Illustration = () => {
9564
8767
  strokeLinecap: "round",
9565
8768
  strokeLinejoin: "round"
9566
8769
  }
9567
- ) }),
9568
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
9569
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9570
- "rect",
8770
+ ) }),
8771
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
8772
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8773
+ "rect",
8774
+ {
8775
+ width: "12",
8776
+ height: "12",
8777
+ fill: "white",
8778
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
8779
+ }
8780
+ ) }),
8781
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8782
+ "rect",
8783
+ {
8784
+ width: "12",
8785
+ height: "12",
8786
+ fill: "white",
8787
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
8788
+ }
8789
+ ) }),
8790
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8791
+ "rect",
8792
+ {
8793
+ width: "12",
8794
+ height: "12",
8795
+ fill: "white",
8796
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
8797
+ }
8798
+ ) }),
8799
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8800
+ "rect",
8801
+ {
8802
+ width: "12",
8803
+ height: "12",
8804
+ fill: "white",
8805
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
8806
+ }
8807
+ ) }),
8808
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8809
+ "rect",
8810
+ {
8811
+ width: "12",
8812
+ height: "12",
8813
+ fill: "white",
8814
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
8815
+ }
8816
+ ) }),
8817
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
8818
+ "rect",
8819
+ {
8820
+ width: "12",
8821
+ height: "12",
8822
+ fill: "white",
8823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
8824
+ }
8825
+ ) })
8826
+ ] })
8827
+ ]
8828
+ }
8829
+ );
8830
+ };
8831
+ const schema = zod.z.object({
8832
+ customer_id: zod.z.string().min(1)
8833
+ });
8834
+ const handle$1 = {
8835
+ permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
8836
+ };
8837
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
8838
+ const Shipping = () => {
8839
+ const { id } = reactRouterDom.useParams();
8840
+ const { order, isPending, isError, error } = useOrder(id, {
8841
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
8842
+ });
8843
+ const {
8844
+ order: preview,
8845
+ isPending: isPreviewPending,
8846
+ isError: isPreviewError,
8847
+ error: previewError
8848
+ } = useOrderPreview(id);
8849
+ useInitiateOrderEdit({ preview });
8850
+ const { onCancel } = useCancelOrderEdit({ preview });
8851
+ if (isError) {
8852
+ throw error;
8853
+ }
8854
+ if (isPreviewError) {
8855
+ throw previewError;
8856
+ }
8857
+ const orderHasItems = (order?.items?.length || 0) > 0;
8858
+ const isReady = preview && !isPreviewPending && order && !isPending;
8859
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
8860
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
8861
+ /* @__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: [
8862
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
8863
+ /* @__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." }) })
8864
+ ] }) }) }),
8865
+ /* @__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" }) }) })
8866
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8867
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
8868
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
8869
+ ] }) });
8870
+ };
8871
+ const ShippingForm = ({ preview, order }) => {
8872
+ const { setIsOpen } = useStackedModal();
8873
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
8874
+ const [data, setData] = React.useState(null);
8875
+ const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
8876
+ const { shipping_options } = useShippingOptions(
8877
+ {
8878
+ id: appliedShippingOptionIds,
8879
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
8880
+ },
8881
+ {
8882
+ enabled: appliedShippingOptionIds.length > 0
8883
+ }
8884
+ );
8885
+ const uniqueShippingProfiles = React.useMemo(() => {
8886
+ const profiles = /* @__PURE__ */ new Map();
8887
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
8888
+ profiles.set(profile.id, profile);
8889
+ });
8890
+ shipping_options?.forEach((option) => {
8891
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
8892
+ });
8893
+ return Array.from(profiles.values());
8894
+ }, [order.items, shipping_options]);
8895
+ const { handleSuccess } = useRouteModal();
8896
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
8897
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
8898
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
8899
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
8900
+ const onSubmit = async () => {
8901
+ setIsSubmitting(true);
8902
+ let requestSucceeded = false;
8903
+ await requestOrderEdit(void 0, {
8904
+ onError: (e) => {
8905
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
8906
+ },
8907
+ onSuccess: () => {
8908
+ requestSucceeded = true;
8909
+ }
8910
+ });
8911
+ if (!requestSucceeded) {
8912
+ setIsSubmitting(false);
8913
+ return;
8914
+ }
8915
+ await confirmOrderEdit(void 0, {
8916
+ onError: (e) => {
8917
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
8918
+ },
8919
+ onSuccess: () => {
8920
+ handleSuccess();
8921
+ },
8922
+ onSettled: () => {
8923
+ setIsSubmitting(false);
8924
+ }
8925
+ });
8926
+ };
8927
+ const onKeydown = React.useCallback(
8928
+ (e) => {
8929
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
8930
+ if (data || isSubmitting) {
8931
+ return;
8932
+ }
8933
+ onSubmit();
8934
+ }
8935
+ },
8936
+ [data, isSubmitting, onSubmit]
8937
+ );
8938
+ React.useEffect(() => {
8939
+ document.addEventListener("keydown", onKeydown);
8940
+ return () => {
8941
+ document.removeEventListener("keydown", onKeydown);
8942
+ };
8943
+ }, [onKeydown]);
8944
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
8945
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
8946
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
8947
+ /* @__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: [
8948
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
8949
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
8950
+ /* @__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." }) })
8951
+ ] }),
8952
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
8953
+ /* @__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: [
8954
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
8955
+ /* @__PURE__ */ jsxRuntime.jsx(
8956
+ ui.Text,
8957
+ {
8958
+ size: "xsmall",
8959
+ weight: "plus",
8960
+ className: "text-ui-fg-muted",
8961
+ children: "Shipping profile"
8962
+ }
8963
+ ),
8964
+ /* @__PURE__ */ jsxRuntime.jsx(
8965
+ ui.Text,
8966
+ {
8967
+ size: "xsmall",
8968
+ weight: "plus",
8969
+ className: "text-ui-fg-muted",
8970
+ children: "Action"
8971
+ }
8972
+ )
8973
+ ] }),
8974
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
8975
+ const items = getItemsWithShippingProfile(
8976
+ profile.id,
8977
+ order.items
8978
+ );
8979
+ const hasItems = items.length > 0;
8980
+ const shippingOption = shipping_options?.find(
8981
+ (option) => option.shipping_profile_id === profile.id
8982
+ );
8983
+ const shippingMethod = preview.shipping_methods.find(
8984
+ (method) => method.shipping_option_id === shippingOption?.id
8985
+ );
8986
+ const addShippingMethodAction = shippingMethod?.actions?.find(
8987
+ (action) => action.action === "SHIPPING_ADD"
8988
+ );
8989
+ return /* @__PURE__ */ jsxRuntime.jsxs(
8990
+ radixUi.Accordion.Item,
8991
+ {
8992
+ value: profile.id,
8993
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
8994
+ children: [
8995
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
8996
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
8997
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
8998
+ ui.IconButton,
8999
+ {
9000
+ size: "2xsmall",
9001
+ variant: "transparent",
9002
+ className: "group/trigger",
9003
+ disabled: !hasItems,
9004
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
9005
+ }
9006
+ ) }),
9007
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
9008
+ /* @__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" }) }) }),
9009
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
9010
+ /* @__PURE__ */ jsxRuntime.jsx(
9011
+ ui.Text,
9012
+ {
9013
+ size: "small",
9014
+ weight: "plus",
9015
+ leading: "compact",
9016
+ children: profile.name
9017
+ }
9018
+ ),
9019
+ /* @__PURE__ */ jsxRuntime.jsxs(
9020
+ ui.Text,
9021
+ {
9022
+ size: "small",
9023
+ leading: "compact",
9024
+ className: "text-ui-fg-subtle",
9025
+ children: [
9026
+ items.length,
9027
+ " ",
9028
+ pluralize(items.length, "items", "item")
9029
+ ]
9030
+ }
9031
+ )
9032
+ ] })
9033
+ ] }) : /* @__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: [
9034
+ /* @__PURE__ */ jsxRuntime.jsx(
9035
+ ui.Tooltip,
9036
+ {
9037
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
9038
+ "li",
9039
+ {
9040
+ children: `${item.quantity}x ${item.variant?.product?.title} (${item.variant?.title})`
9041
+ },
9042
+ item.id
9043
+ )) }),
9044
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
9045
+ ui.Badge,
9046
+ {
9047
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
9048
+ size: "xsmall",
9049
+ children: [
9050
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
9051
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
9052
+ items.reduce(
9053
+ (acc, item) => acc + item.quantity,
9054
+ 0
9055
+ ),
9056
+ "x",
9057
+ " ",
9058
+ pluralize(items.length, "items", "item")
9059
+ ] })
9060
+ ]
9061
+ }
9062
+ )
9063
+ }
9064
+ ),
9065
+ /* @__PURE__ */ jsxRuntime.jsx(
9066
+ ui.Tooltip,
9067
+ {
9068
+ content: shippingOption.service_zone?.fulfillment_set?.location?.name,
9069
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
9070
+ ui.Badge,
9071
+ {
9072
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
9073
+ size: "xsmall",
9074
+ children: [
9075
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
9076
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.service_zone?.fulfillment_set?.location?.name })
9077
+ ]
9078
+ }
9079
+ )
9080
+ }
9081
+ ),
9082
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
9083
+ ui.Badge,
9084
+ {
9085
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
9086
+ size: "xsmall",
9087
+ children: [
9088
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
9089
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
9090
+ ]
9091
+ }
9092
+ ) })
9093
+ ] })
9094
+ ] }),
9095
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
9096
+ ActionMenu,
9097
+ {
9098
+ groups: [
9099
+ {
9100
+ actions: [
9101
+ hasItems ? {
9102
+ label: "Edit shipping option",
9103
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
9104
+ onClick: () => {
9105
+ setIsOpen(
9106
+ STACKED_FOCUS_MODAL_ID,
9107
+ true
9108
+ );
9109
+ setData({
9110
+ shippingProfileId: profile.id,
9111
+ shippingOption,
9112
+ shippingMethod
9113
+ });
9114
+ }
9115
+ } : void 0,
9116
+ {
9117
+ label: "Remove shipping option",
9118
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
9119
+ onClick: () => {
9120
+ if (shippingMethod) {
9121
+ if (addShippingMethodAction) {
9122
+ removeActionShippingMethod(
9123
+ addShippingMethodAction.id
9124
+ );
9125
+ } else {
9126
+ removeShippingMethod(
9127
+ shippingMethod.id
9128
+ );
9129
+ }
9130
+ }
9131
+ }
9132
+ }
9133
+ ].filter(Boolean)
9134
+ }
9135
+ ]
9136
+ }
9137
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
9138
+ StackedModalTrigger,
9139
+ {
9140
+ shippingProfileId: profile.id,
9141
+ shippingOption,
9142
+ shippingMethod,
9143
+ setData,
9144
+ children: "Add shipping option"
9145
+ }
9146
+ )
9147
+ ] }),
9148
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
9149
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9150
+ items.map((item, idx) => {
9151
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9152
+ /* @__PURE__ */ jsxRuntime.jsxs(
9153
+ "div",
9154
+ {
9155
+ className: "flex items-center gap-x-3 px-3",
9156
+ children: [
9157
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
9158
+ ui.Divider,
9159
+ {
9160
+ variant: "dashed",
9161
+ orientation: "vertical"
9162
+ }
9163
+ ) }),
9164
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
9165
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
9166
+ ui.Text,
9167
+ {
9168
+ size: "small",
9169
+ leading: "compact",
9170
+ className: "text-ui-fg-subtle",
9171
+ children: [
9172
+ item.quantity,
9173
+ "x"
9174
+ ]
9175
+ }
9176
+ ) }),
9177
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
9178
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9179
+ /* @__PURE__ */ jsxRuntime.jsxs(
9180
+ ui.Text,
9181
+ {
9182
+ size: "small",
9183
+ leading: "compact",
9184
+ weight: "plus",
9185
+ children: [
9186
+ item.variant?.product?.title,
9187
+ " (",
9188
+ item.variant?.title,
9189
+ ")"
9190
+ ]
9191
+ }
9192
+ ),
9193
+ /* @__PURE__ */ jsxRuntime.jsx(
9194
+ ui.Text,
9195
+ {
9196
+ size: "small",
9197
+ leading: "compact",
9198
+ className: "text-ui-fg-subtle",
9199
+ children: item.variant?.options?.map((option) => option.value).join(" · ")
9200
+ }
9201
+ )
9202
+ ] })
9203
+ ] })
9204
+ ]
9205
+ },
9206
+ item.id
9207
+ ),
9208
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
9209
+ ] }, item.id);
9210
+ })
9211
+ ] })
9212
+ ]
9213
+ },
9214
+ profile.id
9215
+ );
9216
+ }) })
9217
+ ] }) })
9218
+ ] }) }),
9219
+ /* @__PURE__ */ jsxRuntime.jsx(
9220
+ StackedFocusModal,
9221
+ {
9222
+ id: STACKED_FOCUS_MODAL_ID,
9223
+ onOpenChangeCallback: (open) => {
9224
+ if (!open) {
9225
+ setData(null);
9226
+ }
9227
+ return open;
9228
+ },
9229
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
9230
+ }
9231
+ )
9232
+ ] }),
9233
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
9234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9235
+ /* @__PURE__ */ jsxRuntime.jsx(
9236
+ ui.Button,
9237
+ {
9238
+ size: "small",
9239
+ type: "button",
9240
+ isLoading: isSubmitting,
9241
+ onClick: onSubmit,
9242
+ children: "Save"
9243
+ }
9244
+ )
9245
+ ] }) })
9246
+ ] });
9247
+ };
9248
+ const StackedModalTrigger = ({
9249
+ shippingProfileId,
9250
+ shippingOption,
9251
+ shippingMethod,
9252
+ setData,
9253
+ children
9254
+ }) => {
9255
+ const { setIsOpen, getIsOpen } = useStackedModal();
9256
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
9257
+ const onToggle = () => {
9258
+ if (isOpen) {
9259
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
9260
+ setData(null);
9261
+ } else {
9262
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
9263
+ setData({
9264
+ shippingProfileId,
9265
+ shippingOption,
9266
+ shippingMethod
9267
+ });
9268
+ }
9269
+ };
9270
+ return /* @__PURE__ */ jsxRuntime.jsx(
9271
+ ui.Button,
9272
+ {
9273
+ size: "small",
9274
+ variant: "secondary",
9275
+ onClick: onToggle,
9276
+ className: "text-ui-fg-primary shrink-0",
9277
+ children
9278
+ }
9279
+ );
9280
+ };
9281
+ const ShippingProfileForm = ({
9282
+ data,
9283
+ order,
9284
+ preview
9285
+ }) => {
9286
+ const { setIsOpen } = useStackedModal();
9287
+ const form = reactHookForm.useForm({
9288
+ resolver: zod$1.zodResolver(shippingMethodSchema),
9289
+ defaultValues: {
9290
+ location_id: data.shippingOption?.service_zone?.fulfillment_set?.location?.id,
9291
+ shipping_option_id: data.shippingOption?.id,
9292
+ custom_amount: data.shippingMethod?.amount
9293
+ }
9294
+ });
9295
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
9296
+ const {
9297
+ mutateAsync: updateShippingMethod,
9298
+ isPending: isUpdatingShippingMethod
9299
+ } = useDraftOrderUpdateShippingMethod(order.id);
9300
+ const onSubmit = form.handleSubmit(async (values) => {
9301
+ if (dequal.dequal(values, form.formState.defaultValues)) {
9302
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
9303
+ return;
9304
+ }
9305
+ if (data.shippingMethod) {
9306
+ await updateShippingMethod(
9307
+ {
9308
+ method_id: data.shippingMethod.id,
9309
+ shipping_option_id: values.shipping_option_id,
9310
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
9311
+ },
9312
+ {
9313
+ onError: (e) => {
9314
+ ui.toast.error(e.message);
9315
+ },
9316
+ onSuccess: () => {
9317
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
9318
+ }
9319
+ }
9320
+ );
9321
+ return;
9322
+ }
9323
+ await addShippingMethod(
9324
+ {
9325
+ shipping_option_id: values.shipping_option_id,
9326
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
9327
+ },
9328
+ {
9329
+ onError: (e) => {
9330
+ ui.toast.error(e.message);
9331
+ },
9332
+ onSuccess: () => {
9333
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
9334
+ }
9335
+ }
9336
+ );
9337
+ });
9338
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9339
+ KeyboundForm,
9340
+ {
9341
+ className: "flex h-full flex-col overflow-hidden",
9342
+ onSubmit,
9343
+ children: [
9344
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
9345
+ /* @__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: [
9346
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9347
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
9348
+ /* @__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." }) })
9349
+ ] }),
9350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9351
+ /* @__PURE__ */ jsxRuntime.jsx(
9352
+ LocationField,
9571
9353
  {
9572
- width: "12",
9573
- height: "12",
9574
- fill: "white",
9575
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
9354
+ control: form.control,
9355
+ setValue: form.setValue
9576
9356
  }
9577
- ) }),
9578
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9579
- "rect",
9357
+ ),
9358
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9359
+ /* @__PURE__ */ jsxRuntime.jsx(
9360
+ ShippingOptionField,
9580
9361
  {
9581
- width: "12",
9582
- height: "12",
9583
- fill: "white",
9584
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
9362
+ shippingProfileId: data.shippingProfileId,
9363
+ preview,
9364
+ control: form.control
9585
9365
  }
9586
- ) }),
9587
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9588
- "rect",
9366
+ ),
9367
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9368
+ /* @__PURE__ */ jsxRuntime.jsx(
9369
+ CustomAmountField,
9589
9370
  {
9590
- width: "12",
9591
- height: "12",
9592
- fill: "white",
9593
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
9371
+ control: form.control,
9372
+ currencyCode: order.currency_code
9594
9373
  }
9595
- ) }),
9596
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9597
- "rect",
9374
+ ),
9375
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9376
+ /* @__PURE__ */ jsxRuntime.jsx(
9377
+ ItemsPreview,
9378
+ {
9379
+ order,
9380
+ shippingProfileId: data.shippingProfileId
9381
+ }
9382
+ )
9383
+ ] }) }) }),
9384
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
9385
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9386
+ /* @__PURE__ */ jsxRuntime.jsx(
9387
+ ui.Button,
9388
+ {
9389
+ size: "small",
9390
+ type: "submit",
9391
+ isLoading: isPending || isUpdatingShippingMethod,
9392
+ children: data.shippingMethod ? "Update" : "Add"
9393
+ }
9394
+ )
9395
+ ] }) })
9396
+ ]
9397
+ }
9398
+ ) }) });
9399
+ };
9400
+ const shippingMethodSchema = zod.z.object({
9401
+ location_id: zod.z.string(),
9402
+ shipping_option_id: zod.z.string(),
9403
+ custom_amount: zod.z.union([zod.z.number(), zod.z.string()]).optional()
9404
+ });
9405
+ const ItemsPreview = ({ order, shippingProfileId }) => {
9406
+ const matches = order.items.filter(
9407
+ (item) => item.variant?.product?.shipping_profile?.id === shippingProfileId
9408
+ );
9409
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
9410
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9411
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
9412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
9413
+ ] }) }),
9414
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9415
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
9416
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
9417
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
9418
+ ] }),
9419
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches?.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
9420
+ "div",
9421
+ {
9422
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
9423
+ children: [
9424
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
9425
+ /* @__PURE__ */ jsxRuntime.jsx(
9426
+ Thumbnail,
9427
+ {
9428
+ thumbnail: item.thumbnail,
9429
+ alt: item.product_title ?? void 0
9430
+ }
9431
+ ),
9432
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9433
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
9434
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
9435
+ /* @__PURE__ */ jsxRuntime.jsxs(
9436
+ ui.Text,
9437
+ {
9438
+ size: "small",
9439
+ leading: "compact",
9440
+ className: "text-ui-fg-subtle",
9441
+ children: [
9442
+ "(",
9443
+ item.variant_title,
9444
+ ")"
9445
+ ]
9446
+ }
9447
+ )
9448
+ ] }),
9449
+ /* @__PURE__ */ jsxRuntime.jsx(
9450
+ ui.Text,
9451
+ {
9452
+ size: "small",
9453
+ leading: "compact",
9454
+ className: "text-ui-fg-subtle",
9455
+ children: item.variant_sku
9456
+ }
9457
+ )
9458
+ ] })
9459
+ ] }),
9460
+ /* @__PURE__ */ jsxRuntime.jsxs(
9461
+ ui.Text,
9462
+ {
9463
+ size: "small",
9464
+ leading: "compact",
9465
+ className: "text-ui-fg-subtle",
9466
+ children: [
9467
+ item.quantity,
9468
+ "x"
9469
+ ]
9470
+ }
9471
+ )
9472
+ ]
9473
+ },
9474
+ item.id
9475
+ )) : /* @__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: [
9476
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
9477
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
9478
+ 'No items found for "',
9479
+ query,
9480
+ '".'
9481
+ ] })
9482
+ ] }) })
9483
+ ] })
9484
+ ] });
9485
+ };
9486
+ const LocationField = ({ control, setValue }) => {
9487
+ const locations = useComboboxData({
9488
+ queryKey: ["locations"],
9489
+ queryFn: async (params) => {
9490
+ return await sdk.admin.stockLocation.list(params);
9491
+ },
9492
+ getOptions: (data) => {
9493
+ return data.stock_locations.map((location) => ({
9494
+ label: location.name,
9495
+ value: location.id
9496
+ }));
9497
+ }
9498
+ });
9499
+ return /* @__PURE__ */ jsxRuntime.jsx(
9500
+ Form$2.Field,
9501
+ {
9502
+ control,
9503
+ name: "location_id",
9504
+ render: ({ field: { onChange, ...field } }) => {
9505
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
9506
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
9508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
9509
+ ] }),
9510
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9511
+ Combobox,
9598
9512
  {
9599
- width: "12",
9600
- height: "12",
9601
- fill: "white",
9602
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
9513
+ options: locations.options,
9514
+ fetchNextPage: locations.fetchNextPage,
9515
+ isFetchingNextPage: locations.isFetchingNextPage,
9516
+ searchValue: locations.searchValue,
9517
+ onSearchValueChange: locations.onSearchValueChange,
9518
+ placeholder: "Select location",
9519
+ onChange: (value) => {
9520
+ setValue("shipping_option_id", "", {
9521
+ shouldDirty: true,
9522
+ shouldTouch: true
9523
+ });
9524
+ onChange(value);
9525
+ },
9526
+ ...field
9603
9527
  }
9604
- ) }),
9605
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9606
- "rect",
9528
+ ) })
9529
+ ] }) });
9530
+ }
9531
+ }
9532
+ );
9533
+ };
9534
+ const ShippingOptionField = ({
9535
+ shippingProfileId,
9536
+ preview,
9537
+ control
9538
+ }) => {
9539
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
9540
+ const shippingOptions = useComboboxData({
9541
+ queryKey: ["shipping_options", locationId, shippingProfileId],
9542
+ queryFn: async (params) => {
9543
+ return await sdk.admin.shippingOption.list({
9544
+ ...params,
9545
+ stock_location_id: locationId,
9546
+ shipping_profile_id: shippingProfileId
9547
+ });
9548
+ },
9549
+ getOptions: (data) => {
9550
+ return data.shipping_options.map((option) => {
9551
+ if (option.rules?.find(
9552
+ (r) => r.attribute === "is_return" && r.value === "true"
9553
+ )) {
9554
+ return void 0;
9555
+ }
9556
+ return {
9557
+ label: option.name,
9558
+ value: option.id
9559
+ };
9560
+ }).filter(Boolean);
9561
+ },
9562
+ enabled: !!locationId && !!shippingProfileId,
9563
+ defaultValue: preview.shipping_methods[0]?.shipping_option_id || void 0
9564
+ });
9565
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
9566
+ return /* @__PURE__ */ jsxRuntime.jsx(
9567
+ Form$2.Field,
9568
+ {
9569
+ control,
9570
+ name: "shipping_option_id",
9571
+ render: ({ field }) => {
9572
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
9573
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9574
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
9575
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
9576
+ ] }),
9577
+ /* @__PURE__ */ jsxRuntime.jsx(
9578
+ ConditionalTooltip,
9607
9579
  {
9608
- width: "12",
9609
- height: "12",
9610
- fill: "white",
9611
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
9580
+ content: tooltipContent,
9581
+ showTooltip: !locationId || !shippingProfileId,
9582
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9583
+ Combobox,
9584
+ {
9585
+ options: shippingOptions.options,
9586
+ fetchNextPage: shippingOptions.fetchNextPage,
9587
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
9588
+ searchValue: shippingOptions.searchValue,
9589
+ onSearchValueChange: shippingOptions.onSearchValueChange,
9590
+ placeholder: "Select shipping option",
9591
+ ...field,
9592
+ disabled: !locationId || !shippingProfileId
9593
+ }
9594
+ ) }) })
9612
9595
  }
9613
- ) }),
9614
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
9615
- "rect",
9596
+ )
9597
+ ] }) });
9598
+ }
9599
+ }
9600
+ );
9601
+ };
9602
+ const CustomAmountField = ({
9603
+ control,
9604
+ currencyCode
9605
+ }) => {
9606
+ return /* @__PURE__ */ jsxRuntime.jsx(
9607
+ Form$2.Field,
9608
+ {
9609
+ control,
9610
+ name: "custom_amount",
9611
+ render: ({ field: { onChange, ...field } }) => {
9612
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
9613
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9614
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
9615
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
9616
+ ] }),
9617
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9618
+ ui.CurrencyInput,
9616
9619
  {
9617
- width: "12",
9618
- height: "12",
9619
- fill: "white",
9620
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
9620
+ ...field,
9621
+ onValueChange: (value) => onChange(value),
9622
+ symbol: getNativeSymbol(currencyCode),
9623
+ code: currencyCode
9621
9624
  }
9622
9625
  ) })
9623
- ] })
9624
- ]
9626
+ ] });
9627
+ }
9625
9628
  }
9626
9629
  );
9627
9630
  };
9628
- const schema = zod.z.object({
9629
- customer_id: zod.z.string().min(1)
9630
- });
9631
9631
  const handle = {
9632
- permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
9632
+ permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
9633
9633
  };
9634
9634
  const widgetModule = { widgets: [] };
9635
9635
  const routeModule = {
@@ -9687,19 +9687,19 @@ const routeModule = {
9687
9687
  path: "/draft-orders/:id/sales-channel",
9688
9688
  handle: handle$3
9689
9689
  },
9690
- {
9691
- Component: Shipping,
9692
- path: "/draft-orders/:id/shipping",
9693
- handle: handle$2
9694
- },
9695
9690
  {
9696
9691
  Component: ShippingAddress,
9697
9692
  path: "/draft-orders/:id/shipping-address",
9698
- handle: handle$1
9693
+ handle: handle$2
9699
9694
  },
9700
9695
  {
9701
9696
  Component: TransferOwnership,
9702
9697
  path: "/draft-orders/:id/transfer-ownership",
9698
+ handle: handle$1
9699
+ },
9700
+ {
9701
+ Component: Shipping,
9702
+ path: "/draft-orders/:id/shipping",
9703
9703
  handle
9704
9704
  }
9705
9705
  ]