@medusajs/draft-order 2.10.4-preview-20250922060202 → 2.10.4-preview-20250922120207
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 +445 -445
- package/.medusa/server/src/admin/index.mjs +445 -445
- package/package.json +16 -16
|
@@ -9635,6 +9635,27 @@ const EmailForm = ({ order }) => {
|
|
|
9635
9635
|
const schema$5 = objectType({
|
|
9636
9636
|
email: stringType().email()
|
|
9637
9637
|
});
|
|
9638
|
+
const CustomItems = () => {
|
|
9639
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9640
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9641
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9642
|
+
] });
|
|
9643
|
+
};
|
|
9644
|
+
const CustomItemsForm = () => {
|
|
9645
|
+
const form = useForm({
|
|
9646
|
+
resolver: zodResolver(schema$4)
|
|
9647
|
+
});
|
|
9648
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9649
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9650
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9651
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9652
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9653
|
+
] }) })
|
|
9654
|
+
] }) });
|
|
9655
|
+
};
|
|
9656
|
+
const schema$4 = objectType({
|
|
9657
|
+
email: stringType().email()
|
|
9658
|
+
});
|
|
9638
9659
|
const NumberInput = forwardRef(
|
|
9639
9660
|
({
|
|
9640
9661
|
value,
|
|
@@ -11236,10 +11257,116 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11236
11257
|
}
|
|
11237
11258
|
return Array.from(promotionIds);
|
|
11238
11259
|
}
|
|
11239
|
-
const
|
|
11260
|
+
const SalesChannel = () => {
|
|
11261
|
+
const { id } = useParams();
|
|
11262
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11263
|
+
id,
|
|
11264
|
+
{
|
|
11265
|
+
fields: "+sales_channel_id"
|
|
11266
|
+
},
|
|
11267
|
+
{
|
|
11268
|
+
enabled: !!id
|
|
11269
|
+
}
|
|
11270
|
+
);
|
|
11271
|
+
if (isError) {
|
|
11272
|
+
throw error;
|
|
11273
|
+
}
|
|
11274
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11275
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11276
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11277
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11278
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11279
|
+
] }),
|
|
11280
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11281
|
+
] });
|
|
11282
|
+
};
|
|
11283
|
+
const SalesChannelForm = ({ order }) => {
|
|
11284
|
+
const form = useForm({
|
|
11285
|
+
defaultValues: {
|
|
11286
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11287
|
+
},
|
|
11288
|
+
resolver: zodResolver(schema$3)
|
|
11289
|
+
});
|
|
11290
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11291
|
+
const { handleSuccess } = useRouteModal();
|
|
11292
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11293
|
+
await mutateAsync(
|
|
11294
|
+
{
|
|
11295
|
+
sales_channel_id: data.sales_channel_id
|
|
11296
|
+
},
|
|
11297
|
+
{
|
|
11298
|
+
onSuccess: () => {
|
|
11299
|
+
toast.success("Sales channel updated");
|
|
11300
|
+
handleSuccess();
|
|
11301
|
+
},
|
|
11302
|
+
onError: (error) => {
|
|
11303
|
+
toast.error(error.message);
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
);
|
|
11307
|
+
});
|
|
11308
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11309
|
+
KeyboundForm,
|
|
11310
|
+
{
|
|
11311
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11312
|
+
onSubmit,
|
|
11313
|
+
children: [
|
|
11314
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11315
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11316
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11317
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11318
|
+
] }) })
|
|
11319
|
+
]
|
|
11320
|
+
}
|
|
11321
|
+
) });
|
|
11322
|
+
};
|
|
11323
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11324
|
+
const salesChannels = useComboboxData({
|
|
11325
|
+
queryFn: async (params) => {
|
|
11326
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11327
|
+
},
|
|
11328
|
+
queryKey: ["sales-channels"],
|
|
11329
|
+
getOptions: (data) => {
|
|
11330
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11331
|
+
label: salesChannel.name,
|
|
11332
|
+
value: salesChannel.id
|
|
11333
|
+
}));
|
|
11334
|
+
},
|
|
11335
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11336
|
+
});
|
|
11337
|
+
return /* @__PURE__ */ jsx(
|
|
11338
|
+
Form$2.Field,
|
|
11339
|
+
{
|
|
11340
|
+
control,
|
|
11341
|
+
name: "sales_channel_id",
|
|
11342
|
+
render: ({ field }) => {
|
|
11343
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11344
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11345
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11346
|
+
Combobox,
|
|
11347
|
+
{
|
|
11348
|
+
options: salesChannels.options,
|
|
11349
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11350
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11351
|
+
searchValue: salesChannels.searchValue,
|
|
11352
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11353
|
+
placeholder: "Select sales channel",
|
|
11354
|
+
...field
|
|
11355
|
+
}
|
|
11356
|
+
) }),
|
|
11357
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11358
|
+
] });
|
|
11359
|
+
}
|
|
11360
|
+
}
|
|
11361
|
+
);
|
|
11362
|
+
};
|
|
11363
|
+
const schema$3 = objectType({
|
|
11364
|
+
sales_channel_id: stringType().min(1)
|
|
11365
|
+
});
|
|
11366
|
+
const ShippingAddress = () => {
|
|
11240
11367
|
const { id } = useParams();
|
|
11241
11368
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
11242
|
-
fields: "+
|
|
11369
|
+
fields: "+shipping_address"
|
|
11243
11370
|
});
|
|
11244
11371
|
if (isError) {
|
|
11245
11372
|
throw error;
|
|
@@ -11247,34 +11374,47 @@ const BillingAddress = () => {
|
|
|
11247
11374
|
const isReady = !isPending && !!order;
|
|
11248
11375
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11249
11376
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11250
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit
|
|
11251
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the
|
|
11377
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
|
|
11378
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
11252
11379
|
] }),
|
|
11253
|
-
isReady && /* @__PURE__ */ jsx(
|
|
11380
|
+
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
11254
11381
|
] });
|
|
11255
11382
|
};
|
|
11256
|
-
const
|
|
11383
|
+
const ShippingAddressForm = ({ order }) => {
|
|
11257
11384
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11258
11385
|
const form = useForm({
|
|
11259
11386
|
defaultValues: {
|
|
11260
|
-
first_name: ((_a = order.
|
|
11261
|
-
last_name: ((_b = order.
|
|
11262
|
-
company: ((_c = order.
|
|
11263
|
-
address_1: ((_d = order.
|
|
11264
|
-
address_2: ((_e = order.
|
|
11265
|
-
city: ((_f = order.
|
|
11266
|
-
province: ((_g = order.
|
|
11267
|
-
country_code: ((_h = order.
|
|
11268
|
-
postal_code: ((_i = order.
|
|
11269
|
-
phone: ((_j = order.
|
|
11387
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11388
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11389
|
+
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
11390
|
+
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11391
|
+
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11392
|
+
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
11393
|
+
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
11394
|
+
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11395
|
+
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11396
|
+
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
11270
11397
|
},
|
|
11271
|
-
resolver: zodResolver(schema$
|
|
11398
|
+
resolver: zodResolver(schema$2)
|
|
11272
11399
|
});
|
|
11273
11400
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11274
11401
|
const { handleSuccess } = useRouteModal();
|
|
11275
11402
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
11276
11403
|
await mutateAsync(
|
|
11277
|
-
{
|
|
11404
|
+
{
|
|
11405
|
+
shipping_address: {
|
|
11406
|
+
first_name: data.first_name,
|
|
11407
|
+
last_name: data.last_name,
|
|
11408
|
+
company: data.company,
|
|
11409
|
+
address_1: data.address_1,
|
|
11410
|
+
address_2: data.address_2,
|
|
11411
|
+
city: data.city,
|
|
11412
|
+
province: data.province,
|
|
11413
|
+
country_code: data.country_code,
|
|
11414
|
+
postal_code: data.postal_code,
|
|
11415
|
+
phone: data.phone
|
|
11416
|
+
}
|
|
11417
|
+
},
|
|
11278
11418
|
{
|
|
11279
11419
|
onSuccess: () => {
|
|
11280
11420
|
handleSuccess();
|
|
@@ -11425,173 +11565,67 @@ const BillingAddressForm = ({ order }) => {
|
|
|
11425
11565
|
}
|
|
11426
11566
|
) });
|
|
11427
11567
|
};
|
|
11428
|
-
const schema$
|
|
11429
|
-
const
|
|
11568
|
+
const schema$2 = addressSchema;
|
|
11569
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11570
|
+
const Shipping = () => {
|
|
11571
|
+
var _a;
|
|
11430
11572
|
const { id } = useParams();
|
|
11431
|
-
const {
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
|
|
11435
|
-
|
|
11436
|
-
|
|
11437
|
-
|
|
11438
|
-
|
|
11439
|
-
);
|
|
11573
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11574
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11575
|
+
});
|
|
11576
|
+
const {
|
|
11577
|
+
order: preview,
|
|
11578
|
+
isPending: isPreviewPending,
|
|
11579
|
+
isError: isPreviewError,
|
|
11580
|
+
error: previewError
|
|
11581
|
+
} = useOrderPreview(id);
|
|
11582
|
+
useInitiateOrderEdit({ preview });
|
|
11583
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11440
11584
|
if (isError) {
|
|
11441
11585
|
throw error;
|
|
11442
11586
|
}
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11587
|
+
if (isPreviewError) {
|
|
11588
|
+
throw previewError;
|
|
11589
|
+
}
|
|
11590
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11591
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11592
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11593
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11594
|
+
/* @__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 py-16 px-6", children: [
|
|
11595
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11596
|
+
/* @__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." }) })
|
|
11597
|
+
] }) }) }),
|
|
11598
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11599
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11600
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11601
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11602
|
+
] }) });
|
|
11451
11603
|
};
|
|
11452
|
-
const
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11604
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11605
|
+
var _a;
|
|
11606
|
+
const { setIsOpen } = useStackedModal();
|
|
11607
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11608
|
+
const [data, setData] = useState(null);
|
|
11609
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11610
|
+
const { shipping_options } = useShippingOptions(
|
|
11611
|
+
{
|
|
11612
|
+
id: appliedShippingOptionIds,
|
|
11613
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11456
11614
|
},
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
const
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
onError: (error) => {
|
|
11472
|
-
toast.error(error.message);
|
|
11473
|
-
}
|
|
11474
|
-
}
|
|
11475
|
-
);
|
|
11476
|
-
});
|
|
11477
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11478
|
-
KeyboundForm,
|
|
11479
|
-
{
|
|
11480
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11481
|
-
onSubmit,
|
|
11482
|
-
children: [
|
|
11483
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11484
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11485
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11486
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11487
|
-
] }) })
|
|
11488
|
-
]
|
|
11489
|
-
}
|
|
11490
|
-
) });
|
|
11491
|
-
};
|
|
11492
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11493
|
-
const salesChannels = useComboboxData({
|
|
11494
|
-
queryFn: async (params) => {
|
|
11495
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11496
|
-
},
|
|
11497
|
-
queryKey: ["sales-channels"],
|
|
11498
|
-
getOptions: (data) => {
|
|
11499
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11500
|
-
label: salesChannel.name,
|
|
11501
|
-
value: salesChannel.id
|
|
11502
|
-
}));
|
|
11503
|
-
},
|
|
11504
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11505
|
-
});
|
|
11506
|
-
return /* @__PURE__ */ jsx(
|
|
11507
|
-
Form$2.Field,
|
|
11508
|
-
{
|
|
11509
|
-
control,
|
|
11510
|
-
name: "sales_channel_id",
|
|
11511
|
-
render: ({ field }) => {
|
|
11512
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11513
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11514
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11515
|
-
Combobox,
|
|
11516
|
-
{
|
|
11517
|
-
options: salesChannels.options,
|
|
11518
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11519
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11520
|
-
searchValue: salesChannels.searchValue,
|
|
11521
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11522
|
-
placeholder: "Select sales channel",
|
|
11523
|
-
...field
|
|
11524
|
-
}
|
|
11525
|
-
) }),
|
|
11526
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11527
|
-
] });
|
|
11528
|
-
}
|
|
11529
|
-
}
|
|
11530
|
-
);
|
|
11531
|
-
};
|
|
11532
|
-
const schema$3 = objectType({
|
|
11533
|
-
sales_channel_id: stringType().min(1)
|
|
11534
|
-
});
|
|
11535
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11536
|
-
const Shipping = () => {
|
|
11537
|
-
var _a;
|
|
11538
|
-
const { id } = useParams();
|
|
11539
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11540
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11541
|
-
});
|
|
11542
|
-
const {
|
|
11543
|
-
order: preview,
|
|
11544
|
-
isPending: isPreviewPending,
|
|
11545
|
-
isError: isPreviewError,
|
|
11546
|
-
error: previewError
|
|
11547
|
-
} = useOrderPreview(id);
|
|
11548
|
-
useInitiateOrderEdit({ preview });
|
|
11549
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11550
|
-
if (isError) {
|
|
11551
|
-
throw error;
|
|
11552
|
-
}
|
|
11553
|
-
if (isPreviewError) {
|
|
11554
|
-
throw previewError;
|
|
11555
|
-
}
|
|
11556
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11557
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11558
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11559
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11560
|
-
/* @__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 py-16 px-6", children: [
|
|
11561
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11562
|
-
/* @__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." }) })
|
|
11563
|
-
] }) }) }),
|
|
11564
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11565
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11566
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11567
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11568
|
-
] }) });
|
|
11569
|
-
};
|
|
11570
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11571
|
-
var _a;
|
|
11572
|
-
const { setIsOpen } = useStackedModal();
|
|
11573
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11574
|
-
const [data, setData] = useState(null);
|
|
11575
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11576
|
-
const { shipping_options } = useShippingOptions(
|
|
11577
|
-
{
|
|
11578
|
-
id: appliedShippingOptionIds,
|
|
11579
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11580
|
-
},
|
|
11581
|
-
{
|
|
11582
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11583
|
-
}
|
|
11584
|
-
);
|
|
11585
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
11586
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
11587
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11588
|
-
profiles.set(profile.id, profile);
|
|
11589
|
-
});
|
|
11590
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11591
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11592
|
-
});
|
|
11593
|
-
return Array.from(profiles.values());
|
|
11594
|
-
}, [order.items, shipping_options]);
|
|
11615
|
+
{
|
|
11616
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11617
|
+
}
|
|
11618
|
+
);
|
|
11619
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
11620
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
11621
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11622
|
+
profiles.set(profile.id, profile);
|
|
11623
|
+
});
|
|
11624
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11625
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11626
|
+
});
|
|
11627
|
+
return Array.from(profiles.values());
|
|
11628
|
+
}, [order.items, shipping_options]);
|
|
11595
11629
|
const { handleSuccess } = useRouteModal();
|
|
11596
11630
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11597
11631
|
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
@@ -12339,60 +12373,44 @@ const CustomAmountField = ({
|
|
|
12339
12373
|
}
|
|
12340
12374
|
);
|
|
12341
12375
|
};
|
|
12342
|
-
const
|
|
12376
|
+
const TransferOwnership = () => {
|
|
12343
12377
|
const { id } = useParams();
|
|
12344
|
-
const {
|
|
12345
|
-
fields: "
|
|
12378
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
12379
|
+
fields: "id,customer_id,customer.*"
|
|
12346
12380
|
});
|
|
12347
12381
|
if (isError) {
|
|
12348
12382
|
throw error;
|
|
12349
12383
|
}
|
|
12350
|
-
const isReady = !isPending && !!
|
|
12384
|
+
const isReady = !isPending && !!draft_order;
|
|
12351
12385
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12352
12386
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12353
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
12354
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
12387
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
|
|
12388
|
+
/* @__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" }) })
|
|
12355
12389
|
] }),
|
|
12356
|
-
isReady && /* @__PURE__ */ jsx(
|
|
12390
|
+
isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
|
|
12357
12391
|
] });
|
|
12358
12392
|
};
|
|
12359
|
-
const
|
|
12360
|
-
var _a, _b
|
|
12393
|
+
const TransferOwnershipForm = ({ order }) => {
|
|
12394
|
+
var _a, _b;
|
|
12361
12395
|
const form = useForm({
|
|
12362
12396
|
defaultValues: {
|
|
12363
|
-
|
|
12364
|
-
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12365
|
-
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12366
|
-
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12367
|
-
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12368
|
-
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12369
|
-
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12370
|
-
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12371
|
-
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12372
|
-
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12397
|
+
customer_id: order.customer_id || ""
|
|
12373
12398
|
},
|
|
12374
|
-
resolver: zodResolver(schema$
|
|
12399
|
+
resolver: zodResolver(schema$1)
|
|
12375
12400
|
});
|
|
12376
12401
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12377
12402
|
const { handleSuccess } = useRouteModal();
|
|
12403
|
+
const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
|
|
12404
|
+
const currentCustomer = order.customer ? {
|
|
12405
|
+
label: name ? `${name} (${order.customer.email})` : order.customer.email,
|
|
12406
|
+
value: order.customer.id
|
|
12407
|
+
} : null;
|
|
12378
12408
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
12379
12409
|
await mutateAsync(
|
|
12380
|
-
{
|
|
12381
|
-
shipping_address: {
|
|
12382
|
-
first_name: data.first_name,
|
|
12383
|
-
last_name: data.last_name,
|
|
12384
|
-
company: data.company,
|
|
12385
|
-
address_1: data.address_1,
|
|
12386
|
-
address_2: data.address_2,
|
|
12387
|
-
city: data.city,
|
|
12388
|
-
province: data.province,
|
|
12389
|
-
country_code: data.country_code,
|
|
12390
|
-
postal_code: data.postal_code,
|
|
12391
|
-
phone: data.phone
|
|
12392
|
-
}
|
|
12393
|
-
},
|
|
12410
|
+
{ customer_id: data.customer_id },
|
|
12394
12411
|
{
|
|
12395
12412
|
onSuccess: () => {
|
|
12413
|
+
toast.success("Customer updated");
|
|
12396
12414
|
handleSuccess();
|
|
12397
12415
|
},
|
|
12398
12416
|
onError: (error) => {
|
|
@@ -12407,231 +12425,23 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12407
12425
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
12408
12426
|
onSubmit,
|
|
12409
12427
|
children: [
|
|
12410
|
-
/* @__PURE__ */
|
|
12411
|
-
/* @__PURE__ */ jsx(
|
|
12412
|
-
|
|
12413
|
-
{
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
}
|
|
12422
|
-
),
|
|
12423
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12424
|
-
/* @__PURE__ */ jsx(
|
|
12425
|
-
Form$2.Field,
|
|
12426
|
-
{
|
|
12427
|
-
control: form.control,
|
|
12428
|
-
name: "first_name",
|
|
12429
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12430
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12431
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12432
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12433
|
-
] })
|
|
12434
|
-
}
|
|
12435
|
-
),
|
|
12436
|
-
/* @__PURE__ */ jsx(
|
|
12437
|
-
Form$2.Field,
|
|
12438
|
-
{
|
|
12439
|
-
control: form.control,
|
|
12440
|
-
name: "last_name",
|
|
12441
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12442
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12443
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12444
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12445
|
-
] })
|
|
12446
|
-
}
|
|
12447
|
-
)
|
|
12428
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
12429
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
|
|
12430
|
+
currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
|
|
12431
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12432
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
|
|
12433
|
+
/* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
|
|
12434
|
+
] }),
|
|
12435
|
+
/* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
|
|
12436
|
+
/* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
|
|
12437
|
+
/* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
|
|
12438
|
+
] })
|
|
12448
12439
|
] }),
|
|
12449
12440
|
/* @__PURE__ */ jsx(
|
|
12450
|
-
|
|
12451
|
-
{
|
|
12452
|
-
control: form.control,
|
|
12453
|
-
name: "company",
|
|
12454
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12455
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12456
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12457
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12458
|
-
] })
|
|
12459
|
-
}
|
|
12460
|
-
),
|
|
12461
|
-
/* @__PURE__ */ jsx(
|
|
12462
|
-
Form$2.Field,
|
|
12441
|
+
CustomerField,
|
|
12463
12442
|
{
|
|
12464
12443
|
control: form.control,
|
|
12465
|
-
|
|
12466
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12467
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12468
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12469
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12470
|
-
] })
|
|
12471
|
-
}
|
|
12472
|
-
),
|
|
12473
|
-
/* @__PURE__ */ jsx(
|
|
12474
|
-
Form$2.Field,
|
|
12475
|
-
{
|
|
12476
|
-
control: form.control,
|
|
12477
|
-
name: "address_2",
|
|
12478
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12479
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12480
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12481
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12482
|
-
] })
|
|
12483
|
-
}
|
|
12484
|
-
),
|
|
12485
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12486
|
-
/* @__PURE__ */ jsx(
|
|
12487
|
-
Form$2.Field,
|
|
12488
|
-
{
|
|
12489
|
-
control: form.control,
|
|
12490
|
-
name: "postal_code",
|
|
12491
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12492
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12493
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12494
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12495
|
-
] })
|
|
12496
|
-
}
|
|
12497
|
-
),
|
|
12498
|
-
/* @__PURE__ */ jsx(
|
|
12499
|
-
Form$2.Field,
|
|
12500
|
-
{
|
|
12501
|
-
control: form.control,
|
|
12502
|
-
name: "city",
|
|
12503
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12504
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12505
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12506
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12507
|
-
] })
|
|
12508
|
-
}
|
|
12509
|
-
)
|
|
12510
|
-
] }),
|
|
12511
|
-
/* @__PURE__ */ jsx(
|
|
12512
|
-
Form$2.Field,
|
|
12513
|
-
{
|
|
12514
|
-
control: form.control,
|
|
12515
|
-
name: "province",
|
|
12516
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12517
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12518
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12519
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12520
|
-
] })
|
|
12521
|
-
}
|
|
12522
|
-
),
|
|
12523
|
-
/* @__PURE__ */ jsx(
|
|
12524
|
-
Form$2.Field,
|
|
12525
|
-
{
|
|
12526
|
-
control: form.control,
|
|
12527
|
-
name: "phone",
|
|
12528
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12529
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12530
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12531
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12532
|
-
] })
|
|
12533
|
-
}
|
|
12534
|
-
)
|
|
12535
|
-
] }) }),
|
|
12536
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12537
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12538
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12539
|
-
] }) })
|
|
12540
|
-
]
|
|
12541
|
-
}
|
|
12542
|
-
) });
|
|
12543
|
-
};
|
|
12544
|
-
const schema$2 = addressSchema;
|
|
12545
|
-
const CustomItems = () => {
|
|
12546
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12547
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
12548
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
12549
|
-
] });
|
|
12550
|
-
};
|
|
12551
|
-
const CustomItemsForm = () => {
|
|
12552
|
-
const form = useForm({
|
|
12553
|
-
resolver: zodResolver(schema$1)
|
|
12554
|
-
});
|
|
12555
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
12556
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
12557
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12558
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12559
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
12560
|
-
] }) })
|
|
12561
|
-
] }) });
|
|
12562
|
-
};
|
|
12563
|
-
const schema$1 = objectType({
|
|
12564
|
-
email: stringType().email()
|
|
12565
|
-
});
|
|
12566
|
-
const TransferOwnership = () => {
|
|
12567
|
-
const { id } = useParams();
|
|
12568
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
12569
|
-
fields: "id,customer_id,customer.*"
|
|
12570
|
-
});
|
|
12571
|
-
if (isError) {
|
|
12572
|
-
throw error;
|
|
12573
|
-
}
|
|
12574
|
-
const isReady = !isPending && !!draft_order;
|
|
12575
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12576
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12577
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
|
|
12578
|
-
/* @__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" }) })
|
|
12579
|
-
] }),
|
|
12580
|
-
isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
|
|
12581
|
-
] });
|
|
12582
|
-
};
|
|
12583
|
-
const TransferOwnershipForm = ({ order }) => {
|
|
12584
|
-
var _a, _b;
|
|
12585
|
-
const form = useForm({
|
|
12586
|
-
defaultValues: {
|
|
12587
|
-
customer_id: order.customer_id || ""
|
|
12588
|
-
},
|
|
12589
|
-
resolver: zodResolver(schema)
|
|
12590
|
-
});
|
|
12591
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12592
|
-
const { handleSuccess } = useRouteModal();
|
|
12593
|
-
const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
|
|
12594
|
-
const currentCustomer = order.customer ? {
|
|
12595
|
-
label: name ? `${name} (${order.customer.email})` : order.customer.email,
|
|
12596
|
-
value: order.customer.id
|
|
12597
|
-
} : null;
|
|
12598
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12599
|
-
await mutateAsync(
|
|
12600
|
-
{ customer_id: data.customer_id },
|
|
12601
|
-
{
|
|
12602
|
-
onSuccess: () => {
|
|
12603
|
-
toast.success("Customer updated");
|
|
12604
|
-
handleSuccess();
|
|
12605
|
-
},
|
|
12606
|
-
onError: (error) => {
|
|
12607
|
-
toast.error(error.message);
|
|
12608
|
-
}
|
|
12609
|
-
}
|
|
12610
|
-
);
|
|
12611
|
-
});
|
|
12612
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12613
|
-
KeyboundForm,
|
|
12614
|
-
{
|
|
12615
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12616
|
-
onSubmit,
|
|
12617
|
-
children: [
|
|
12618
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
12619
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
|
|
12620
|
-
currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
|
|
12621
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12622
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
|
|
12623
|
-
/* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
|
|
12624
|
-
] }),
|
|
12625
|
-
/* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
|
|
12626
|
-
/* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
|
|
12627
|
-
/* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
|
|
12628
|
-
] })
|
|
12629
|
-
] }),
|
|
12630
|
-
/* @__PURE__ */ jsx(
|
|
12631
|
-
CustomerField,
|
|
12632
|
-
{
|
|
12633
|
-
control: form.control,
|
|
12634
|
-
currentCustomerId: order.customer_id
|
|
12444
|
+
currentCustomerId: order.customer_id
|
|
12635
12445
|
}
|
|
12636
12446
|
)
|
|
12637
12447
|
] }),
|
|
@@ -13036,9 +12846,199 @@ const Illustration = () => {
|
|
|
13036
12846
|
}
|
|
13037
12847
|
);
|
|
13038
12848
|
};
|
|
13039
|
-
const schema = objectType({
|
|
12849
|
+
const schema$1 = objectType({
|
|
13040
12850
|
customer_id: stringType().min(1)
|
|
13041
12851
|
});
|
|
12852
|
+
const BillingAddress = () => {
|
|
12853
|
+
const { id } = useParams();
|
|
12854
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12855
|
+
fields: "+billing_address"
|
|
12856
|
+
});
|
|
12857
|
+
if (isError) {
|
|
12858
|
+
throw error;
|
|
12859
|
+
}
|
|
12860
|
+
const isReady = !isPending && !!order;
|
|
12861
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12862
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12863
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
12864
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
12865
|
+
] }),
|
|
12866
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
12867
|
+
] });
|
|
12868
|
+
};
|
|
12869
|
+
const BillingAddressForm = ({ order }) => {
|
|
12870
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12871
|
+
const form = useForm({
|
|
12872
|
+
defaultValues: {
|
|
12873
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12874
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12875
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
12876
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12877
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12878
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
12879
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
12880
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12881
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12882
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
12883
|
+
},
|
|
12884
|
+
resolver: zodResolver(schema)
|
|
12885
|
+
});
|
|
12886
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12887
|
+
const { handleSuccess } = useRouteModal();
|
|
12888
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12889
|
+
await mutateAsync(
|
|
12890
|
+
{ billing_address: data },
|
|
12891
|
+
{
|
|
12892
|
+
onSuccess: () => {
|
|
12893
|
+
handleSuccess();
|
|
12894
|
+
},
|
|
12895
|
+
onError: (error) => {
|
|
12896
|
+
toast.error(error.message);
|
|
12897
|
+
}
|
|
12898
|
+
}
|
|
12899
|
+
);
|
|
12900
|
+
});
|
|
12901
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12902
|
+
KeyboundForm,
|
|
12903
|
+
{
|
|
12904
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12905
|
+
onSubmit,
|
|
12906
|
+
children: [
|
|
12907
|
+
/* @__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: [
|
|
12908
|
+
/* @__PURE__ */ jsx(
|
|
12909
|
+
Form$2.Field,
|
|
12910
|
+
{
|
|
12911
|
+
control: form.control,
|
|
12912
|
+
name: "country_code",
|
|
12913
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12914
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12915
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12916
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12917
|
+
] })
|
|
12918
|
+
}
|
|
12919
|
+
),
|
|
12920
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12921
|
+
/* @__PURE__ */ jsx(
|
|
12922
|
+
Form$2.Field,
|
|
12923
|
+
{
|
|
12924
|
+
control: form.control,
|
|
12925
|
+
name: "first_name",
|
|
12926
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12927
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12928
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12929
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12930
|
+
] })
|
|
12931
|
+
}
|
|
12932
|
+
),
|
|
12933
|
+
/* @__PURE__ */ jsx(
|
|
12934
|
+
Form$2.Field,
|
|
12935
|
+
{
|
|
12936
|
+
control: form.control,
|
|
12937
|
+
name: "last_name",
|
|
12938
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12939
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12940
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12941
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12942
|
+
] })
|
|
12943
|
+
}
|
|
12944
|
+
)
|
|
12945
|
+
] }),
|
|
12946
|
+
/* @__PURE__ */ jsx(
|
|
12947
|
+
Form$2.Field,
|
|
12948
|
+
{
|
|
12949
|
+
control: form.control,
|
|
12950
|
+
name: "company",
|
|
12951
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12952
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12953
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12954
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12955
|
+
] })
|
|
12956
|
+
}
|
|
12957
|
+
),
|
|
12958
|
+
/* @__PURE__ */ jsx(
|
|
12959
|
+
Form$2.Field,
|
|
12960
|
+
{
|
|
12961
|
+
control: form.control,
|
|
12962
|
+
name: "address_1",
|
|
12963
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12964
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12965
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12966
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12967
|
+
] })
|
|
12968
|
+
}
|
|
12969
|
+
),
|
|
12970
|
+
/* @__PURE__ */ jsx(
|
|
12971
|
+
Form$2.Field,
|
|
12972
|
+
{
|
|
12973
|
+
control: form.control,
|
|
12974
|
+
name: "address_2",
|
|
12975
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12976
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12977
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12978
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12979
|
+
] })
|
|
12980
|
+
}
|
|
12981
|
+
),
|
|
12982
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12983
|
+
/* @__PURE__ */ jsx(
|
|
12984
|
+
Form$2.Field,
|
|
12985
|
+
{
|
|
12986
|
+
control: form.control,
|
|
12987
|
+
name: "postal_code",
|
|
12988
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12989
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12990
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12991
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12992
|
+
] })
|
|
12993
|
+
}
|
|
12994
|
+
),
|
|
12995
|
+
/* @__PURE__ */ jsx(
|
|
12996
|
+
Form$2.Field,
|
|
12997
|
+
{
|
|
12998
|
+
control: form.control,
|
|
12999
|
+
name: "city",
|
|
13000
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13001
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
13002
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13003
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13004
|
+
] })
|
|
13005
|
+
}
|
|
13006
|
+
)
|
|
13007
|
+
] }),
|
|
13008
|
+
/* @__PURE__ */ jsx(
|
|
13009
|
+
Form$2.Field,
|
|
13010
|
+
{
|
|
13011
|
+
control: form.control,
|
|
13012
|
+
name: "province",
|
|
13013
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13014
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13015
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13016
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13017
|
+
] })
|
|
13018
|
+
}
|
|
13019
|
+
),
|
|
13020
|
+
/* @__PURE__ */ jsx(
|
|
13021
|
+
Form$2.Field,
|
|
13022
|
+
{
|
|
13023
|
+
control: form.control,
|
|
13024
|
+
name: "phone",
|
|
13025
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13026
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13027
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13028
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13029
|
+
] })
|
|
13030
|
+
}
|
|
13031
|
+
)
|
|
13032
|
+
] }) }),
|
|
13033
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13034
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13035
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13036
|
+
] }) })
|
|
13037
|
+
]
|
|
13038
|
+
}
|
|
13039
|
+
) });
|
|
13040
|
+
};
|
|
13041
|
+
const schema = addressSchema;
|
|
13042
13042
|
const widgetModule = { widgets: [] };
|
|
13043
13043
|
const routeModule = {
|
|
13044
13044
|
routes: [
|
|
@@ -13063,6 +13063,10 @@ const routeModule = {
|
|
|
13063
13063
|
Component: Email,
|
|
13064
13064
|
path: "/draft-orders/:id/email"
|
|
13065
13065
|
},
|
|
13066
|
+
{
|
|
13067
|
+
Component: CustomItems,
|
|
13068
|
+
path: "/draft-orders/:id/custom-items"
|
|
13069
|
+
},
|
|
13066
13070
|
{
|
|
13067
13071
|
Component: Items,
|
|
13068
13072
|
path: "/draft-orders/:id/items"
|
|
@@ -13075,29 +13079,25 @@ const routeModule = {
|
|
|
13075
13079
|
Component: Promotions,
|
|
13076
13080
|
path: "/draft-orders/:id/promotions"
|
|
13077
13081
|
},
|
|
13078
|
-
{
|
|
13079
|
-
Component: BillingAddress,
|
|
13080
|
-
path: "/draft-orders/:id/billing-address"
|
|
13081
|
-
},
|
|
13082
13082
|
{
|
|
13083
13083
|
Component: SalesChannel,
|
|
13084
13084
|
path: "/draft-orders/:id/sales-channel"
|
|
13085
13085
|
},
|
|
13086
|
-
{
|
|
13087
|
-
Component: Shipping,
|
|
13088
|
-
path: "/draft-orders/:id/shipping"
|
|
13089
|
-
},
|
|
13090
13086
|
{
|
|
13091
13087
|
Component: ShippingAddress,
|
|
13092
13088
|
path: "/draft-orders/:id/shipping-address"
|
|
13093
13089
|
},
|
|
13094
13090
|
{
|
|
13095
|
-
Component:
|
|
13096
|
-
path: "/draft-orders/:id/
|
|
13091
|
+
Component: Shipping,
|
|
13092
|
+
path: "/draft-orders/:id/shipping"
|
|
13097
13093
|
},
|
|
13098
13094
|
{
|
|
13099
13095
|
Component: TransferOwnership,
|
|
13100
13096
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13097
|
+
},
|
|
13098
|
+
{
|
|
13099
|
+
Component: BillingAddress,
|
|
13100
|
+
path: "/draft-orders/:id/billing-address"
|
|
13101
13101
|
}
|
|
13102
13102
|
]
|
|
13103
13103
|
}
|