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