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