@medusajs/draft-order 2.10.4-preview-20251011030926 → 2.10.4-preview-20251011060147
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 +2044 -2044
- package/.medusa/server/src/admin/index.mjs +2045 -2045
- package/package.json +16 -16
|
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
|
|
|
4
4
|
import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
|
|
6
6
|
import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
|
|
7
|
-
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent,
|
|
7
|
+
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
|
|
8
8
|
import Medusa from "@medusajs/js-sdk";
|
|
9
9
|
import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
|
|
10
10
|
import { enUS } from "date-fns/locale";
|
|
@@ -9567,196 +9567,6 @@ const ID = () => {
|
|
|
9567
9567
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9568
9568
|
] });
|
|
9569
9569
|
};
|
|
9570
|
-
const BillingAddress = () => {
|
|
9571
|
-
const { id } = useParams();
|
|
9572
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9573
|
-
fields: "+billing_address"
|
|
9574
|
-
});
|
|
9575
|
-
if (isError) {
|
|
9576
|
-
throw error;
|
|
9577
|
-
}
|
|
9578
|
-
const isReady = !isPending && !!order;
|
|
9579
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9580
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9581
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9582
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9583
|
-
] }),
|
|
9584
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9585
|
-
] });
|
|
9586
|
-
};
|
|
9587
|
-
const BillingAddressForm = ({ order }) => {
|
|
9588
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9589
|
-
const form = useForm({
|
|
9590
|
-
defaultValues: {
|
|
9591
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9592
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9593
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9594
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9595
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9596
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9597
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9598
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9599
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9600
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9601
|
-
},
|
|
9602
|
-
resolver: zodResolver(schema$5)
|
|
9603
|
-
});
|
|
9604
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9605
|
-
const { handleSuccess } = useRouteModal();
|
|
9606
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9607
|
-
await mutateAsync(
|
|
9608
|
-
{ billing_address: data },
|
|
9609
|
-
{
|
|
9610
|
-
onSuccess: () => {
|
|
9611
|
-
handleSuccess();
|
|
9612
|
-
},
|
|
9613
|
-
onError: (error) => {
|
|
9614
|
-
toast.error(error.message);
|
|
9615
|
-
}
|
|
9616
|
-
}
|
|
9617
|
-
);
|
|
9618
|
-
});
|
|
9619
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9620
|
-
KeyboundForm,
|
|
9621
|
-
{
|
|
9622
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9623
|
-
onSubmit,
|
|
9624
|
-
children: [
|
|
9625
|
-
/* @__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: [
|
|
9626
|
-
/* @__PURE__ */ jsx(
|
|
9627
|
-
Form$2.Field,
|
|
9628
|
-
{
|
|
9629
|
-
control: form.control,
|
|
9630
|
-
name: "country_code",
|
|
9631
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9632
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9633
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9634
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9635
|
-
] })
|
|
9636
|
-
}
|
|
9637
|
-
),
|
|
9638
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9639
|
-
/* @__PURE__ */ jsx(
|
|
9640
|
-
Form$2.Field,
|
|
9641
|
-
{
|
|
9642
|
-
control: form.control,
|
|
9643
|
-
name: "first_name",
|
|
9644
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9645
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9646
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9647
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9648
|
-
] })
|
|
9649
|
-
}
|
|
9650
|
-
),
|
|
9651
|
-
/* @__PURE__ */ jsx(
|
|
9652
|
-
Form$2.Field,
|
|
9653
|
-
{
|
|
9654
|
-
control: form.control,
|
|
9655
|
-
name: "last_name",
|
|
9656
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9657
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9658
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9659
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9660
|
-
] })
|
|
9661
|
-
}
|
|
9662
|
-
)
|
|
9663
|
-
] }),
|
|
9664
|
-
/* @__PURE__ */ jsx(
|
|
9665
|
-
Form$2.Field,
|
|
9666
|
-
{
|
|
9667
|
-
control: form.control,
|
|
9668
|
-
name: "company",
|
|
9669
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9670
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9671
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9672
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9673
|
-
] })
|
|
9674
|
-
}
|
|
9675
|
-
),
|
|
9676
|
-
/* @__PURE__ */ jsx(
|
|
9677
|
-
Form$2.Field,
|
|
9678
|
-
{
|
|
9679
|
-
control: form.control,
|
|
9680
|
-
name: "address_1",
|
|
9681
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9682
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9683
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9684
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9685
|
-
] })
|
|
9686
|
-
}
|
|
9687
|
-
),
|
|
9688
|
-
/* @__PURE__ */ jsx(
|
|
9689
|
-
Form$2.Field,
|
|
9690
|
-
{
|
|
9691
|
-
control: form.control,
|
|
9692
|
-
name: "address_2",
|
|
9693
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9694
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9695
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9696
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9697
|
-
] })
|
|
9698
|
-
}
|
|
9699
|
-
),
|
|
9700
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9701
|
-
/* @__PURE__ */ jsx(
|
|
9702
|
-
Form$2.Field,
|
|
9703
|
-
{
|
|
9704
|
-
control: form.control,
|
|
9705
|
-
name: "postal_code",
|
|
9706
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9707
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9708
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9709
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9710
|
-
] })
|
|
9711
|
-
}
|
|
9712
|
-
),
|
|
9713
|
-
/* @__PURE__ */ jsx(
|
|
9714
|
-
Form$2.Field,
|
|
9715
|
-
{
|
|
9716
|
-
control: form.control,
|
|
9717
|
-
name: "city",
|
|
9718
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9719
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9720
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9721
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9722
|
-
] })
|
|
9723
|
-
}
|
|
9724
|
-
)
|
|
9725
|
-
] }),
|
|
9726
|
-
/* @__PURE__ */ jsx(
|
|
9727
|
-
Form$2.Field,
|
|
9728
|
-
{
|
|
9729
|
-
control: form.control,
|
|
9730
|
-
name: "province",
|
|
9731
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9732
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9733
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9734
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9735
|
-
] })
|
|
9736
|
-
}
|
|
9737
|
-
),
|
|
9738
|
-
/* @__PURE__ */ jsx(
|
|
9739
|
-
Form$2.Field,
|
|
9740
|
-
{
|
|
9741
|
-
control: form.control,
|
|
9742
|
-
name: "phone",
|
|
9743
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9744
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9745
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9746
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9747
|
-
] })
|
|
9748
|
-
}
|
|
9749
|
-
)
|
|
9750
|
-
] }) }),
|
|
9751
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9752
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9753
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9754
|
-
] }) })
|
|
9755
|
-
]
|
|
9756
|
-
}
|
|
9757
|
-
) });
|
|
9758
|
-
};
|
|
9759
|
-
const schema$5 = addressSchema;
|
|
9760
9570
|
const CustomItems = () => {
|
|
9761
9571
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9762
9572
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9765,7 +9575,7 @@ const CustomItems = () => {
|
|
|
9765
9575
|
};
|
|
9766
9576
|
const CustomItemsForm = () => {
|
|
9767
9577
|
const form = useForm({
|
|
9768
|
-
resolver: zodResolver(schema$
|
|
9578
|
+
resolver: zodResolver(schema$5)
|
|
9769
9579
|
});
|
|
9770
9580
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9771
9581
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9775,13 +9585,57 @@ const CustomItemsForm = () => {
|
|
|
9775
9585
|
] }) })
|
|
9776
9586
|
] }) });
|
|
9777
9587
|
};
|
|
9778
|
-
const schema$
|
|
9588
|
+
const schema$5 = objectType({
|
|
9779
9589
|
email: stringType().email()
|
|
9780
9590
|
});
|
|
9781
|
-
const
|
|
9591
|
+
const InlineTip = forwardRef(
|
|
9592
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9593
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9594
|
+
return /* @__PURE__ */ jsxs(
|
|
9595
|
+
"div",
|
|
9596
|
+
{
|
|
9597
|
+
ref,
|
|
9598
|
+
className: clx(
|
|
9599
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9600
|
+
className
|
|
9601
|
+
),
|
|
9602
|
+
...props,
|
|
9603
|
+
children: [
|
|
9604
|
+
/* @__PURE__ */ jsx(
|
|
9605
|
+
"div",
|
|
9606
|
+
{
|
|
9607
|
+
role: "presentation",
|
|
9608
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9609
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9610
|
+
})
|
|
9611
|
+
}
|
|
9612
|
+
),
|
|
9613
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9614
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9615
|
+
labelValue,
|
|
9616
|
+
":"
|
|
9617
|
+
] }),
|
|
9618
|
+
" ",
|
|
9619
|
+
children
|
|
9620
|
+
] })
|
|
9621
|
+
]
|
|
9622
|
+
}
|
|
9623
|
+
);
|
|
9624
|
+
}
|
|
9625
|
+
);
|
|
9626
|
+
InlineTip.displayName = "InlineTip";
|
|
9627
|
+
const MetadataFieldSchema = objectType({
|
|
9628
|
+
key: stringType(),
|
|
9629
|
+
disabled: booleanType().optional(),
|
|
9630
|
+
value: anyType()
|
|
9631
|
+
});
|
|
9632
|
+
const MetadataSchema = objectType({
|
|
9633
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
9634
|
+
});
|
|
9635
|
+
const Metadata = () => {
|
|
9782
9636
|
const { id } = useParams();
|
|
9783
9637
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9784
|
-
fields: "
|
|
9638
|
+
fields: "metadata"
|
|
9785
9639
|
});
|
|
9786
9640
|
if (isError) {
|
|
9787
9641
|
throw error;
|
|
@@ -9789,26 +9643,33 @@ const Email = () => {
|
|
|
9789
9643
|
const isReady = !isPending && !!order;
|
|
9790
9644
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9791
9645
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9792
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
9793
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
9646
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
9647
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9794
9648
|
] }),
|
|
9795
|
-
isReady
|
|
9649
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
9796
9650
|
] });
|
|
9797
9651
|
};
|
|
9798
|
-
const
|
|
9652
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9653
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9654
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
9655
|
+
const { handleSuccess } = useRouteModal();
|
|
9656
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9657
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9799
9658
|
const form = useForm({
|
|
9800
9659
|
defaultValues: {
|
|
9801
|
-
|
|
9660
|
+
metadata: getDefaultValues(metadata)
|
|
9802
9661
|
},
|
|
9803
|
-
resolver: zodResolver(
|
|
9662
|
+
resolver: zodResolver(MetadataSchema)
|
|
9804
9663
|
});
|
|
9805
|
-
const
|
|
9806
|
-
|
|
9807
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9664
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9665
|
+
const parsedData = parseValues(data);
|
|
9808
9666
|
await mutateAsync(
|
|
9809
|
-
{
|
|
9667
|
+
{
|
|
9668
|
+
metadata: parsedData
|
|
9669
|
+
},
|
|
9810
9670
|
{
|
|
9811
9671
|
onSuccess: () => {
|
|
9672
|
+
toast.success("Metadata updated");
|
|
9812
9673
|
handleSuccess();
|
|
9813
9674
|
},
|
|
9814
9675
|
onError: (error) => {
|
|
@@ -9817,156 +9678,282 @@ const EmailForm = ({ order }) => {
|
|
|
9817
9678
|
}
|
|
9818
9679
|
);
|
|
9819
9680
|
});
|
|
9681
|
+
const { fields, insert, remove } = useFieldArray({
|
|
9682
|
+
control: form.control,
|
|
9683
|
+
name: "metadata"
|
|
9684
|
+
});
|
|
9685
|
+
function deleteRow(index) {
|
|
9686
|
+
remove(index);
|
|
9687
|
+
if (fields.length === 1) {
|
|
9688
|
+
insert(0, {
|
|
9689
|
+
key: "",
|
|
9690
|
+
value: "",
|
|
9691
|
+
disabled: false
|
|
9692
|
+
});
|
|
9693
|
+
}
|
|
9694
|
+
}
|
|
9695
|
+
function insertRow(index, position) {
|
|
9696
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9697
|
+
key: "",
|
|
9698
|
+
value: "",
|
|
9699
|
+
disabled: false
|
|
9700
|
+
});
|
|
9701
|
+
}
|
|
9820
9702
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9821
9703
|
KeyboundForm,
|
|
9822
9704
|
{
|
|
9705
|
+
onSubmit: handleSubmit,
|
|
9823
9706
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9824
|
-
onSubmit,
|
|
9825
9707
|
children: [
|
|
9826
|
-
/* @__PURE__ */
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9708
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9709
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9710
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9711
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
9712
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
9713
|
+
] }),
|
|
9714
|
+
fields.map((field, index) => {
|
|
9715
|
+
const isDisabled = field.disabled || false;
|
|
9716
|
+
let placeholder = "-";
|
|
9717
|
+
if (typeof field.value === "object") {
|
|
9718
|
+
placeholder = "{ ... }";
|
|
9719
|
+
}
|
|
9720
|
+
if (Array.isArray(field.value)) {
|
|
9721
|
+
placeholder = "[ ... ]";
|
|
9722
|
+
}
|
|
9723
|
+
return /* @__PURE__ */ jsx(
|
|
9724
|
+
ConditionalTooltip,
|
|
9725
|
+
{
|
|
9726
|
+
showTooltip: isDisabled,
|
|
9727
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9728
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9729
|
+
/* @__PURE__ */ jsxs(
|
|
9730
|
+
"div",
|
|
9731
|
+
{
|
|
9732
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
9733
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9734
|
+
}),
|
|
9735
|
+
children: [
|
|
9736
|
+
/* @__PURE__ */ jsx(
|
|
9737
|
+
Form$2.Field,
|
|
9738
|
+
{
|
|
9739
|
+
control: form.control,
|
|
9740
|
+
name: `metadata.${index}.key`,
|
|
9741
|
+
render: ({ field: field2 }) => {
|
|
9742
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9743
|
+
GridInput,
|
|
9744
|
+
{
|
|
9745
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9746
|
+
...field2,
|
|
9747
|
+
disabled: isDisabled,
|
|
9748
|
+
placeholder: "Key"
|
|
9749
|
+
}
|
|
9750
|
+
) }) });
|
|
9751
|
+
}
|
|
9752
|
+
}
|
|
9753
|
+
),
|
|
9754
|
+
/* @__PURE__ */ jsx(
|
|
9755
|
+
Form$2.Field,
|
|
9756
|
+
{
|
|
9757
|
+
control: form.control,
|
|
9758
|
+
name: `metadata.${index}.value`,
|
|
9759
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
9760
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9761
|
+
GridInput,
|
|
9762
|
+
{
|
|
9763
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9764
|
+
...field2,
|
|
9765
|
+
value: isDisabled ? placeholder : value,
|
|
9766
|
+
disabled: isDisabled,
|
|
9767
|
+
placeholder: "Value"
|
|
9768
|
+
}
|
|
9769
|
+
) }) });
|
|
9770
|
+
}
|
|
9771
|
+
}
|
|
9772
|
+
)
|
|
9773
|
+
]
|
|
9774
|
+
}
|
|
9775
|
+
),
|
|
9776
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
9777
|
+
/* @__PURE__ */ jsx(
|
|
9778
|
+
DropdownMenu.Trigger,
|
|
9779
|
+
{
|
|
9780
|
+
className: clx(
|
|
9781
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9782
|
+
{
|
|
9783
|
+
hidden: isDisabled
|
|
9784
|
+
}
|
|
9785
|
+
),
|
|
9786
|
+
disabled: isDisabled,
|
|
9787
|
+
asChild: true,
|
|
9788
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
9789
|
+
}
|
|
9790
|
+
),
|
|
9791
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
9792
|
+
/* @__PURE__ */ jsxs(
|
|
9793
|
+
DropdownMenu.Item,
|
|
9794
|
+
{
|
|
9795
|
+
className: "gap-x-2",
|
|
9796
|
+
onClick: () => insertRow(index, "above"),
|
|
9797
|
+
children: [
|
|
9798
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9799
|
+
"Insert row above"
|
|
9800
|
+
]
|
|
9801
|
+
}
|
|
9802
|
+
),
|
|
9803
|
+
/* @__PURE__ */ jsxs(
|
|
9804
|
+
DropdownMenu.Item,
|
|
9805
|
+
{
|
|
9806
|
+
className: "gap-x-2",
|
|
9807
|
+
onClick: () => insertRow(index, "below"),
|
|
9808
|
+
children: [
|
|
9809
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9810
|
+
"Insert row below"
|
|
9811
|
+
]
|
|
9812
|
+
}
|
|
9813
|
+
),
|
|
9814
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
9815
|
+
/* @__PURE__ */ jsxs(
|
|
9816
|
+
DropdownMenu.Item,
|
|
9817
|
+
{
|
|
9818
|
+
className: "gap-x-2",
|
|
9819
|
+
onClick: () => deleteRow(index),
|
|
9820
|
+
children: [
|
|
9821
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
9822
|
+
"Delete row"
|
|
9823
|
+
]
|
|
9824
|
+
}
|
|
9825
|
+
)
|
|
9826
|
+
] })
|
|
9827
|
+
] })
|
|
9828
|
+
] })
|
|
9829
|
+
},
|
|
9830
|
+
field.id
|
|
9831
|
+
);
|
|
9832
|
+
})
|
|
9833
|
+
] }),
|
|
9834
|
+
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
9835
|
+
] }),
|
|
9836
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9837
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9840
9838
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9841
9839
|
] }) })
|
|
9842
9840
|
]
|
|
9843
9841
|
}
|
|
9844
9842
|
) });
|
|
9845
9843
|
};
|
|
9846
|
-
const
|
|
9847
|
-
|
|
9844
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
9845
|
+
return /* @__PURE__ */ jsx(
|
|
9846
|
+
"input",
|
|
9847
|
+
{
|
|
9848
|
+
ref,
|
|
9849
|
+
...props,
|
|
9850
|
+
autoComplete: "off",
|
|
9851
|
+
className: clx(
|
|
9852
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
9853
|
+
className
|
|
9854
|
+
)
|
|
9855
|
+
}
|
|
9856
|
+
);
|
|
9848
9857
|
});
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
const handleIncrement = () => {
|
|
9868
|
-
const newValue = value + step;
|
|
9869
|
-
if (max === void 0 || newValue <= max) {
|
|
9870
|
-
onChange(newValue);
|
|
9871
|
-
}
|
|
9872
|
-
};
|
|
9873
|
-
const handleDecrement = () => {
|
|
9874
|
-
const newValue = value - step;
|
|
9875
|
-
if (min === void 0 || newValue >= min) {
|
|
9876
|
-
onChange(newValue);
|
|
9858
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
9859
|
+
const PlaceholderInner = () => {
|
|
9860
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
9861
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
9862
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9863
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
9864
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
9865
|
+
] }) })
|
|
9866
|
+
] });
|
|
9867
|
+
};
|
|
9868
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
9869
|
+
function getDefaultValues(metadata) {
|
|
9870
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
9871
|
+
return [
|
|
9872
|
+
{
|
|
9873
|
+
key: "",
|
|
9874
|
+
value: "",
|
|
9875
|
+
disabled: false
|
|
9877
9876
|
}
|
|
9877
|
+
];
|
|
9878
|
+
}
|
|
9879
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
9880
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
9881
|
+
return {
|
|
9882
|
+
key,
|
|
9883
|
+
value,
|
|
9884
|
+
disabled: true
|
|
9885
|
+
};
|
|
9886
|
+
}
|
|
9887
|
+
let stringValue = value;
|
|
9888
|
+
if (typeof value !== "string") {
|
|
9889
|
+
stringValue = JSON.stringify(value);
|
|
9890
|
+
}
|
|
9891
|
+
return {
|
|
9892
|
+
key,
|
|
9893
|
+
value: stringValue,
|
|
9894
|
+
original_key: key
|
|
9878
9895
|
};
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
"button",
|
|
9912
|
-
{
|
|
9913
|
-
className: clx(
|
|
9914
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9915
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9916
|
-
"focus:bg-ui-bg-field-component-hover",
|
|
9917
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
9918
|
-
{
|
|
9919
|
-
"size-7": size === "small",
|
|
9920
|
-
"size-8": size === "base"
|
|
9921
|
-
}
|
|
9922
|
-
),
|
|
9923
|
-
type: "button",
|
|
9924
|
-
onClick: handleDecrement,
|
|
9925
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
9926
|
-
children: [
|
|
9927
|
-
/* @__PURE__ */ jsx(Minus, {}),
|
|
9928
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9929
|
-
]
|
|
9930
|
-
}
|
|
9931
|
-
),
|
|
9932
|
-
/* @__PURE__ */ jsxs(
|
|
9933
|
-
"button",
|
|
9934
|
-
{
|
|
9935
|
-
className: clx(
|
|
9936
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9937
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9938
|
-
"focus:bg-ui-bg-field-hover",
|
|
9939
|
-
"hover:bg-ui-bg-field-hover",
|
|
9940
|
-
{
|
|
9941
|
-
"size-7": size === "small",
|
|
9942
|
-
"size-8": size === "base"
|
|
9943
|
-
}
|
|
9944
|
-
),
|
|
9945
|
-
type: "button",
|
|
9946
|
-
onClick: handleIncrement,
|
|
9947
|
-
disabled: max !== void 0 && value >= max || disabled,
|
|
9948
|
-
children: [
|
|
9949
|
-
/* @__PURE__ */ jsx(Plus, {}),
|
|
9950
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
9951
|
-
]
|
|
9952
|
-
}
|
|
9953
|
-
)
|
|
9954
|
-
]
|
|
9896
|
+
});
|
|
9897
|
+
}
|
|
9898
|
+
function parseValues(values) {
|
|
9899
|
+
const metadata = values.metadata;
|
|
9900
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
9901
|
+
if (isEmpty) {
|
|
9902
|
+
return null;
|
|
9903
|
+
}
|
|
9904
|
+
const update = {};
|
|
9905
|
+
metadata.forEach((field) => {
|
|
9906
|
+
let key = field.key;
|
|
9907
|
+
let value = field.value;
|
|
9908
|
+
const disabled = field.disabled;
|
|
9909
|
+
if (!key || !value) {
|
|
9910
|
+
return;
|
|
9911
|
+
}
|
|
9912
|
+
if (disabled) {
|
|
9913
|
+
update[key] = value;
|
|
9914
|
+
return;
|
|
9915
|
+
}
|
|
9916
|
+
key = key.trim();
|
|
9917
|
+
value = value.trim();
|
|
9918
|
+
if (value === "true") {
|
|
9919
|
+
update[key] = true;
|
|
9920
|
+
} else if (value === "false") {
|
|
9921
|
+
update[key] = false;
|
|
9922
|
+
} else {
|
|
9923
|
+
const parsedNumber = parseFloat(value);
|
|
9924
|
+
if (!isNaN(parsedNumber)) {
|
|
9925
|
+
update[key] = parsedNumber;
|
|
9926
|
+
} else {
|
|
9927
|
+
update[key] = value;
|
|
9955
9928
|
}
|
|
9956
|
-
|
|
9929
|
+
}
|
|
9930
|
+
});
|
|
9931
|
+
return update;
|
|
9932
|
+
}
|
|
9933
|
+
function getHasUneditableRows(metadata) {
|
|
9934
|
+
if (!metadata) {
|
|
9935
|
+
return false;
|
|
9957
9936
|
}
|
|
9958
|
-
)
|
|
9959
|
-
|
|
9960
|
-
|
|
9937
|
+
return Object.values(metadata).some(
|
|
9938
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
9939
|
+
);
|
|
9940
|
+
}
|
|
9941
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
9942
|
+
const promotionsQueryKeys = {
|
|
9961
9943
|
list: (query2) => [
|
|
9962
|
-
|
|
9944
|
+
PROMOTION_QUERY_KEY,
|
|
9945
|
+
query2 ? query2 : void 0
|
|
9946
|
+
],
|
|
9947
|
+
detail: (id, query2) => [
|
|
9948
|
+
PROMOTION_QUERY_KEY,
|
|
9949
|
+
id,
|
|
9963
9950
|
query2 ? query2 : void 0
|
|
9964
9951
|
]
|
|
9965
9952
|
};
|
|
9966
|
-
const
|
|
9953
|
+
const usePromotions = (query2, options) => {
|
|
9967
9954
|
const { data, ...rest } = useQuery({
|
|
9968
|
-
queryKey:
|
|
9969
|
-
queryFn: async () =>
|
|
9955
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
9956
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
9970
9957
|
...options
|
|
9971
9958
|
});
|
|
9972
9959
|
return { ...data, ...rest };
|
|
@@ -10017,65 +10004,85 @@ const useInitiateOrderEdit = ({
|
|
|
10017
10004
|
run();
|
|
10018
10005
|
}, [preview, navigate, mutateAsync]);
|
|
10019
10006
|
};
|
|
10020
|
-
|
|
10021
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10022
|
-
}
|
|
10023
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10024
|
-
const Items = () => {
|
|
10007
|
+
const Promotions = () => {
|
|
10025
10008
|
const { id } = useParams();
|
|
10026
10009
|
const {
|
|
10027
10010
|
order: preview,
|
|
10028
|
-
isPending: isPreviewPending,
|
|
10029
10011
|
isError: isPreviewError,
|
|
10030
10012
|
error: previewError
|
|
10031
|
-
} = useOrderPreview(id, void 0
|
|
10032
|
-
placeholderData: keepPreviousData
|
|
10033
|
-
});
|
|
10013
|
+
} = useOrderPreview(id, void 0);
|
|
10034
10014
|
useInitiateOrderEdit({ preview });
|
|
10035
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10036
|
-
id,
|
|
10037
|
-
{
|
|
10038
|
-
fields: "currency_code"
|
|
10039
|
-
},
|
|
10040
|
-
{
|
|
10041
|
-
enabled: !!id
|
|
10042
|
-
}
|
|
10043
|
-
);
|
|
10044
10015
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10045
|
-
if (isError) {
|
|
10046
|
-
throw error;
|
|
10047
|
-
}
|
|
10048
10016
|
if (isPreviewError) {
|
|
10049
10017
|
throw previewError;
|
|
10050
10018
|
}
|
|
10051
|
-
const
|
|
10052
|
-
return /* @__PURE__ */
|
|
10053
|
-
/* @__PURE__ */ jsx(
|
|
10054
|
-
|
|
10055
|
-
] })
|
|
10019
|
+
const isReady = !!preview;
|
|
10020
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10021
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10022
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10023
|
+
] });
|
|
10056
10024
|
};
|
|
10057
|
-
const
|
|
10058
|
-
|
|
10025
|
+
const PromotionForm = ({ preview }) => {
|
|
10026
|
+
const { items, shipping_methods } = preview;
|
|
10059
10027
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10060
|
-
const [
|
|
10061
|
-
null
|
|
10062
|
-
);
|
|
10028
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
10063
10029
|
const { handleSuccess } = useRouteModal();
|
|
10064
|
-
const {
|
|
10030
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10031
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10032
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10033
|
+
{
|
|
10034
|
+
id: promoIds
|
|
10035
|
+
},
|
|
10036
|
+
{
|
|
10037
|
+
enabled: !!promoIds.length
|
|
10038
|
+
}
|
|
10039
|
+
);
|
|
10040
|
+
const comboboxData = useComboboxData({
|
|
10041
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10042
|
+
queryFn: async (params) => {
|
|
10043
|
+
return await sdk.admin.promotion.list({
|
|
10044
|
+
...params,
|
|
10045
|
+
id: {
|
|
10046
|
+
$nin: promoIds
|
|
10047
|
+
}
|
|
10048
|
+
});
|
|
10049
|
+
},
|
|
10050
|
+
getOptions: (data) => {
|
|
10051
|
+
return data.promotions.map((promotion) => ({
|
|
10052
|
+
label: promotion.code,
|
|
10053
|
+
value: promotion.code
|
|
10054
|
+
}));
|
|
10055
|
+
}
|
|
10056
|
+
});
|
|
10057
|
+
const add = async (value) => {
|
|
10058
|
+
if (!value) {
|
|
10059
|
+
return;
|
|
10060
|
+
}
|
|
10061
|
+
addPromotions(
|
|
10062
|
+
{
|
|
10063
|
+
promo_codes: [value]
|
|
10064
|
+
},
|
|
10065
|
+
{
|
|
10066
|
+
onError: (e) => {
|
|
10067
|
+
toast.error(e.message);
|
|
10068
|
+
comboboxData.onSearchValueChange("");
|
|
10069
|
+
setComboboxValue("");
|
|
10070
|
+
},
|
|
10071
|
+
onSuccess: () => {
|
|
10072
|
+
comboboxData.onSearchValueChange("");
|
|
10073
|
+
setComboboxValue("");
|
|
10074
|
+
}
|
|
10075
|
+
}
|
|
10076
|
+
);
|
|
10077
|
+
};
|
|
10065
10078
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10066
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10067
|
-
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10068
|
-
const matches = useMemo(() => {
|
|
10069
|
-
return matchSorter(preview.items, query2, {
|
|
10070
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10071
|
-
});
|
|
10072
|
-
}, [preview.items, query2]);
|
|
10079
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10073
10080
|
const onSubmit = async () => {
|
|
10074
10081
|
setIsSubmitting(true);
|
|
10075
10082
|
let requestSucceeded = false;
|
|
10076
10083
|
await requestOrderEdit(void 0, {
|
|
10077
10084
|
onError: (e) => {
|
|
10078
|
-
toast.error(
|
|
10085
|
+
toast.error(e.message);
|
|
10079
10086
|
},
|
|
10080
10087
|
onSuccess: () => {
|
|
10081
10088
|
requestSucceeded = true;
|
|
@@ -10087,7 +10094,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10087
10094
|
}
|
|
10088
10095
|
await confirmOrderEdit(void 0, {
|
|
10089
10096
|
onError: (e) => {
|
|
10090
|
-
toast.error(
|
|
10097
|
+
toast.error(e.message);
|
|
10091
10098
|
},
|
|
10092
10099
|
onSuccess: () => {
|
|
10093
10100
|
handleSuccess();
|
|
@@ -10097,1589 +10104,399 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10097
10104
|
}
|
|
10098
10105
|
});
|
|
10099
10106
|
};
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
onOpenChangeCallback: (open) => {
|
|
10124
|
-
if (!open) {
|
|
10125
|
-
setModalContent(null);
|
|
10107
|
+
if (isError) {
|
|
10108
|
+
throw error;
|
|
10109
|
+
}
|
|
10110
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10111
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10112
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10113
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10114
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10115
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10116
|
+
] }),
|
|
10117
|
+
/* @__PURE__ */ jsx(
|
|
10118
|
+
Combobox,
|
|
10119
|
+
{
|
|
10120
|
+
id: "promotion-combobox",
|
|
10121
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10122
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10123
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10124
|
+
options: comboboxData.options,
|
|
10125
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10126
|
+
searchValue: comboboxData.searchValue,
|
|
10127
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10128
|
+
onChange: add,
|
|
10129
|
+
value: comboboxValue
|
|
10126
10130
|
}
|
|
10131
|
+
)
|
|
10132
|
+
] }),
|
|
10133
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10134
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10135
|
+
PromotionItem,
|
|
10136
|
+
{
|
|
10137
|
+
promotion,
|
|
10138
|
+
orderId: preview.id,
|
|
10139
|
+
isLoading: isPending
|
|
10127
10140
|
},
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
] }),
|
|
10134
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10135
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10136
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10137
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10138
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10139
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10140
|
-
] }),
|
|
10141
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10142
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10143
|
-
Input,
|
|
10144
|
-
{
|
|
10145
|
-
type: "search",
|
|
10146
|
-
placeholder: "Search items",
|
|
10147
|
-
value: searchValue,
|
|
10148
|
-
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10149
|
-
}
|
|
10150
|
-
) }),
|
|
10151
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10152
|
-
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10153
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10154
|
-
/* @__PURE__ */ jsx(
|
|
10155
|
-
StackedModalTrigger$1,
|
|
10156
|
-
{
|
|
10157
|
-
type: "add-items",
|
|
10158
|
-
setModalContent
|
|
10159
|
-
}
|
|
10160
|
-
),
|
|
10161
|
-
/* @__PURE__ */ jsx(
|
|
10162
|
-
StackedModalTrigger$1,
|
|
10163
|
-
{
|
|
10164
|
-
type: "add-custom-item",
|
|
10165
|
-
setModalContent
|
|
10166
|
-
}
|
|
10167
|
-
)
|
|
10168
|
-
] })
|
|
10169
|
-
] })
|
|
10170
|
-
] })
|
|
10171
|
-
] }),
|
|
10172
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10173
|
-
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
10174
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10175
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10176
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10177
|
-
/* @__PURE__ */ jsx("div", {})
|
|
10178
|
-
] }) }),
|
|
10179
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__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: [
|
|
10180
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10181
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10182
|
-
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10183
|
-
Item,
|
|
10184
|
-
{
|
|
10185
|
-
item,
|
|
10186
|
-
preview,
|
|
10187
|
-
currencyCode
|
|
10188
|
-
},
|
|
10189
|
-
item.id
|
|
10190
|
-
)) : /* @__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: [
|
|
10191
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10192
|
-
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10193
|
-
'No items found for "',
|
|
10194
|
-
query2,
|
|
10195
|
-
'".'
|
|
10196
|
-
] })
|
|
10197
|
-
] }) })
|
|
10198
|
-
] })
|
|
10199
|
-
] }),
|
|
10200
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10201
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10202
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10203
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10204
|
-
Text,
|
|
10205
|
-
{
|
|
10206
|
-
size: "small",
|
|
10207
|
-
leading: "compact",
|
|
10208
|
-
className: "text-ui-fg-subtle",
|
|
10209
|
-
children: [
|
|
10210
|
-
itemCount,
|
|
10211
|
-
" ",
|
|
10212
|
-
itemCount === 1 ? "item" : "items"
|
|
10213
|
-
]
|
|
10214
|
-
}
|
|
10215
|
-
) }),
|
|
10216
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10217
|
-
] })
|
|
10218
|
-
] }) }),
|
|
10219
|
-
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10220
|
-
CustomItemForm,
|
|
10221
|
-
{
|
|
10222
|
-
orderId: preview.id,
|
|
10223
|
-
currencyCode
|
|
10224
|
-
}
|
|
10225
|
-
) : null)
|
|
10226
|
-
]
|
|
10227
|
-
}
|
|
10228
|
-
) }),
|
|
10229
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10230
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10141
|
+
promotion.id
|
|
10142
|
+
)) })
|
|
10143
|
+
] }) }),
|
|
10144
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10145
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10231
10146
|
/* @__PURE__ */ jsx(
|
|
10232
10147
|
Button,
|
|
10233
10148
|
{
|
|
10234
10149
|
size: "small",
|
|
10235
|
-
type: "
|
|
10236
|
-
|
|
10237
|
-
isLoading: isSubmitting,
|
|
10150
|
+
type: "submit",
|
|
10151
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10238
10152
|
children: "Save"
|
|
10239
10153
|
}
|
|
10240
10154
|
)
|
|
10241
10155
|
] }) })
|
|
10242
10156
|
] });
|
|
10243
10157
|
};
|
|
10244
|
-
const
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
const
|
|
10251
|
-
const
|
|
10252
|
-
|
|
10253
|
-
defaultValues: {
|
|
10254
|
-
quantity: item.quantity,
|
|
10255
|
-
unit_price: item.unit_price
|
|
10256
|
-
},
|
|
10257
|
-
resolver: zodResolver(variantItemSchema)
|
|
10258
|
-
});
|
|
10259
|
-
const actionId = useMemo(() => {
|
|
10260
|
-
var _a, _b;
|
|
10261
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10262
|
-
}, [item]);
|
|
10263
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10264
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10265
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10266
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10267
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10268
|
-
setEditing(false);
|
|
10269
|
-
return;
|
|
10270
|
-
}
|
|
10271
|
-
if (!actionId) {
|
|
10272
|
-
await updateOriginalItem(
|
|
10273
|
-
{
|
|
10274
|
-
item_id: item.id,
|
|
10275
|
-
quantity: data.quantity,
|
|
10276
|
-
unit_price: convertNumber(data.unit_price)
|
|
10277
|
-
},
|
|
10278
|
-
{
|
|
10279
|
-
onSuccess: () => {
|
|
10280
|
-
setEditing(false);
|
|
10281
|
-
},
|
|
10282
|
-
onError: (e) => {
|
|
10283
|
-
toast.error(e.message);
|
|
10284
|
-
}
|
|
10285
|
-
}
|
|
10286
|
-
);
|
|
10287
|
-
return;
|
|
10288
|
-
}
|
|
10289
|
-
await updateActionItem(
|
|
10158
|
+
const PromotionItem = ({
|
|
10159
|
+
promotion,
|
|
10160
|
+
orderId,
|
|
10161
|
+
isLoading
|
|
10162
|
+
}) => {
|
|
10163
|
+
var _a;
|
|
10164
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10165
|
+
const onRemove = async () => {
|
|
10166
|
+
removePromotions(
|
|
10290
10167
|
{
|
|
10291
|
-
|
|
10292
|
-
quantity: data.quantity,
|
|
10293
|
-
unit_price: convertNumber(data.unit_price)
|
|
10168
|
+
promo_codes: [promotion.code]
|
|
10294
10169
|
},
|
|
10295
10170
|
{
|
|
10296
|
-
onSuccess: () => {
|
|
10297
|
-
setEditing(false);
|
|
10298
|
-
},
|
|
10299
10171
|
onError: (e) => {
|
|
10300
10172
|
toast.error(e.message);
|
|
10301
10173
|
}
|
|
10302
10174
|
}
|
|
10303
10175
|
);
|
|
10304
|
-
}
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10176
|
+
};
|
|
10177
|
+
const displayValue = getDisplayValue(promotion);
|
|
10178
|
+
return /* @__PURE__ */ jsxs(
|
|
10179
|
+
"div",
|
|
10180
|
+
{
|
|
10181
|
+
className: clx(
|
|
10182
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
10309
10183
|
{
|
|
10310
|
-
|
|
10311
|
-
alt: item.product_title ?? void 0
|
|
10184
|
+
"animate-pulse": isLoading
|
|
10312
10185
|
}
|
|
10313
10186
|
),
|
|
10314
|
-
|
|
10315
|
-
/* @__PURE__ */ jsxs("div", {
|
|
10316
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children:
|
|
10317
|
-
/* @__PURE__ */ jsxs(
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
size: "small",
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
"(",
|
|
10325
|
-
item.variant_title,
|
|
10326
|
-
")"
|
|
10327
|
-
]
|
|
10328
|
-
}
|
|
10329
|
-
)
|
|
10187
|
+
children: [
|
|
10188
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10189
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
10190
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
10191
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
10192
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
10193
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
10194
|
+
] }),
|
|
10195
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
10196
|
+
] })
|
|
10330
10197
|
] }),
|
|
10331
10198
|
/* @__PURE__ */ jsx(
|
|
10332
|
-
|
|
10199
|
+
IconButton,
|
|
10333
10200
|
{
|
|
10334
10201
|
size: "small",
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10202
|
+
type: "button",
|
|
10203
|
+
variant: "transparent",
|
|
10204
|
+
onClick: onRemove,
|
|
10205
|
+
isLoading: isPending || isLoading,
|
|
10206
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
10338
10207
|
}
|
|
10339
10208
|
)
|
|
10340
|
-
]
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10209
|
+
]
|
|
10210
|
+
},
|
|
10211
|
+
promotion.id
|
|
10212
|
+
);
|
|
10213
|
+
};
|
|
10214
|
+
function getDisplayValue(promotion) {
|
|
10215
|
+
var _a, _b, _c, _d;
|
|
10216
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
10217
|
+
if (!value) {
|
|
10218
|
+
return null;
|
|
10219
|
+
}
|
|
10220
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
10221
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
10222
|
+
if (!currency) {
|
|
10223
|
+
return null;
|
|
10224
|
+
}
|
|
10225
|
+
return getLocaleAmount(value, currency);
|
|
10226
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
10227
|
+
return formatPercentage(value);
|
|
10228
|
+
}
|
|
10229
|
+
return null;
|
|
10230
|
+
}
|
|
10231
|
+
const formatter = new Intl.NumberFormat([], {
|
|
10232
|
+
style: "percent",
|
|
10233
|
+
minimumFractionDigits: 2
|
|
10234
|
+
});
|
|
10235
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
10236
|
+
let val = value || 0;
|
|
10237
|
+
if (!isPercentageValue) {
|
|
10238
|
+
val = val / 100;
|
|
10239
|
+
}
|
|
10240
|
+
return formatter.format(val);
|
|
10241
|
+
};
|
|
10242
|
+
function getPromotionIds(items, shippingMethods) {
|
|
10243
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
10244
|
+
for (const item of items) {
|
|
10245
|
+
if (item.adjustments) {
|
|
10246
|
+
for (const adjustment of item.adjustments) {
|
|
10247
|
+
if (adjustment.promotion_id) {
|
|
10248
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10349
10249
|
}
|
|
10350
10250
|
}
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10359
|
-
CurrencyInput,
|
|
10360
|
-
{
|
|
10361
|
-
...field,
|
|
10362
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10363
|
-
code: currencyCode,
|
|
10364
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10365
|
-
}
|
|
10366
|
-
) }) });
|
|
10251
|
+
}
|
|
10252
|
+
}
|
|
10253
|
+
for (const shippingMethod of shippingMethods) {
|
|
10254
|
+
if (shippingMethod.adjustments) {
|
|
10255
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
10256
|
+
if (adjustment.promotion_id) {
|
|
10257
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10367
10258
|
}
|
|
10368
10259
|
}
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10260
|
+
}
|
|
10261
|
+
}
|
|
10262
|
+
return Array.from(promotionIds);
|
|
10263
|
+
}
|
|
10264
|
+
const SalesChannel = () => {
|
|
10265
|
+
const { id } = useParams();
|
|
10266
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10267
|
+
id,
|
|
10268
|
+
{
|
|
10269
|
+
fields: "+sales_channel_id"
|
|
10270
|
+
},
|
|
10271
|
+
{
|
|
10272
|
+
enabled: !!id
|
|
10273
|
+
}
|
|
10274
|
+
);
|
|
10275
|
+
if (isError) {
|
|
10276
|
+
throw error;
|
|
10277
|
+
}
|
|
10278
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
10279
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10280
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10281
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
10282
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
10283
|
+
] }),
|
|
10284
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
10285
|
+
] });
|
|
10383
10286
|
};
|
|
10384
|
-
const
|
|
10385
|
-
quantity: numberType(),
|
|
10386
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10387
|
-
});
|
|
10388
|
-
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
10389
|
-
const [editing, setEditing] = useState(false);
|
|
10390
|
-
const { quantity, unit_price, title } = item;
|
|
10287
|
+
const SalesChannelForm = ({ order }) => {
|
|
10391
10288
|
const form = useForm({
|
|
10392
10289
|
defaultValues: {
|
|
10393
|
-
|
|
10394
|
-
quantity,
|
|
10395
|
-
unit_price
|
|
10290
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
10396
10291
|
},
|
|
10397
|
-
resolver: zodResolver(
|
|
10292
|
+
resolver: zodResolver(schema$4)
|
|
10398
10293
|
});
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
title,
|
|
10402
|
-
quantity,
|
|
10403
|
-
unit_price
|
|
10404
|
-
});
|
|
10405
|
-
}, [form, title, quantity, unit_price]);
|
|
10406
|
-
const actionId = useMemo(() => {
|
|
10407
|
-
var _a, _b;
|
|
10408
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10409
|
-
}, [item]);
|
|
10410
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10411
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10412
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10413
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10294
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10295
|
+
const { handleSuccess } = useRouteModal();
|
|
10414
10296
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10415
|
-
|
|
10416
|
-
setEditing(false);
|
|
10417
|
-
return;
|
|
10418
|
-
}
|
|
10419
|
-
if (!actionId) {
|
|
10420
|
-
await updateOriginalItem(
|
|
10421
|
-
{
|
|
10422
|
-
item_id: item.id,
|
|
10423
|
-
quantity: data.quantity,
|
|
10424
|
-
unit_price: convertNumber(data.unit_price)
|
|
10425
|
-
},
|
|
10426
|
-
{
|
|
10427
|
-
onSuccess: () => {
|
|
10428
|
-
setEditing(false);
|
|
10429
|
-
},
|
|
10430
|
-
onError: (e) => {
|
|
10431
|
-
toast.error(e.message);
|
|
10432
|
-
}
|
|
10433
|
-
}
|
|
10434
|
-
);
|
|
10435
|
-
return;
|
|
10436
|
-
}
|
|
10437
|
-
if (data.quantity === 0) {
|
|
10438
|
-
await removeActionItem(actionId, {
|
|
10439
|
-
onSuccess: () => {
|
|
10440
|
-
setEditing(false);
|
|
10441
|
-
},
|
|
10442
|
-
onError: (e) => {
|
|
10443
|
-
toast.error(e.message);
|
|
10444
|
-
}
|
|
10445
|
-
});
|
|
10446
|
-
return;
|
|
10447
|
-
}
|
|
10448
|
-
await updateActionItem(
|
|
10297
|
+
await mutateAsync(
|
|
10449
10298
|
{
|
|
10450
|
-
|
|
10451
|
-
quantity: data.quantity,
|
|
10452
|
-
unit_price: convertNumber(data.unit_price)
|
|
10299
|
+
sales_channel_id: data.sales_channel_id
|
|
10453
10300
|
},
|
|
10454
10301
|
{
|
|
10455
10302
|
onSuccess: () => {
|
|
10456
|
-
|
|
10303
|
+
toast.success("Sales channel updated");
|
|
10304
|
+
handleSuccess();
|
|
10457
10305
|
},
|
|
10458
|
-
onError: (
|
|
10459
|
-
toast.error(
|
|
10306
|
+
onError: (error) => {
|
|
10307
|
+
toast.error(error.message);
|
|
10460
10308
|
}
|
|
10461
10309
|
}
|
|
10462
10310
|
);
|
|
10463
10311
|
});
|
|
10464
|
-
return /* @__PURE__ */ jsx(Form
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
{
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
type: "button",
|
|
10516
|
-
size: "small",
|
|
10517
|
-
onClick: editing ? onSubmit : () => {
|
|
10518
|
-
setEditing(true);
|
|
10519
|
-
},
|
|
10520
|
-
disabled: isPending,
|
|
10521
|
-
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10312
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10313
|
+
KeyboundForm,
|
|
10314
|
+
{
|
|
10315
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10316
|
+
onSubmit,
|
|
10317
|
+
children: [
|
|
10318
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
10319
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10320
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10321
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10322
|
+
] }) })
|
|
10323
|
+
]
|
|
10324
|
+
}
|
|
10325
|
+
) });
|
|
10326
|
+
};
|
|
10327
|
+
const SalesChannelField = ({ control, order }) => {
|
|
10328
|
+
const salesChannels = useComboboxData({
|
|
10329
|
+
queryFn: async (params) => {
|
|
10330
|
+
return await sdk.admin.salesChannel.list(params);
|
|
10331
|
+
},
|
|
10332
|
+
queryKey: ["sales-channels"],
|
|
10333
|
+
getOptions: (data) => {
|
|
10334
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
10335
|
+
label: salesChannel.name,
|
|
10336
|
+
value: salesChannel.id
|
|
10337
|
+
}));
|
|
10338
|
+
},
|
|
10339
|
+
defaultValue: order.sales_channel_id || void 0
|
|
10340
|
+
});
|
|
10341
|
+
return /* @__PURE__ */ jsx(
|
|
10342
|
+
Form$2.Field,
|
|
10343
|
+
{
|
|
10344
|
+
control,
|
|
10345
|
+
name: "sales_channel_id",
|
|
10346
|
+
render: ({ field }) => {
|
|
10347
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10348
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
10349
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10350
|
+
Combobox,
|
|
10351
|
+
{
|
|
10352
|
+
options: salesChannels.options,
|
|
10353
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
10354
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
10355
|
+
searchValue: salesChannels.searchValue,
|
|
10356
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
10357
|
+
placeholder: "Select sales channel",
|
|
10358
|
+
...field
|
|
10359
|
+
}
|
|
10360
|
+
) }),
|
|
10361
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10362
|
+
] });
|
|
10522
10363
|
}
|
|
10523
|
-
|
|
10524
|
-
|
|
10364
|
+
}
|
|
10365
|
+
);
|
|
10525
10366
|
};
|
|
10526
|
-
const
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10367
|
+
const schema$4 = objectType({
|
|
10368
|
+
sales_channel_id: stringType().min(1)
|
|
10369
|
+
});
|
|
10370
|
+
function convertNumber(value) {
|
|
10371
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10372
|
+
}
|
|
10373
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
10374
|
+
const Shipping = () => {
|
|
10375
|
+
var _a;
|
|
10376
|
+
const { id } = useParams();
|
|
10377
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10378
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
10379
|
+
});
|
|
10380
|
+
const {
|
|
10381
|
+
order: preview,
|
|
10382
|
+
isPending: isPreviewPending,
|
|
10383
|
+
isError: isPreviewError,
|
|
10384
|
+
error: previewError
|
|
10385
|
+
} = useOrderPreview(id);
|
|
10386
|
+
useInitiateOrderEdit({ preview });
|
|
10387
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10388
|
+
if (isError) {
|
|
10389
|
+
throw error;
|
|
10390
|
+
}
|
|
10391
|
+
if (isPreviewError) {
|
|
10392
|
+
throw previewError;
|
|
10393
|
+
}
|
|
10394
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
10395
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
10396
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
10397
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10398
|
+
/* @__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: [
|
|
10399
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
10400
|
+
/* @__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." }) })
|
|
10401
|
+
] }) }) }),
|
|
10402
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
10403
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10404
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
10405
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10406
|
+
] }) });
|
|
10536
10407
|
};
|
|
10537
|
-
const
|
|
10538
|
-
|
|
10539
|
-
const ExistingItemsForm = ({ orderId, items }) => {
|
|
10408
|
+
const ShippingForm = ({ preview, order }) => {
|
|
10409
|
+
var _a;
|
|
10540
10410
|
const { setIsOpen } = useStackedModal();
|
|
10541
|
-
const [
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
}, {})
|
|
10546
|
-
);
|
|
10547
|
-
useEffect(() => {
|
|
10548
|
-
setRowSelection(
|
|
10549
|
-
items.reduce((acc, item) => {
|
|
10550
|
-
if (item.variant_id) {
|
|
10551
|
-
acc[item.variant_id] = true;
|
|
10552
|
-
}
|
|
10553
|
-
return acc;
|
|
10554
|
-
}, {})
|
|
10555
|
-
);
|
|
10556
|
-
}, [items]);
|
|
10557
|
-
const { q, order, offset } = useQueryParams(
|
|
10558
|
-
["q", "order", "offset"],
|
|
10559
|
-
VARIANT_PREFIX
|
|
10560
|
-
);
|
|
10561
|
-
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10411
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10412
|
+
const [data, setData] = useState(null);
|
|
10413
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
10414
|
+
const { shipping_options } = useShippingOptions(
|
|
10562
10415
|
{
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
offset: offset ? parseInt(offset) : void 0,
|
|
10566
|
-
limit: LIMIT
|
|
10416
|
+
id: appliedShippingOptionIds,
|
|
10417
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
10567
10418
|
},
|
|
10568
10419
|
{
|
|
10569
|
-
|
|
10420
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
10570
10421
|
}
|
|
10571
10422
|
);
|
|
10572
|
-
const
|
|
10573
|
-
|
|
10423
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
10424
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
10425
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
10426
|
+
profiles.set(profile.id, profile);
|
|
10427
|
+
});
|
|
10428
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
10429
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
10430
|
+
});
|
|
10431
|
+
return Array.from(profiles.values());
|
|
10432
|
+
}, [order.items, shipping_options]);
|
|
10433
|
+
const { handleSuccess } = useRouteModal();
|
|
10434
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10435
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10436
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
10437
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
10574
10438
|
const onSubmit = async () => {
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
items: ids.map((id) => ({
|
|
10581
|
-
variant_id: id,
|
|
10582
|
-
quantity: 1
|
|
10583
|
-
}))
|
|
10439
|
+
setIsSubmitting(true);
|
|
10440
|
+
let requestSucceeded = false;
|
|
10441
|
+
await requestOrderEdit(void 0, {
|
|
10442
|
+
onError: (e) => {
|
|
10443
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
10584
10444
|
},
|
|
10585
|
-
{
|
|
10586
|
-
|
|
10587
|
-
setRowSelection({});
|
|
10588
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10589
|
-
},
|
|
10590
|
-
onError: (e) => {
|
|
10591
|
-
toast.error(e.message);
|
|
10592
|
-
}
|
|
10445
|
+
onSuccess: () => {
|
|
10446
|
+
requestSucceeded = true;
|
|
10593
10447
|
}
|
|
10594
|
-
);
|
|
10448
|
+
});
|
|
10449
|
+
if (!requestSucceeded) {
|
|
10450
|
+
setIsSubmitting(false);
|
|
10451
|
+
return;
|
|
10452
|
+
}
|
|
10453
|
+
await confirmOrderEdit(void 0, {
|
|
10454
|
+
onError: (e) => {
|
|
10455
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10456
|
+
},
|
|
10457
|
+
onSuccess: () => {
|
|
10458
|
+
handleSuccess();
|
|
10459
|
+
},
|
|
10460
|
+
onSettled: () => {
|
|
10461
|
+
setIsSubmitting(false);
|
|
10462
|
+
}
|
|
10463
|
+
});
|
|
10595
10464
|
};
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
{
|
|
10602
|
-
onOpenAutoFocus: (e) => {
|
|
10603
|
-
e.preventDefault();
|
|
10604
|
-
const searchInput = document.querySelector(
|
|
10605
|
-
"[data-modal-id='modal-search-input']"
|
|
10606
|
-
);
|
|
10607
|
-
if (searchInput) {
|
|
10608
|
-
searchInput.focus();
|
|
10465
|
+
const onKeydown = useCallback(
|
|
10466
|
+
(e) => {
|
|
10467
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10468
|
+
if (data || isSubmitting) {
|
|
10469
|
+
return;
|
|
10609
10470
|
}
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
10615
|
-
] }),
|
|
10616
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
10617
|
-
DataTable,
|
|
10618
|
-
{
|
|
10619
|
-
data: variants,
|
|
10620
|
-
columns,
|
|
10621
|
-
isLoading: isPending,
|
|
10622
|
-
getRowId: (row) => row.id,
|
|
10623
|
-
rowCount: count,
|
|
10624
|
-
prefix: VARIANT_PREFIX,
|
|
10625
|
-
layout: "fill",
|
|
10626
|
-
rowSelection: {
|
|
10627
|
-
state: rowSelection,
|
|
10628
|
-
onRowSelectionChange: setRowSelection,
|
|
10629
|
-
enableRowSelection: (row) => {
|
|
10630
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
10631
|
-
}
|
|
10632
|
-
},
|
|
10633
|
-
autoFocusSearch: true
|
|
10634
|
-
}
|
|
10635
|
-
) }),
|
|
10636
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10637
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10638
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
10639
|
-
] }) })
|
|
10640
|
-
]
|
|
10641
|
-
}
|
|
10471
|
+
onSubmit();
|
|
10472
|
+
}
|
|
10473
|
+
},
|
|
10474
|
+
[data, isSubmitting, onSubmit]
|
|
10642
10475
|
);
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10476
|
+
useEffect(() => {
|
|
10477
|
+
document.addEventListener("keydown", onKeydown);
|
|
10478
|
+
return () => {
|
|
10479
|
+
document.removeEventListener("keydown", onKeydown);
|
|
10480
|
+
};
|
|
10481
|
+
}, [onKeydown]);
|
|
10482
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10483
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10484
|
+
/* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10485
|
+
/* @__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: [
|
|
10486
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10487
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
10488
|
+
/* @__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." }) })
|
|
10489
|
+
] }),
|
|
10490
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10491
|
+
/* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
|
|
10492
|
+
/* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
|
|
10654
10493
|
/* @__PURE__ */ jsx(
|
|
10655
|
-
|
|
10494
|
+
Text,
|
|
10656
10495
|
{
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
|
|
10660
|
-
|
|
10661
|
-
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10662
|
-
] });
|
|
10663
|
-
},
|
|
10664
|
-
enableSorting: true
|
|
10665
|
-
}),
|
|
10666
|
-
columnHelper.accessor("title", {
|
|
10667
|
-
header: "Variant",
|
|
10668
|
-
enableSorting: true
|
|
10669
|
-
}),
|
|
10670
|
-
columnHelper.accessor("sku", {
|
|
10671
|
-
header: "SKU",
|
|
10672
|
-
cell: ({ getValue }) => {
|
|
10673
|
-
return getValue() ?? "-";
|
|
10674
|
-
},
|
|
10675
|
-
enableSorting: true
|
|
10676
|
-
}),
|
|
10677
|
-
columnHelper.accessor("updated_at", {
|
|
10678
|
-
header: "Updated",
|
|
10679
|
-
cell: ({ getValue }) => {
|
|
10680
|
-
return /* @__PURE__ */ jsx(
|
|
10681
|
-
Tooltip,
|
|
10682
|
-
{
|
|
10683
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10684
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10685
|
-
}
|
|
10686
|
-
);
|
|
10687
|
-
},
|
|
10688
|
-
enableSorting: true,
|
|
10689
|
-
sortAscLabel: "Oldest first",
|
|
10690
|
-
sortDescLabel: "Newest first"
|
|
10691
|
-
}),
|
|
10692
|
-
columnHelper.accessor("created_at", {
|
|
10693
|
-
header: "Created",
|
|
10694
|
-
cell: ({ getValue }) => {
|
|
10695
|
-
return /* @__PURE__ */ jsx(
|
|
10696
|
-
Tooltip,
|
|
10697
|
-
{
|
|
10698
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10699
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10700
|
-
}
|
|
10701
|
-
);
|
|
10702
|
-
},
|
|
10703
|
-
enableSorting: true,
|
|
10704
|
-
sortAscLabel: "Oldest first",
|
|
10705
|
-
sortDescLabel: "Newest first"
|
|
10706
|
-
})
|
|
10707
|
-
];
|
|
10708
|
-
}, []);
|
|
10709
|
-
};
|
|
10710
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10711
|
-
const { setIsOpen } = useStackedModal();
|
|
10712
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10713
|
-
const form = useForm({
|
|
10714
|
-
defaultValues: {
|
|
10715
|
-
title: "",
|
|
10716
|
-
quantity: 1,
|
|
10717
|
-
unit_price: ""
|
|
10718
|
-
},
|
|
10719
|
-
resolver: zodResolver(customItemSchema)
|
|
10720
|
-
});
|
|
10721
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10722
|
-
await addItems(
|
|
10723
|
-
{
|
|
10724
|
-
items: [
|
|
10725
|
-
{
|
|
10726
|
-
title: data.title,
|
|
10727
|
-
quantity: data.quantity,
|
|
10728
|
-
unit_price: convertNumber(data.unit_price)
|
|
10729
|
-
}
|
|
10730
|
-
]
|
|
10731
|
-
},
|
|
10732
|
-
{
|
|
10733
|
-
onSuccess: () => {
|
|
10734
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10735
|
-
},
|
|
10736
|
-
onError: (e) => {
|
|
10737
|
-
toast.error(e.message);
|
|
10738
|
-
}
|
|
10739
|
-
}
|
|
10740
|
-
);
|
|
10741
|
-
});
|
|
10742
|
-
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
10743
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
10744
|
-
/* @__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-2 py-16", children: [
|
|
10745
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10746
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10747
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
10748
|
-
] }),
|
|
10749
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10750
|
-
/* @__PURE__ */ jsx(
|
|
10751
|
-
Form$2.Field,
|
|
10752
|
-
{
|
|
10753
|
-
control: form.control,
|
|
10754
|
-
name: "title",
|
|
10755
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10756
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10757
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
10758
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10759
|
-
] }),
|
|
10760
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10761
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10762
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10763
|
-
] })
|
|
10764
|
-
] }) })
|
|
10765
|
-
}
|
|
10766
|
-
),
|
|
10767
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10768
|
-
/* @__PURE__ */ jsx(
|
|
10769
|
-
Form$2.Field,
|
|
10770
|
-
{
|
|
10771
|
-
control: form.control,
|
|
10772
|
-
name: "unit_price",
|
|
10773
|
-
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10774
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10775
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
10776
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10777
|
-
] }),
|
|
10778
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10779
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10780
|
-
CurrencyInput,
|
|
10781
|
-
{
|
|
10782
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10783
|
-
code: currencyCode,
|
|
10784
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10785
|
-
...field
|
|
10786
|
-
}
|
|
10787
|
-
) }),
|
|
10788
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10789
|
-
] })
|
|
10790
|
-
] }) })
|
|
10791
|
-
}
|
|
10792
|
-
),
|
|
10793
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10794
|
-
/* @__PURE__ */ jsx(
|
|
10795
|
-
Form$2.Field,
|
|
10796
|
-
{
|
|
10797
|
-
control: form.control,
|
|
10798
|
-
name: "quantity",
|
|
10799
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10800
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10801
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10802
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10803
|
-
] }),
|
|
10804
|
-
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
10805
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10806
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10807
|
-
] })
|
|
10808
|
-
] }) })
|
|
10809
|
-
}
|
|
10810
|
-
)
|
|
10811
|
-
] }) }) }),
|
|
10812
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10813
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10814
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10815
|
-
] }) })
|
|
10816
|
-
] }) }) });
|
|
10817
|
-
};
|
|
10818
|
-
const customItemSchema = objectType({
|
|
10819
|
-
title: stringType().min(1),
|
|
10820
|
-
quantity: numberType(),
|
|
10821
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10822
|
-
});
|
|
10823
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10824
|
-
const promotionsQueryKeys = {
|
|
10825
|
-
list: (query2) => [
|
|
10826
|
-
PROMOTION_QUERY_KEY,
|
|
10827
|
-
query2 ? query2 : void 0
|
|
10828
|
-
],
|
|
10829
|
-
detail: (id, query2) => [
|
|
10830
|
-
PROMOTION_QUERY_KEY,
|
|
10831
|
-
id,
|
|
10832
|
-
query2 ? query2 : void 0
|
|
10833
|
-
]
|
|
10834
|
-
};
|
|
10835
|
-
const usePromotions = (query2, options) => {
|
|
10836
|
-
const { data, ...rest } = useQuery({
|
|
10837
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10838
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10839
|
-
...options
|
|
10840
|
-
});
|
|
10841
|
-
return { ...data, ...rest };
|
|
10842
|
-
};
|
|
10843
|
-
const Promotions = () => {
|
|
10844
|
-
const { id } = useParams();
|
|
10845
|
-
const {
|
|
10846
|
-
order: preview,
|
|
10847
|
-
isError: isPreviewError,
|
|
10848
|
-
error: previewError
|
|
10849
|
-
} = useOrderPreview(id, void 0);
|
|
10850
|
-
useInitiateOrderEdit({ preview });
|
|
10851
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10852
|
-
if (isPreviewError) {
|
|
10853
|
-
throw previewError;
|
|
10854
|
-
}
|
|
10855
|
-
const isReady = !!preview;
|
|
10856
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10857
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10858
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10859
|
-
] });
|
|
10860
|
-
};
|
|
10861
|
-
const PromotionForm = ({ preview }) => {
|
|
10862
|
-
const { items, shipping_methods } = preview;
|
|
10863
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10864
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
10865
|
-
const { handleSuccess } = useRouteModal();
|
|
10866
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10867
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10868
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10869
|
-
{
|
|
10870
|
-
id: promoIds
|
|
10871
|
-
},
|
|
10872
|
-
{
|
|
10873
|
-
enabled: !!promoIds.length
|
|
10874
|
-
}
|
|
10875
|
-
);
|
|
10876
|
-
const comboboxData = useComboboxData({
|
|
10877
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10878
|
-
queryFn: async (params) => {
|
|
10879
|
-
return await sdk.admin.promotion.list({
|
|
10880
|
-
...params,
|
|
10881
|
-
id: {
|
|
10882
|
-
$nin: promoIds
|
|
10883
|
-
}
|
|
10884
|
-
});
|
|
10885
|
-
},
|
|
10886
|
-
getOptions: (data) => {
|
|
10887
|
-
return data.promotions.map((promotion) => ({
|
|
10888
|
-
label: promotion.code,
|
|
10889
|
-
value: promotion.code
|
|
10890
|
-
}));
|
|
10891
|
-
}
|
|
10892
|
-
});
|
|
10893
|
-
const add = async (value) => {
|
|
10894
|
-
if (!value) {
|
|
10895
|
-
return;
|
|
10896
|
-
}
|
|
10897
|
-
addPromotions(
|
|
10898
|
-
{
|
|
10899
|
-
promo_codes: [value]
|
|
10900
|
-
},
|
|
10901
|
-
{
|
|
10902
|
-
onError: (e) => {
|
|
10903
|
-
toast.error(e.message);
|
|
10904
|
-
comboboxData.onSearchValueChange("");
|
|
10905
|
-
setComboboxValue("");
|
|
10906
|
-
},
|
|
10907
|
-
onSuccess: () => {
|
|
10908
|
-
comboboxData.onSearchValueChange("");
|
|
10909
|
-
setComboboxValue("");
|
|
10910
|
-
}
|
|
10911
|
-
}
|
|
10912
|
-
);
|
|
10913
|
-
};
|
|
10914
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10915
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10916
|
-
const onSubmit = async () => {
|
|
10917
|
-
setIsSubmitting(true);
|
|
10918
|
-
let requestSucceeded = false;
|
|
10919
|
-
await requestOrderEdit(void 0, {
|
|
10920
|
-
onError: (e) => {
|
|
10921
|
-
toast.error(e.message);
|
|
10922
|
-
},
|
|
10923
|
-
onSuccess: () => {
|
|
10924
|
-
requestSucceeded = true;
|
|
10925
|
-
}
|
|
10926
|
-
});
|
|
10927
|
-
if (!requestSucceeded) {
|
|
10928
|
-
setIsSubmitting(false);
|
|
10929
|
-
return;
|
|
10930
|
-
}
|
|
10931
|
-
await confirmOrderEdit(void 0, {
|
|
10932
|
-
onError: (e) => {
|
|
10933
|
-
toast.error(e.message);
|
|
10934
|
-
},
|
|
10935
|
-
onSuccess: () => {
|
|
10936
|
-
handleSuccess();
|
|
10937
|
-
},
|
|
10938
|
-
onSettled: () => {
|
|
10939
|
-
setIsSubmitting(false);
|
|
10940
|
-
}
|
|
10941
|
-
});
|
|
10942
|
-
};
|
|
10943
|
-
if (isError) {
|
|
10944
|
-
throw error;
|
|
10945
|
-
}
|
|
10946
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10947
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10948
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10949
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10950
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10951
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10952
|
-
] }),
|
|
10953
|
-
/* @__PURE__ */ jsx(
|
|
10954
|
-
Combobox,
|
|
10955
|
-
{
|
|
10956
|
-
id: "promotion-combobox",
|
|
10957
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10958
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10959
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10960
|
-
options: comboboxData.options,
|
|
10961
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10962
|
-
searchValue: comboboxData.searchValue,
|
|
10963
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10964
|
-
onChange: add,
|
|
10965
|
-
value: comboboxValue
|
|
10966
|
-
}
|
|
10967
|
-
)
|
|
10968
|
-
] }),
|
|
10969
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10970
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10971
|
-
PromotionItem,
|
|
10972
|
-
{
|
|
10973
|
-
promotion,
|
|
10974
|
-
orderId: preview.id,
|
|
10975
|
-
isLoading: isPending
|
|
10976
|
-
},
|
|
10977
|
-
promotion.id
|
|
10978
|
-
)) })
|
|
10979
|
-
] }) }),
|
|
10980
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10981
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10982
|
-
/* @__PURE__ */ jsx(
|
|
10983
|
-
Button,
|
|
10984
|
-
{
|
|
10985
|
-
size: "small",
|
|
10986
|
-
type: "submit",
|
|
10987
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10988
|
-
children: "Save"
|
|
10989
|
-
}
|
|
10990
|
-
)
|
|
10991
|
-
] }) })
|
|
10992
|
-
] });
|
|
10993
|
-
};
|
|
10994
|
-
const PromotionItem = ({
|
|
10995
|
-
promotion,
|
|
10996
|
-
orderId,
|
|
10997
|
-
isLoading
|
|
10998
|
-
}) => {
|
|
10999
|
-
var _a;
|
|
11000
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11001
|
-
const onRemove = async () => {
|
|
11002
|
-
removePromotions(
|
|
11003
|
-
{
|
|
11004
|
-
promo_codes: [promotion.code]
|
|
11005
|
-
},
|
|
11006
|
-
{
|
|
11007
|
-
onError: (e) => {
|
|
11008
|
-
toast.error(e.message);
|
|
11009
|
-
}
|
|
11010
|
-
}
|
|
11011
|
-
);
|
|
11012
|
-
};
|
|
11013
|
-
const displayValue = getDisplayValue(promotion);
|
|
11014
|
-
return /* @__PURE__ */ jsxs(
|
|
11015
|
-
"div",
|
|
11016
|
-
{
|
|
11017
|
-
className: clx(
|
|
11018
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11019
|
-
{
|
|
11020
|
-
"animate-pulse": isLoading
|
|
11021
|
-
}
|
|
11022
|
-
),
|
|
11023
|
-
children: [
|
|
11024
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11025
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11026
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11027
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11028
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11029
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11030
|
-
] }),
|
|
11031
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11032
|
-
] })
|
|
11033
|
-
] }),
|
|
11034
|
-
/* @__PURE__ */ jsx(
|
|
11035
|
-
IconButton,
|
|
11036
|
-
{
|
|
11037
|
-
size: "small",
|
|
11038
|
-
type: "button",
|
|
11039
|
-
variant: "transparent",
|
|
11040
|
-
onClick: onRemove,
|
|
11041
|
-
isLoading: isPending || isLoading,
|
|
11042
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11043
|
-
}
|
|
11044
|
-
)
|
|
11045
|
-
]
|
|
11046
|
-
},
|
|
11047
|
-
promotion.id
|
|
11048
|
-
);
|
|
11049
|
-
};
|
|
11050
|
-
function getDisplayValue(promotion) {
|
|
11051
|
-
var _a, _b, _c, _d;
|
|
11052
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11053
|
-
if (!value) {
|
|
11054
|
-
return null;
|
|
11055
|
-
}
|
|
11056
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11057
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11058
|
-
if (!currency) {
|
|
11059
|
-
return null;
|
|
11060
|
-
}
|
|
11061
|
-
return getLocaleAmount(value, currency);
|
|
11062
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11063
|
-
return formatPercentage(value);
|
|
11064
|
-
}
|
|
11065
|
-
return null;
|
|
11066
|
-
}
|
|
11067
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11068
|
-
style: "percent",
|
|
11069
|
-
minimumFractionDigits: 2
|
|
11070
|
-
});
|
|
11071
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11072
|
-
let val = value || 0;
|
|
11073
|
-
if (!isPercentageValue) {
|
|
11074
|
-
val = val / 100;
|
|
11075
|
-
}
|
|
11076
|
-
return formatter.format(val);
|
|
11077
|
-
};
|
|
11078
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11079
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11080
|
-
for (const item of items) {
|
|
11081
|
-
if (item.adjustments) {
|
|
11082
|
-
for (const adjustment of item.adjustments) {
|
|
11083
|
-
if (adjustment.promotion_id) {
|
|
11084
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11085
|
-
}
|
|
11086
|
-
}
|
|
11087
|
-
}
|
|
11088
|
-
}
|
|
11089
|
-
for (const shippingMethod of shippingMethods) {
|
|
11090
|
-
if (shippingMethod.adjustments) {
|
|
11091
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11092
|
-
if (adjustment.promotion_id) {
|
|
11093
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11094
|
-
}
|
|
11095
|
-
}
|
|
11096
|
-
}
|
|
11097
|
-
}
|
|
11098
|
-
return Array.from(promotionIds);
|
|
11099
|
-
}
|
|
11100
|
-
const InlineTip = forwardRef(
|
|
11101
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11102
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11103
|
-
return /* @__PURE__ */ jsxs(
|
|
11104
|
-
"div",
|
|
11105
|
-
{
|
|
11106
|
-
ref,
|
|
11107
|
-
className: clx(
|
|
11108
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11109
|
-
className
|
|
11110
|
-
),
|
|
11111
|
-
...props,
|
|
11112
|
-
children: [
|
|
11113
|
-
/* @__PURE__ */ jsx(
|
|
11114
|
-
"div",
|
|
11115
|
-
{
|
|
11116
|
-
role: "presentation",
|
|
11117
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11118
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11119
|
-
})
|
|
11120
|
-
}
|
|
11121
|
-
),
|
|
11122
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11123
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11124
|
-
labelValue,
|
|
11125
|
-
":"
|
|
11126
|
-
] }),
|
|
11127
|
-
" ",
|
|
11128
|
-
children
|
|
11129
|
-
] })
|
|
11130
|
-
]
|
|
11131
|
-
}
|
|
11132
|
-
);
|
|
11133
|
-
}
|
|
11134
|
-
);
|
|
11135
|
-
InlineTip.displayName = "InlineTip";
|
|
11136
|
-
const MetadataFieldSchema = objectType({
|
|
11137
|
-
key: stringType(),
|
|
11138
|
-
disabled: booleanType().optional(),
|
|
11139
|
-
value: anyType()
|
|
11140
|
-
});
|
|
11141
|
-
const MetadataSchema = objectType({
|
|
11142
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11143
|
-
});
|
|
11144
|
-
const Metadata = () => {
|
|
11145
|
-
const { id } = useParams();
|
|
11146
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11147
|
-
fields: "metadata"
|
|
11148
|
-
});
|
|
11149
|
-
if (isError) {
|
|
11150
|
-
throw error;
|
|
11151
|
-
}
|
|
11152
|
-
const isReady = !isPending && !!order;
|
|
11153
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11154
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11155
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
11156
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11157
|
-
] }),
|
|
11158
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11159
|
-
] });
|
|
11160
|
-
};
|
|
11161
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11162
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11163
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
11164
|
-
const { handleSuccess } = useRouteModal();
|
|
11165
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11166
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11167
|
-
const form = useForm({
|
|
11168
|
-
defaultValues: {
|
|
11169
|
-
metadata: getDefaultValues(metadata)
|
|
11170
|
-
},
|
|
11171
|
-
resolver: zodResolver(MetadataSchema)
|
|
11172
|
-
});
|
|
11173
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11174
|
-
const parsedData = parseValues(data);
|
|
11175
|
-
await mutateAsync(
|
|
11176
|
-
{
|
|
11177
|
-
metadata: parsedData
|
|
11178
|
-
},
|
|
11179
|
-
{
|
|
11180
|
-
onSuccess: () => {
|
|
11181
|
-
toast.success("Metadata updated");
|
|
11182
|
-
handleSuccess();
|
|
11183
|
-
},
|
|
11184
|
-
onError: (error) => {
|
|
11185
|
-
toast.error(error.message);
|
|
11186
|
-
}
|
|
11187
|
-
}
|
|
11188
|
-
);
|
|
11189
|
-
});
|
|
11190
|
-
const { fields, insert, remove } = useFieldArray({
|
|
11191
|
-
control: form.control,
|
|
11192
|
-
name: "metadata"
|
|
11193
|
-
});
|
|
11194
|
-
function deleteRow(index) {
|
|
11195
|
-
remove(index);
|
|
11196
|
-
if (fields.length === 1) {
|
|
11197
|
-
insert(0, {
|
|
11198
|
-
key: "",
|
|
11199
|
-
value: "",
|
|
11200
|
-
disabled: false
|
|
11201
|
-
});
|
|
11202
|
-
}
|
|
11203
|
-
}
|
|
11204
|
-
function insertRow(index, position) {
|
|
11205
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11206
|
-
key: "",
|
|
11207
|
-
value: "",
|
|
11208
|
-
disabled: false
|
|
11209
|
-
});
|
|
11210
|
-
}
|
|
11211
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11212
|
-
KeyboundForm,
|
|
11213
|
-
{
|
|
11214
|
-
onSubmit: handleSubmit,
|
|
11215
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11216
|
-
children: [
|
|
11217
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11218
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11219
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
11220
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
11221
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
11222
|
-
] }),
|
|
11223
|
-
fields.map((field, index) => {
|
|
11224
|
-
const isDisabled = field.disabled || false;
|
|
11225
|
-
let placeholder = "-";
|
|
11226
|
-
if (typeof field.value === "object") {
|
|
11227
|
-
placeholder = "{ ... }";
|
|
11228
|
-
}
|
|
11229
|
-
if (Array.isArray(field.value)) {
|
|
11230
|
-
placeholder = "[ ... ]";
|
|
11231
|
-
}
|
|
11232
|
-
return /* @__PURE__ */ jsx(
|
|
11233
|
-
ConditionalTooltip,
|
|
11234
|
-
{
|
|
11235
|
-
showTooltip: isDisabled,
|
|
11236
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
11237
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
11238
|
-
/* @__PURE__ */ jsxs(
|
|
11239
|
-
"div",
|
|
11240
|
-
{
|
|
11241
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
11242
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11243
|
-
}),
|
|
11244
|
-
children: [
|
|
11245
|
-
/* @__PURE__ */ jsx(
|
|
11246
|
-
Form$2.Field,
|
|
11247
|
-
{
|
|
11248
|
-
control: form.control,
|
|
11249
|
-
name: `metadata.${index}.key`,
|
|
11250
|
-
render: ({ field: field2 }) => {
|
|
11251
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11252
|
-
GridInput,
|
|
11253
|
-
{
|
|
11254
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11255
|
-
...field2,
|
|
11256
|
-
disabled: isDisabled,
|
|
11257
|
-
placeholder: "Key"
|
|
11258
|
-
}
|
|
11259
|
-
) }) });
|
|
11260
|
-
}
|
|
11261
|
-
}
|
|
11262
|
-
),
|
|
11263
|
-
/* @__PURE__ */ jsx(
|
|
11264
|
-
Form$2.Field,
|
|
11265
|
-
{
|
|
11266
|
-
control: form.control,
|
|
11267
|
-
name: `metadata.${index}.value`,
|
|
11268
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
11269
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11270
|
-
GridInput,
|
|
11271
|
-
{
|
|
11272
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11273
|
-
...field2,
|
|
11274
|
-
value: isDisabled ? placeholder : value,
|
|
11275
|
-
disabled: isDisabled,
|
|
11276
|
-
placeholder: "Value"
|
|
11277
|
-
}
|
|
11278
|
-
) }) });
|
|
11279
|
-
}
|
|
11280
|
-
}
|
|
11281
|
-
)
|
|
11282
|
-
]
|
|
11283
|
-
}
|
|
11284
|
-
),
|
|
11285
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11286
|
-
/* @__PURE__ */ jsx(
|
|
11287
|
-
DropdownMenu.Trigger,
|
|
11288
|
-
{
|
|
11289
|
-
className: clx(
|
|
11290
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11291
|
-
{
|
|
11292
|
-
hidden: isDisabled
|
|
11293
|
-
}
|
|
11294
|
-
),
|
|
11295
|
-
disabled: isDisabled,
|
|
11296
|
-
asChild: true,
|
|
11297
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11298
|
-
}
|
|
11299
|
-
),
|
|
11300
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11301
|
-
/* @__PURE__ */ jsxs(
|
|
11302
|
-
DropdownMenu.Item,
|
|
11303
|
-
{
|
|
11304
|
-
className: "gap-x-2",
|
|
11305
|
-
onClick: () => insertRow(index, "above"),
|
|
11306
|
-
children: [
|
|
11307
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11308
|
-
"Insert row above"
|
|
11309
|
-
]
|
|
11310
|
-
}
|
|
11311
|
-
),
|
|
11312
|
-
/* @__PURE__ */ jsxs(
|
|
11313
|
-
DropdownMenu.Item,
|
|
11314
|
-
{
|
|
11315
|
-
className: "gap-x-2",
|
|
11316
|
-
onClick: () => insertRow(index, "below"),
|
|
11317
|
-
children: [
|
|
11318
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11319
|
-
"Insert row below"
|
|
11320
|
-
]
|
|
11321
|
-
}
|
|
11322
|
-
),
|
|
11323
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11324
|
-
/* @__PURE__ */ jsxs(
|
|
11325
|
-
DropdownMenu.Item,
|
|
11326
|
-
{
|
|
11327
|
-
className: "gap-x-2",
|
|
11328
|
-
onClick: () => deleteRow(index),
|
|
11329
|
-
children: [
|
|
11330
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11331
|
-
"Delete row"
|
|
11332
|
-
]
|
|
11333
|
-
}
|
|
11334
|
-
)
|
|
11335
|
-
] })
|
|
11336
|
-
] })
|
|
11337
|
-
] })
|
|
11338
|
-
},
|
|
11339
|
-
field.id
|
|
11340
|
-
);
|
|
11341
|
-
})
|
|
11342
|
-
] }),
|
|
11343
|
-
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11344
|
-
] }),
|
|
11345
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11346
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11347
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11348
|
-
] }) })
|
|
11349
|
-
]
|
|
11350
|
-
}
|
|
11351
|
-
) });
|
|
11352
|
-
};
|
|
11353
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11354
|
-
return /* @__PURE__ */ jsx(
|
|
11355
|
-
"input",
|
|
11356
|
-
{
|
|
11357
|
-
ref,
|
|
11358
|
-
...props,
|
|
11359
|
-
autoComplete: "off",
|
|
11360
|
-
className: clx(
|
|
11361
|
-
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
11362
|
-
className
|
|
11363
|
-
)
|
|
11364
|
-
}
|
|
11365
|
-
);
|
|
11366
|
-
});
|
|
11367
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11368
|
-
const PlaceholderInner = () => {
|
|
11369
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11370
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11371
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11372
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11373
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11374
|
-
] }) })
|
|
11375
|
-
] });
|
|
11376
|
-
};
|
|
11377
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11378
|
-
function getDefaultValues(metadata) {
|
|
11379
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11380
|
-
return [
|
|
11381
|
-
{
|
|
11382
|
-
key: "",
|
|
11383
|
-
value: "",
|
|
11384
|
-
disabled: false
|
|
11385
|
-
}
|
|
11386
|
-
];
|
|
11387
|
-
}
|
|
11388
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11389
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11390
|
-
return {
|
|
11391
|
-
key,
|
|
11392
|
-
value,
|
|
11393
|
-
disabled: true
|
|
11394
|
-
};
|
|
11395
|
-
}
|
|
11396
|
-
let stringValue = value;
|
|
11397
|
-
if (typeof value !== "string") {
|
|
11398
|
-
stringValue = JSON.stringify(value);
|
|
11399
|
-
}
|
|
11400
|
-
return {
|
|
11401
|
-
key,
|
|
11402
|
-
value: stringValue,
|
|
11403
|
-
original_key: key
|
|
11404
|
-
};
|
|
11405
|
-
});
|
|
11406
|
-
}
|
|
11407
|
-
function parseValues(values) {
|
|
11408
|
-
const metadata = values.metadata;
|
|
11409
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11410
|
-
if (isEmpty) {
|
|
11411
|
-
return null;
|
|
11412
|
-
}
|
|
11413
|
-
const update = {};
|
|
11414
|
-
metadata.forEach((field) => {
|
|
11415
|
-
let key = field.key;
|
|
11416
|
-
let value = field.value;
|
|
11417
|
-
const disabled = field.disabled;
|
|
11418
|
-
if (!key || !value) {
|
|
11419
|
-
return;
|
|
11420
|
-
}
|
|
11421
|
-
if (disabled) {
|
|
11422
|
-
update[key] = value;
|
|
11423
|
-
return;
|
|
11424
|
-
}
|
|
11425
|
-
key = key.trim();
|
|
11426
|
-
value = value.trim();
|
|
11427
|
-
if (value === "true") {
|
|
11428
|
-
update[key] = true;
|
|
11429
|
-
} else if (value === "false") {
|
|
11430
|
-
update[key] = false;
|
|
11431
|
-
} else {
|
|
11432
|
-
const parsedNumber = parseFloat(value);
|
|
11433
|
-
if (!isNaN(parsedNumber)) {
|
|
11434
|
-
update[key] = parsedNumber;
|
|
11435
|
-
} else {
|
|
11436
|
-
update[key] = value;
|
|
11437
|
-
}
|
|
11438
|
-
}
|
|
11439
|
-
});
|
|
11440
|
-
return update;
|
|
11441
|
-
}
|
|
11442
|
-
function getHasUneditableRows(metadata) {
|
|
11443
|
-
if (!metadata) {
|
|
11444
|
-
return false;
|
|
11445
|
-
}
|
|
11446
|
-
return Object.values(metadata).some(
|
|
11447
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11448
|
-
);
|
|
11449
|
-
}
|
|
11450
|
-
const SalesChannel = () => {
|
|
11451
|
-
const { id } = useParams();
|
|
11452
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11453
|
-
id,
|
|
11454
|
-
{
|
|
11455
|
-
fields: "+sales_channel_id"
|
|
11456
|
-
},
|
|
11457
|
-
{
|
|
11458
|
-
enabled: !!id
|
|
11459
|
-
}
|
|
11460
|
-
);
|
|
11461
|
-
if (isError) {
|
|
11462
|
-
throw error;
|
|
11463
|
-
}
|
|
11464
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11465
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11466
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11467
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11468
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11469
|
-
] }),
|
|
11470
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11471
|
-
] });
|
|
11472
|
-
};
|
|
11473
|
-
const SalesChannelForm = ({ order }) => {
|
|
11474
|
-
const form = useForm({
|
|
11475
|
-
defaultValues: {
|
|
11476
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11477
|
-
},
|
|
11478
|
-
resolver: zodResolver(schema$2)
|
|
11479
|
-
});
|
|
11480
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11481
|
-
const { handleSuccess } = useRouteModal();
|
|
11482
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11483
|
-
await mutateAsync(
|
|
11484
|
-
{
|
|
11485
|
-
sales_channel_id: data.sales_channel_id
|
|
11486
|
-
},
|
|
11487
|
-
{
|
|
11488
|
-
onSuccess: () => {
|
|
11489
|
-
toast.success("Sales channel updated");
|
|
11490
|
-
handleSuccess();
|
|
11491
|
-
},
|
|
11492
|
-
onError: (error) => {
|
|
11493
|
-
toast.error(error.message);
|
|
11494
|
-
}
|
|
11495
|
-
}
|
|
11496
|
-
);
|
|
11497
|
-
});
|
|
11498
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11499
|
-
KeyboundForm,
|
|
11500
|
-
{
|
|
11501
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11502
|
-
onSubmit,
|
|
11503
|
-
children: [
|
|
11504
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11505
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11506
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11507
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11508
|
-
] }) })
|
|
11509
|
-
]
|
|
11510
|
-
}
|
|
11511
|
-
) });
|
|
11512
|
-
};
|
|
11513
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11514
|
-
const salesChannels = useComboboxData({
|
|
11515
|
-
queryFn: async (params) => {
|
|
11516
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11517
|
-
},
|
|
11518
|
-
queryKey: ["sales-channels"],
|
|
11519
|
-
getOptions: (data) => {
|
|
11520
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11521
|
-
label: salesChannel.name,
|
|
11522
|
-
value: salesChannel.id
|
|
11523
|
-
}));
|
|
11524
|
-
},
|
|
11525
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11526
|
-
});
|
|
11527
|
-
return /* @__PURE__ */ jsx(
|
|
11528
|
-
Form$2.Field,
|
|
11529
|
-
{
|
|
11530
|
-
control,
|
|
11531
|
-
name: "sales_channel_id",
|
|
11532
|
-
render: ({ field }) => {
|
|
11533
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11534
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11535
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11536
|
-
Combobox,
|
|
11537
|
-
{
|
|
11538
|
-
options: salesChannels.options,
|
|
11539
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11540
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11541
|
-
searchValue: salesChannels.searchValue,
|
|
11542
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11543
|
-
placeholder: "Select sales channel",
|
|
11544
|
-
...field
|
|
11545
|
-
}
|
|
11546
|
-
) }),
|
|
11547
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11548
|
-
] });
|
|
11549
|
-
}
|
|
11550
|
-
}
|
|
11551
|
-
);
|
|
11552
|
-
};
|
|
11553
|
-
const schema$2 = objectType({
|
|
11554
|
-
sales_channel_id: stringType().min(1)
|
|
11555
|
-
});
|
|
11556
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11557
|
-
const Shipping = () => {
|
|
11558
|
-
var _a;
|
|
11559
|
-
const { id } = useParams();
|
|
11560
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11561
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11562
|
-
});
|
|
11563
|
-
const {
|
|
11564
|
-
order: preview,
|
|
11565
|
-
isPending: isPreviewPending,
|
|
11566
|
-
isError: isPreviewError,
|
|
11567
|
-
error: previewError
|
|
11568
|
-
} = useOrderPreview(id);
|
|
11569
|
-
useInitiateOrderEdit({ preview });
|
|
11570
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11571
|
-
if (isError) {
|
|
11572
|
-
throw error;
|
|
11573
|
-
}
|
|
11574
|
-
if (isPreviewError) {
|
|
11575
|
-
throw previewError;
|
|
11576
|
-
}
|
|
11577
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11578
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11579
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11580
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11581
|
-
/* @__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: [
|
|
11582
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11583
|
-
/* @__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." }) })
|
|
11584
|
-
] }) }) }),
|
|
11585
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11586
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11587
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11588
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11589
|
-
] }) });
|
|
11590
|
-
};
|
|
11591
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11592
|
-
var _a;
|
|
11593
|
-
const { setIsOpen } = useStackedModal();
|
|
11594
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11595
|
-
const [data, setData] = useState(null);
|
|
11596
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11597
|
-
const { shipping_options } = useShippingOptions(
|
|
11598
|
-
{
|
|
11599
|
-
id: appliedShippingOptionIds,
|
|
11600
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11601
|
-
},
|
|
11602
|
-
{
|
|
11603
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11604
|
-
}
|
|
11605
|
-
);
|
|
11606
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
11607
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
11608
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11609
|
-
profiles.set(profile.id, profile);
|
|
11610
|
-
});
|
|
11611
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11612
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11613
|
-
});
|
|
11614
|
-
return Array.from(profiles.values());
|
|
11615
|
-
}, [order.items, shipping_options]);
|
|
11616
|
-
const { handleSuccess } = useRouteModal();
|
|
11617
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11618
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11619
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11620
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11621
|
-
const onSubmit = async () => {
|
|
11622
|
-
setIsSubmitting(true);
|
|
11623
|
-
let requestSucceeded = false;
|
|
11624
|
-
await requestOrderEdit(void 0, {
|
|
11625
|
-
onError: (e) => {
|
|
11626
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11627
|
-
},
|
|
11628
|
-
onSuccess: () => {
|
|
11629
|
-
requestSucceeded = true;
|
|
11630
|
-
}
|
|
11631
|
-
});
|
|
11632
|
-
if (!requestSucceeded) {
|
|
11633
|
-
setIsSubmitting(false);
|
|
11634
|
-
return;
|
|
11635
|
-
}
|
|
11636
|
-
await confirmOrderEdit(void 0, {
|
|
11637
|
-
onError: (e) => {
|
|
11638
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11639
|
-
},
|
|
11640
|
-
onSuccess: () => {
|
|
11641
|
-
handleSuccess();
|
|
11642
|
-
},
|
|
11643
|
-
onSettled: () => {
|
|
11644
|
-
setIsSubmitting(false);
|
|
11645
|
-
}
|
|
11646
|
-
});
|
|
11647
|
-
};
|
|
11648
|
-
const onKeydown = useCallback(
|
|
11649
|
-
(e) => {
|
|
11650
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11651
|
-
if (data || isSubmitting) {
|
|
11652
|
-
return;
|
|
11653
|
-
}
|
|
11654
|
-
onSubmit();
|
|
11655
|
-
}
|
|
11656
|
-
},
|
|
11657
|
-
[data, isSubmitting, onSubmit]
|
|
11658
|
-
);
|
|
11659
|
-
useEffect(() => {
|
|
11660
|
-
document.addEventListener("keydown", onKeydown);
|
|
11661
|
-
return () => {
|
|
11662
|
-
document.removeEventListener("keydown", onKeydown);
|
|
11663
|
-
};
|
|
11664
|
-
}, [onKeydown]);
|
|
11665
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
11666
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11667
|
-
/* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11668
|
-
/* @__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: [
|
|
11669
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11670
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11671
|
-
/* @__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." }) })
|
|
11672
|
-
] }),
|
|
11673
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11674
|
-
/* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
|
|
11675
|
-
/* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
|
|
11676
|
-
/* @__PURE__ */ jsx(
|
|
11677
|
-
Text,
|
|
11678
|
-
{
|
|
11679
|
-
size: "xsmall",
|
|
11680
|
-
weight: "plus",
|
|
11681
|
-
className: "text-ui-fg-muted",
|
|
11682
|
-
children: "Shipping profile"
|
|
10496
|
+
size: "xsmall",
|
|
10497
|
+
weight: "plus",
|
|
10498
|
+
className: "text-ui-fg-muted",
|
|
10499
|
+
children: "Shipping profile"
|
|
11683
10500
|
}
|
|
11684
10501
|
),
|
|
11685
10502
|
/* @__PURE__ */ jsx(
|
|
@@ -11860,7 +10677,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11860
10677
|
]
|
|
11861
10678
|
}
|
|
11862
10679
|
) : /* @__PURE__ */ jsx(
|
|
11863
|
-
StackedModalTrigger,
|
|
10680
|
+
StackedModalTrigger$1,
|
|
11864
10681
|
{
|
|
11865
10682
|
shippingProfileId: profile.id,
|
|
11866
10683
|
shippingOption,
|
|
@@ -11971,7 +10788,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11971
10788
|
] }) })
|
|
11972
10789
|
] });
|
|
11973
10790
|
};
|
|
11974
|
-
const StackedModalTrigger = ({
|
|
10791
|
+
const StackedModalTrigger$1 = ({
|
|
11975
10792
|
shippingProfileId,
|
|
11976
10793
|
shippingOption,
|
|
11977
10794
|
shippingMethod,
|
|
@@ -12392,7 +11209,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12392
11209
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12393
11210
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12394
11211
|
},
|
|
12395
|
-
resolver: zodResolver(schema$
|
|
11212
|
+
resolver: zodResolver(schema$3)
|
|
12396
11213
|
});
|
|
12397
11214
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12398
11215
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12562,7 +11379,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12562
11379
|
}
|
|
12563
11380
|
) });
|
|
12564
11381
|
};
|
|
12565
|
-
const schema$
|
|
11382
|
+
const schema$3 = addressSchema;
|
|
12566
11383
|
const TransferOwnership = () => {
|
|
12567
11384
|
const { id } = useParams();
|
|
12568
11385
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12586,7 +11403,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12586
11403
|
defaultValues: {
|
|
12587
11404
|
customer_id: order.customer_id || ""
|
|
12588
11405
|
},
|
|
12589
|
-
resolver: zodResolver(schema)
|
|
11406
|
+
resolver: zodResolver(schema$2)
|
|
12590
11407
|
});
|
|
12591
11408
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12592
11409
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12885,159 +11702,1342 @@ const Illustration = () => {
|
|
|
12885
11702
|
/* @__PURE__ */ jsx(
|
|
12886
11703
|
"path",
|
|
12887
11704
|
{
|
|
12888
|
-
d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
|
|
12889
|
-
fill: "#A1A1AA"
|
|
12890
|
-
}
|
|
11705
|
+
d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
|
|
11706
|
+
fill: "#A1A1AA"
|
|
11707
|
+
}
|
|
11708
|
+
),
|
|
11709
|
+
/* @__PURE__ */ jsx(
|
|
11710
|
+
"rect",
|
|
11711
|
+
{
|
|
11712
|
+
width: "17",
|
|
11713
|
+
height: "3",
|
|
11714
|
+
rx: "1.5",
|
|
11715
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
11716
|
+
fill: "#A1A1AA"
|
|
11717
|
+
}
|
|
11718
|
+
),
|
|
11719
|
+
/* @__PURE__ */ jsx(
|
|
11720
|
+
"rect",
|
|
11721
|
+
{
|
|
11722
|
+
width: "12",
|
|
11723
|
+
height: "3",
|
|
11724
|
+
rx: "1.5",
|
|
11725
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
11726
|
+
fill: "#A1A1AA"
|
|
11727
|
+
}
|
|
11728
|
+
),
|
|
11729
|
+
/* @__PURE__ */ jsx(
|
|
11730
|
+
"path",
|
|
11731
|
+
{
|
|
11732
|
+
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
11733
|
+
fill: "#52525B"
|
|
11734
|
+
}
|
|
11735
|
+
),
|
|
11736
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11737
|
+
"path",
|
|
11738
|
+
{
|
|
11739
|
+
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
11740
|
+
stroke: "#A1A1AA",
|
|
11741
|
+
strokeWidth: "1.5",
|
|
11742
|
+
strokeLinecap: "round",
|
|
11743
|
+
strokeLinejoin: "round"
|
|
11744
|
+
}
|
|
11745
|
+
) }),
|
|
11746
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11747
|
+
"path",
|
|
11748
|
+
{
|
|
11749
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
11750
|
+
stroke: "#A1A1AA",
|
|
11751
|
+
strokeWidth: "1.5",
|
|
11752
|
+
strokeLinecap: "round",
|
|
11753
|
+
strokeLinejoin: "round"
|
|
11754
|
+
}
|
|
11755
|
+
) }),
|
|
11756
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11757
|
+
"path",
|
|
11758
|
+
{
|
|
11759
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
11760
|
+
stroke: "#A1A1AA",
|
|
11761
|
+
strokeWidth: "1.5",
|
|
11762
|
+
strokeLinecap: "round",
|
|
11763
|
+
strokeLinejoin: "round"
|
|
11764
|
+
}
|
|
11765
|
+
) }),
|
|
11766
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11767
|
+
"path",
|
|
11768
|
+
{
|
|
11769
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
11770
|
+
stroke: "#A1A1AA",
|
|
11771
|
+
strokeWidth: "1.5",
|
|
11772
|
+
strokeLinecap: "round",
|
|
11773
|
+
strokeLinejoin: "round"
|
|
11774
|
+
}
|
|
11775
|
+
) }),
|
|
11776
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11777
|
+
"path",
|
|
11778
|
+
{
|
|
11779
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
11780
|
+
stroke: "#A1A1AA",
|
|
11781
|
+
strokeWidth: "1.5",
|
|
11782
|
+
strokeLinecap: "round",
|
|
11783
|
+
strokeLinejoin: "round"
|
|
11784
|
+
}
|
|
11785
|
+
) }),
|
|
11786
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
11787
|
+
"path",
|
|
11788
|
+
{
|
|
11789
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
11790
|
+
stroke: "#A1A1AA",
|
|
11791
|
+
strokeWidth: "1.5",
|
|
11792
|
+
strokeLinecap: "round",
|
|
11793
|
+
strokeLinejoin: "round"
|
|
11794
|
+
}
|
|
11795
|
+
) }),
|
|
11796
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
11797
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11798
|
+
"rect",
|
|
11799
|
+
{
|
|
11800
|
+
width: "12",
|
|
11801
|
+
height: "12",
|
|
11802
|
+
fill: "white",
|
|
11803
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
11804
|
+
}
|
|
11805
|
+
) }),
|
|
11806
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11807
|
+
"rect",
|
|
11808
|
+
{
|
|
11809
|
+
width: "12",
|
|
11810
|
+
height: "12",
|
|
11811
|
+
fill: "white",
|
|
11812
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
11813
|
+
}
|
|
11814
|
+
) }),
|
|
11815
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11816
|
+
"rect",
|
|
11817
|
+
{
|
|
11818
|
+
width: "12",
|
|
11819
|
+
height: "12",
|
|
11820
|
+
fill: "white",
|
|
11821
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
11822
|
+
}
|
|
11823
|
+
) }),
|
|
11824
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11825
|
+
"rect",
|
|
11826
|
+
{
|
|
11827
|
+
width: "12",
|
|
11828
|
+
height: "12",
|
|
11829
|
+
fill: "white",
|
|
11830
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
11831
|
+
}
|
|
11832
|
+
) }),
|
|
11833
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11834
|
+
"rect",
|
|
11835
|
+
{
|
|
11836
|
+
width: "12",
|
|
11837
|
+
height: "12",
|
|
11838
|
+
fill: "white",
|
|
11839
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
11840
|
+
}
|
|
11841
|
+
) }),
|
|
11842
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11843
|
+
"rect",
|
|
11844
|
+
{
|
|
11845
|
+
width: "12",
|
|
11846
|
+
height: "12",
|
|
11847
|
+
fill: "white",
|
|
11848
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
11849
|
+
}
|
|
11850
|
+
) })
|
|
11851
|
+
] })
|
|
11852
|
+
]
|
|
11853
|
+
}
|
|
11854
|
+
);
|
|
11855
|
+
};
|
|
11856
|
+
const schema$2 = objectType({
|
|
11857
|
+
customer_id: stringType().min(1)
|
|
11858
|
+
});
|
|
11859
|
+
const BillingAddress = () => {
|
|
11860
|
+
const { id } = useParams();
|
|
11861
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11862
|
+
fields: "+billing_address"
|
|
11863
|
+
});
|
|
11864
|
+
if (isError) {
|
|
11865
|
+
throw error;
|
|
11866
|
+
}
|
|
11867
|
+
const isReady = !isPending && !!order;
|
|
11868
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11869
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11870
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
11871
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
11872
|
+
] }),
|
|
11873
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
11874
|
+
] });
|
|
11875
|
+
};
|
|
11876
|
+
const BillingAddressForm = ({ order }) => {
|
|
11877
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11878
|
+
const form = useForm({
|
|
11879
|
+
defaultValues: {
|
|
11880
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11881
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11882
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
11883
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11884
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11885
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
11886
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
11887
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11888
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11889
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
11890
|
+
},
|
|
11891
|
+
resolver: zodResolver(schema$1)
|
|
11892
|
+
});
|
|
11893
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11894
|
+
const { handleSuccess } = useRouteModal();
|
|
11895
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11896
|
+
await mutateAsync(
|
|
11897
|
+
{ billing_address: data },
|
|
11898
|
+
{
|
|
11899
|
+
onSuccess: () => {
|
|
11900
|
+
handleSuccess();
|
|
11901
|
+
},
|
|
11902
|
+
onError: (error) => {
|
|
11903
|
+
toast.error(error.message);
|
|
11904
|
+
}
|
|
11905
|
+
}
|
|
11906
|
+
);
|
|
11907
|
+
});
|
|
11908
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11909
|
+
KeyboundForm,
|
|
11910
|
+
{
|
|
11911
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11912
|
+
onSubmit,
|
|
11913
|
+
children: [
|
|
11914
|
+
/* @__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: [
|
|
11915
|
+
/* @__PURE__ */ jsx(
|
|
11916
|
+
Form$2.Field,
|
|
11917
|
+
{
|
|
11918
|
+
control: form.control,
|
|
11919
|
+
name: "country_code",
|
|
11920
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11921
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
11922
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
11923
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11924
|
+
] })
|
|
11925
|
+
}
|
|
11926
|
+
),
|
|
11927
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11928
|
+
/* @__PURE__ */ jsx(
|
|
11929
|
+
Form$2.Field,
|
|
11930
|
+
{
|
|
11931
|
+
control: form.control,
|
|
11932
|
+
name: "first_name",
|
|
11933
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11934
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
11935
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11936
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11937
|
+
] })
|
|
11938
|
+
}
|
|
11939
|
+
),
|
|
11940
|
+
/* @__PURE__ */ jsx(
|
|
11941
|
+
Form$2.Field,
|
|
11942
|
+
{
|
|
11943
|
+
control: form.control,
|
|
11944
|
+
name: "last_name",
|
|
11945
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11946
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
11947
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11948
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11949
|
+
] })
|
|
11950
|
+
}
|
|
11951
|
+
)
|
|
11952
|
+
] }),
|
|
11953
|
+
/* @__PURE__ */ jsx(
|
|
11954
|
+
Form$2.Field,
|
|
11955
|
+
{
|
|
11956
|
+
control: form.control,
|
|
11957
|
+
name: "company",
|
|
11958
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11959
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
11960
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11961
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11962
|
+
] })
|
|
11963
|
+
}
|
|
11964
|
+
),
|
|
11965
|
+
/* @__PURE__ */ jsx(
|
|
11966
|
+
Form$2.Field,
|
|
11967
|
+
{
|
|
11968
|
+
control: form.control,
|
|
11969
|
+
name: "address_1",
|
|
11970
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11971
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
11972
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11973
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11974
|
+
] })
|
|
11975
|
+
}
|
|
11976
|
+
),
|
|
11977
|
+
/* @__PURE__ */ jsx(
|
|
11978
|
+
Form$2.Field,
|
|
11979
|
+
{
|
|
11980
|
+
control: form.control,
|
|
11981
|
+
name: "address_2",
|
|
11982
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11983
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
11984
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11985
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11986
|
+
] })
|
|
11987
|
+
}
|
|
11988
|
+
),
|
|
11989
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11990
|
+
/* @__PURE__ */ jsx(
|
|
11991
|
+
Form$2.Field,
|
|
11992
|
+
{
|
|
11993
|
+
control: form.control,
|
|
11994
|
+
name: "postal_code",
|
|
11995
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11996
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
11997
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11998
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11999
|
+
] })
|
|
12000
|
+
}
|
|
12001
|
+
),
|
|
12002
|
+
/* @__PURE__ */ jsx(
|
|
12003
|
+
Form$2.Field,
|
|
12004
|
+
{
|
|
12005
|
+
control: form.control,
|
|
12006
|
+
name: "city",
|
|
12007
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12008
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12009
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12010
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12011
|
+
] })
|
|
12012
|
+
}
|
|
12013
|
+
)
|
|
12014
|
+
] }),
|
|
12015
|
+
/* @__PURE__ */ jsx(
|
|
12016
|
+
Form$2.Field,
|
|
12017
|
+
{
|
|
12018
|
+
control: form.control,
|
|
12019
|
+
name: "province",
|
|
12020
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12021
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12022
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12023
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12024
|
+
] })
|
|
12025
|
+
}
|
|
12026
|
+
),
|
|
12027
|
+
/* @__PURE__ */ jsx(
|
|
12028
|
+
Form$2.Field,
|
|
12029
|
+
{
|
|
12030
|
+
control: form.control,
|
|
12031
|
+
name: "phone",
|
|
12032
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12033
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12034
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12035
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12036
|
+
] })
|
|
12037
|
+
}
|
|
12038
|
+
)
|
|
12039
|
+
] }) }),
|
|
12040
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12041
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12042
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12043
|
+
] }) })
|
|
12044
|
+
]
|
|
12045
|
+
}
|
|
12046
|
+
) });
|
|
12047
|
+
};
|
|
12048
|
+
const schema$1 = addressSchema;
|
|
12049
|
+
const NumberInput = forwardRef(
|
|
12050
|
+
({
|
|
12051
|
+
value,
|
|
12052
|
+
onChange,
|
|
12053
|
+
size = "base",
|
|
12054
|
+
min = 0,
|
|
12055
|
+
max = 100,
|
|
12056
|
+
step = 1,
|
|
12057
|
+
className,
|
|
12058
|
+
disabled,
|
|
12059
|
+
...props
|
|
12060
|
+
}, ref) => {
|
|
12061
|
+
const handleChange = (event) => {
|
|
12062
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
12063
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
12064
|
+
onChange(newValue);
|
|
12065
|
+
}
|
|
12066
|
+
};
|
|
12067
|
+
const handleIncrement = () => {
|
|
12068
|
+
const newValue = value + step;
|
|
12069
|
+
if (max === void 0 || newValue <= max) {
|
|
12070
|
+
onChange(newValue);
|
|
12071
|
+
}
|
|
12072
|
+
};
|
|
12073
|
+
const handleDecrement = () => {
|
|
12074
|
+
const newValue = value - step;
|
|
12075
|
+
if (min === void 0 || newValue >= min) {
|
|
12076
|
+
onChange(newValue);
|
|
12077
|
+
}
|
|
12078
|
+
};
|
|
12079
|
+
return /* @__PURE__ */ jsxs(
|
|
12080
|
+
"div",
|
|
12081
|
+
{
|
|
12082
|
+
className: clx(
|
|
12083
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
12084
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
12085
|
+
{
|
|
12086
|
+
"h-7": size === "small",
|
|
12087
|
+
"h-8": size === "base"
|
|
12088
|
+
},
|
|
12089
|
+
className
|
|
12891
12090
|
),
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12091
|
+
children: [
|
|
12092
|
+
/* @__PURE__ */ jsx(
|
|
12093
|
+
"input",
|
|
12094
|
+
{
|
|
12095
|
+
ref,
|
|
12096
|
+
type: "number",
|
|
12097
|
+
value,
|
|
12098
|
+
onChange: handleChange,
|
|
12099
|
+
min,
|
|
12100
|
+
max,
|
|
12101
|
+
step,
|
|
12102
|
+
className: clx(
|
|
12103
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
12104
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
12105
|
+
"placeholder:text-ui-fg-muted"
|
|
12106
|
+
),
|
|
12107
|
+
...props
|
|
12108
|
+
}
|
|
12109
|
+
),
|
|
12110
|
+
/* @__PURE__ */ jsxs(
|
|
12111
|
+
"button",
|
|
12112
|
+
{
|
|
12113
|
+
className: clx(
|
|
12114
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
12115
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
12116
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
12117
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
12118
|
+
{
|
|
12119
|
+
"size-7": size === "small",
|
|
12120
|
+
"size-8": size === "base"
|
|
12121
|
+
}
|
|
12122
|
+
),
|
|
12123
|
+
type: "button",
|
|
12124
|
+
onClick: handleDecrement,
|
|
12125
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
12126
|
+
children: [
|
|
12127
|
+
/* @__PURE__ */ jsx(Minus, {}),
|
|
12128
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
12129
|
+
]
|
|
12130
|
+
}
|
|
12131
|
+
),
|
|
12132
|
+
/* @__PURE__ */ jsxs(
|
|
12133
|
+
"button",
|
|
12134
|
+
{
|
|
12135
|
+
className: clx(
|
|
12136
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
12137
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
12138
|
+
"focus:bg-ui-bg-field-hover",
|
|
12139
|
+
"hover:bg-ui-bg-field-hover",
|
|
12140
|
+
{
|
|
12141
|
+
"size-7": size === "small",
|
|
12142
|
+
"size-8": size === "base"
|
|
12143
|
+
}
|
|
12144
|
+
),
|
|
12145
|
+
type: "button",
|
|
12146
|
+
onClick: handleIncrement,
|
|
12147
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
12148
|
+
children: [
|
|
12149
|
+
/* @__PURE__ */ jsx(Plus, {}),
|
|
12150
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
12151
|
+
]
|
|
12152
|
+
}
|
|
12153
|
+
)
|
|
12154
|
+
]
|
|
12155
|
+
}
|
|
12156
|
+
);
|
|
12157
|
+
}
|
|
12158
|
+
);
|
|
12159
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
12160
|
+
const productVariantsQueryKeys = {
|
|
12161
|
+
list: (query2) => [
|
|
12162
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
12163
|
+
query2 ? query2 : void 0
|
|
12164
|
+
]
|
|
12165
|
+
};
|
|
12166
|
+
const useProductVariants = (query2, options) => {
|
|
12167
|
+
const { data, ...rest } = useQuery({
|
|
12168
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
12169
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
12170
|
+
...options
|
|
12171
|
+
});
|
|
12172
|
+
return { ...data, ...rest };
|
|
12173
|
+
};
|
|
12174
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
12175
|
+
const Items = () => {
|
|
12176
|
+
const { id } = useParams();
|
|
12177
|
+
const {
|
|
12178
|
+
order: preview,
|
|
12179
|
+
isPending: isPreviewPending,
|
|
12180
|
+
isError: isPreviewError,
|
|
12181
|
+
error: previewError
|
|
12182
|
+
} = useOrderPreview(id, void 0, {
|
|
12183
|
+
placeholderData: keepPreviousData
|
|
12184
|
+
});
|
|
12185
|
+
useInitiateOrderEdit({ preview });
|
|
12186
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12187
|
+
id,
|
|
12188
|
+
{
|
|
12189
|
+
fields: "currency_code"
|
|
12190
|
+
},
|
|
12191
|
+
{
|
|
12192
|
+
enabled: !!id
|
|
12193
|
+
}
|
|
12194
|
+
);
|
|
12195
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12196
|
+
if (isError) {
|
|
12197
|
+
throw error;
|
|
12198
|
+
}
|
|
12199
|
+
if (isPreviewError) {
|
|
12200
|
+
throw previewError;
|
|
12201
|
+
}
|
|
12202
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
12203
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
12204
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
12205
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
12206
|
+
] }) });
|
|
12207
|
+
};
|
|
12208
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
12209
|
+
var _a;
|
|
12210
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12211
|
+
const [modalContent, setModalContent] = useState(
|
|
12212
|
+
null
|
|
12213
|
+
);
|
|
12214
|
+
const { handleSuccess } = useRouteModal();
|
|
12215
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
12216
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12217
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
12218
|
+
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
12219
|
+
const matches = useMemo(() => {
|
|
12220
|
+
return matchSorter(preview.items, query2, {
|
|
12221
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
12222
|
+
});
|
|
12223
|
+
}, [preview.items, query2]);
|
|
12224
|
+
const onSubmit = async () => {
|
|
12225
|
+
setIsSubmitting(true);
|
|
12226
|
+
let requestSucceeded = false;
|
|
12227
|
+
await requestOrderEdit(void 0, {
|
|
12228
|
+
onError: (e) => {
|
|
12229
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
12230
|
+
},
|
|
12231
|
+
onSuccess: () => {
|
|
12232
|
+
requestSucceeded = true;
|
|
12233
|
+
}
|
|
12234
|
+
});
|
|
12235
|
+
if (!requestSucceeded) {
|
|
12236
|
+
setIsSubmitting(false);
|
|
12237
|
+
return;
|
|
12238
|
+
}
|
|
12239
|
+
await confirmOrderEdit(void 0, {
|
|
12240
|
+
onError: (e) => {
|
|
12241
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
12242
|
+
},
|
|
12243
|
+
onSuccess: () => {
|
|
12244
|
+
handleSuccess();
|
|
12245
|
+
},
|
|
12246
|
+
onSettled: () => {
|
|
12247
|
+
setIsSubmitting(false);
|
|
12248
|
+
}
|
|
12249
|
+
});
|
|
12250
|
+
};
|
|
12251
|
+
const onKeyDown = useCallback(
|
|
12252
|
+
(e) => {
|
|
12253
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
12254
|
+
if (modalContent || isSubmitting) {
|
|
12255
|
+
return;
|
|
12256
|
+
}
|
|
12257
|
+
onSubmit();
|
|
12258
|
+
}
|
|
12259
|
+
},
|
|
12260
|
+
[modalContent, isSubmitting, onSubmit]
|
|
12261
|
+
);
|
|
12262
|
+
useEffect(() => {
|
|
12263
|
+
document.addEventListener("keydown", onKeyDown);
|
|
12264
|
+
return () => {
|
|
12265
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
12266
|
+
};
|
|
12267
|
+
}, [onKeyDown]);
|
|
12268
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
12269
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
12270
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
12271
|
+
StackedFocusModal,
|
|
12272
|
+
{
|
|
12273
|
+
id: STACKED_MODAL_ID,
|
|
12274
|
+
onOpenChangeCallback: (open) => {
|
|
12275
|
+
if (!open) {
|
|
12276
|
+
setModalContent(null);
|
|
12900
12277
|
}
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
"
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12278
|
+
},
|
|
12279
|
+
children: [
|
|
12280
|
+
/* @__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: [
|
|
12281
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12282
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
|
|
12283
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
|
|
12284
|
+
] }),
|
|
12285
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12286
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
12287
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
12288
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12289
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
12290
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
12291
|
+
] }),
|
|
12292
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
12293
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
12294
|
+
Input,
|
|
12295
|
+
{
|
|
12296
|
+
type: "search",
|
|
12297
|
+
placeholder: "Search items",
|
|
12298
|
+
value: searchValue,
|
|
12299
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
12300
|
+
}
|
|
12301
|
+
) }),
|
|
12302
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12303
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
12304
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12305
|
+
/* @__PURE__ */ jsx(
|
|
12306
|
+
StackedModalTrigger,
|
|
12307
|
+
{
|
|
12308
|
+
type: "add-items",
|
|
12309
|
+
setModalContent
|
|
12310
|
+
}
|
|
12311
|
+
),
|
|
12312
|
+
/* @__PURE__ */ jsx(
|
|
12313
|
+
StackedModalTrigger,
|
|
12314
|
+
{
|
|
12315
|
+
type: "add-custom-item",
|
|
12316
|
+
setModalContent
|
|
12317
|
+
}
|
|
12318
|
+
)
|
|
12319
|
+
] })
|
|
12320
|
+
] })
|
|
12321
|
+
] })
|
|
12322
|
+
] }),
|
|
12323
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
12324
|
+
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
12325
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
12326
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
12327
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
12328
|
+
/* @__PURE__ */ jsx("div", {})
|
|
12329
|
+
] }) }),
|
|
12330
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__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: [
|
|
12331
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
12332
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
12333
|
+
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
12334
|
+
Item,
|
|
12335
|
+
{
|
|
12336
|
+
item,
|
|
12337
|
+
preview,
|
|
12338
|
+
currencyCode
|
|
12339
|
+
},
|
|
12340
|
+
item.id
|
|
12341
|
+
)) : /* @__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: [
|
|
12342
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
12343
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
12344
|
+
'No items found for "',
|
|
12345
|
+
query2,
|
|
12346
|
+
'".'
|
|
12347
|
+
] })
|
|
12348
|
+
] }) })
|
|
12349
|
+
] })
|
|
12350
|
+
] }),
|
|
12351
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12352
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
12353
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
12354
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
12355
|
+
Text,
|
|
12356
|
+
{
|
|
12357
|
+
size: "small",
|
|
12358
|
+
leading: "compact",
|
|
12359
|
+
className: "text-ui-fg-subtle",
|
|
12360
|
+
children: [
|
|
12361
|
+
itemCount,
|
|
12362
|
+
" ",
|
|
12363
|
+
itemCount === 1 ? "item" : "items"
|
|
12364
|
+
]
|
|
12365
|
+
}
|
|
12366
|
+
) }),
|
|
12367
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
12368
|
+
] })
|
|
12369
|
+
] }) }),
|
|
12370
|
+
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
12371
|
+
CustomItemForm,
|
|
12372
|
+
{
|
|
12373
|
+
orderId: preview.id,
|
|
12374
|
+
currencyCode
|
|
12375
|
+
}
|
|
12376
|
+
) : null)
|
|
12377
|
+
]
|
|
12378
|
+
}
|
|
12379
|
+
) }),
|
|
12380
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12381
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12382
|
+
/* @__PURE__ */ jsx(
|
|
12383
|
+
Button,
|
|
12384
|
+
{
|
|
12385
|
+
size: "small",
|
|
12386
|
+
type: "button",
|
|
12387
|
+
onClick: onSubmit,
|
|
12388
|
+
isLoading: isSubmitting,
|
|
12389
|
+
children: "Save"
|
|
12390
|
+
}
|
|
12391
|
+
)
|
|
12392
|
+
] }) })
|
|
12393
|
+
] });
|
|
12394
|
+
};
|
|
12395
|
+
const Item = ({ item, preview, currencyCode }) => {
|
|
12396
|
+
if (item.variant_id) {
|
|
12397
|
+
return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
|
|
12398
|
+
}
|
|
12399
|
+
return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
|
|
12400
|
+
};
|
|
12401
|
+
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
12402
|
+
const [editing, setEditing] = useState(false);
|
|
12403
|
+
const form = useForm({
|
|
12404
|
+
defaultValues: {
|
|
12405
|
+
quantity: item.quantity,
|
|
12406
|
+
unit_price: item.unit_price
|
|
12407
|
+
},
|
|
12408
|
+
resolver: zodResolver(variantItemSchema)
|
|
12409
|
+
});
|
|
12410
|
+
const actionId = useMemo(() => {
|
|
12411
|
+
var _a, _b;
|
|
12412
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
12413
|
+
}, [item]);
|
|
12414
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
12415
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
12416
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
12417
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12418
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
12419
|
+
setEditing(false);
|
|
12420
|
+
return;
|
|
12421
|
+
}
|
|
12422
|
+
if (!actionId) {
|
|
12423
|
+
await updateOriginalItem(
|
|
12424
|
+
{
|
|
12425
|
+
item_id: item.id,
|
|
12426
|
+
quantity: data.quantity,
|
|
12427
|
+
unit_price: convertNumber(data.unit_price)
|
|
12428
|
+
},
|
|
12429
|
+
{
|
|
12430
|
+
onSuccess: () => {
|
|
12431
|
+
setEditing(false);
|
|
12432
|
+
},
|
|
12433
|
+
onError: (e) => {
|
|
12434
|
+
toast.error(e.message);
|
|
12910
12435
|
}
|
|
12911
|
-
|
|
12436
|
+
}
|
|
12437
|
+
);
|
|
12438
|
+
return;
|
|
12439
|
+
}
|
|
12440
|
+
await updateActionItem(
|
|
12441
|
+
{
|
|
12442
|
+
action_id: actionId,
|
|
12443
|
+
quantity: data.quantity,
|
|
12444
|
+
unit_price: convertNumber(data.unit_price)
|
|
12445
|
+
},
|
|
12446
|
+
{
|
|
12447
|
+
onSuccess: () => {
|
|
12448
|
+
setEditing(false);
|
|
12449
|
+
},
|
|
12450
|
+
onError: (e) => {
|
|
12451
|
+
toast.error(e.message);
|
|
12452
|
+
}
|
|
12453
|
+
}
|
|
12454
|
+
);
|
|
12455
|
+
});
|
|
12456
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
12457
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
|
|
12458
|
+
/* @__PURE__ */ jsx(
|
|
12459
|
+
Thumbnail,
|
|
12460
|
+
{
|
|
12461
|
+
thumbnail: item.thumbnail,
|
|
12462
|
+
alt: item.product_title ?? void 0
|
|
12463
|
+
}
|
|
12464
|
+
),
|
|
12465
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12466
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
12467
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
12468
|
+
/* @__PURE__ */ jsxs(
|
|
12469
|
+
Text,
|
|
12470
|
+
{
|
|
12471
|
+
size: "small",
|
|
12472
|
+
leading: "compact",
|
|
12473
|
+
className: "text-ui-fg-subtle",
|
|
12474
|
+
children: [
|
|
12475
|
+
"(",
|
|
12476
|
+
item.variant_title,
|
|
12477
|
+
")"
|
|
12478
|
+
]
|
|
12479
|
+
}
|
|
12480
|
+
)
|
|
12481
|
+
] }),
|
|
12912
12482
|
/* @__PURE__ */ jsx(
|
|
12913
|
-
|
|
12914
|
-
{
|
|
12915
|
-
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
12916
|
-
fill: "#52525B"
|
|
12917
|
-
}
|
|
12918
|
-
),
|
|
12919
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12920
|
-
"path",
|
|
12483
|
+
Text,
|
|
12921
12484
|
{
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
strokeLinejoin: "round"
|
|
12485
|
+
size: "small",
|
|
12486
|
+
leading: "compact",
|
|
12487
|
+
className: "text-ui-fg-subtle",
|
|
12488
|
+
children: item.variant_sku
|
|
12927
12489
|
}
|
|
12928
|
-
)
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
|
|
12490
|
+
)
|
|
12491
|
+
] })
|
|
12492
|
+
] }),
|
|
12493
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
12494
|
+
Form$2.Field,
|
|
12495
|
+
{
|
|
12496
|
+
control: form.control,
|
|
12497
|
+
name: "quantity",
|
|
12498
|
+
render: ({ field }) => {
|
|
12499
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
12500
|
+
}
|
|
12501
|
+
}
|
|
12502
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
12503
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
12504
|
+
Form$2.Field,
|
|
12505
|
+
{
|
|
12506
|
+
control: form.control,
|
|
12507
|
+
name: "unit_price",
|
|
12508
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12509
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12510
|
+
CurrencyInput,
|
|
12511
|
+
{
|
|
12512
|
+
...field,
|
|
12513
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12514
|
+
code: currencyCode,
|
|
12515
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
12516
|
+
}
|
|
12517
|
+
) }) });
|
|
12518
|
+
}
|
|
12519
|
+
}
|
|
12520
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
12521
|
+
/* @__PURE__ */ jsx(
|
|
12522
|
+
IconButton,
|
|
12523
|
+
{
|
|
12524
|
+
type: "button",
|
|
12525
|
+
size: "small",
|
|
12526
|
+
onClick: editing ? onSubmit : () => {
|
|
12527
|
+
setEditing(true);
|
|
12528
|
+
},
|
|
12529
|
+
disabled: isPending,
|
|
12530
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
12531
|
+
}
|
|
12532
|
+
)
|
|
12533
|
+
] }) }) });
|
|
12534
|
+
};
|
|
12535
|
+
const variantItemSchema = objectType({
|
|
12536
|
+
quantity: numberType(),
|
|
12537
|
+
unit_price: unionType([numberType(), stringType()])
|
|
12538
|
+
});
|
|
12539
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
12540
|
+
const [editing, setEditing] = useState(false);
|
|
12541
|
+
const { quantity, unit_price, title } = item;
|
|
12542
|
+
const form = useForm({
|
|
12543
|
+
defaultValues: {
|
|
12544
|
+
title,
|
|
12545
|
+
quantity,
|
|
12546
|
+
unit_price
|
|
12547
|
+
},
|
|
12548
|
+
resolver: zodResolver(customItemSchema)
|
|
12549
|
+
});
|
|
12550
|
+
useEffect(() => {
|
|
12551
|
+
form.reset({
|
|
12552
|
+
title,
|
|
12553
|
+
quantity,
|
|
12554
|
+
unit_price
|
|
12555
|
+
});
|
|
12556
|
+
}, [form, title, quantity, unit_price]);
|
|
12557
|
+
const actionId = useMemo(() => {
|
|
12558
|
+
var _a, _b;
|
|
12559
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
12560
|
+
}, [item]);
|
|
12561
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
12562
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
12563
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
12564
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
12565
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12566
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
12567
|
+
setEditing(false);
|
|
12568
|
+
return;
|
|
12569
|
+
}
|
|
12570
|
+
if (!actionId) {
|
|
12571
|
+
await updateOriginalItem(
|
|
12572
|
+
{
|
|
12573
|
+
item_id: item.id,
|
|
12574
|
+
quantity: data.quantity,
|
|
12575
|
+
unit_price: convertNumber(data.unit_price)
|
|
12576
|
+
},
|
|
12577
|
+
{
|
|
12578
|
+
onSuccess: () => {
|
|
12579
|
+
setEditing(false);
|
|
12580
|
+
},
|
|
12581
|
+
onError: (e) => {
|
|
12582
|
+
toast.error(e.message);
|
|
12937
12583
|
}
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12584
|
+
}
|
|
12585
|
+
);
|
|
12586
|
+
return;
|
|
12587
|
+
}
|
|
12588
|
+
if (data.quantity === 0) {
|
|
12589
|
+
await removeActionItem(actionId, {
|
|
12590
|
+
onSuccess: () => {
|
|
12591
|
+
setEditing(false);
|
|
12592
|
+
},
|
|
12593
|
+
onError: (e) => {
|
|
12594
|
+
toast.error(e.message);
|
|
12595
|
+
}
|
|
12596
|
+
});
|
|
12597
|
+
return;
|
|
12598
|
+
}
|
|
12599
|
+
await updateActionItem(
|
|
12600
|
+
{
|
|
12601
|
+
action_id: actionId,
|
|
12602
|
+
quantity: data.quantity,
|
|
12603
|
+
unit_price: convertNumber(data.unit_price)
|
|
12604
|
+
},
|
|
12605
|
+
{
|
|
12606
|
+
onSuccess: () => {
|
|
12607
|
+
setEditing(false);
|
|
12608
|
+
},
|
|
12609
|
+
onError: (e) => {
|
|
12610
|
+
toast.error(e.message);
|
|
12611
|
+
}
|
|
12612
|
+
}
|
|
12613
|
+
);
|
|
12614
|
+
});
|
|
12615
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
12616
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
12617
|
+
/* @__PURE__ */ jsx(
|
|
12618
|
+
Thumbnail,
|
|
12619
|
+
{
|
|
12620
|
+
thumbnail: item.thumbnail,
|
|
12621
|
+
alt: item.title ?? void 0
|
|
12622
|
+
}
|
|
12623
|
+
),
|
|
12624
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12625
|
+
Form$2.Field,
|
|
12626
|
+
{
|
|
12627
|
+
control: form.control,
|
|
12628
|
+
name: "title",
|
|
12629
|
+
render: ({ field }) => {
|
|
12630
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
12947
12631
|
}
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12632
|
+
}
|
|
12633
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
12634
|
+
] }),
|
|
12635
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12636
|
+
Form$2.Field,
|
|
12637
|
+
{
|
|
12638
|
+
control: form.control,
|
|
12639
|
+
name: "quantity",
|
|
12640
|
+
render: ({ field }) => {
|
|
12641
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
12642
|
+
}
|
|
12643
|
+
}
|
|
12644
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
12645
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12646
|
+
Form$2.Field,
|
|
12647
|
+
{
|
|
12648
|
+
control: form.control,
|
|
12649
|
+
name: "unit_price",
|
|
12650
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12651
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12652
|
+
CurrencyInput,
|
|
12653
|
+
{
|
|
12654
|
+
...field,
|
|
12655
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12656
|
+
code: currencyCode,
|
|
12657
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
12658
|
+
}
|
|
12659
|
+
) }) });
|
|
12660
|
+
}
|
|
12661
|
+
}
|
|
12662
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
12663
|
+
/* @__PURE__ */ jsx(
|
|
12664
|
+
IconButton,
|
|
12665
|
+
{
|
|
12666
|
+
type: "button",
|
|
12667
|
+
size: "small",
|
|
12668
|
+
onClick: editing ? onSubmit : () => {
|
|
12669
|
+
setEditing(true);
|
|
12670
|
+
},
|
|
12671
|
+
disabled: isPending,
|
|
12672
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
12673
|
+
}
|
|
12674
|
+
)
|
|
12675
|
+
] }) }) });
|
|
12676
|
+
};
|
|
12677
|
+
const StackedModalTrigger = ({
|
|
12678
|
+
type,
|
|
12679
|
+
setModalContent
|
|
12680
|
+
}) => {
|
|
12681
|
+
const { setIsOpen } = useStackedModal();
|
|
12682
|
+
const onClick = useCallback(() => {
|
|
12683
|
+
setModalContent(type);
|
|
12684
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
12685
|
+
}, [setModalContent, setIsOpen, type]);
|
|
12686
|
+
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
12687
|
+
};
|
|
12688
|
+
const VARIANT_PREFIX = "items";
|
|
12689
|
+
const LIMIT = 50;
|
|
12690
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
12691
|
+
const { setIsOpen } = useStackedModal();
|
|
12692
|
+
const [rowSelection, setRowSelection] = useState(
|
|
12693
|
+
items.reduce((acc, item) => {
|
|
12694
|
+
acc[item.variant_id] = true;
|
|
12695
|
+
return acc;
|
|
12696
|
+
}, {})
|
|
12697
|
+
);
|
|
12698
|
+
useEffect(() => {
|
|
12699
|
+
setRowSelection(
|
|
12700
|
+
items.reduce((acc, item) => {
|
|
12701
|
+
if (item.variant_id) {
|
|
12702
|
+
acc[item.variant_id] = true;
|
|
12703
|
+
}
|
|
12704
|
+
return acc;
|
|
12705
|
+
}, {})
|
|
12706
|
+
);
|
|
12707
|
+
}, [items]);
|
|
12708
|
+
const { q, order, offset } = useQueryParams(
|
|
12709
|
+
["q", "order", "offset"],
|
|
12710
|
+
VARIANT_PREFIX
|
|
12711
|
+
);
|
|
12712
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
12713
|
+
{
|
|
12714
|
+
q,
|
|
12715
|
+
order,
|
|
12716
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
12717
|
+
limit: LIMIT
|
|
12718
|
+
},
|
|
12719
|
+
{
|
|
12720
|
+
placeholderData: keepPreviousData
|
|
12721
|
+
}
|
|
12722
|
+
);
|
|
12723
|
+
const columns = useColumns();
|
|
12724
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
12725
|
+
const onSubmit = async () => {
|
|
12726
|
+
const ids = Object.keys(rowSelection).filter(
|
|
12727
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
12728
|
+
);
|
|
12729
|
+
await mutateAsync(
|
|
12730
|
+
{
|
|
12731
|
+
items: ids.map((id) => ({
|
|
12732
|
+
variant_id: id,
|
|
12733
|
+
quantity: 1
|
|
12734
|
+
}))
|
|
12735
|
+
},
|
|
12736
|
+
{
|
|
12737
|
+
onSuccess: () => {
|
|
12738
|
+
setRowSelection({});
|
|
12739
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
12740
|
+
},
|
|
12741
|
+
onError: (e) => {
|
|
12742
|
+
toast.error(e.message);
|
|
12743
|
+
}
|
|
12744
|
+
}
|
|
12745
|
+
);
|
|
12746
|
+
};
|
|
12747
|
+
if (isError) {
|
|
12748
|
+
throw error;
|
|
12749
|
+
}
|
|
12750
|
+
return /* @__PURE__ */ jsxs(
|
|
12751
|
+
StackedFocusModal.Content,
|
|
12752
|
+
{
|
|
12753
|
+
onOpenAutoFocus: (e) => {
|
|
12754
|
+
e.preventDefault();
|
|
12755
|
+
const searchInput = document.querySelector(
|
|
12756
|
+
"[data-modal-id='modal-search-input']"
|
|
12757
|
+
);
|
|
12758
|
+
if (searchInput) {
|
|
12759
|
+
searchInput.focus();
|
|
12760
|
+
}
|
|
12761
|
+
},
|
|
12762
|
+
children: [
|
|
12763
|
+
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
12764
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
12765
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
12766
|
+
] }),
|
|
12767
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
12768
|
+
DataTable,
|
|
12951
12769
|
{
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
|
|
12770
|
+
data: variants,
|
|
12771
|
+
columns,
|
|
12772
|
+
isLoading: isPending,
|
|
12773
|
+
getRowId: (row) => row.id,
|
|
12774
|
+
rowCount: count,
|
|
12775
|
+
prefix: VARIANT_PREFIX,
|
|
12776
|
+
layout: "fill",
|
|
12777
|
+
rowSelection: {
|
|
12778
|
+
state: rowSelection,
|
|
12779
|
+
onRowSelectionChange: setRowSelection,
|
|
12780
|
+
enableRowSelection: (row) => {
|
|
12781
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
12782
|
+
}
|
|
12783
|
+
},
|
|
12784
|
+
autoFocusSearch: true
|
|
12957
12785
|
}
|
|
12958
12786
|
) }),
|
|
12959
|
-
/* @__PURE__ */ jsx("
|
|
12960
|
-
"
|
|
12787
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12788
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12789
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
12790
|
+
] }) })
|
|
12791
|
+
]
|
|
12792
|
+
}
|
|
12793
|
+
);
|
|
12794
|
+
};
|
|
12795
|
+
const columnHelper = createDataTableColumnHelper();
|
|
12796
|
+
const useColumns = () => {
|
|
12797
|
+
return useMemo(() => {
|
|
12798
|
+
return [
|
|
12799
|
+
columnHelper.select(),
|
|
12800
|
+
columnHelper.accessor("product.title", {
|
|
12801
|
+
header: "Product",
|
|
12802
|
+
cell: ({ row }) => {
|
|
12803
|
+
var _a, _b, _c;
|
|
12804
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
12805
|
+
/* @__PURE__ */ jsx(
|
|
12806
|
+
Thumbnail,
|
|
12807
|
+
{
|
|
12808
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
12809
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
12810
|
+
}
|
|
12811
|
+
),
|
|
12812
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
12813
|
+
] });
|
|
12814
|
+
},
|
|
12815
|
+
enableSorting: true
|
|
12816
|
+
}),
|
|
12817
|
+
columnHelper.accessor("title", {
|
|
12818
|
+
header: "Variant",
|
|
12819
|
+
enableSorting: true
|
|
12820
|
+
}),
|
|
12821
|
+
columnHelper.accessor("sku", {
|
|
12822
|
+
header: "SKU",
|
|
12823
|
+
cell: ({ getValue }) => {
|
|
12824
|
+
return getValue() ?? "-";
|
|
12825
|
+
},
|
|
12826
|
+
enableSorting: true
|
|
12827
|
+
}),
|
|
12828
|
+
columnHelper.accessor("updated_at", {
|
|
12829
|
+
header: "Updated",
|
|
12830
|
+
cell: ({ getValue }) => {
|
|
12831
|
+
return /* @__PURE__ */ jsx(
|
|
12832
|
+
Tooltip,
|
|
12833
|
+
{
|
|
12834
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
12835
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
12836
|
+
}
|
|
12837
|
+
);
|
|
12838
|
+
},
|
|
12839
|
+
enableSorting: true,
|
|
12840
|
+
sortAscLabel: "Oldest first",
|
|
12841
|
+
sortDescLabel: "Newest first"
|
|
12842
|
+
}),
|
|
12843
|
+
columnHelper.accessor("created_at", {
|
|
12844
|
+
header: "Created",
|
|
12845
|
+
cell: ({ getValue }) => {
|
|
12846
|
+
return /* @__PURE__ */ jsx(
|
|
12847
|
+
Tooltip,
|
|
12848
|
+
{
|
|
12849
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
12850
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
12851
|
+
}
|
|
12852
|
+
);
|
|
12853
|
+
},
|
|
12854
|
+
enableSorting: true,
|
|
12855
|
+
sortAscLabel: "Oldest first",
|
|
12856
|
+
sortDescLabel: "Newest first"
|
|
12857
|
+
})
|
|
12858
|
+
];
|
|
12859
|
+
}, []);
|
|
12860
|
+
};
|
|
12861
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
12862
|
+
const { setIsOpen } = useStackedModal();
|
|
12863
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
12864
|
+
const form = useForm({
|
|
12865
|
+
defaultValues: {
|
|
12866
|
+
title: "",
|
|
12867
|
+
quantity: 1,
|
|
12868
|
+
unit_price: ""
|
|
12869
|
+
},
|
|
12870
|
+
resolver: zodResolver(customItemSchema)
|
|
12871
|
+
});
|
|
12872
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12873
|
+
await addItems(
|
|
12874
|
+
{
|
|
12875
|
+
items: [
|
|
12961
12876
|
{
|
|
12962
|
-
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
strokeLinecap: "round",
|
|
12966
|
-
strokeLinejoin: "round"
|
|
12877
|
+
title: data.title,
|
|
12878
|
+
quantity: data.quantity,
|
|
12879
|
+
unit_price: convertNumber(data.unit_price)
|
|
12967
12880
|
}
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12881
|
+
]
|
|
12882
|
+
},
|
|
12883
|
+
{
|
|
12884
|
+
onSuccess: () => {
|
|
12885
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
12886
|
+
},
|
|
12887
|
+
onError: (e) => {
|
|
12888
|
+
toast.error(e.message);
|
|
12889
|
+
}
|
|
12890
|
+
}
|
|
12891
|
+
);
|
|
12892
|
+
});
|
|
12893
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
12894
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
12895
|
+
/* @__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-2 py-16", children: [
|
|
12896
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12897
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
12898
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
12899
|
+
] }),
|
|
12900
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12901
|
+
/* @__PURE__ */ jsx(
|
|
12902
|
+
Form$2.Field,
|
|
12903
|
+
{
|
|
12904
|
+
control: form.control,
|
|
12905
|
+
name: "title",
|
|
12906
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12907
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12908
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
12909
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
12910
|
+
] }),
|
|
12911
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12912
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12913
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12914
|
+
] })
|
|
12915
|
+
] }) })
|
|
12916
|
+
}
|
|
12917
|
+
),
|
|
12918
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12919
|
+
/* @__PURE__ */ jsx(
|
|
12920
|
+
Form$2.Field,
|
|
12921
|
+
{
|
|
12922
|
+
control: form.control,
|
|
12923
|
+
name: "unit_price",
|
|
12924
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12925
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12926
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
12927
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
12928
|
+
] }),
|
|
12929
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12930
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12931
|
+
CurrencyInput,
|
|
12932
|
+
{
|
|
12933
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12934
|
+
code: currencyCode,
|
|
12935
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
12936
|
+
...field
|
|
12937
|
+
}
|
|
12938
|
+
) }),
|
|
12939
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12940
|
+
] })
|
|
12941
|
+
] }) })
|
|
12942
|
+
}
|
|
12943
|
+
),
|
|
12944
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12945
|
+
/* @__PURE__ */ jsx(
|
|
12946
|
+
Form$2.Field,
|
|
12947
|
+
{
|
|
12948
|
+
control: form.control,
|
|
12949
|
+
name: "quantity",
|
|
12950
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12951
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12952
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
12953
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
12954
|
+
] }),
|
|
12955
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
12956
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
12957
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12958
|
+
] })
|
|
12959
|
+
] }) })
|
|
12960
|
+
}
|
|
12961
|
+
)
|
|
12962
|
+
] }) }) }),
|
|
12963
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12964
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12965
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
12966
|
+
] }) })
|
|
12967
|
+
] }) }) });
|
|
12968
|
+
};
|
|
12969
|
+
const customItemSchema = objectType({
|
|
12970
|
+
title: stringType().min(1),
|
|
12971
|
+
quantity: numberType(),
|
|
12972
|
+
unit_price: unionType([numberType(), stringType()])
|
|
12973
|
+
});
|
|
12974
|
+
const Email = () => {
|
|
12975
|
+
const { id } = useParams();
|
|
12976
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12977
|
+
fields: "+email"
|
|
12978
|
+
});
|
|
12979
|
+
if (isError) {
|
|
12980
|
+
throw error;
|
|
12981
|
+
}
|
|
12982
|
+
const isReady = !isPending && !!order;
|
|
12983
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12984
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12985
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
12986
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
12987
|
+
] }),
|
|
12988
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
12989
|
+
] });
|
|
12990
|
+
};
|
|
12991
|
+
const EmailForm = ({ order }) => {
|
|
12992
|
+
const form = useForm({
|
|
12993
|
+
defaultValues: {
|
|
12994
|
+
email: order.email ?? ""
|
|
12995
|
+
},
|
|
12996
|
+
resolver: zodResolver(schema)
|
|
12997
|
+
});
|
|
12998
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12999
|
+
const { handleSuccess } = useRouteModal();
|
|
13000
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
13001
|
+
await mutateAsync(
|
|
13002
|
+
{ email: data.email },
|
|
13003
|
+
{
|
|
13004
|
+
onSuccess: () => {
|
|
13005
|
+
handleSuccess();
|
|
13006
|
+
},
|
|
13007
|
+
onError: (error) => {
|
|
13008
|
+
toast.error(error.message);
|
|
13009
|
+
}
|
|
13010
|
+
}
|
|
13011
|
+
);
|
|
13012
|
+
});
|
|
13013
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
13014
|
+
KeyboundForm,
|
|
13015
|
+
{
|
|
13016
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
13017
|
+
onSubmit,
|
|
13018
|
+
children: [
|
|
13019
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
13020
|
+
Form$2.Field,
|
|
12971
13021
|
{
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
13022
|
+
control: form.control,
|
|
13023
|
+
name: "email",
|
|
13024
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13025
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
13026
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13027
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13028
|
+
] })
|
|
12977
13029
|
}
|
|
12978
13030
|
) }),
|
|
12979
|
-
/* @__PURE__ */ jsxs("
|
|
12980
|
-
/* @__PURE__ */ jsx(
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
width: "12",
|
|
12984
|
-
height: "12",
|
|
12985
|
-
fill: "white",
|
|
12986
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12987
|
-
}
|
|
12988
|
-
) }),
|
|
12989
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12990
|
-
"rect",
|
|
12991
|
-
{
|
|
12992
|
-
width: "12",
|
|
12993
|
-
height: "12",
|
|
12994
|
-
fill: "white",
|
|
12995
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12996
|
-
}
|
|
12997
|
-
) }),
|
|
12998
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12999
|
-
"rect",
|
|
13000
|
-
{
|
|
13001
|
-
width: "12",
|
|
13002
|
-
height: "12",
|
|
13003
|
-
fill: "white",
|
|
13004
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
13005
|
-
}
|
|
13006
|
-
) }),
|
|
13007
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13008
|
-
"rect",
|
|
13009
|
-
{
|
|
13010
|
-
width: "12",
|
|
13011
|
-
height: "12",
|
|
13012
|
-
fill: "white",
|
|
13013
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13014
|
-
}
|
|
13015
|
-
) }),
|
|
13016
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13017
|
-
"rect",
|
|
13018
|
-
{
|
|
13019
|
-
width: "12",
|
|
13020
|
-
height: "12",
|
|
13021
|
-
fill: "white",
|
|
13022
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13023
|
-
}
|
|
13024
|
-
) }),
|
|
13025
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13026
|
-
"rect",
|
|
13027
|
-
{
|
|
13028
|
-
width: "12",
|
|
13029
|
-
height: "12",
|
|
13030
|
-
fill: "white",
|
|
13031
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13032
|
-
}
|
|
13033
|
-
) })
|
|
13034
|
-
] })
|
|
13031
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13032
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13033
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13034
|
+
] }) })
|
|
13035
13035
|
]
|
|
13036
13036
|
}
|
|
13037
|
-
);
|
|
13037
|
+
) });
|
|
13038
13038
|
};
|
|
13039
13039
|
const schema = objectType({
|
|
13040
|
-
|
|
13040
|
+
email: stringType().email()
|
|
13041
13041
|
});
|
|
13042
13042
|
const widgetModule = { widgets: [] };
|
|
13043
13043
|
const routeModule = {
|
|
@@ -13059,30 +13059,18 @@ const routeModule = {
|
|
|
13059
13059
|
handle,
|
|
13060
13060
|
loader,
|
|
13061
13061
|
children: [
|
|
13062
|
-
{
|
|
13063
|
-
Component: BillingAddress,
|
|
13064
|
-
path: "/draft-orders/:id/billing-address"
|
|
13065
|
-
},
|
|
13066
13062
|
{
|
|
13067
13063
|
Component: CustomItems,
|
|
13068
13064
|
path: "/draft-orders/:id/custom-items"
|
|
13069
13065
|
},
|
|
13070
13066
|
{
|
|
13071
|
-
Component:
|
|
13072
|
-
path: "/draft-orders/:id/
|
|
13073
|
-
},
|
|
13074
|
-
{
|
|
13075
|
-
Component: Items,
|
|
13076
|
-
path: "/draft-orders/:id/items"
|
|
13067
|
+
Component: Metadata,
|
|
13068
|
+
path: "/draft-orders/:id/metadata"
|
|
13077
13069
|
},
|
|
13078
13070
|
{
|
|
13079
13071
|
Component: Promotions,
|
|
13080
13072
|
path: "/draft-orders/:id/promotions"
|
|
13081
13073
|
},
|
|
13082
|
-
{
|
|
13083
|
-
Component: Metadata,
|
|
13084
|
-
path: "/draft-orders/:id/metadata"
|
|
13085
|
-
},
|
|
13086
13074
|
{
|
|
13087
13075
|
Component: SalesChannel,
|
|
13088
13076
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13098,6 +13086,18 @@ const routeModule = {
|
|
|
13098
13086
|
{
|
|
13099
13087
|
Component: TransferOwnership,
|
|
13100
13088
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13089
|
+
},
|
|
13090
|
+
{
|
|
13091
|
+
Component: BillingAddress,
|
|
13092
|
+
path: "/draft-orders/:id/billing-address"
|
|
13093
|
+
},
|
|
13094
|
+
{
|
|
13095
|
+
Component: Items,
|
|
13096
|
+
path: "/draft-orders/:id/items"
|
|
13097
|
+
},
|
|
13098
|
+
{
|
|
13099
|
+
Component: Email,
|
|
13100
|
+
path: "/draft-orders/:id/email"
|
|
13101
13101
|
}
|
|
13102
13102
|
]
|
|
13103
13103
|
}
|