@medusajs/draft-order 2.10.2-preview-20250902210158 → 2.10.2-preview-20250903030934
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 +1213 -1213
- package/.medusa/server/src/admin/index.mjs +1214 -1214
- 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, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } 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";
|
|
@@ -9554,6 +9554,196 @@ const ID = () => {
|
|
|
9554
9554
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9555
9555
|
] });
|
|
9556
9556
|
};
|
|
9557
|
+
const BillingAddress = () => {
|
|
9558
|
+
const { id } = useParams();
|
|
9559
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9560
|
+
fields: "+billing_address"
|
|
9561
|
+
});
|
|
9562
|
+
if (isError) {
|
|
9563
|
+
throw error;
|
|
9564
|
+
}
|
|
9565
|
+
const isReady = !isPending && !!order;
|
|
9566
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9567
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9568
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9569
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9570
|
+
] }),
|
|
9571
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9572
|
+
] });
|
|
9573
|
+
};
|
|
9574
|
+
const BillingAddressForm = ({ order }) => {
|
|
9575
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9576
|
+
const form = useForm({
|
|
9577
|
+
defaultValues: {
|
|
9578
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9579
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9580
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9581
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9582
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9583
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9584
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9585
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9586
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9587
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9588
|
+
},
|
|
9589
|
+
resolver: zodResolver(schema$5)
|
|
9590
|
+
});
|
|
9591
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9592
|
+
const { handleSuccess } = useRouteModal();
|
|
9593
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9594
|
+
await mutateAsync(
|
|
9595
|
+
{ billing_address: data },
|
|
9596
|
+
{
|
|
9597
|
+
onSuccess: () => {
|
|
9598
|
+
handleSuccess();
|
|
9599
|
+
},
|
|
9600
|
+
onError: (error) => {
|
|
9601
|
+
toast.error(error.message);
|
|
9602
|
+
}
|
|
9603
|
+
}
|
|
9604
|
+
);
|
|
9605
|
+
});
|
|
9606
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9607
|
+
KeyboundForm,
|
|
9608
|
+
{
|
|
9609
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9610
|
+
onSubmit,
|
|
9611
|
+
children: [
|
|
9612
|
+
/* @__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: [
|
|
9613
|
+
/* @__PURE__ */ jsx(
|
|
9614
|
+
Form$2.Field,
|
|
9615
|
+
{
|
|
9616
|
+
control: form.control,
|
|
9617
|
+
name: "country_code",
|
|
9618
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9619
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9620
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9621
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9622
|
+
] })
|
|
9623
|
+
}
|
|
9624
|
+
),
|
|
9625
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9626
|
+
/* @__PURE__ */ jsx(
|
|
9627
|
+
Form$2.Field,
|
|
9628
|
+
{
|
|
9629
|
+
control: form.control,
|
|
9630
|
+
name: "first_name",
|
|
9631
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9632
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9633
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9634
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9635
|
+
] })
|
|
9636
|
+
}
|
|
9637
|
+
),
|
|
9638
|
+
/* @__PURE__ */ jsx(
|
|
9639
|
+
Form$2.Field,
|
|
9640
|
+
{
|
|
9641
|
+
control: form.control,
|
|
9642
|
+
name: "last_name",
|
|
9643
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9644
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9645
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9646
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9647
|
+
] })
|
|
9648
|
+
}
|
|
9649
|
+
)
|
|
9650
|
+
] }),
|
|
9651
|
+
/* @__PURE__ */ jsx(
|
|
9652
|
+
Form$2.Field,
|
|
9653
|
+
{
|
|
9654
|
+
control: form.control,
|
|
9655
|
+
name: "company",
|
|
9656
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9657
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9658
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9659
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9660
|
+
] })
|
|
9661
|
+
}
|
|
9662
|
+
),
|
|
9663
|
+
/* @__PURE__ */ jsx(
|
|
9664
|
+
Form$2.Field,
|
|
9665
|
+
{
|
|
9666
|
+
control: form.control,
|
|
9667
|
+
name: "address_1",
|
|
9668
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9669
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9670
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9671
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9672
|
+
] })
|
|
9673
|
+
}
|
|
9674
|
+
),
|
|
9675
|
+
/* @__PURE__ */ jsx(
|
|
9676
|
+
Form$2.Field,
|
|
9677
|
+
{
|
|
9678
|
+
control: form.control,
|
|
9679
|
+
name: "address_2",
|
|
9680
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9681
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9682
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9683
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9684
|
+
] })
|
|
9685
|
+
}
|
|
9686
|
+
),
|
|
9687
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9688
|
+
/* @__PURE__ */ jsx(
|
|
9689
|
+
Form$2.Field,
|
|
9690
|
+
{
|
|
9691
|
+
control: form.control,
|
|
9692
|
+
name: "postal_code",
|
|
9693
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9694
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9695
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9696
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9697
|
+
] })
|
|
9698
|
+
}
|
|
9699
|
+
),
|
|
9700
|
+
/* @__PURE__ */ jsx(
|
|
9701
|
+
Form$2.Field,
|
|
9702
|
+
{
|
|
9703
|
+
control: form.control,
|
|
9704
|
+
name: "city",
|
|
9705
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9706
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9707
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9708
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9709
|
+
] })
|
|
9710
|
+
}
|
|
9711
|
+
)
|
|
9712
|
+
] }),
|
|
9713
|
+
/* @__PURE__ */ jsx(
|
|
9714
|
+
Form$2.Field,
|
|
9715
|
+
{
|
|
9716
|
+
control: form.control,
|
|
9717
|
+
name: "province",
|
|
9718
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9719
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9720
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9721
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9722
|
+
] })
|
|
9723
|
+
}
|
|
9724
|
+
),
|
|
9725
|
+
/* @__PURE__ */ jsx(
|
|
9726
|
+
Form$2.Field,
|
|
9727
|
+
{
|
|
9728
|
+
control: form.control,
|
|
9729
|
+
name: "phone",
|
|
9730
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9731
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9732
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9733
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9734
|
+
] })
|
|
9735
|
+
}
|
|
9736
|
+
)
|
|
9737
|
+
] }) }),
|
|
9738
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9739
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9740
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9741
|
+
] }) })
|
|
9742
|
+
]
|
|
9743
|
+
}
|
|
9744
|
+
) });
|
|
9745
|
+
};
|
|
9746
|
+
const schema$5 = addressSchema;
|
|
9557
9747
|
const CustomItems = () => {
|
|
9558
9748
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9559
9749
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9562,7 +9752,7 @@ const CustomItems = () => {
|
|
|
9562
9752
|
};
|
|
9563
9753
|
const CustomItemsForm = () => {
|
|
9564
9754
|
const form = useForm({
|
|
9565
|
-
resolver: zodResolver(schema$
|
|
9755
|
+
resolver: zodResolver(schema$4)
|
|
9566
9756
|
});
|
|
9567
9757
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9568
9758
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9572,7 +9762,7 @@ const CustomItemsForm = () => {
|
|
|
9572
9762
|
] }) })
|
|
9573
9763
|
] }) });
|
|
9574
9764
|
};
|
|
9575
|
-
const schema$
|
|
9765
|
+
const schema$4 = objectType({
|
|
9576
9766
|
email: stringType().email()
|
|
9577
9767
|
});
|
|
9578
9768
|
const Email = () => {
|
|
@@ -9597,7 +9787,7 @@ const EmailForm = ({ order }) => {
|
|
|
9597
9787
|
defaultValues: {
|
|
9598
9788
|
email: order.email ?? ""
|
|
9599
9789
|
},
|
|
9600
|
-
resolver: zodResolver(schema$
|
|
9790
|
+
resolver: zodResolver(schema$3)
|
|
9601
9791
|
});
|
|
9602
9792
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9603
9793
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9640,608 +9830,258 @@ const EmailForm = ({ order }) => {
|
|
|
9640
9830
|
}
|
|
9641
9831
|
) });
|
|
9642
9832
|
};
|
|
9643
|
-
const schema$
|
|
9833
|
+
const schema$3 = objectType({
|
|
9644
9834
|
email: stringType().email()
|
|
9645
9835
|
});
|
|
9646
|
-
const
|
|
9647
|
-
({
|
|
9648
|
-
|
|
9836
|
+
const NumberInput = forwardRef(
|
|
9837
|
+
({
|
|
9838
|
+
value,
|
|
9839
|
+
onChange,
|
|
9840
|
+
size = "base",
|
|
9841
|
+
min = 0,
|
|
9842
|
+
max = 100,
|
|
9843
|
+
step = 1,
|
|
9844
|
+
className,
|
|
9845
|
+
disabled,
|
|
9846
|
+
...props
|
|
9847
|
+
}, ref) => {
|
|
9848
|
+
const handleChange = (event) => {
|
|
9849
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9850
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9851
|
+
onChange(newValue);
|
|
9852
|
+
}
|
|
9853
|
+
};
|
|
9854
|
+
const handleIncrement = () => {
|
|
9855
|
+
const newValue = value + step;
|
|
9856
|
+
if (max === void 0 || newValue <= max) {
|
|
9857
|
+
onChange(newValue);
|
|
9858
|
+
}
|
|
9859
|
+
};
|
|
9860
|
+
const handleDecrement = () => {
|
|
9861
|
+
const newValue = value - step;
|
|
9862
|
+
if (min === void 0 || newValue >= min) {
|
|
9863
|
+
onChange(newValue);
|
|
9864
|
+
}
|
|
9865
|
+
};
|
|
9649
9866
|
return /* @__PURE__ */ jsxs(
|
|
9650
9867
|
"div",
|
|
9651
9868
|
{
|
|
9652
|
-
ref,
|
|
9653
9869
|
className: clx(
|
|
9654
|
-
"
|
|
9870
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9871
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9872
|
+
{
|
|
9873
|
+
"h-7": size === "small",
|
|
9874
|
+
"h-8": size === "base"
|
|
9875
|
+
},
|
|
9655
9876
|
className
|
|
9656
9877
|
),
|
|
9657
|
-
...props,
|
|
9658
9878
|
children: [
|
|
9659
9879
|
/* @__PURE__ */ jsx(
|
|
9660
|
-
"
|
|
9880
|
+
"input",
|
|
9661
9881
|
{
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9882
|
+
ref,
|
|
9883
|
+
type: "number",
|
|
9884
|
+
value,
|
|
9885
|
+
onChange: handleChange,
|
|
9886
|
+
min,
|
|
9887
|
+
max,
|
|
9888
|
+
step,
|
|
9889
|
+
className: clx(
|
|
9890
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
9891
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
9892
|
+
"placeholder:text-ui-fg-muted"
|
|
9893
|
+
),
|
|
9894
|
+
...props
|
|
9895
|
+
}
|
|
9896
|
+
),
|
|
9897
|
+
/* @__PURE__ */ jsxs(
|
|
9898
|
+
"button",
|
|
9899
|
+
{
|
|
9900
|
+
className: clx(
|
|
9901
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
9902
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9903
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
9904
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
9905
|
+
{
|
|
9906
|
+
"size-7": size === "small",
|
|
9907
|
+
"size-8": size === "base"
|
|
9908
|
+
}
|
|
9909
|
+
),
|
|
9910
|
+
type: "button",
|
|
9911
|
+
onClick: handleDecrement,
|
|
9912
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
9913
|
+
children: [
|
|
9914
|
+
/* @__PURE__ */ jsx(Minus, {}),
|
|
9915
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9916
|
+
]
|
|
9917
|
+
}
|
|
9918
|
+
),
|
|
9919
|
+
/* @__PURE__ */ jsxs(
|
|
9920
|
+
"button",
|
|
9921
|
+
{
|
|
9922
|
+
className: clx(
|
|
9923
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
9924
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9925
|
+
"focus:bg-ui-bg-field-hover",
|
|
9926
|
+
"hover:bg-ui-bg-field-hover",
|
|
9927
|
+
{
|
|
9928
|
+
"size-7": size === "small",
|
|
9929
|
+
"size-8": size === "base"
|
|
9930
|
+
}
|
|
9931
|
+
),
|
|
9932
|
+
type: "button",
|
|
9933
|
+
onClick: handleIncrement,
|
|
9934
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
9935
|
+
children: [
|
|
9936
|
+
/* @__PURE__ */ jsx(Plus, {}),
|
|
9937
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
9938
|
+
]
|
|
9939
|
+
}
|
|
9940
|
+
)
|
|
9941
|
+
]
|
|
9942
|
+
}
|
|
9678
9943
|
);
|
|
9679
9944
|
}
|
|
9680
9945
|
);
|
|
9681
|
-
|
|
9682
|
-
const
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
}
|
|
9690
|
-
|
|
9946
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
9947
|
+
const productVariantsQueryKeys = {
|
|
9948
|
+
list: (query2) => [
|
|
9949
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
9950
|
+
query2 ? query2 : void 0
|
|
9951
|
+
]
|
|
9952
|
+
};
|
|
9953
|
+
const useProductVariants = (query2, options) => {
|
|
9954
|
+
const { data, ...rest } = useQuery({
|
|
9955
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
9956
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
9957
|
+
...options
|
|
9958
|
+
});
|
|
9959
|
+
return { ...data, ...rest };
|
|
9960
|
+
};
|
|
9961
|
+
const useCancelOrderEdit = ({ preview }) => {
|
|
9962
|
+
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
9963
|
+
const onCancel = useCallback(async () => {
|
|
9964
|
+
if (!preview) {
|
|
9965
|
+
return true;
|
|
9966
|
+
}
|
|
9967
|
+
let res = false;
|
|
9968
|
+
await cancelOrderEdit(void 0, {
|
|
9969
|
+
onError: (e) => {
|
|
9970
|
+
toast.error(e.message);
|
|
9971
|
+
},
|
|
9972
|
+
onSuccess: () => {
|
|
9973
|
+
res = true;
|
|
9974
|
+
}
|
|
9975
|
+
});
|
|
9976
|
+
return res;
|
|
9977
|
+
}, [preview, cancelOrderEdit]);
|
|
9978
|
+
return { onCancel };
|
|
9979
|
+
};
|
|
9980
|
+
let IS_REQUEST_RUNNING = false;
|
|
9981
|
+
const useInitiateOrderEdit = ({
|
|
9982
|
+
preview
|
|
9983
|
+
}) => {
|
|
9984
|
+
const navigate = useNavigate();
|
|
9985
|
+
const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
|
|
9986
|
+
useEffect(() => {
|
|
9987
|
+
async function run() {
|
|
9988
|
+
if (IS_REQUEST_RUNNING || !preview) {
|
|
9989
|
+
return;
|
|
9990
|
+
}
|
|
9991
|
+
if (preview.order_change) {
|
|
9992
|
+
return;
|
|
9993
|
+
}
|
|
9994
|
+
IS_REQUEST_RUNNING = true;
|
|
9995
|
+
await mutateAsync(void 0, {
|
|
9996
|
+
onError: (e) => {
|
|
9997
|
+
toast.error(e.message);
|
|
9998
|
+
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
9999
|
+
return;
|
|
10000
|
+
}
|
|
10001
|
+
});
|
|
10002
|
+
IS_REQUEST_RUNNING = false;
|
|
10003
|
+
}
|
|
10004
|
+
run();
|
|
10005
|
+
}, [preview, navigate, mutateAsync]);
|
|
10006
|
+
};
|
|
10007
|
+
function convertNumber(value) {
|
|
10008
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10009
|
+
}
|
|
10010
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10011
|
+
const Items = () => {
|
|
9691
10012
|
const { id } = useParams();
|
|
9692
|
-
const {
|
|
9693
|
-
|
|
10013
|
+
const {
|
|
10014
|
+
order: preview,
|
|
10015
|
+
isPending: isPreviewPending,
|
|
10016
|
+
isError: isPreviewError,
|
|
10017
|
+
error: previewError
|
|
10018
|
+
} = useOrderPreview(id, void 0, {
|
|
10019
|
+
placeholderData: keepPreviousData
|
|
9694
10020
|
});
|
|
10021
|
+
useInitiateOrderEdit({ preview });
|
|
10022
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10023
|
+
id,
|
|
10024
|
+
{
|
|
10025
|
+
fields: "currency_code"
|
|
10026
|
+
},
|
|
10027
|
+
{
|
|
10028
|
+
enabled: !!id
|
|
10029
|
+
}
|
|
10030
|
+
);
|
|
10031
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
9695
10032
|
if (isError) {
|
|
9696
10033
|
throw error;
|
|
9697
10034
|
}
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
] });
|
|
10035
|
+
if (isPreviewError) {
|
|
10036
|
+
throw previewError;
|
|
10037
|
+
}
|
|
10038
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
10039
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10040
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
10041
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10042
|
+
] }) });
|
|
9706
10043
|
};
|
|
9707
|
-
const
|
|
9708
|
-
|
|
9709
|
-
const
|
|
10044
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
10045
|
+
var _a;
|
|
10046
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10047
|
+
const [modalContent, setModalContent] = useState(
|
|
10048
|
+
null
|
|
10049
|
+
);
|
|
9710
10050
|
const { handleSuccess } = useRouteModal();
|
|
9711
|
-
const
|
|
9712
|
-
const { mutateAsync
|
|
9713
|
-
const
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
10051
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
10052
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10053
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10054
|
+
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10055
|
+
const matches = useMemo(() => {
|
|
10056
|
+
return matchSorter(preview.items, query2, {
|
|
10057
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10058
|
+
});
|
|
10059
|
+
}, [preview.items, query2]);
|
|
10060
|
+
const onSubmit = async () => {
|
|
10061
|
+
setIsSubmitting(true);
|
|
10062
|
+
let requestSucceeded = false;
|
|
10063
|
+
await requestOrderEdit(void 0, {
|
|
10064
|
+
onError: (e) => {
|
|
10065
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
9724
10066
|
},
|
|
9725
|
-
{
|
|
9726
|
-
|
|
9727
|
-
toast.success("Metadata updated");
|
|
9728
|
-
handleSuccess();
|
|
9729
|
-
},
|
|
9730
|
-
onError: (error) => {
|
|
9731
|
-
toast.error(error.message);
|
|
9732
|
-
}
|
|
10067
|
+
onSuccess: () => {
|
|
10068
|
+
requestSucceeded = true;
|
|
9733
10069
|
}
|
|
9734
|
-
);
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
name: "metadata"
|
|
9739
|
-
});
|
|
9740
|
-
function deleteRow(index) {
|
|
9741
|
-
remove(index);
|
|
9742
|
-
if (fields.length === 1) {
|
|
9743
|
-
insert(0, {
|
|
9744
|
-
key: "",
|
|
9745
|
-
value: "",
|
|
9746
|
-
disabled: false
|
|
9747
|
-
});
|
|
10070
|
+
});
|
|
10071
|
+
if (!requestSucceeded) {
|
|
10072
|
+
setIsSubmitting(false);
|
|
10073
|
+
return;
|
|
9748
10074
|
}
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
{
|
|
9760
|
-
onSubmit: handleSubmit,
|
|
9761
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9762
|
-
children: [
|
|
9763
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9764
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9765
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9766
|
-
/* @__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" }) }),
|
|
9767
|
-
/* @__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" }) })
|
|
9768
|
-
] }),
|
|
9769
|
-
fields.map((field, index) => {
|
|
9770
|
-
const isDisabled = field.disabled || false;
|
|
9771
|
-
let placeholder = "-";
|
|
9772
|
-
if (typeof field.value === "object") {
|
|
9773
|
-
placeholder = "{ ... }";
|
|
9774
|
-
}
|
|
9775
|
-
if (Array.isArray(field.value)) {
|
|
9776
|
-
placeholder = "[ ... ]";
|
|
9777
|
-
}
|
|
9778
|
-
return /* @__PURE__ */ jsx(
|
|
9779
|
-
ConditionalTooltip,
|
|
9780
|
-
{
|
|
9781
|
-
showTooltip: isDisabled,
|
|
9782
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
9783
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9784
|
-
/* @__PURE__ */ jsxs(
|
|
9785
|
-
"div",
|
|
9786
|
-
{
|
|
9787
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
9788
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9789
|
-
}),
|
|
9790
|
-
children: [
|
|
9791
|
-
/* @__PURE__ */ jsx(
|
|
9792
|
-
Form$2.Field,
|
|
9793
|
-
{
|
|
9794
|
-
control: form.control,
|
|
9795
|
-
name: `metadata.${index}.key`,
|
|
9796
|
-
render: ({ field: field2 }) => {
|
|
9797
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9798
|
-
GridInput,
|
|
9799
|
-
{
|
|
9800
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9801
|
-
...field2,
|
|
9802
|
-
disabled: isDisabled,
|
|
9803
|
-
placeholder: "Key"
|
|
9804
|
-
}
|
|
9805
|
-
) }) });
|
|
9806
|
-
}
|
|
9807
|
-
}
|
|
9808
|
-
),
|
|
9809
|
-
/* @__PURE__ */ jsx(
|
|
9810
|
-
Form$2.Field,
|
|
9811
|
-
{
|
|
9812
|
-
control: form.control,
|
|
9813
|
-
name: `metadata.${index}.value`,
|
|
9814
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
9815
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9816
|
-
GridInput,
|
|
9817
|
-
{
|
|
9818
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9819
|
-
...field2,
|
|
9820
|
-
value: isDisabled ? placeholder : value,
|
|
9821
|
-
disabled: isDisabled,
|
|
9822
|
-
placeholder: "Value"
|
|
9823
|
-
}
|
|
9824
|
-
) }) });
|
|
9825
|
-
}
|
|
9826
|
-
}
|
|
9827
|
-
)
|
|
9828
|
-
]
|
|
9829
|
-
}
|
|
9830
|
-
),
|
|
9831
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
9832
|
-
/* @__PURE__ */ jsx(
|
|
9833
|
-
DropdownMenu.Trigger,
|
|
9834
|
-
{
|
|
9835
|
-
className: clx(
|
|
9836
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9837
|
-
{
|
|
9838
|
-
hidden: isDisabled
|
|
9839
|
-
}
|
|
9840
|
-
),
|
|
9841
|
-
disabled: isDisabled,
|
|
9842
|
-
asChild: true,
|
|
9843
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
9844
|
-
}
|
|
9845
|
-
),
|
|
9846
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
9847
|
-
/* @__PURE__ */ jsxs(
|
|
9848
|
-
DropdownMenu.Item,
|
|
9849
|
-
{
|
|
9850
|
-
className: "gap-x-2",
|
|
9851
|
-
onClick: () => insertRow(index, "above"),
|
|
9852
|
-
children: [
|
|
9853
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9854
|
-
"Insert row above"
|
|
9855
|
-
]
|
|
9856
|
-
}
|
|
9857
|
-
),
|
|
9858
|
-
/* @__PURE__ */ jsxs(
|
|
9859
|
-
DropdownMenu.Item,
|
|
9860
|
-
{
|
|
9861
|
-
className: "gap-x-2",
|
|
9862
|
-
onClick: () => insertRow(index, "below"),
|
|
9863
|
-
children: [
|
|
9864
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9865
|
-
"Insert row below"
|
|
9866
|
-
]
|
|
9867
|
-
}
|
|
9868
|
-
),
|
|
9869
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
9870
|
-
/* @__PURE__ */ jsxs(
|
|
9871
|
-
DropdownMenu.Item,
|
|
9872
|
-
{
|
|
9873
|
-
className: "gap-x-2",
|
|
9874
|
-
onClick: () => deleteRow(index),
|
|
9875
|
-
children: [
|
|
9876
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
9877
|
-
"Delete row"
|
|
9878
|
-
]
|
|
9879
|
-
}
|
|
9880
|
-
)
|
|
9881
|
-
] })
|
|
9882
|
-
] })
|
|
9883
|
-
] })
|
|
9884
|
-
},
|
|
9885
|
-
field.id
|
|
9886
|
-
);
|
|
9887
|
-
})
|
|
9888
|
-
] }),
|
|
9889
|
-
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." })
|
|
9890
|
-
] }),
|
|
9891
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9892
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9893
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9894
|
-
] }) })
|
|
9895
|
-
]
|
|
9896
|
-
}
|
|
9897
|
-
) });
|
|
9898
|
-
};
|
|
9899
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
9900
|
-
return /* @__PURE__ */ jsx(
|
|
9901
|
-
"input",
|
|
9902
|
-
{
|
|
9903
|
-
ref,
|
|
9904
|
-
...props,
|
|
9905
|
-
autoComplete: "off",
|
|
9906
|
-
className: clx(
|
|
9907
|
-
"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",
|
|
9908
|
-
className
|
|
9909
|
-
)
|
|
9910
|
-
}
|
|
9911
|
-
);
|
|
9912
|
-
});
|
|
9913
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
9914
|
-
const PlaceholderInner = () => {
|
|
9915
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
9916
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
9917
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9918
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
9919
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
9920
|
-
] }) })
|
|
9921
|
-
] });
|
|
9922
|
-
};
|
|
9923
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
9924
|
-
function getDefaultValues(metadata) {
|
|
9925
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
9926
|
-
return [
|
|
9927
|
-
{
|
|
9928
|
-
key: "",
|
|
9929
|
-
value: "",
|
|
9930
|
-
disabled: false
|
|
9931
|
-
}
|
|
9932
|
-
];
|
|
9933
|
-
}
|
|
9934
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
9935
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
9936
|
-
return {
|
|
9937
|
-
key,
|
|
9938
|
-
value,
|
|
9939
|
-
disabled: true
|
|
9940
|
-
};
|
|
9941
|
-
}
|
|
9942
|
-
let stringValue = value;
|
|
9943
|
-
if (typeof value !== "string") {
|
|
9944
|
-
stringValue = JSON.stringify(value);
|
|
9945
|
-
}
|
|
9946
|
-
return {
|
|
9947
|
-
key,
|
|
9948
|
-
value: stringValue,
|
|
9949
|
-
original_key: key
|
|
9950
|
-
};
|
|
9951
|
-
});
|
|
9952
|
-
}
|
|
9953
|
-
function parseValues(values) {
|
|
9954
|
-
const metadata = values.metadata;
|
|
9955
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
9956
|
-
if (isEmpty) {
|
|
9957
|
-
return null;
|
|
9958
|
-
}
|
|
9959
|
-
const update = {};
|
|
9960
|
-
metadata.forEach((field) => {
|
|
9961
|
-
let key = field.key;
|
|
9962
|
-
let value = field.value;
|
|
9963
|
-
const disabled = field.disabled;
|
|
9964
|
-
if (!key || !value) {
|
|
9965
|
-
return;
|
|
9966
|
-
}
|
|
9967
|
-
if (disabled) {
|
|
9968
|
-
update[key] = value;
|
|
9969
|
-
return;
|
|
9970
|
-
}
|
|
9971
|
-
key = key.trim();
|
|
9972
|
-
value = value.trim();
|
|
9973
|
-
if (value === "true") {
|
|
9974
|
-
update[key] = true;
|
|
9975
|
-
} else if (value === "false") {
|
|
9976
|
-
update[key] = false;
|
|
9977
|
-
} else {
|
|
9978
|
-
const parsedNumber = parseFloat(value);
|
|
9979
|
-
if (!isNaN(parsedNumber)) {
|
|
9980
|
-
update[key] = parsedNumber;
|
|
9981
|
-
} else {
|
|
9982
|
-
update[key] = value;
|
|
9983
|
-
}
|
|
9984
|
-
}
|
|
9985
|
-
});
|
|
9986
|
-
return update;
|
|
9987
|
-
}
|
|
9988
|
-
function getHasUneditableRows(metadata) {
|
|
9989
|
-
if (!metadata) {
|
|
9990
|
-
return false;
|
|
9991
|
-
}
|
|
9992
|
-
return Object.values(metadata).some(
|
|
9993
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
9994
|
-
);
|
|
9995
|
-
}
|
|
9996
|
-
const NumberInput = forwardRef(
|
|
9997
|
-
({
|
|
9998
|
-
value,
|
|
9999
|
-
onChange,
|
|
10000
|
-
size = "base",
|
|
10001
|
-
min = 0,
|
|
10002
|
-
max = 100,
|
|
10003
|
-
step = 1,
|
|
10004
|
-
className,
|
|
10005
|
-
disabled,
|
|
10006
|
-
...props
|
|
10007
|
-
}, ref) => {
|
|
10008
|
-
const handleChange = (event) => {
|
|
10009
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
10010
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
10011
|
-
onChange(newValue);
|
|
10012
|
-
}
|
|
10013
|
-
};
|
|
10014
|
-
const handleIncrement = () => {
|
|
10015
|
-
const newValue = value + step;
|
|
10016
|
-
if (max === void 0 || newValue <= max) {
|
|
10017
|
-
onChange(newValue);
|
|
10018
|
-
}
|
|
10019
|
-
};
|
|
10020
|
-
const handleDecrement = () => {
|
|
10021
|
-
const newValue = value - step;
|
|
10022
|
-
if (min === void 0 || newValue >= min) {
|
|
10023
|
-
onChange(newValue);
|
|
10024
|
-
}
|
|
10025
|
-
};
|
|
10026
|
-
return /* @__PURE__ */ jsxs(
|
|
10027
|
-
"div",
|
|
10028
|
-
{
|
|
10029
|
-
className: clx(
|
|
10030
|
-
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
10031
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
10032
|
-
{
|
|
10033
|
-
"h-7": size === "small",
|
|
10034
|
-
"h-8": size === "base"
|
|
10035
|
-
},
|
|
10036
|
-
className
|
|
10037
|
-
),
|
|
10038
|
-
children: [
|
|
10039
|
-
/* @__PURE__ */ jsx(
|
|
10040
|
-
"input",
|
|
10041
|
-
{
|
|
10042
|
-
ref,
|
|
10043
|
-
type: "number",
|
|
10044
|
-
value,
|
|
10045
|
-
onChange: handleChange,
|
|
10046
|
-
min,
|
|
10047
|
-
max,
|
|
10048
|
-
step,
|
|
10049
|
-
className: clx(
|
|
10050
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
10051
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
10052
|
-
"placeholder:text-ui-fg-muted"
|
|
10053
|
-
),
|
|
10054
|
-
...props
|
|
10055
|
-
}
|
|
10056
|
-
),
|
|
10057
|
-
/* @__PURE__ */ jsxs(
|
|
10058
|
-
"button",
|
|
10059
|
-
{
|
|
10060
|
-
className: clx(
|
|
10061
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
10062
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10063
|
-
"focus:bg-ui-bg-field-component-hover",
|
|
10064
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
10065
|
-
{
|
|
10066
|
-
"size-7": size === "small",
|
|
10067
|
-
"size-8": size === "base"
|
|
10068
|
-
}
|
|
10069
|
-
),
|
|
10070
|
-
type: "button",
|
|
10071
|
-
onClick: handleDecrement,
|
|
10072
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
10073
|
-
children: [
|
|
10074
|
-
/* @__PURE__ */ jsx(Minus, {}),
|
|
10075
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
10076
|
-
]
|
|
10077
|
-
}
|
|
10078
|
-
),
|
|
10079
|
-
/* @__PURE__ */ jsxs(
|
|
10080
|
-
"button",
|
|
10081
|
-
{
|
|
10082
|
-
className: clx(
|
|
10083
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
10084
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10085
|
-
"focus:bg-ui-bg-field-hover",
|
|
10086
|
-
"hover:bg-ui-bg-field-hover",
|
|
10087
|
-
{
|
|
10088
|
-
"size-7": size === "small",
|
|
10089
|
-
"size-8": size === "base"
|
|
10090
|
-
}
|
|
10091
|
-
),
|
|
10092
|
-
type: "button",
|
|
10093
|
-
onClick: handleIncrement,
|
|
10094
|
-
disabled: max !== void 0 && value >= max || disabled,
|
|
10095
|
-
children: [
|
|
10096
|
-
/* @__PURE__ */ jsx(Plus, {}),
|
|
10097
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
10098
|
-
]
|
|
10099
|
-
}
|
|
10100
|
-
)
|
|
10101
|
-
]
|
|
10102
|
-
}
|
|
10103
|
-
);
|
|
10104
|
-
}
|
|
10105
|
-
);
|
|
10106
|
-
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
10107
|
-
const productVariantsQueryKeys = {
|
|
10108
|
-
list: (query2) => [
|
|
10109
|
-
PRODUCT_VARIANTS_QUERY_KEY,
|
|
10110
|
-
query2 ? query2 : void 0
|
|
10111
|
-
]
|
|
10112
|
-
};
|
|
10113
|
-
const useProductVariants = (query2, options) => {
|
|
10114
|
-
const { data, ...rest } = useQuery({
|
|
10115
|
-
queryKey: productVariantsQueryKeys.list(query2),
|
|
10116
|
-
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
10117
|
-
...options
|
|
10118
|
-
});
|
|
10119
|
-
return { ...data, ...rest };
|
|
10120
|
-
};
|
|
10121
|
-
const useCancelOrderEdit = ({ preview }) => {
|
|
10122
|
-
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
10123
|
-
const onCancel = useCallback(async () => {
|
|
10124
|
-
if (!preview) {
|
|
10125
|
-
return true;
|
|
10126
|
-
}
|
|
10127
|
-
let res = false;
|
|
10128
|
-
await cancelOrderEdit(void 0, {
|
|
10129
|
-
onError: (e) => {
|
|
10130
|
-
toast.error(e.message);
|
|
10131
|
-
},
|
|
10132
|
-
onSuccess: () => {
|
|
10133
|
-
res = true;
|
|
10134
|
-
}
|
|
10135
|
-
});
|
|
10136
|
-
return res;
|
|
10137
|
-
}, [preview, cancelOrderEdit]);
|
|
10138
|
-
return { onCancel };
|
|
10139
|
-
};
|
|
10140
|
-
let IS_REQUEST_RUNNING = false;
|
|
10141
|
-
const useInitiateOrderEdit = ({
|
|
10142
|
-
preview
|
|
10143
|
-
}) => {
|
|
10144
|
-
const navigate = useNavigate();
|
|
10145
|
-
const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
|
|
10146
|
-
useEffect(() => {
|
|
10147
|
-
async function run() {
|
|
10148
|
-
if (IS_REQUEST_RUNNING || !preview) {
|
|
10149
|
-
return;
|
|
10150
|
-
}
|
|
10151
|
-
if (preview.order_change) {
|
|
10152
|
-
return;
|
|
10153
|
-
}
|
|
10154
|
-
IS_REQUEST_RUNNING = true;
|
|
10155
|
-
await mutateAsync(void 0, {
|
|
10156
|
-
onError: (e) => {
|
|
10157
|
-
toast.error(e.message);
|
|
10158
|
-
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
10159
|
-
return;
|
|
10160
|
-
}
|
|
10161
|
-
});
|
|
10162
|
-
IS_REQUEST_RUNNING = false;
|
|
10163
|
-
}
|
|
10164
|
-
run();
|
|
10165
|
-
}, [preview, navigate, mutateAsync]);
|
|
10166
|
-
};
|
|
10167
|
-
function convertNumber(value) {
|
|
10168
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10169
|
-
}
|
|
10170
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10171
|
-
const Items = () => {
|
|
10172
|
-
const { id } = useParams();
|
|
10173
|
-
const {
|
|
10174
|
-
order: preview,
|
|
10175
|
-
isPending: isPreviewPending,
|
|
10176
|
-
isError: isPreviewError,
|
|
10177
|
-
error: previewError
|
|
10178
|
-
} = useOrderPreview(id, void 0, {
|
|
10179
|
-
placeholderData: keepPreviousData
|
|
10180
|
-
});
|
|
10181
|
-
useInitiateOrderEdit({ preview });
|
|
10182
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10183
|
-
id,
|
|
10184
|
-
{
|
|
10185
|
-
fields: "currency_code"
|
|
10186
|
-
},
|
|
10187
|
-
{
|
|
10188
|
-
enabled: !!id
|
|
10189
|
-
}
|
|
10190
|
-
);
|
|
10191
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10192
|
-
if (isError) {
|
|
10193
|
-
throw error;
|
|
10194
|
-
}
|
|
10195
|
-
if (isPreviewError) {
|
|
10196
|
-
throw previewError;
|
|
10197
|
-
}
|
|
10198
|
-
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
10199
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10200
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
10201
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10202
|
-
] }) });
|
|
10203
|
-
};
|
|
10204
|
-
const ItemsForm = ({ preview, currencyCode }) => {
|
|
10205
|
-
var _a;
|
|
10206
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10207
|
-
const [modalContent, setModalContent] = useState(
|
|
10208
|
-
null
|
|
10209
|
-
);
|
|
10210
|
-
const { handleSuccess } = useRouteModal();
|
|
10211
|
-
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
10212
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10213
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10214
|
-
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10215
|
-
const matches = useMemo(() => {
|
|
10216
|
-
return matchSorter(preview.items, query2, {
|
|
10217
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10218
|
-
});
|
|
10219
|
-
}, [preview.items, query2]);
|
|
10220
|
-
const onSubmit = async () => {
|
|
10221
|
-
setIsSubmitting(true);
|
|
10222
|
-
let requestSucceeded = false;
|
|
10223
|
-
await requestOrderEdit(void 0, {
|
|
10224
|
-
onError: (e) => {
|
|
10225
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
10226
|
-
},
|
|
10227
|
-
onSuccess: () => {
|
|
10228
|
-
requestSucceeded = true;
|
|
10229
|
-
}
|
|
10230
|
-
});
|
|
10231
|
-
if (!requestSucceeded) {
|
|
10232
|
-
setIsSubmitting(false);
|
|
10233
|
-
return;
|
|
10234
|
-
}
|
|
10235
|
-
await confirmOrderEdit(void 0, {
|
|
10236
|
-
onError: (e) => {
|
|
10237
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10238
|
-
},
|
|
10239
|
-
onSuccess: () => {
|
|
10240
|
-
handleSuccess();
|
|
10241
|
-
},
|
|
10242
|
-
onSettled: () => {
|
|
10243
|
-
setIsSubmitting(false);
|
|
10244
|
-
}
|
|
10075
|
+
await confirmOrderEdit(void 0, {
|
|
10076
|
+
onError: (e) => {
|
|
10077
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10078
|
+
},
|
|
10079
|
+
onSuccess: () => {
|
|
10080
|
+
handleSuccess();
|
|
10081
|
+
},
|
|
10082
|
+
onSettled: () => {
|
|
10083
|
+
setIsSubmitting(false);
|
|
10084
|
+
}
|
|
10245
10085
|
});
|
|
10246
10086
|
};
|
|
10247
10087
|
const onKeyDown = useCallback(
|
|
@@ -10398,20 +10238,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10398
10238
|
const [editing, setEditing] = useState(false);
|
|
10399
10239
|
const form = useForm({
|
|
10400
10240
|
defaultValues: {
|
|
10401
|
-
quantity: item.quantity,
|
|
10402
|
-
unit_price: item.unit_price
|
|
10241
|
+
quantity: item.quantity,
|
|
10242
|
+
unit_price: item.unit_price
|
|
10243
|
+
},
|
|
10244
|
+
resolver: zodResolver(variantItemSchema)
|
|
10245
|
+
});
|
|
10246
|
+
const actionId = useMemo(() => {
|
|
10247
|
+
var _a, _b;
|
|
10248
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10249
|
+
}, [item]);
|
|
10250
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10251
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10252
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10253
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10254
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10255
|
+
setEditing(false);
|
|
10256
|
+
return;
|
|
10257
|
+
}
|
|
10258
|
+
if (!actionId) {
|
|
10259
|
+
await updateOriginalItem(
|
|
10260
|
+
{
|
|
10261
|
+
item_id: item.id,
|
|
10262
|
+
quantity: data.quantity,
|
|
10263
|
+
unit_price: convertNumber(data.unit_price)
|
|
10264
|
+
},
|
|
10265
|
+
{
|
|
10266
|
+
onSuccess: () => {
|
|
10267
|
+
setEditing(false);
|
|
10268
|
+
},
|
|
10269
|
+
onError: (e) => {
|
|
10270
|
+
toast.error(e.message);
|
|
10271
|
+
}
|
|
10272
|
+
}
|
|
10273
|
+
);
|
|
10274
|
+
return;
|
|
10275
|
+
}
|
|
10276
|
+
await updateActionItem(
|
|
10277
|
+
{
|
|
10278
|
+
action_id: actionId,
|
|
10279
|
+
quantity: data.quantity,
|
|
10280
|
+
unit_price: convertNumber(data.unit_price)
|
|
10281
|
+
},
|
|
10282
|
+
{
|
|
10283
|
+
onSuccess: () => {
|
|
10284
|
+
setEditing(false);
|
|
10285
|
+
},
|
|
10286
|
+
onError: (e) => {
|
|
10287
|
+
toast.error(e.message);
|
|
10288
|
+
}
|
|
10289
|
+
}
|
|
10290
|
+
);
|
|
10291
|
+
});
|
|
10292
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
|
|
10293
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
|
|
10294
|
+
/* @__PURE__ */ jsx(
|
|
10295
|
+
Thumbnail,
|
|
10296
|
+
{
|
|
10297
|
+
thumbnail: item.thumbnail,
|
|
10298
|
+
alt: item.product_title ?? void 0
|
|
10299
|
+
}
|
|
10300
|
+
),
|
|
10301
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10302
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
10303
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
10304
|
+
/* @__PURE__ */ jsxs(
|
|
10305
|
+
Text,
|
|
10306
|
+
{
|
|
10307
|
+
size: "small",
|
|
10308
|
+
leading: "compact",
|
|
10309
|
+
className: "text-ui-fg-subtle",
|
|
10310
|
+
children: [
|
|
10311
|
+
"(",
|
|
10312
|
+
item.variant_title,
|
|
10313
|
+
")"
|
|
10314
|
+
]
|
|
10315
|
+
}
|
|
10316
|
+
)
|
|
10317
|
+
] }),
|
|
10318
|
+
/* @__PURE__ */ jsx(
|
|
10319
|
+
Text,
|
|
10320
|
+
{
|
|
10321
|
+
size: "small",
|
|
10322
|
+
leading: "compact",
|
|
10323
|
+
className: "text-ui-fg-subtle",
|
|
10324
|
+
children: item.variant_sku
|
|
10325
|
+
}
|
|
10326
|
+
)
|
|
10327
|
+
] })
|
|
10328
|
+
] }),
|
|
10329
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
|
|
10330
|
+
Form$2.Field,
|
|
10331
|
+
{
|
|
10332
|
+
control: form.control,
|
|
10333
|
+
name: "quantity",
|
|
10334
|
+
render: ({ field }) => {
|
|
10335
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
10336
|
+
}
|
|
10337
|
+
}
|
|
10338
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
10339
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
|
|
10340
|
+
Form$2.Field,
|
|
10341
|
+
{
|
|
10342
|
+
control: form.control,
|
|
10343
|
+
name: "unit_price",
|
|
10344
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
10345
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10346
|
+
CurrencyInput,
|
|
10347
|
+
{
|
|
10348
|
+
...field,
|
|
10349
|
+
symbol: getNativeSymbol(currencyCode),
|
|
10350
|
+
code: currencyCode,
|
|
10351
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10352
|
+
}
|
|
10353
|
+
) }) });
|
|
10354
|
+
}
|
|
10355
|
+
}
|
|
10356
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10357
|
+
/* @__PURE__ */ jsx(
|
|
10358
|
+
IconButton,
|
|
10359
|
+
{
|
|
10360
|
+
type: "button",
|
|
10361
|
+
size: "small",
|
|
10362
|
+
onClick: editing ? onSubmit : () => {
|
|
10363
|
+
setEditing(true);
|
|
10364
|
+
},
|
|
10365
|
+
disabled: isPending,
|
|
10366
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10367
|
+
}
|
|
10368
|
+
)
|
|
10369
|
+
] }) }) });
|
|
10370
|
+
};
|
|
10371
|
+
const variantItemSchema = objectType({
|
|
10372
|
+
quantity: numberType(),
|
|
10373
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10374
|
+
});
|
|
10375
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
10376
|
+
const [editing, setEditing] = useState(false);
|
|
10377
|
+
const { quantity, unit_price, title } = item;
|
|
10378
|
+
const form = useForm({
|
|
10379
|
+
defaultValues: {
|
|
10380
|
+
title,
|
|
10381
|
+
quantity,
|
|
10382
|
+
unit_price
|
|
10403
10383
|
},
|
|
10404
|
-
resolver: zodResolver(
|
|
10384
|
+
resolver: zodResolver(customItemSchema)
|
|
10405
10385
|
});
|
|
10386
|
+
useEffect(() => {
|
|
10387
|
+
form.reset({
|
|
10388
|
+
title,
|
|
10389
|
+
quantity,
|
|
10390
|
+
unit_price
|
|
10391
|
+
});
|
|
10392
|
+
}, [form, title, quantity, unit_price]);
|
|
10406
10393
|
const actionId = useMemo(() => {
|
|
10407
10394
|
var _a, _b;
|
|
10408
10395
|
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10409
10396
|
}, [item]);
|
|
10410
10397
|
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10398
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10411
10399
|
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10412
10400
|
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10413
10401
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10414
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10402
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
10415
10403
|
setEditing(false);
|
|
10416
10404
|
return;
|
|
10417
10405
|
}
|
|
@@ -10433,6 +10421,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10433
10421
|
);
|
|
10434
10422
|
return;
|
|
10435
10423
|
}
|
|
10424
|
+
if (data.quantity === 0) {
|
|
10425
|
+
await removeActionItem(actionId, {
|
|
10426
|
+
onSuccess: () => {
|
|
10427
|
+
setEditing(false);
|
|
10428
|
+
},
|
|
10429
|
+
onError: (e) => {
|
|
10430
|
+
toast.error(e.message);
|
|
10431
|
+
}
|
|
10432
|
+
});
|
|
10433
|
+
return;
|
|
10434
|
+
}
|
|
10436
10435
|
await updateActionItem(
|
|
10437
10436
|
{
|
|
10438
10437
|
action_id: actionId,
|
|
@@ -10450,43 +10449,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10450
10449
|
);
|
|
10451
10450
|
});
|
|
10452
10451
|
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
|
|
10453
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3
|
|
10452
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
10454
10453
|
/* @__PURE__ */ jsx(
|
|
10455
10454
|
Thumbnail,
|
|
10456
10455
|
{
|
|
10457
10456
|
thumbnail: item.thumbnail,
|
|
10458
|
-
alt: item.
|
|
10457
|
+
alt: item.title ?? void 0
|
|
10459
10458
|
}
|
|
10460
10459
|
),
|
|
10461
|
-
/* @__PURE__ */
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
leading: "compact",
|
|
10469
|
-
className: "text-ui-fg-subtle",
|
|
10470
|
-
children: [
|
|
10471
|
-
"(",
|
|
10472
|
-
item.variant_title,
|
|
10473
|
-
")"
|
|
10474
|
-
]
|
|
10475
|
-
}
|
|
10476
|
-
)
|
|
10477
|
-
] }),
|
|
10478
|
-
/* @__PURE__ */ jsx(
|
|
10479
|
-
Text,
|
|
10480
|
-
{
|
|
10481
|
-
size: "small",
|
|
10482
|
-
leading: "compact",
|
|
10483
|
-
className: "text-ui-fg-subtle",
|
|
10484
|
-
children: item.variant_sku
|
|
10460
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10461
|
+
Form$2.Field,
|
|
10462
|
+
{
|
|
10463
|
+
control: form.control,
|
|
10464
|
+
name: "title",
|
|
10465
|
+
render: ({ field }) => {
|
|
10466
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
10485
10467
|
}
|
|
10486
|
-
|
|
10487
|
-
|
|
10468
|
+
}
|
|
10469
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
10488
10470
|
] }),
|
|
10489
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10471
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10490
10472
|
Form$2.Field,
|
|
10491
10473
|
{
|
|
10492
10474
|
control: form.control,
|
|
@@ -10495,8 +10477,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10495
10477
|
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
10496
10478
|
}
|
|
10497
10479
|
}
|
|
10498
|
-
)
|
|
10499
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10480
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
10481
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10500
10482
|
Form$2.Field,
|
|
10501
10483
|
{
|
|
10502
10484
|
control: form.control,
|
|
@@ -10513,7 +10495,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10513
10495
|
) }) });
|
|
10514
10496
|
}
|
|
10515
10497
|
}
|
|
10516
|
-
)
|
|
10498
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10517
10499
|
/* @__PURE__ */ jsx(
|
|
10518
10500
|
IconButton,
|
|
10519
10501
|
{
|
|
@@ -10522,85 +10504,221 @@ const VariantItem = ({ item, preview, currencyCode }) => {
|
|
|
10522
10504
|
onClick: editing ? onSubmit : () => {
|
|
10523
10505
|
setEditing(true);
|
|
10524
10506
|
},
|
|
10525
|
-
disabled: isPending,
|
|
10526
|
-
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10527
|
-
}
|
|
10528
|
-
)
|
|
10529
|
-
] }) }) });
|
|
10507
|
+
disabled: isPending,
|
|
10508
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10509
|
+
}
|
|
10510
|
+
)
|
|
10511
|
+
] }) }) });
|
|
10512
|
+
};
|
|
10513
|
+
const StackedModalTrigger$1 = ({
|
|
10514
|
+
type,
|
|
10515
|
+
setModalContent
|
|
10516
|
+
}) => {
|
|
10517
|
+
const { setIsOpen } = useStackedModal();
|
|
10518
|
+
const onClick = useCallback(() => {
|
|
10519
|
+
setModalContent(type);
|
|
10520
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
10521
|
+
}, [setModalContent, setIsOpen, type]);
|
|
10522
|
+
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
10523
|
+
};
|
|
10524
|
+
const VARIANT_PREFIX = "items";
|
|
10525
|
+
const LIMIT = 50;
|
|
10526
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
10527
|
+
const { setIsOpen } = useStackedModal();
|
|
10528
|
+
const [rowSelection, setRowSelection] = useState(
|
|
10529
|
+
items.reduce((acc, item) => {
|
|
10530
|
+
acc[item.variant_id] = true;
|
|
10531
|
+
return acc;
|
|
10532
|
+
}, {})
|
|
10533
|
+
);
|
|
10534
|
+
useEffect(() => {
|
|
10535
|
+
setRowSelection(
|
|
10536
|
+
items.reduce((acc, item) => {
|
|
10537
|
+
if (item.variant_id) {
|
|
10538
|
+
acc[item.variant_id] = true;
|
|
10539
|
+
}
|
|
10540
|
+
return acc;
|
|
10541
|
+
}, {})
|
|
10542
|
+
);
|
|
10543
|
+
}, [items]);
|
|
10544
|
+
const { q, order, offset } = useQueryParams(
|
|
10545
|
+
["q", "order", "offset"],
|
|
10546
|
+
VARIANT_PREFIX
|
|
10547
|
+
);
|
|
10548
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10549
|
+
{
|
|
10550
|
+
q,
|
|
10551
|
+
order,
|
|
10552
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
10553
|
+
limit: LIMIT
|
|
10554
|
+
},
|
|
10555
|
+
{
|
|
10556
|
+
placeholderData: keepPreviousData
|
|
10557
|
+
}
|
|
10558
|
+
);
|
|
10559
|
+
const columns = useColumns();
|
|
10560
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10561
|
+
const onSubmit = async () => {
|
|
10562
|
+
const ids = Object.keys(rowSelection).filter(
|
|
10563
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
10564
|
+
);
|
|
10565
|
+
await mutateAsync(
|
|
10566
|
+
{
|
|
10567
|
+
items: ids.map((id) => ({
|
|
10568
|
+
variant_id: id,
|
|
10569
|
+
quantity: 1
|
|
10570
|
+
}))
|
|
10571
|
+
},
|
|
10572
|
+
{
|
|
10573
|
+
onSuccess: () => {
|
|
10574
|
+
setRowSelection({});
|
|
10575
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
10576
|
+
},
|
|
10577
|
+
onError: (e) => {
|
|
10578
|
+
toast.error(e.message);
|
|
10579
|
+
}
|
|
10580
|
+
}
|
|
10581
|
+
);
|
|
10582
|
+
};
|
|
10583
|
+
if (isError) {
|
|
10584
|
+
throw error;
|
|
10585
|
+
}
|
|
10586
|
+
return /* @__PURE__ */ jsxs(
|
|
10587
|
+
StackedFocusModal.Content,
|
|
10588
|
+
{
|
|
10589
|
+
onOpenAutoFocus: (e) => {
|
|
10590
|
+
e.preventDefault();
|
|
10591
|
+
const searchInput = document.querySelector(
|
|
10592
|
+
"[data-modal-id='modal-search-input']"
|
|
10593
|
+
);
|
|
10594
|
+
if (searchInput) {
|
|
10595
|
+
searchInput.focus();
|
|
10596
|
+
}
|
|
10597
|
+
},
|
|
10598
|
+
children: [
|
|
10599
|
+
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
10600
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
10601
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
10602
|
+
] }),
|
|
10603
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
10604
|
+
DataTable,
|
|
10605
|
+
{
|
|
10606
|
+
data: variants,
|
|
10607
|
+
columns,
|
|
10608
|
+
isLoading: isPending,
|
|
10609
|
+
getRowId: (row) => row.id,
|
|
10610
|
+
rowCount: count,
|
|
10611
|
+
prefix: VARIANT_PREFIX,
|
|
10612
|
+
layout: "fill",
|
|
10613
|
+
rowSelection: {
|
|
10614
|
+
state: rowSelection,
|
|
10615
|
+
onRowSelectionChange: setRowSelection,
|
|
10616
|
+
enableRowSelection: (row) => {
|
|
10617
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
10618
|
+
}
|
|
10619
|
+
},
|
|
10620
|
+
autoFocusSearch: true
|
|
10621
|
+
}
|
|
10622
|
+
) }),
|
|
10623
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10624
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10625
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
10626
|
+
] }) })
|
|
10627
|
+
]
|
|
10628
|
+
}
|
|
10629
|
+
);
|
|
10630
|
+
};
|
|
10631
|
+
const columnHelper = createDataTableColumnHelper();
|
|
10632
|
+
const useColumns = () => {
|
|
10633
|
+
return useMemo(() => {
|
|
10634
|
+
return [
|
|
10635
|
+
columnHelper.select(),
|
|
10636
|
+
columnHelper.accessor("product.title", {
|
|
10637
|
+
header: "Product",
|
|
10638
|
+
cell: ({ row }) => {
|
|
10639
|
+
var _a, _b, _c;
|
|
10640
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10641
|
+
/* @__PURE__ */ jsx(
|
|
10642
|
+
Thumbnail,
|
|
10643
|
+
{
|
|
10644
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
10645
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
10646
|
+
}
|
|
10647
|
+
),
|
|
10648
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10649
|
+
] });
|
|
10650
|
+
},
|
|
10651
|
+
enableSorting: true
|
|
10652
|
+
}),
|
|
10653
|
+
columnHelper.accessor("title", {
|
|
10654
|
+
header: "Variant",
|
|
10655
|
+
enableSorting: true
|
|
10656
|
+
}),
|
|
10657
|
+
columnHelper.accessor("sku", {
|
|
10658
|
+
header: "SKU",
|
|
10659
|
+
cell: ({ getValue }) => {
|
|
10660
|
+
return getValue() ?? "-";
|
|
10661
|
+
},
|
|
10662
|
+
enableSorting: true
|
|
10663
|
+
}),
|
|
10664
|
+
columnHelper.accessor("updated_at", {
|
|
10665
|
+
header: "Updated",
|
|
10666
|
+
cell: ({ getValue }) => {
|
|
10667
|
+
return /* @__PURE__ */ jsx(
|
|
10668
|
+
Tooltip,
|
|
10669
|
+
{
|
|
10670
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10671
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10672
|
+
}
|
|
10673
|
+
);
|
|
10674
|
+
},
|
|
10675
|
+
enableSorting: true,
|
|
10676
|
+
sortAscLabel: "Oldest first",
|
|
10677
|
+
sortDescLabel: "Newest first"
|
|
10678
|
+
}),
|
|
10679
|
+
columnHelper.accessor("created_at", {
|
|
10680
|
+
header: "Created",
|
|
10681
|
+
cell: ({ getValue }) => {
|
|
10682
|
+
return /* @__PURE__ */ jsx(
|
|
10683
|
+
Tooltip,
|
|
10684
|
+
{
|
|
10685
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10686
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10687
|
+
}
|
|
10688
|
+
);
|
|
10689
|
+
},
|
|
10690
|
+
enableSorting: true,
|
|
10691
|
+
sortAscLabel: "Oldest first",
|
|
10692
|
+
sortDescLabel: "Newest first"
|
|
10693
|
+
})
|
|
10694
|
+
];
|
|
10695
|
+
}, []);
|
|
10530
10696
|
};
|
|
10531
|
-
const
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
});
|
|
10535
|
-
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
10536
|
-
const [editing, setEditing] = useState(false);
|
|
10537
|
-
const { quantity, unit_price, title } = item;
|
|
10697
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10698
|
+
const { setIsOpen } = useStackedModal();
|
|
10699
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10538
10700
|
const form = useForm({
|
|
10539
10701
|
defaultValues: {
|
|
10540
|
-
title,
|
|
10541
|
-
quantity,
|
|
10542
|
-
unit_price
|
|
10702
|
+
title: "",
|
|
10703
|
+
quantity: 1,
|
|
10704
|
+
unit_price: ""
|
|
10543
10705
|
},
|
|
10544
10706
|
resolver: zodResolver(customItemSchema)
|
|
10545
10707
|
});
|
|
10546
|
-
useEffect(() => {
|
|
10547
|
-
form.reset({
|
|
10548
|
-
title,
|
|
10549
|
-
quantity,
|
|
10550
|
-
unit_price
|
|
10551
|
-
});
|
|
10552
|
-
}, [form, title, quantity, unit_price]);
|
|
10553
|
-
const actionId = useMemo(() => {
|
|
10554
|
-
var _a, _b;
|
|
10555
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10556
|
-
}, [item]);
|
|
10557
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10558
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10559
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10560
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10561
10708
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10562
|
-
|
|
10563
|
-
setEditing(false);
|
|
10564
|
-
return;
|
|
10565
|
-
}
|
|
10566
|
-
if (!actionId) {
|
|
10567
|
-
await updateOriginalItem(
|
|
10568
|
-
{
|
|
10569
|
-
item_id: item.id,
|
|
10570
|
-
quantity: data.quantity,
|
|
10571
|
-
unit_price: convertNumber(data.unit_price)
|
|
10572
|
-
},
|
|
10573
|
-
{
|
|
10574
|
-
onSuccess: () => {
|
|
10575
|
-
setEditing(false);
|
|
10576
|
-
},
|
|
10577
|
-
onError: (e) => {
|
|
10578
|
-
toast.error(e.message);
|
|
10579
|
-
}
|
|
10580
|
-
}
|
|
10581
|
-
);
|
|
10582
|
-
return;
|
|
10583
|
-
}
|
|
10584
|
-
if (data.quantity === 0) {
|
|
10585
|
-
await removeActionItem(actionId, {
|
|
10586
|
-
onSuccess: () => {
|
|
10587
|
-
setEditing(false);
|
|
10588
|
-
},
|
|
10589
|
-
onError: (e) => {
|
|
10590
|
-
toast.error(e.message);
|
|
10591
|
-
}
|
|
10592
|
-
});
|
|
10593
|
-
return;
|
|
10594
|
-
}
|
|
10595
|
-
await updateActionItem(
|
|
10709
|
+
await addItems(
|
|
10596
10710
|
{
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10711
|
+
items: [
|
|
10712
|
+
{
|
|
10713
|
+
title: data.title,
|
|
10714
|
+
quantity: data.quantity,
|
|
10715
|
+
unit_price: convertNumber(data.unit_price)
|
|
10716
|
+
}
|
|
10717
|
+
]
|
|
10600
10718
|
},
|
|
10601
10719
|
{
|
|
10602
10720
|
onSuccess: () => {
|
|
10603
|
-
|
|
10721
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
10604
10722
|
},
|
|
10605
10723
|
onError: (e) => {
|
|
10606
10724
|
toast.error(e.message);
|
|
@@ -10608,365 +10726,437 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10608
10726
|
}
|
|
10609
10727
|
);
|
|
10610
10728
|
});
|
|
10611
|
-
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(
|
|
10612
|
-
/* @__PURE__ */
|
|
10729
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
10730
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
10731
|
+
/* @__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: [
|
|
10732
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10733
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10734
|
+
/* @__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." }) })
|
|
10735
|
+
] }),
|
|
10736
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10613
10737
|
/* @__PURE__ */ jsx(
|
|
10614
|
-
|
|
10738
|
+
Form$2.Field,
|
|
10615
10739
|
{
|
|
10616
|
-
|
|
10617
|
-
|
|
10740
|
+
control: form.control,
|
|
10741
|
+
name: "title",
|
|
10742
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10743
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10744
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
10745
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10746
|
+
] }),
|
|
10747
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10748
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10749
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10750
|
+
] })
|
|
10751
|
+
] }) })
|
|
10618
10752
|
}
|
|
10619
10753
|
),
|
|
10620
|
-
|
|
10754
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10755
|
+
/* @__PURE__ */ jsx(
|
|
10621
10756
|
Form$2.Field,
|
|
10622
10757
|
{
|
|
10623
10758
|
control: form.control,
|
|
10624
|
-
name: "
|
|
10625
|
-
render: ({ field }) => {
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10759
|
+
name: "unit_price",
|
|
10760
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10761
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10762
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
10763
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10764
|
+
] }),
|
|
10765
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10766
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10767
|
+
CurrencyInput,
|
|
10768
|
+
{
|
|
10769
|
+
symbol: getNativeSymbol(currencyCode),
|
|
10770
|
+
code: currencyCode,
|
|
10771
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10772
|
+
...field
|
|
10773
|
+
}
|
|
10774
|
+
) }),
|
|
10775
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10776
|
+
] })
|
|
10777
|
+
] }) })
|
|
10638
10778
|
}
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
}
|
|
10655
|
-
|
|
10779
|
+
),
|
|
10780
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10781
|
+
/* @__PURE__ */ jsx(
|
|
10782
|
+
Form$2.Field,
|
|
10783
|
+
{
|
|
10784
|
+
control: form.control,
|
|
10785
|
+
name: "quantity",
|
|
10786
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10787
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10788
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10789
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10790
|
+
] }),
|
|
10791
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
|
|
10792
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10793
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10794
|
+
] })
|
|
10795
|
+
] }) })
|
|
10656
10796
|
}
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
/* @__PURE__ */ jsx(
|
|
10660
|
-
|
|
10661
|
-
{
|
|
10662
|
-
|
|
10663
|
-
size: "small",
|
|
10664
|
-
onClick: editing ? onSubmit : () => {
|
|
10665
|
-
setEditing(true);
|
|
10666
|
-
},
|
|
10667
|
-
disabled: isPending,
|
|
10668
|
-
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10669
|
-
}
|
|
10670
|
-
)
|
|
10797
|
+
)
|
|
10798
|
+
] }) }) }),
|
|
10799
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10800
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10801
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10802
|
+
] }) })
|
|
10671
10803
|
] }) }) });
|
|
10672
10804
|
};
|
|
10673
|
-
const
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
10678
|
-
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10805
|
+
const customItemSchema = objectType({
|
|
10806
|
+
title: stringType().min(1),
|
|
10807
|
+
quantity: numberType(),
|
|
10808
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10809
|
+
});
|
|
10810
|
+
const InlineTip = forwardRef(
|
|
10811
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10812
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10813
|
+
return /* @__PURE__ */ jsxs(
|
|
10814
|
+
"div",
|
|
10815
|
+
{
|
|
10816
|
+
ref,
|
|
10817
|
+
className: clx(
|
|
10818
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10819
|
+
className
|
|
10820
|
+
),
|
|
10821
|
+
...props,
|
|
10822
|
+
children: [
|
|
10823
|
+
/* @__PURE__ */ jsx(
|
|
10824
|
+
"div",
|
|
10825
|
+
{
|
|
10826
|
+
role: "presentation",
|
|
10827
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10828
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10829
|
+
})
|
|
10830
|
+
}
|
|
10831
|
+
),
|
|
10832
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10833
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10834
|
+
labelValue,
|
|
10835
|
+
":"
|
|
10836
|
+
] }),
|
|
10837
|
+
" ",
|
|
10838
|
+
children
|
|
10839
|
+
] })
|
|
10840
|
+
]
|
|
10841
|
+
}
|
|
10702
10842
|
);
|
|
10703
|
-
}
|
|
10704
|
-
|
|
10705
|
-
|
|
10706
|
-
|
|
10707
|
-
)
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
|
|
10843
|
+
}
|
|
10844
|
+
);
|
|
10845
|
+
InlineTip.displayName = "InlineTip";
|
|
10846
|
+
const MetadataFieldSchema = objectType({
|
|
10847
|
+
key: stringType(),
|
|
10848
|
+
disabled: booleanType().optional(),
|
|
10849
|
+
value: anyType()
|
|
10850
|
+
});
|
|
10851
|
+
const MetadataSchema = objectType({
|
|
10852
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10853
|
+
});
|
|
10854
|
+
const Metadata = () => {
|
|
10855
|
+
const { id } = useParams();
|
|
10856
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10857
|
+
fields: "metadata"
|
|
10858
|
+
});
|
|
10859
|
+
if (isError) {
|
|
10860
|
+
throw error;
|
|
10861
|
+
}
|
|
10862
|
+
const isReady = !isPending && !!order;
|
|
10863
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10864
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10865
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10866
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10867
|
+
] }),
|
|
10868
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10869
|
+
] });
|
|
10870
|
+
};
|
|
10871
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10872
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10873
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10874
|
+
const { handleSuccess } = useRouteModal();
|
|
10875
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10876
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10877
|
+
const form = useForm({
|
|
10878
|
+
defaultValues: {
|
|
10879
|
+
metadata: getDefaultValues(metadata)
|
|
10714
10880
|
},
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
const columns = useColumns();
|
|
10720
|
-
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10721
|
-
const onSubmit = async () => {
|
|
10722
|
-
const ids = Object.keys(rowSelection).filter(
|
|
10723
|
-
(id) => !items.find((i) => i.variant_id === id)
|
|
10724
|
-
);
|
|
10881
|
+
resolver: zodResolver(MetadataSchema)
|
|
10882
|
+
});
|
|
10883
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10884
|
+
const parsedData = parseValues(data);
|
|
10725
10885
|
await mutateAsync(
|
|
10726
10886
|
{
|
|
10727
|
-
|
|
10728
|
-
variant_id: id,
|
|
10729
|
-
quantity: 1
|
|
10730
|
-
}))
|
|
10887
|
+
metadata: parsedData
|
|
10731
10888
|
},
|
|
10732
10889
|
{
|
|
10733
10890
|
onSuccess: () => {
|
|
10734
|
-
|
|
10735
|
-
|
|
10891
|
+
toast.success("Metadata updated");
|
|
10892
|
+
handleSuccess();
|
|
10736
10893
|
},
|
|
10737
|
-
onError: (
|
|
10738
|
-
toast.error(
|
|
10894
|
+
onError: (error) => {
|
|
10895
|
+
toast.error(error.message);
|
|
10739
10896
|
}
|
|
10740
10897
|
}
|
|
10741
10898
|
);
|
|
10742
|
-
};
|
|
10743
|
-
|
|
10744
|
-
|
|
10899
|
+
});
|
|
10900
|
+
const { fields, insert, remove } = useFieldArray({
|
|
10901
|
+
control: form.control,
|
|
10902
|
+
name: "metadata"
|
|
10903
|
+
});
|
|
10904
|
+
function deleteRow(index) {
|
|
10905
|
+
remove(index);
|
|
10906
|
+
if (fields.length === 1) {
|
|
10907
|
+
insert(0, {
|
|
10908
|
+
key: "",
|
|
10909
|
+
value: "",
|
|
10910
|
+
disabled: false
|
|
10911
|
+
});
|
|
10912
|
+
}
|
|
10745
10913
|
}
|
|
10746
|
-
|
|
10747
|
-
|
|
10914
|
+
function insertRow(index, position) {
|
|
10915
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10916
|
+
key: "",
|
|
10917
|
+
value: "",
|
|
10918
|
+
disabled: false
|
|
10919
|
+
});
|
|
10920
|
+
}
|
|
10921
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10922
|
+
KeyboundForm,
|
|
10748
10923
|
{
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
const searchInput = document.querySelector(
|
|
10752
|
-
"[data-modal-id='modal-search-input']"
|
|
10753
|
-
);
|
|
10754
|
-
if (searchInput) {
|
|
10755
|
-
searchInput.focus();
|
|
10756
|
-
}
|
|
10757
|
-
},
|
|
10924
|
+
onSubmit: handleSubmit,
|
|
10925
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10758
10926
|
children: [
|
|
10759
|
-
/* @__PURE__ */ jsxs(
|
|
10760
|
-
/* @__PURE__ */
|
|
10761
|
-
|
|
10927
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10928
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10929
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10930
|
+
/* @__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" }) }),
|
|
10931
|
+
/* @__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" }) })
|
|
10932
|
+
] }),
|
|
10933
|
+
fields.map((field, index) => {
|
|
10934
|
+
const isDisabled = field.disabled || false;
|
|
10935
|
+
let placeholder = "-";
|
|
10936
|
+
if (typeof field.value === "object") {
|
|
10937
|
+
placeholder = "{ ... }";
|
|
10938
|
+
}
|
|
10939
|
+
if (Array.isArray(field.value)) {
|
|
10940
|
+
placeholder = "[ ... ]";
|
|
10941
|
+
}
|
|
10942
|
+
return /* @__PURE__ */ jsx(
|
|
10943
|
+
ConditionalTooltip,
|
|
10944
|
+
{
|
|
10945
|
+
showTooltip: isDisabled,
|
|
10946
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10947
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10948
|
+
/* @__PURE__ */ jsxs(
|
|
10949
|
+
"div",
|
|
10950
|
+
{
|
|
10951
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
10952
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10953
|
+
}),
|
|
10954
|
+
children: [
|
|
10955
|
+
/* @__PURE__ */ jsx(
|
|
10956
|
+
Form$2.Field,
|
|
10957
|
+
{
|
|
10958
|
+
control: form.control,
|
|
10959
|
+
name: `metadata.${index}.key`,
|
|
10960
|
+
render: ({ field: field2 }) => {
|
|
10961
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10962
|
+
GridInput,
|
|
10963
|
+
{
|
|
10964
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10965
|
+
...field2,
|
|
10966
|
+
disabled: isDisabled,
|
|
10967
|
+
placeholder: "Key"
|
|
10968
|
+
}
|
|
10969
|
+
) }) });
|
|
10970
|
+
}
|
|
10971
|
+
}
|
|
10972
|
+
),
|
|
10973
|
+
/* @__PURE__ */ jsx(
|
|
10974
|
+
Form$2.Field,
|
|
10975
|
+
{
|
|
10976
|
+
control: form.control,
|
|
10977
|
+
name: `metadata.${index}.value`,
|
|
10978
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10979
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10980
|
+
GridInput,
|
|
10981
|
+
{
|
|
10982
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10983
|
+
...field2,
|
|
10984
|
+
value: isDisabled ? placeholder : value,
|
|
10985
|
+
disabled: isDisabled,
|
|
10986
|
+
placeholder: "Value"
|
|
10987
|
+
}
|
|
10988
|
+
) }) });
|
|
10989
|
+
}
|
|
10990
|
+
}
|
|
10991
|
+
)
|
|
10992
|
+
]
|
|
10993
|
+
}
|
|
10994
|
+
),
|
|
10995
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10996
|
+
/* @__PURE__ */ jsx(
|
|
10997
|
+
DropdownMenu.Trigger,
|
|
10998
|
+
{
|
|
10999
|
+
className: clx(
|
|
11000
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11001
|
+
{
|
|
11002
|
+
hidden: isDisabled
|
|
11003
|
+
}
|
|
11004
|
+
),
|
|
11005
|
+
disabled: isDisabled,
|
|
11006
|
+
asChild: true,
|
|
11007
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11008
|
+
}
|
|
11009
|
+
),
|
|
11010
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11011
|
+
/* @__PURE__ */ jsxs(
|
|
11012
|
+
DropdownMenu.Item,
|
|
11013
|
+
{
|
|
11014
|
+
className: "gap-x-2",
|
|
11015
|
+
onClick: () => insertRow(index, "above"),
|
|
11016
|
+
children: [
|
|
11017
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11018
|
+
"Insert row above"
|
|
11019
|
+
]
|
|
11020
|
+
}
|
|
11021
|
+
),
|
|
11022
|
+
/* @__PURE__ */ jsxs(
|
|
11023
|
+
DropdownMenu.Item,
|
|
11024
|
+
{
|
|
11025
|
+
className: "gap-x-2",
|
|
11026
|
+
onClick: () => insertRow(index, "below"),
|
|
11027
|
+
children: [
|
|
11028
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11029
|
+
"Insert row below"
|
|
11030
|
+
]
|
|
11031
|
+
}
|
|
11032
|
+
),
|
|
11033
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11034
|
+
/* @__PURE__ */ jsxs(
|
|
11035
|
+
DropdownMenu.Item,
|
|
11036
|
+
{
|
|
11037
|
+
className: "gap-x-2",
|
|
11038
|
+
onClick: () => deleteRow(index),
|
|
11039
|
+
children: [
|
|
11040
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11041
|
+
"Delete row"
|
|
11042
|
+
]
|
|
11043
|
+
}
|
|
11044
|
+
)
|
|
11045
|
+
] })
|
|
11046
|
+
] })
|
|
11047
|
+
] })
|
|
11048
|
+
},
|
|
11049
|
+
field.id
|
|
11050
|
+
);
|
|
11051
|
+
})
|
|
11052
|
+
] }),
|
|
11053
|
+
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." })
|
|
10762
11054
|
] }),
|
|
10763
|
-
/* @__PURE__ */ jsx(
|
|
10764
|
-
|
|
10765
|
-
{
|
|
10766
|
-
data: variants,
|
|
10767
|
-
columns,
|
|
10768
|
-
isLoading: isPending,
|
|
10769
|
-
getRowId: (row) => row.id,
|
|
10770
|
-
rowCount: count,
|
|
10771
|
-
prefix: VARIANT_PREFIX,
|
|
10772
|
-
layout: "fill",
|
|
10773
|
-
rowSelection: {
|
|
10774
|
-
state: rowSelection,
|
|
10775
|
-
onRowSelectionChange: setRowSelection,
|
|
10776
|
-
enableRowSelection: (row) => {
|
|
10777
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
10778
|
-
}
|
|
10779
|
-
},
|
|
10780
|
-
autoFocusSearch: true
|
|
10781
|
-
}
|
|
10782
|
-
) }),
|
|
10783
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10784
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10785
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
11055
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11056
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11057
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10786
11058
|
] }) })
|
|
10787
11059
|
]
|
|
10788
11060
|
}
|
|
11061
|
+
) });
|
|
11062
|
+
};
|
|
11063
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11064
|
+
return /* @__PURE__ */ jsx(
|
|
11065
|
+
"input",
|
|
11066
|
+
{
|
|
11067
|
+
ref,
|
|
11068
|
+
...props,
|
|
11069
|
+
autoComplete: "off",
|
|
11070
|
+
className: clx(
|
|
11071
|
+
"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",
|
|
11072
|
+
className
|
|
11073
|
+
)
|
|
11074
|
+
}
|
|
10789
11075
|
);
|
|
11076
|
+
});
|
|
11077
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11078
|
+
const PlaceholderInner = () => {
|
|
11079
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11080
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11081
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11082
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11083
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11084
|
+
] }) })
|
|
11085
|
+
] });
|
|
10790
11086
|
};
|
|
10791
|
-
const
|
|
10792
|
-
|
|
10793
|
-
|
|
11087
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11088
|
+
function getDefaultValues(metadata) {
|
|
11089
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
10794
11090
|
return [
|
|
10795
|
-
columnHelper.select(),
|
|
10796
|
-
columnHelper.accessor("product.title", {
|
|
10797
|
-
header: "Product",
|
|
10798
|
-
cell: ({ row }) => {
|
|
10799
|
-
var _a, _b, _c;
|
|
10800
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10801
|
-
/* @__PURE__ */ jsx(
|
|
10802
|
-
Thumbnail,
|
|
10803
|
-
{
|
|
10804
|
-
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
10805
|
-
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
10806
|
-
}
|
|
10807
|
-
),
|
|
10808
|
-
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10809
|
-
] });
|
|
10810
|
-
},
|
|
10811
|
-
enableSorting: true
|
|
10812
|
-
}),
|
|
10813
|
-
columnHelper.accessor("title", {
|
|
10814
|
-
header: "Variant",
|
|
10815
|
-
enableSorting: true
|
|
10816
|
-
}),
|
|
10817
|
-
columnHelper.accessor("sku", {
|
|
10818
|
-
header: "SKU",
|
|
10819
|
-
cell: ({ getValue }) => {
|
|
10820
|
-
return getValue() ?? "-";
|
|
10821
|
-
},
|
|
10822
|
-
enableSorting: true
|
|
10823
|
-
}),
|
|
10824
|
-
columnHelper.accessor("updated_at", {
|
|
10825
|
-
header: "Updated",
|
|
10826
|
-
cell: ({ getValue }) => {
|
|
10827
|
-
return /* @__PURE__ */ jsx(
|
|
10828
|
-
Tooltip,
|
|
10829
|
-
{
|
|
10830
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10831
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10832
|
-
}
|
|
10833
|
-
);
|
|
10834
|
-
},
|
|
10835
|
-
enableSorting: true,
|
|
10836
|
-
sortAscLabel: "Oldest first",
|
|
10837
|
-
sortDescLabel: "Newest first"
|
|
10838
|
-
}),
|
|
10839
|
-
columnHelper.accessor("created_at", {
|
|
10840
|
-
header: "Created",
|
|
10841
|
-
cell: ({ getValue }) => {
|
|
10842
|
-
return /* @__PURE__ */ jsx(
|
|
10843
|
-
Tooltip,
|
|
10844
|
-
{
|
|
10845
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10846
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10847
|
-
}
|
|
10848
|
-
);
|
|
10849
|
-
},
|
|
10850
|
-
enableSorting: true,
|
|
10851
|
-
sortAscLabel: "Oldest first",
|
|
10852
|
-
sortDescLabel: "Newest first"
|
|
10853
|
-
})
|
|
10854
|
-
];
|
|
10855
|
-
}, []);
|
|
10856
|
-
};
|
|
10857
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10858
|
-
const { setIsOpen } = useStackedModal();
|
|
10859
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10860
|
-
const form = useForm({
|
|
10861
|
-
defaultValues: {
|
|
10862
|
-
title: "",
|
|
10863
|
-
quantity: 1,
|
|
10864
|
-
unit_price: ""
|
|
10865
|
-
},
|
|
10866
|
-
resolver: zodResolver(customItemSchema)
|
|
10867
|
-
});
|
|
10868
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10869
|
-
await addItems(
|
|
10870
|
-
{
|
|
10871
|
-
items: [
|
|
10872
|
-
{
|
|
10873
|
-
title: data.title,
|
|
10874
|
-
quantity: data.quantity,
|
|
10875
|
-
unit_price: convertNumber(data.unit_price)
|
|
10876
|
-
}
|
|
10877
|
-
]
|
|
10878
|
-
},
|
|
10879
11091
|
{
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
onError: (e) => {
|
|
10884
|
-
toast.error(e.message);
|
|
10885
|
-
}
|
|
11092
|
+
key: "",
|
|
11093
|
+
value: "",
|
|
11094
|
+
disabled: false
|
|
10886
11095
|
}
|
|
10887
|
-
|
|
11096
|
+
];
|
|
11097
|
+
}
|
|
11098
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11099
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11100
|
+
return {
|
|
11101
|
+
key,
|
|
11102
|
+
value,
|
|
11103
|
+
disabled: true
|
|
11104
|
+
};
|
|
11105
|
+
}
|
|
11106
|
+
let stringValue = value;
|
|
11107
|
+
if (typeof value !== "string") {
|
|
11108
|
+
stringValue = JSON.stringify(value);
|
|
11109
|
+
}
|
|
11110
|
+
return {
|
|
11111
|
+
key,
|
|
11112
|
+
value: stringValue,
|
|
11113
|
+
original_key: key
|
|
11114
|
+
};
|
|
10888
11115
|
});
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
}
|
|
10934
|
-
) }),
|
|
10935
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10936
|
-
] })
|
|
10937
|
-
] }) })
|
|
10938
|
-
}
|
|
10939
|
-
),
|
|
10940
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10941
|
-
/* @__PURE__ */ jsx(
|
|
10942
|
-
Form$2.Field,
|
|
10943
|
-
{
|
|
10944
|
-
control: form.control,
|
|
10945
|
-
name: "quantity",
|
|
10946
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10947
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10948
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10949
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10950
|
-
] }),
|
|
10951
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
|
|
10952
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10953
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10954
|
-
] })
|
|
10955
|
-
] }) })
|
|
10956
|
-
}
|
|
10957
|
-
)
|
|
10958
|
-
] }) }) }),
|
|
10959
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10960
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10961
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10962
|
-
] }) })
|
|
10963
|
-
] }) }) });
|
|
10964
|
-
};
|
|
10965
|
-
const customItemSchema = objectType({
|
|
10966
|
-
title: stringType().min(1),
|
|
10967
|
-
quantity: numberType(),
|
|
10968
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10969
|
-
});
|
|
11116
|
+
}
|
|
11117
|
+
function parseValues(values) {
|
|
11118
|
+
const metadata = values.metadata;
|
|
11119
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11120
|
+
if (isEmpty) {
|
|
11121
|
+
return null;
|
|
11122
|
+
}
|
|
11123
|
+
const update = {};
|
|
11124
|
+
metadata.forEach((field) => {
|
|
11125
|
+
let key = field.key;
|
|
11126
|
+
let value = field.value;
|
|
11127
|
+
const disabled = field.disabled;
|
|
11128
|
+
if (!key || !value) {
|
|
11129
|
+
return;
|
|
11130
|
+
}
|
|
11131
|
+
if (disabled) {
|
|
11132
|
+
update[key] = value;
|
|
11133
|
+
return;
|
|
11134
|
+
}
|
|
11135
|
+
key = key.trim();
|
|
11136
|
+
value = value.trim();
|
|
11137
|
+
if (value === "true") {
|
|
11138
|
+
update[key] = true;
|
|
11139
|
+
} else if (value === "false") {
|
|
11140
|
+
update[key] = false;
|
|
11141
|
+
} else {
|
|
11142
|
+
const parsedNumber = parseFloat(value);
|
|
11143
|
+
if (!isNaN(parsedNumber)) {
|
|
11144
|
+
update[key] = parsedNumber;
|
|
11145
|
+
} else {
|
|
11146
|
+
update[key] = value;
|
|
11147
|
+
}
|
|
11148
|
+
}
|
|
11149
|
+
});
|
|
11150
|
+
return update;
|
|
11151
|
+
}
|
|
11152
|
+
function getHasUneditableRows(metadata) {
|
|
11153
|
+
if (!metadata) {
|
|
11154
|
+
return false;
|
|
11155
|
+
}
|
|
11156
|
+
return Object.values(metadata).some(
|
|
11157
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11158
|
+
);
|
|
11159
|
+
}
|
|
10970
11160
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
10971
11161
|
const promotionsQueryKeys = {
|
|
10972
11162
|
list: (query2) => [
|
|
@@ -11272,7 +11462,7 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11272
11462
|
defaultValues: {
|
|
11273
11463
|
sales_channel_id: order.sales_channel_id || ""
|
|
11274
11464
|
},
|
|
11275
|
-
resolver: zodResolver(schema$
|
|
11465
|
+
resolver: zodResolver(schema$2)
|
|
11276
11466
|
});
|
|
11277
11467
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11278
11468
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11347,7 +11537,7 @@ const SalesChannelField = ({ control, order }) => {
|
|
|
11347
11537
|
}
|
|
11348
11538
|
);
|
|
11349
11539
|
};
|
|
11350
|
-
const schema$
|
|
11540
|
+
const schema$2 = objectType({
|
|
11351
11541
|
sales_channel_id: stringType().min(1)
|
|
11352
11542
|
});
|
|
11353
11543
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
@@ -12189,7 +12379,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12189
12379
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12190
12380
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12191
12381
|
},
|
|
12192
|
-
resolver: zodResolver(schema$
|
|
12382
|
+
resolver: zodResolver(schema$1)
|
|
12193
12383
|
});
|
|
12194
12384
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12195
12385
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12359,7 +12549,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12359
12549
|
}
|
|
12360
12550
|
) });
|
|
12361
12551
|
};
|
|
12362
|
-
const schema$
|
|
12552
|
+
const schema$1 = addressSchema;
|
|
12363
12553
|
const TransferOwnership = () => {
|
|
12364
12554
|
const { id } = useParams();
|
|
12365
12555
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12383,7 +12573,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12383
12573
|
defaultValues: {
|
|
12384
12574
|
customer_id: order.customer_id || ""
|
|
12385
12575
|
},
|
|
12386
|
-
resolver: zodResolver(schema
|
|
12576
|
+
resolver: zodResolver(schema)
|
|
12387
12577
|
});
|
|
12388
12578
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12389
12579
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12833,199 +13023,9 @@ const Illustration = () => {
|
|
|
12833
13023
|
}
|
|
12834
13024
|
);
|
|
12835
13025
|
};
|
|
12836
|
-
const schema
|
|
13026
|
+
const schema = objectType({
|
|
12837
13027
|
customer_id: stringType().min(1)
|
|
12838
13028
|
});
|
|
12839
|
-
const BillingAddress = () => {
|
|
12840
|
-
const { id } = useParams();
|
|
12841
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12842
|
-
fields: "+billing_address"
|
|
12843
|
-
});
|
|
12844
|
-
if (isError) {
|
|
12845
|
-
throw error;
|
|
12846
|
-
}
|
|
12847
|
-
const isReady = !isPending && !!order;
|
|
12848
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12849
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12850
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
12851
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
12852
|
-
] }),
|
|
12853
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
12854
|
-
] });
|
|
12855
|
-
};
|
|
12856
|
-
const BillingAddressForm = ({ order }) => {
|
|
12857
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12858
|
-
const form = useForm({
|
|
12859
|
-
defaultValues: {
|
|
12860
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12861
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12862
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
12863
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12864
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12865
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
12866
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
12867
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12868
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12869
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
12870
|
-
},
|
|
12871
|
-
resolver: zodResolver(schema)
|
|
12872
|
-
});
|
|
12873
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12874
|
-
const { handleSuccess } = useRouteModal();
|
|
12875
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12876
|
-
await mutateAsync(
|
|
12877
|
-
{ billing_address: data },
|
|
12878
|
-
{
|
|
12879
|
-
onSuccess: () => {
|
|
12880
|
-
handleSuccess();
|
|
12881
|
-
},
|
|
12882
|
-
onError: (error) => {
|
|
12883
|
-
toast.error(error.message);
|
|
12884
|
-
}
|
|
12885
|
-
}
|
|
12886
|
-
);
|
|
12887
|
-
});
|
|
12888
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12889
|
-
KeyboundForm,
|
|
12890
|
-
{
|
|
12891
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12892
|
-
onSubmit,
|
|
12893
|
-
children: [
|
|
12894
|
-
/* @__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: [
|
|
12895
|
-
/* @__PURE__ */ jsx(
|
|
12896
|
-
Form$2.Field,
|
|
12897
|
-
{
|
|
12898
|
-
control: form.control,
|
|
12899
|
-
name: "country_code",
|
|
12900
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12901
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12902
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12903
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12904
|
-
] })
|
|
12905
|
-
}
|
|
12906
|
-
),
|
|
12907
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12908
|
-
/* @__PURE__ */ jsx(
|
|
12909
|
-
Form$2.Field,
|
|
12910
|
-
{
|
|
12911
|
-
control: form.control,
|
|
12912
|
-
name: "first_name",
|
|
12913
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12914
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12915
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12916
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12917
|
-
] })
|
|
12918
|
-
}
|
|
12919
|
-
),
|
|
12920
|
-
/* @__PURE__ */ jsx(
|
|
12921
|
-
Form$2.Field,
|
|
12922
|
-
{
|
|
12923
|
-
control: form.control,
|
|
12924
|
-
name: "last_name",
|
|
12925
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12926
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12927
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12928
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12929
|
-
] })
|
|
12930
|
-
}
|
|
12931
|
-
)
|
|
12932
|
-
] }),
|
|
12933
|
-
/* @__PURE__ */ jsx(
|
|
12934
|
-
Form$2.Field,
|
|
12935
|
-
{
|
|
12936
|
-
control: form.control,
|
|
12937
|
-
name: "company",
|
|
12938
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12939
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12940
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12941
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12942
|
-
] })
|
|
12943
|
-
}
|
|
12944
|
-
),
|
|
12945
|
-
/* @__PURE__ */ jsx(
|
|
12946
|
-
Form$2.Field,
|
|
12947
|
-
{
|
|
12948
|
-
control: form.control,
|
|
12949
|
-
name: "address_1",
|
|
12950
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12951
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12952
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12953
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12954
|
-
] })
|
|
12955
|
-
}
|
|
12956
|
-
),
|
|
12957
|
-
/* @__PURE__ */ jsx(
|
|
12958
|
-
Form$2.Field,
|
|
12959
|
-
{
|
|
12960
|
-
control: form.control,
|
|
12961
|
-
name: "address_2",
|
|
12962
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12963
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12964
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12965
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12966
|
-
] })
|
|
12967
|
-
}
|
|
12968
|
-
),
|
|
12969
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12970
|
-
/* @__PURE__ */ jsx(
|
|
12971
|
-
Form$2.Field,
|
|
12972
|
-
{
|
|
12973
|
-
control: form.control,
|
|
12974
|
-
name: "postal_code",
|
|
12975
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12976
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12977
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12978
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12979
|
-
] })
|
|
12980
|
-
}
|
|
12981
|
-
),
|
|
12982
|
-
/* @__PURE__ */ jsx(
|
|
12983
|
-
Form$2.Field,
|
|
12984
|
-
{
|
|
12985
|
-
control: form.control,
|
|
12986
|
-
name: "city",
|
|
12987
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12988
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12989
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12990
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12991
|
-
] })
|
|
12992
|
-
}
|
|
12993
|
-
)
|
|
12994
|
-
] }),
|
|
12995
|
-
/* @__PURE__ */ jsx(
|
|
12996
|
-
Form$2.Field,
|
|
12997
|
-
{
|
|
12998
|
-
control: form.control,
|
|
12999
|
-
name: "province",
|
|
13000
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13001
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13002
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13003
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13004
|
-
] })
|
|
13005
|
-
}
|
|
13006
|
-
),
|
|
13007
|
-
/* @__PURE__ */ jsx(
|
|
13008
|
-
Form$2.Field,
|
|
13009
|
-
{
|
|
13010
|
-
control: form.control,
|
|
13011
|
-
name: "phone",
|
|
13012
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13013
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13014
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13015
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13016
|
-
] })
|
|
13017
|
-
}
|
|
13018
|
-
)
|
|
13019
|
-
] }) }),
|
|
13020
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13021
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13022
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13023
|
-
] }) })
|
|
13024
|
-
]
|
|
13025
|
-
}
|
|
13026
|
-
) });
|
|
13027
|
-
};
|
|
13028
|
-
const schema = addressSchema;
|
|
13029
13029
|
const widgetModule = { widgets: [] };
|
|
13030
13030
|
const routeModule = {
|
|
13031
13031
|
routes: [
|
|
@@ -13046,6 +13046,10 @@ const routeModule = {
|
|
|
13046
13046
|
handle,
|
|
13047
13047
|
loader,
|
|
13048
13048
|
children: [
|
|
13049
|
+
{
|
|
13050
|
+
Component: BillingAddress,
|
|
13051
|
+
path: "/draft-orders/:id/billing-address"
|
|
13052
|
+
},
|
|
13049
13053
|
{
|
|
13050
13054
|
Component: CustomItems,
|
|
13051
13055
|
path: "/draft-orders/:id/custom-items"
|
|
@@ -13054,14 +13058,14 @@ const routeModule = {
|
|
|
13054
13058
|
Component: Email,
|
|
13055
13059
|
path: "/draft-orders/:id/email"
|
|
13056
13060
|
},
|
|
13057
|
-
{
|
|
13058
|
-
Component: Metadata,
|
|
13059
|
-
path: "/draft-orders/:id/metadata"
|
|
13060
|
-
},
|
|
13061
13061
|
{
|
|
13062
13062
|
Component: Items,
|
|
13063
13063
|
path: "/draft-orders/:id/items"
|
|
13064
13064
|
},
|
|
13065
|
+
{
|
|
13066
|
+
Component: Metadata,
|
|
13067
|
+
path: "/draft-orders/:id/metadata"
|
|
13068
|
+
},
|
|
13065
13069
|
{
|
|
13066
13070
|
Component: Promotions,
|
|
13067
13071
|
path: "/draft-orders/:id/promotions"
|
|
@@ -13081,10 +13085,6 @@ const routeModule = {
|
|
|
13081
13085
|
{
|
|
13082
13086
|
Component: TransferOwnership,
|
|
13083
13087
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13084
|
-
},
|
|
13085
|
-
{
|
|
13086
|
-
Component: BillingAddress,
|
|
13087
|
-
path: "/draft-orders/:id/billing-address"
|
|
13088
13088
|
}
|
|
13089
13089
|
]
|
|
13090
13090
|
}
|