@medusajs/draft-order 2.10.0-snapshot-20250828141936 → 2.10.1-snapshot-20250828200335
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 +1711 -1711
- package/.medusa/server/src/admin/index.mjs +1712 -1712
- package/package.json +23 -24
|
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
|
|
|
4
4
|
import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
|
|
6
6
|
import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
|
|
7
|
-
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent,
|
|
7
|
+
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
|
|
8
8
|
import Medusa from "@medusajs/js-sdk";
|
|
9
9
|
import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
|
|
10
10
|
import { enUS } from "date-fns/locale";
|
|
@@ -9554,6 +9554,95 @@ const ID = () => {
|
|
|
9554
9554
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9555
9555
|
] });
|
|
9556
9556
|
};
|
|
9557
|
+
const Email = () => {
|
|
9558
|
+
const { id } = useParams();
|
|
9559
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9560
|
+
fields: "+email"
|
|
9561
|
+
});
|
|
9562
|
+
if (isError) {
|
|
9563
|
+
throw error;
|
|
9564
|
+
}
|
|
9565
|
+
const isReady = !isPending && !!order;
|
|
9566
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9567
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9568
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9569
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9570
|
+
] }),
|
|
9571
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9572
|
+
] });
|
|
9573
|
+
};
|
|
9574
|
+
const EmailForm = ({ order }) => {
|
|
9575
|
+
const form = useForm({
|
|
9576
|
+
defaultValues: {
|
|
9577
|
+
email: order.email ?? ""
|
|
9578
|
+
},
|
|
9579
|
+
resolver: zodResolver(schema$5)
|
|
9580
|
+
});
|
|
9581
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9582
|
+
const { handleSuccess } = useRouteModal();
|
|
9583
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9584
|
+
await mutateAsync(
|
|
9585
|
+
{ email: data.email },
|
|
9586
|
+
{
|
|
9587
|
+
onSuccess: () => {
|
|
9588
|
+
handleSuccess();
|
|
9589
|
+
},
|
|
9590
|
+
onError: (error) => {
|
|
9591
|
+
toast.error(error.message);
|
|
9592
|
+
}
|
|
9593
|
+
}
|
|
9594
|
+
);
|
|
9595
|
+
});
|
|
9596
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9597
|
+
KeyboundForm,
|
|
9598
|
+
{
|
|
9599
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9600
|
+
onSubmit,
|
|
9601
|
+
children: [
|
|
9602
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9603
|
+
Form$2.Field,
|
|
9604
|
+
{
|
|
9605
|
+
control: form.control,
|
|
9606
|
+
name: "email",
|
|
9607
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9608
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9609
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9610
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9611
|
+
] })
|
|
9612
|
+
}
|
|
9613
|
+
) }),
|
|
9614
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9615
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9616
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9617
|
+
] }) })
|
|
9618
|
+
]
|
|
9619
|
+
}
|
|
9620
|
+
) });
|
|
9621
|
+
};
|
|
9622
|
+
const schema$5 = objectType({
|
|
9623
|
+
email: stringType().email()
|
|
9624
|
+
});
|
|
9625
|
+
const CustomItems = () => {
|
|
9626
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9627
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9628
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9629
|
+
] });
|
|
9630
|
+
};
|
|
9631
|
+
const CustomItemsForm = () => {
|
|
9632
|
+
const form = useForm({
|
|
9633
|
+
resolver: zodResolver(schema$4)
|
|
9634
|
+
});
|
|
9635
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9636
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9637
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9638
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9639
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9640
|
+
] }) })
|
|
9641
|
+
] }) });
|
|
9642
|
+
};
|
|
9643
|
+
const schema$4 = objectType({
|
|
9644
|
+
email: stringType().email()
|
|
9645
|
+
});
|
|
9557
9646
|
const BillingAddress = () => {
|
|
9558
9647
|
const { id } = useParams();
|
|
9559
9648
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9586,7 +9675,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9586
9675
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9587
9676
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9588
9677
|
},
|
|
9589
|
-
resolver: zodResolver(schema$
|
|
9678
|
+
resolver: zodResolver(schema$3)
|
|
9590
9679
|
});
|
|
9591
9680
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9592
9681
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9743,32 +9832,55 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9743
9832
|
}
|
|
9744
9833
|
) });
|
|
9745
9834
|
};
|
|
9746
|
-
const schema$
|
|
9747
|
-
const
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
/* @__PURE__ */
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9835
|
+
const schema$3 = addressSchema;
|
|
9836
|
+
const InlineTip = forwardRef(
|
|
9837
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9838
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9839
|
+
return /* @__PURE__ */ jsxs(
|
|
9840
|
+
"div",
|
|
9841
|
+
{
|
|
9842
|
+
ref,
|
|
9843
|
+
className: clx(
|
|
9844
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9845
|
+
className
|
|
9846
|
+
),
|
|
9847
|
+
...props,
|
|
9848
|
+
children: [
|
|
9849
|
+
/* @__PURE__ */ jsx(
|
|
9850
|
+
"div",
|
|
9851
|
+
{
|
|
9852
|
+
role: "presentation",
|
|
9853
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9854
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9855
|
+
})
|
|
9856
|
+
}
|
|
9857
|
+
),
|
|
9858
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9859
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9860
|
+
labelValue,
|
|
9861
|
+
":"
|
|
9862
|
+
] }),
|
|
9863
|
+
" ",
|
|
9864
|
+
children
|
|
9865
|
+
] })
|
|
9866
|
+
]
|
|
9867
|
+
}
|
|
9868
|
+
);
|
|
9869
|
+
}
|
|
9870
|
+
);
|
|
9871
|
+
InlineTip.displayName = "InlineTip";
|
|
9872
|
+
const MetadataFieldSchema = objectType({
|
|
9873
|
+
key: stringType(),
|
|
9874
|
+
disabled: booleanType().optional(),
|
|
9875
|
+
value: anyType()
|
|
9767
9876
|
});
|
|
9768
|
-
const
|
|
9877
|
+
const MetadataSchema = objectType({
|
|
9878
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
9879
|
+
});
|
|
9880
|
+
const Metadata = () => {
|
|
9769
9881
|
const { id } = useParams();
|
|
9770
9882
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
9771
|
-
fields: "
|
|
9883
|
+
fields: "metadata"
|
|
9772
9884
|
});
|
|
9773
9885
|
if (isError) {
|
|
9774
9886
|
throw error;
|
|
@@ -9776,26 +9888,33 @@ const Email = () => {
|
|
|
9776
9888
|
const isReady = !isPending && !!order;
|
|
9777
9889
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9778
9890
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9779
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
9780
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
9891
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
9892
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9781
9893
|
] }),
|
|
9782
|
-
isReady
|
|
9894
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
9783
9895
|
] });
|
|
9784
9896
|
};
|
|
9785
|
-
const
|
|
9897
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9898
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9899
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
9900
|
+
const { handleSuccess } = useRouteModal();
|
|
9901
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9902
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9786
9903
|
const form = useForm({
|
|
9787
9904
|
defaultValues: {
|
|
9788
|
-
|
|
9905
|
+
metadata: getDefaultValues(metadata)
|
|
9789
9906
|
},
|
|
9790
|
-
resolver: zodResolver(
|
|
9907
|
+
resolver: zodResolver(MetadataSchema)
|
|
9791
9908
|
});
|
|
9792
|
-
const
|
|
9793
|
-
|
|
9794
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9909
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9910
|
+
const parsedData = parseValues(data);
|
|
9795
9911
|
await mutateAsync(
|
|
9796
|
-
{
|
|
9912
|
+
{
|
|
9913
|
+
metadata: parsedData
|
|
9914
|
+
},
|
|
9797
9915
|
{
|
|
9798
9916
|
onSuccess: () => {
|
|
9917
|
+
toast.success("Metadata updated");
|
|
9799
9918
|
handleSuccess();
|
|
9800
9919
|
},
|
|
9801
9920
|
onError: (error) => {
|
|
@@ -9804,188 +9923,314 @@ const EmailForm = ({ order }) => {
|
|
|
9804
9923
|
}
|
|
9805
9924
|
);
|
|
9806
9925
|
});
|
|
9926
|
+
const { fields, insert, remove } = useFieldArray({
|
|
9927
|
+
control: form.control,
|
|
9928
|
+
name: "metadata"
|
|
9929
|
+
});
|
|
9930
|
+
function deleteRow(index) {
|
|
9931
|
+
remove(index);
|
|
9932
|
+
if (fields.length === 1) {
|
|
9933
|
+
insert(0, {
|
|
9934
|
+
key: "",
|
|
9935
|
+
value: "",
|
|
9936
|
+
disabled: false
|
|
9937
|
+
});
|
|
9938
|
+
}
|
|
9939
|
+
}
|
|
9940
|
+
function insertRow(index, position) {
|
|
9941
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9942
|
+
key: "",
|
|
9943
|
+
value: "",
|
|
9944
|
+
disabled: false
|
|
9945
|
+
});
|
|
9946
|
+
}
|
|
9807
9947
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9808
9948
|
KeyboundForm,
|
|
9809
9949
|
{
|
|
9950
|
+
onSubmit: handleSubmit,
|
|
9810
9951
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
9811
|
-
onSubmit,
|
|
9812
9952
|
children: [
|
|
9813
|
-
/* @__PURE__ */
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
}
|
|
9831
|
-
) });
|
|
9832
|
-
};
|
|
9833
|
-
const schema$3 = objectType({
|
|
9834
|
-
email: stringType().email()
|
|
9835
|
-
});
|
|
9836
|
-
const NumberInput = forwardRef(
|
|
9837
|
-
({
|
|
9838
|
-
value,
|
|
9839
|
-
onChange,
|
|
9840
|
-
size = "base",
|
|
9841
|
-
min = 0,
|
|
9842
|
-
max = 100,
|
|
9843
|
-
step = 1,
|
|
9844
|
-
className,
|
|
9845
|
-
disabled,
|
|
9846
|
-
...props
|
|
9847
|
-
}, ref) => {
|
|
9848
|
-
const handleChange = (event) => {
|
|
9849
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9850
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9851
|
-
onChange(newValue);
|
|
9852
|
-
}
|
|
9853
|
-
};
|
|
9854
|
-
const handleIncrement = () => {
|
|
9855
|
-
const newValue = value + step;
|
|
9856
|
-
if (max === void 0 || newValue <= max) {
|
|
9857
|
-
onChange(newValue);
|
|
9858
|
-
}
|
|
9859
|
-
};
|
|
9860
|
-
const handleDecrement = () => {
|
|
9861
|
-
const newValue = value - step;
|
|
9862
|
-
if (min === void 0 || newValue >= min) {
|
|
9863
|
-
onChange(newValue);
|
|
9864
|
-
}
|
|
9865
|
-
};
|
|
9866
|
-
return /* @__PURE__ */ jsxs(
|
|
9867
|
-
"div",
|
|
9868
|
-
{
|
|
9869
|
-
className: clx(
|
|
9870
|
-
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9871
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9872
|
-
{
|
|
9873
|
-
"h-7": size === "small",
|
|
9874
|
-
"h-8": size === "base"
|
|
9875
|
-
},
|
|
9876
|
-
className
|
|
9877
|
-
),
|
|
9878
|
-
children: [
|
|
9879
|
-
/* @__PURE__ */ jsx(
|
|
9880
|
-
"input",
|
|
9881
|
-
{
|
|
9882
|
-
ref,
|
|
9883
|
-
type: "number",
|
|
9884
|
-
value,
|
|
9885
|
-
onChange: handleChange,
|
|
9886
|
-
min,
|
|
9887
|
-
max,
|
|
9888
|
-
step,
|
|
9889
|
-
className: clx(
|
|
9890
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
9891
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
9892
|
-
"placeholder:text-ui-fg-muted"
|
|
9893
|
-
),
|
|
9894
|
-
...props
|
|
9895
|
-
}
|
|
9896
|
-
),
|
|
9897
|
-
/* @__PURE__ */ jsxs(
|
|
9898
|
-
"button",
|
|
9899
|
-
{
|
|
9900
|
-
className: clx(
|
|
9901
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9902
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9903
|
-
"focus:bg-ui-bg-field-component-hover",
|
|
9904
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
9905
|
-
{
|
|
9906
|
-
"size-7": size === "small",
|
|
9907
|
-
"size-8": size === "base"
|
|
9908
|
-
}
|
|
9909
|
-
),
|
|
9910
|
-
type: "button",
|
|
9911
|
-
onClick: handleDecrement,
|
|
9912
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
9913
|
-
children: [
|
|
9914
|
-
/* @__PURE__ */ jsx(Minus, {}),
|
|
9915
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9916
|
-
]
|
|
9917
|
-
}
|
|
9918
|
-
),
|
|
9919
|
-
/* @__PURE__ */ jsxs(
|
|
9920
|
-
"button",
|
|
9921
|
-
{
|
|
9922
|
-
className: clx(
|
|
9923
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9924
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9925
|
-
"focus:bg-ui-bg-field-hover",
|
|
9926
|
-
"hover:bg-ui-bg-field-hover",
|
|
9953
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9954
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9955
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9956
|
+
/* @__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" }) }),
|
|
9957
|
+
/* @__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" }) })
|
|
9958
|
+
] }),
|
|
9959
|
+
fields.map((field, index) => {
|
|
9960
|
+
const isDisabled = field.disabled || false;
|
|
9961
|
+
let placeholder = "-";
|
|
9962
|
+
if (typeof field.value === "object") {
|
|
9963
|
+
placeholder = "{ ... }";
|
|
9964
|
+
}
|
|
9965
|
+
if (Array.isArray(field.value)) {
|
|
9966
|
+
placeholder = "[ ... ]";
|
|
9967
|
+
}
|
|
9968
|
+
return /* @__PURE__ */ jsx(
|
|
9969
|
+
ConditionalTooltip,
|
|
9927
9970
|
{
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
};
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
}
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9971
|
+
showTooltip: isDisabled,
|
|
9972
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9973
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9974
|
+
/* @__PURE__ */ jsxs(
|
|
9975
|
+
"div",
|
|
9976
|
+
{
|
|
9977
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
9978
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9979
|
+
}),
|
|
9980
|
+
children: [
|
|
9981
|
+
/* @__PURE__ */ jsx(
|
|
9982
|
+
Form$2.Field,
|
|
9983
|
+
{
|
|
9984
|
+
control: form.control,
|
|
9985
|
+
name: `metadata.${index}.key`,
|
|
9986
|
+
render: ({ field: field2 }) => {
|
|
9987
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9988
|
+
GridInput,
|
|
9989
|
+
{
|
|
9990
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9991
|
+
...field2,
|
|
9992
|
+
disabled: isDisabled,
|
|
9993
|
+
placeholder: "Key"
|
|
9994
|
+
}
|
|
9995
|
+
) }) });
|
|
9996
|
+
}
|
|
9997
|
+
}
|
|
9998
|
+
),
|
|
9999
|
+
/* @__PURE__ */ jsx(
|
|
10000
|
+
Form$2.Field,
|
|
10001
|
+
{
|
|
10002
|
+
control: form.control,
|
|
10003
|
+
name: `metadata.${index}.value`,
|
|
10004
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10005
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10006
|
+
GridInput,
|
|
10007
|
+
{
|
|
10008
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10009
|
+
...field2,
|
|
10010
|
+
value: isDisabled ? placeholder : value,
|
|
10011
|
+
disabled: isDisabled,
|
|
10012
|
+
placeholder: "Value"
|
|
10013
|
+
}
|
|
10014
|
+
) }) });
|
|
10015
|
+
}
|
|
10016
|
+
}
|
|
10017
|
+
)
|
|
10018
|
+
]
|
|
10019
|
+
}
|
|
10020
|
+
),
|
|
10021
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10022
|
+
/* @__PURE__ */ jsx(
|
|
10023
|
+
DropdownMenu.Trigger,
|
|
10024
|
+
{
|
|
10025
|
+
className: clx(
|
|
10026
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10027
|
+
{
|
|
10028
|
+
hidden: isDisabled
|
|
10029
|
+
}
|
|
10030
|
+
),
|
|
10031
|
+
disabled: isDisabled,
|
|
10032
|
+
asChild: true,
|
|
10033
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
10034
|
+
}
|
|
10035
|
+
),
|
|
10036
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10037
|
+
/* @__PURE__ */ jsxs(
|
|
10038
|
+
DropdownMenu.Item,
|
|
10039
|
+
{
|
|
10040
|
+
className: "gap-x-2",
|
|
10041
|
+
onClick: () => insertRow(index, "above"),
|
|
10042
|
+
children: [
|
|
10043
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
10044
|
+
"Insert row above"
|
|
10045
|
+
]
|
|
10046
|
+
}
|
|
10047
|
+
),
|
|
10048
|
+
/* @__PURE__ */ jsxs(
|
|
10049
|
+
DropdownMenu.Item,
|
|
10050
|
+
{
|
|
10051
|
+
className: "gap-x-2",
|
|
10052
|
+
onClick: () => insertRow(index, "below"),
|
|
10053
|
+
children: [
|
|
10054
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
10055
|
+
"Insert row below"
|
|
10056
|
+
]
|
|
10057
|
+
}
|
|
10058
|
+
),
|
|
10059
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
10060
|
+
/* @__PURE__ */ jsxs(
|
|
10061
|
+
DropdownMenu.Item,
|
|
10062
|
+
{
|
|
10063
|
+
className: "gap-x-2",
|
|
10064
|
+
onClick: () => deleteRow(index),
|
|
10065
|
+
children: [
|
|
10066
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
10067
|
+
"Delete row"
|
|
10068
|
+
]
|
|
10069
|
+
}
|
|
10070
|
+
)
|
|
10071
|
+
] })
|
|
10072
|
+
] })
|
|
10073
|
+
] })
|
|
10074
|
+
},
|
|
10075
|
+
field.id
|
|
10076
|
+
);
|
|
10077
|
+
})
|
|
10078
|
+
] }),
|
|
10079
|
+
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." })
|
|
10080
|
+
] }),
|
|
10081
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10082
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10083
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10084
|
+
] }) })
|
|
10085
|
+
]
|
|
9966
10086
|
}
|
|
9967
|
-
|
|
9968
|
-
await cancelOrderEdit(void 0, {
|
|
9969
|
-
onError: (e) => {
|
|
9970
|
-
toast.error(e.message);
|
|
9971
|
-
},
|
|
9972
|
-
onSuccess: () => {
|
|
9973
|
-
res = true;
|
|
9974
|
-
}
|
|
9975
|
-
});
|
|
9976
|
-
return res;
|
|
9977
|
-
}, [preview, cancelOrderEdit]);
|
|
9978
|
-
return { onCancel };
|
|
10087
|
+
) });
|
|
9979
10088
|
};
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
|
|
9983
|
-
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
10089
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
10090
|
+
return /* @__PURE__ */ jsx(
|
|
10091
|
+
"input",
|
|
10092
|
+
{
|
|
10093
|
+
ref,
|
|
10094
|
+
...props,
|
|
10095
|
+
autoComplete: "off",
|
|
10096
|
+
className: clx(
|
|
10097
|
+
"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",
|
|
10098
|
+
className
|
|
10099
|
+
)
|
|
10100
|
+
}
|
|
10101
|
+
);
|
|
10102
|
+
});
|
|
10103
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
10104
|
+
const PlaceholderInner = () => {
|
|
10105
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10106
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10107
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10108
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10109
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10110
|
+
] }) })
|
|
10111
|
+
] });
|
|
10112
|
+
};
|
|
10113
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10114
|
+
function getDefaultValues(metadata) {
|
|
10115
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
10116
|
+
return [
|
|
10117
|
+
{
|
|
10118
|
+
key: "",
|
|
10119
|
+
value: "",
|
|
10120
|
+
disabled: false
|
|
10121
|
+
}
|
|
10122
|
+
];
|
|
10123
|
+
}
|
|
10124
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
10125
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10126
|
+
return {
|
|
10127
|
+
key,
|
|
10128
|
+
value,
|
|
10129
|
+
disabled: true
|
|
10130
|
+
};
|
|
10131
|
+
}
|
|
10132
|
+
let stringValue = value;
|
|
10133
|
+
if (typeof value !== "string") {
|
|
10134
|
+
stringValue = JSON.stringify(value);
|
|
10135
|
+
}
|
|
10136
|
+
return {
|
|
10137
|
+
key,
|
|
10138
|
+
value: stringValue,
|
|
10139
|
+
original_key: key
|
|
10140
|
+
};
|
|
10141
|
+
});
|
|
10142
|
+
}
|
|
10143
|
+
function parseValues(values) {
|
|
10144
|
+
const metadata = values.metadata;
|
|
10145
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10146
|
+
if (isEmpty) {
|
|
10147
|
+
return null;
|
|
10148
|
+
}
|
|
10149
|
+
const update = {};
|
|
10150
|
+
metadata.forEach((field) => {
|
|
10151
|
+
let key = field.key;
|
|
10152
|
+
let value = field.value;
|
|
10153
|
+
const disabled = field.disabled;
|
|
10154
|
+
if (!key || !value) {
|
|
10155
|
+
return;
|
|
10156
|
+
}
|
|
10157
|
+
if (disabled) {
|
|
10158
|
+
update[key] = value;
|
|
10159
|
+
return;
|
|
10160
|
+
}
|
|
10161
|
+
key = key.trim();
|
|
10162
|
+
value = value.trim();
|
|
10163
|
+
if (value === "true") {
|
|
10164
|
+
update[key] = true;
|
|
10165
|
+
} else if (value === "false") {
|
|
10166
|
+
update[key] = false;
|
|
10167
|
+
} else {
|
|
10168
|
+
const parsedNumber = parseFloat(value);
|
|
10169
|
+
if (!isNaN(parsedNumber)) {
|
|
10170
|
+
update[key] = parsedNumber;
|
|
10171
|
+
} else {
|
|
10172
|
+
update[key] = value;
|
|
10173
|
+
}
|
|
10174
|
+
}
|
|
10175
|
+
});
|
|
10176
|
+
return update;
|
|
10177
|
+
}
|
|
10178
|
+
function getHasUneditableRows(metadata) {
|
|
10179
|
+
if (!metadata) {
|
|
10180
|
+
return false;
|
|
10181
|
+
}
|
|
10182
|
+
return Object.values(metadata).some(
|
|
10183
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10184
|
+
);
|
|
10185
|
+
}
|
|
10186
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10187
|
+
const promotionsQueryKeys = {
|
|
10188
|
+
list: (query2) => [
|
|
10189
|
+
PROMOTION_QUERY_KEY,
|
|
10190
|
+
query2 ? query2 : void 0
|
|
10191
|
+
],
|
|
10192
|
+
detail: (id, query2) => [
|
|
10193
|
+
PROMOTION_QUERY_KEY,
|
|
10194
|
+
id,
|
|
10195
|
+
query2 ? query2 : void 0
|
|
10196
|
+
]
|
|
10197
|
+
};
|
|
10198
|
+
const usePromotions = (query2, options) => {
|
|
10199
|
+
const { data, ...rest } = useQuery({
|
|
10200
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10201
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10202
|
+
...options
|
|
10203
|
+
});
|
|
10204
|
+
return { ...data, ...rest };
|
|
10205
|
+
};
|
|
10206
|
+
const useCancelOrderEdit = ({ preview }) => {
|
|
10207
|
+
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
10208
|
+
const onCancel = useCallback(async () => {
|
|
10209
|
+
if (!preview) {
|
|
10210
|
+
return true;
|
|
10211
|
+
}
|
|
10212
|
+
let res = false;
|
|
10213
|
+
await cancelOrderEdit(void 0, {
|
|
10214
|
+
onError: (e) => {
|
|
10215
|
+
toast.error(e.message);
|
|
10216
|
+
},
|
|
10217
|
+
onSuccess: () => {
|
|
10218
|
+
res = true;
|
|
10219
|
+
}
|
|
10220
|
+
});
|
|
10221
|
+
return res;
|
|
10222
|
+
}, [preview, cancelOrderEdit]);
|
|
10223
|
+
return { onCancel };
|
|
10224
|
+
};
|
|
10225
|
+
let IS_REQUEST_RUNNING = false;
|
|
10226
|
+
const useInitiateOrderEdit = ({
|
|
10227
|
+
preview
|
|
10228
|
+
}) => {
|
|
10229
|
+
const navigate = useNavigate();
|
|
10230
|
+
const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
|
|
10231
|
+
useEffect(() => {
|
|
10232
|
+
async function run() {
|
|
10233
|
+
if (IS_REQUEST_RUNNING || !preview) {
|
|
9989
10234
|
return;
|
|
9990
10235
|
}
|
|
9991
10236
|
if (preview.order_change) {
|
|
@@ -10004,65 +10249,85 @@ const useInitiateOrderEdit = ({
|
|
|
10004
10249
|
run();
|
|
10005
10250
|
}, [preview, navigate, mutateAsync]);
|
|
10006
10251
|
};
|
|
10007
|
-
|
|
10008
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10009
|
-
}
|
|
10010
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10011
|
-
const Items = () => {
|
|
10252
|
+
const Promotions = () => {
|
|
10012
10253
|
const { id } = useParams();
|
|
10013
10254
|
const {
|
|
10014
10255
|
order: preview,
|
|
10015
|
-
isPending: isPreviewPending,
|
|
10016
10256
|
isError: isPreviewError,
|
|
10017
10257
|
error: previewError
|
|
10018
|
-
} = useOrderPreview(id, void 0
|
|
10019
|
-
placeholderData: keepPreviousData
|
|
10020
|
-
});
|
|
10258
|
+
} = useOrderPreview(id, void 0);
|
|
10021
10259
|
useInitiateOrderEdit({ preview });
|
|
10022
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10023
|
-
id,
|
|
10024
|
-
{
|
|
10025
|
-
fields: "currency_code"
|
|
10026
|
-
},
|
|
10027
|
-
{
|
|
10028
|
-
enabled: !!id
|
|
10029
|
-
}
|
|
10030
|
-
);
|
|
10031
10260
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10032
|
-
if (isError) {
|
|
10033
|
-
throw error;
|
|
10034
|
-
}
|
|
10035
10261
|
if (isPreviewError) {
|
|
10036
10262
|
throw previewError;
|
|
10037
10263
|
}
|
|
10038
|
-
const
|
|
10039
|
-
return /* @__PURE__ */
|
|
10040
|
-
/* @__PURE__ */ jsx(
|
|
10041
|
-
|
|
10042
|
-
] })
|
|
10264
|
+
const isReady = !!preview;
|
|
10265
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10266
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10267
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10268
|
+
] });
|
|
10043
10269
|
};
|
|
10044
|
-
const
|
|
10045
|
-
|
|
10270
|
+
const PromotionForm = ({ preview }) => {
|
|
10271
|
+
const { items, shipping_methods } = preview;
|
|
10046
10272
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10047
|
-
const [
|
|
10048
|
-
null
|
|
10049
|
-
);
|
|
10273
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
10050
10274
|
const { handleSuccess } = useRouteModal();
|
|
10051
|
-
const {
|
|
10275
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10276
|
+
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
10277
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10278
|
+
{
|
|
10279
|
+
code: promoCodes
|
|
10280
|
+
},
|
|
10281
|
+
{
|
|
10282
|
+
enabled: !!promoCodes.length
|
|
10283
|
+
}
|
|
10284
|
+
);
|
|
10285
|
+
const comboboxData = useComboboxData({
|
|
10286
|
+
queryKey: ["promotions", "combobox", promoCodes],
|
|
10287
|
+
queryFn: async (params) => {
|
|
10288
|
+
return await sdk.admin.promotion.list({
|
|
10289
|
+
...params,
|
|
10290
|
+
code: {
|
|
10291
|
+
$nin: promoCodes
|
|
10292
|
+
}
|
|
10293
|
+
});
|
|
10294
|
+
},
|
|
10295
|
+
getOptions: (data) => {
|
|
10296
|
+
return data.promotions.map((promotion) => ({
|
|
10297
|
+
label: promotion.code,
|
|
10298
|
+
value: promotion.code
|
|
10299
|
+
}));
|
|
10300
|
+
}
|
|
10301
|
+
});
|
|
10302
|
+
const add = async (value) => {
|
|
10303
|
+
if (!value) {
|
|
10304
|
+
return;
|
|
10305
|
+
}
|
|
10306
|
+
addPromotions(
|
|
10307
|
+
{
|
|
10308
|
+
promo_codes: [value]
|
|
10309
|
+
},
|
|
10310
|
+
{
|
|
10311
|
+
onError: (e) => {
|
|
10312
|
+
toast.error(e.message);
|
|
10313
|
+
comboboxData.onSearchValueChange("");
|
|
10314
|
+
setComboboxValue("");
|
|
10315
|
+
},
|
|
10316
|
+
onSuccess: () => {
|
|
10317
|
+
comboboxData.onSearchValueChange("");
|
|
10318
|
+
setComboboxValue("");
|
|
10319
|
+
}
|
|
10320
|
+
}
|
|
10321
|
+
);
|
|
10322
|
+
};
|
|
10052
10323
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10053
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10054
|
-
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10055
|
-
const matches = useMemo(() => {
|
|
10056
|
-
return matchSorter(preview.items, query2, {
|
|
10057
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10058
|
-
});
|
|
10059
|
-
}, [preview.items, query2]);
|
|
10324
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10060
10325
|
const onSubmit = async () => {
|
|
10061
10326
|
setIsSubmitting(true);
|
|
10062
10327
|
let requestSucceeded = false;
|
|
10063
10328
|
await requestOrderEdit(void 0, {
|
|
10064
10329
|
onError: (e) => {
|
|
10065
|
-
toast.error(
|
|
10330
|
+
toast.error(e.message);
|
|
10066
10331
|
},
|
|
10067
10332
|
onSuccess: () => {
|
|
10068
10333
|
requestSucceeded = true;
|
|
@@ -10074,7 +10339,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10074
10339
|
}
|
|
10075
10340
|
await confirmOrderEdit(void 0, {
|
|
10076
10341
|
onError: (e) => {
|
|
10077
|
-
toast.error(
|
|
10342
|
+
toast.error(e.message);
|
|
10078
10343
|
},
|
|
10079
10344
|
onSuccess: () => {
|
|
10080
10345
|
handleSuccess();
|
|
@@ -10084,1111 +10349,1196 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10084
10349
|
}
|
|
10085
10350
|
});
|
|
10086
10351
|
};
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
onOpenChangeCallback: (open) => {
|
|
10111
|
-
if (!open) {
|
|
10112
|
-
setModalContent(null);
|
|
10352
|
+
if (isError) {
|
|
10353
|
+
throw error;
|
|
10354
|
+
}
|
|
10355
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10356
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10357
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10358
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10359
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10360
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10361
|
+
] }),
|
|
10362
|
+
/* @__PURE__ */ jsx(
|
|
10363
|
+
Combobox,
|
|
10364
|
+
{
|
|
10365
|
+
id: "promotion-combobox",
|
|
10366
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10367
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10368
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10369
|
+
options: comboboxData.options,
|
|
10370
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10371
|
+
searchValue: comboboxData.searchValue,
|
|
10372
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10373
|
+
onChange: add,
|
|
10374
|
+
value: comboboxValue
|
|
10113
10375
|
}
|
|
10376
|
+
)
|
|
10377
|
+
] }),
|
|
10378
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10379
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10380
|
+
PromotionItem,
|
|
10381
|
+
{
|
|
10382
|
+
promotion,
|
|
10383
|
+
orderId: preview.id,
|
|
10384
|
+
isLoading: isPending
|
|
10114
10385
|
},
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
] }),
|
|
10121
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10122
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10123
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10124
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10125
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10126
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10127
|
-
] }),
|
|
10128
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10129
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10130
|
-
Input,
|
|
10131
|
-
{
|
|
10132
|
-
type: "search",
|
|
10133
|
-
placeholder: "Search items",
|
|
10134
|
-
value: searchValue,
|
|
10135
|
-
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10136
|
-
}
|
|
10137
|
-
) }),
|
|
10138
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10139
|
-
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10140
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10141
|
-
/* @__PURE__ */ jsx(
|
|
10142
|
-
StackedModalTrigger$1,
|
|
10143
|
-
{
|
|
10144
|
-
type: "add-items",
|
|
10145
|
-
setModalContent
|
|
10146
|
-
}
|
|
10147
|
-
),
|
|
10148
|
-
/* @__PURE__ */ jsx(
|
|
10149
|
-
StackedModalTrigger$1,
|
|
10150
|
-
{
|
|
10151
|
-
type: "add-custom-item",
|
|
10152
|
-
setModalContent
|
|
10153
|
-
}
|
|
10154
|
-
)
|
|
10155
|
-
] })
|
|
10156
|
-
] })
|
|
10157
|
-
] })
|
|
10158
|
-
] }),
|
|
10159
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10160
|
-
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
|
|
10161
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10162
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10163
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10164
|
-
/* @__PURE__ */ jsx("div", {})
|
|
10165
|
-
] }) }),
|
|
10166
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
10167
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10168
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10169
|
-
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10170
|
-
Item,
|
|
10171
|
-
{
|
|
10172
|
-
item,
|
|
10173
|
-
preview,
|
|
10174
|
-
currencyCode
|
|
10175
|
-
},
|
|
10176
|
-
item.id
|
|
10177
|
-
)) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
10178
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10179
|
-
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10180
|
-
'No items found for "',
|
|
10181
|
-
query2,
|
|
10182
|
-
'".'
|
|
10183
|
-
] })
|
|
10184
|
-
] }) })
|
|
10185
|
-
] })
|
|
10186
|
-
] }),
|
|
10187
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10188
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10189
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10190
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10191
|
-
Text,
|
|
10192
|
-
{
|
|
10193
|
-
size: "small",
|
|
10194
|
-
leading: "compact",
|
|
10195
|
-
className: "text-ui-fg-subtle",
|
|
10196
|
-
children: [
|
|
10197
|
-
itemCount,
|
|
10198
|
-
" ",
|
|
10199
|
-
itemCount === 1 ? "item" : "items"
|
|
10200
|
-
]
|
|
10201
|
-
}
|
|
10202
|
-
) }),
|
|
10203
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10204
|
-
] })
|
|
10205
|
-
] }) }),
|
|
10206
|
-
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10207
|
-
CustomItemForm,
|
|
10208
|
-
{
|
|
10209
|
-
orderId: preview.id,
|
|
10210
|
-
currencyCode
|
|
10211
|
-
}
|
|
10212
|
-
) : null)
|
|
10213
|
-
]
|
|
10214
|
-
}
|
|
10215
|
-
) }),
|
|
10216
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10217
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10386
|
+
promotion.id
|
|
10387
|
+
)) })
|
|
10388
|
+
] }) }),
|
|
10389
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10390
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10218
10391
|
/* @__PURE__ */ jsx(
|
|
10219
10392
|
Button,
|
|
10220
10393
|
{
|
|
10221
10394
|
size: "small",
|
|
10222
|
-
type: "
|
|
10223
|
-
|
|
10224
|
-
isLoading: isSubmitting,
|
|
10395
|
+
type: "submit",
|
|
10396
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10225
10397
|
children: "Save"
|
|
10226
10398
|
}
|
|
10227
10399
|
)
|
|
10228
10400
|
] }) })
|
|
10229
10401
|
] });
|
|
10230
10402
|
};
|
|
10231
|
-
const
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
const
|
|
10238
|
-
const
|
|
10239
|
-
|
|
10240
|
-
defaultValues: {
|
|
10241
|
-
quantity: item.quantity,
|
|
10242
|
-
unit_price: item.unit_price
|
|
10243
|
-
},
|
|
10244
|
-
resolver: zodResolver(variantItemSchema)
|
|
10245
|
-
});
|
|
10246
|
-
const actionId = useMemo(() => {
|
|
10247
|
-
var _a, _b;
|
|
10248
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10249
|
-
}, [item]);
|
|
10250
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10251
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10252
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10253
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10254
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10255
|
-
setEditing(false);
|
|
10256
|
-
return;
|
|
10257
|
-
}
|
|
10258
|
-
if (!actionId) {
|
|
10259
|
-
await updateOriginalItem(
|
|
10260
|
-
{
|
|
10261
|
-
item_id: item.id,
|
|
10262
|
-
quantity: data.quantity,
|
|
10263
|
-
unit_price: convertNumber(data.unit_price)
|
|
10264
|
-
},
|
|
10265
|
-
{
|
|
10266
|
-
onSuccess: () => {
|
|
10267
|
-
setEditing(false);
|
|
10268
|
-
},
|
|
10269
|
-
onError: (e) => {
|
|
10270
|
-
toast.error(e.message);
|
|
10271
|
-
}
|
|
10272
|
-
}
|
|
10273
|
-
);
|
|
10274
|
-
return;
|
|
10275
|
-
}
|
|
10276
|
-
await updateActionItem(
|
|
10403
|
+
const PromotionItem = ({
|
|
10404
|
+
promotion,
|
|
10405
|
+
orderId,
|
|
10406
|
+
isLoading
|
|
10407
|
+
}) => {
|
|
10408
|
+
var _a;
|
|
10409
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10410
|
+
const onRemove = async () => {
|
|
10411
|
+
removePromotions(
|
|
10277
10412
|
{
|
|
10278
|
-
|
|
10279
|
-
quantity: data.quantity,
|
|
10280
|
-
unit_price: convertNumber(data.unit_price)
|
|
10413
|
+
promo_codes: [promotion.code]
|
|
10281
10414
|
},
|
|
10282
10415
|
{
|
|
10283
|
-
onSuccess: () => {
|
|
10284
|
-
setEditing(false);
|
|
10285
|
-
},
|
|
10286
10416
|
onError: (e) => {
|
|
10287
10417
|
toast.error(e.message);
|
|
10288
10418
|
}
|
|
10289
10419
|
}
|
|
10290
10420
|
);
|
|
10291
|
-
}
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
10421
|
+
};
|
|
10422
|
+
const displayValue = getDisplayValue(promotion);
|
|
10423
|
+
return /* @__PURE__ */ jsxs(
|
|
10424
|
+
"div",
|
|
10425
|
+
{
|
|
10426
|
+
className: clx(
|
|
10427
|
+
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
10296
10428
|
{
|
|
10297
|
-
|
|
10298
|
-
alt: item.product_title ?? void 0
|
|
10429
|
+
"animate-pulse": isLoading
|
|
10299
10430
|
}
|
|
10300
10431
|
),
|
|
10301
|
-
|
|
10302
|
-
/* @__PURE__ */ jsxs("div", {
|
|
10303
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children:
|
|
10304
|
-
/* @__PURE__ */ jsxs(
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
size: "small",
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
item.variant_title,
|
|
10313
|
-
")"
|
|
10314
|
-
]
|
|
10315
|
-
}
|
|
10316
|
-
)
|
|
10317
|
-
] }),
|
|
10432
|
+
children: [
|
|
10433
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10434
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
10435
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
10436
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
10437
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
10438
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
10439
|
+
] }),
|
|
10440
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
10441
|
+
] })
|
|
10442
|
+
] }),
|
|
10318
10443
|
/* @__PURE__ */ jsx(
|
|
10319
|
-
|
|
10444
|
+
IconButton,
|
|
10320
10445
|
{
|
|
10321
10446
|
size: "small",
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10447
|
+
type: "button",
|
|
10448
|
+
variant: "transparent",
|
|
10449
|
+
onClick: onRemove,
|
|
10450
|
+
isLoading: isPending || isLoading,
|
|
10451
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
10325
10452
|
}
|
|
10326
10453
|
)
|
|
10327
|
-
]
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10454
|
+
]
|
|
10455
|
+
},
|
|
10456
|
+
promotion.id
|
|
10457
|
+
);
|
|
10458
|
+
};
|
|
10459
|
+
function getDisplayValue(promotion) {
|
|
10460
|
+
var _a, _b, _c, _d;
|
|
10461
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
10462
|
+
if (!value) {
|
|
10463
|
+
return null;
|
|
10464
|
+
}
|
|
10465
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
10466
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
10467
|
+
if (!currency) {
|
|
10468
|
+
return null;
|
|
10469
|
+
}
|
|
10470
|
+
return getLocaleAmount(value, currency);
|
|
10471
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
10472
|
+
return formatPercentage(value);
|
|
10473
|
+
}
|
|
10474
|
+
return null;
|
|
10475
|
+
}
|
|
10476
|
+
const formatter = new Intl.NumberFormat([], {
|
|
10477
|
+
style: "percent",
|
|
10478
|
+
minimumFractionDigits: 2
|
|
10479
|
+
});
|
|
10480
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
10481
|
+
let val = value || 0;
|
|
10482
|
+
if (!isPercentageValue) {
|
|
10483
|
+
val = val / 100;
|
|
10484
|
+
}
|
|
10485
|
+
return formatter.format(val);
|
|
10486
|
+
};
|
|
10487
|
+
function getPromotionCodes(items, shippingMethods) {
|
|
10488
|
+
const codes = /* @__PURE__ */ new Set();
|
|
10489
|
+
for (const item of items) {
|
|
10490
|
+
if (item.adjustments) {
|
|
10491
|
+
for (const adjustment of item.adjustments) {
|
|
10492
|
+
if (adjustment.code) {
|
|
10493
|
+
codes.add(adjustment.code);
|
|
10336
10494
|
}
|
|
10337
10495
|
}
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10346
|
-
CurrencyInput,
|
|
10347
|
-
{
|
|
10348
|
-
...field,
|
|
10349
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10350
|
-
code: currencyCode,
|
|
10351
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10352
|
-
}
|
|
10353
|
-
) }) });
|
|
10496
|
+
}
|
|
10497
|
+
}
|
|
10498
|
+
for (const shippingMethod of shippingMethods) {
|
|
10499
|
+
if (shippingMethod.adjustments) {
|
|
10500
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
10501
|
+
if (adjustment.code) {
|
|
10502
|
+
codes.add(adjustment.code);
|
|
10354
10503
|
}
|
|
10355
10504
|
}
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10363
|
-
|
|
10364
|
-
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10505
|
+
}
|
|
10506
|
+
}
|
|
10507
|
+
return Array.from(codes);
|
|
10508
|
+
}
|
|
10509
|
+
const SalesChannel = () => {
|
|
10510
|
+
const { id } = useParams();
|
|
10511
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10512
|
+
id,
|
|
10513
|
+
{
|
|
10514
|
+
fields: "+sales_channel_id"
|
|
10515
|
+
},
|
|
10516
|
+
{
|
|
10517
|
+
enabled: !!id
|
|
10518
|
+
}
|
|
10519
|
+
);
|
|
10520
|
+
if (isError) {
|
|
10521
|
+
throw error;
|
|
10522
|
+
}
|
|
10523
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
10524
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10525
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10526
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
10527
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
10528
|
+
] }),
|
|
10529
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
10530
|
+
] });
|
|
10370
10531
|
};
|
|
10371
|
-
const
|
|
10372
|
-
quantity: numberType(),
|
|
10373
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10374
|
-
});
|
|
10375
|
-
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
10376
|
-
const [editing, setEditing] = useState(false);
|
|
10377
|
-
const { quantity, unit_price, title } = item;
|
|
10532
|
+
const SalesChannelForm = ({ order }) => {
|
|
10378
10533
|
const form = useForm({
|
|
10379
10534
|
defaultValues: {
|
|
10380
|
-
|
|
10381
|
-
quantity,
|
|
10382
|
-
unit_price
|
|
10535
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
10383
10536
|
},
|
|
10384
|
-
resolver: zodResolver(
|
|
10537
|
+
resolver: zodResolver(schema$2)
|
|
10385
10538
|
});
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
title,
|
|
10389
|
-
quantity,
|
|
10390
|
-
unit_price
|
|
10391
|
-
});
|
|
10392
|
-
}, [form, title, quantity, unit_price]);
|
|
10393
|
-
const actionId = useMemo(() => {
|
|
10394
|
-
var _a, _b;
|
|
10395
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10396
|
-
}, [item]);
|
|
10397
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10398
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10399
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10400
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10539
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10540
|
+
const { handleSuccess } = useRouteModal();
|
|
10401
10541
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10402
|
-
|
|
10403
|
-
setEditing(false);
|
|
10404
|
-
return;
|
|
10405
|
-
}
|
|
10406
|
-
if (!actionId) {
|
|
10407
|
-
await updateOriginalItem(
|
|
10408
|
-
{
|
|
10409
|
-
item_id: item.id,
|
|
10410
|
-
quantity: data.quantity,
|
|
10411
|
-
unit_price: convertNumber(data.unit_price)
|
|
10412
|
-
},
|
|
10413
|
-
{
|
|
10414
|
-
onSuccess: () => {
|
|
10415
|
-
setEditing(false);
|
|
10416
|
-
},
|
|
10417
|
-
onError: (e) => {
|
|
10418
|
-
toast.error(e.message);
|
|
10419
|
-
}
|
|
10420
|
-
}
|
|
10421
|
-
);
|
|
10422
|
-
return;
|
|
10423
|
-
}
|
|
10424
|
-
if (data.quantity === 0) {
|
|
10425
|
-
await removeActionItem(actionId, {
|
|
10426
|
-
onSuccess: () => {
|
|
10427
|
-
setEditing(false);
|
|
10428
|
-
},
|
|
10429
|
-
onError: (e) => {
|
|
10430
|
-
toast.error(e.message);
|
|
10431
|
-
}
|
|
10432
|
-
});
|
|
10433
|
-
return;
|
|
10434
|
-
}
|
|
10435
|
-
await updateActionItem(
|
|
10542
|
+
await mutateAsync(
|
|
10436
10543
|
{
|
|
10437
|
-
|
|
10438
|
-
quantity: data.quantity,
|
|
10439
|
-
unit_price: convertNumber(data.unit_price)
|
|
10544
|
+
sales_channel_id: data.sales_channel_id
|
|
10440
10545
|
},
|
|
10441
10546
|
{
|
|
10442
10547
|
onSuccess: () => {
|
|
10443
|
-
|
|
10548
|
+
toast.success("Sales channel updated");
|
|
10549
|
+
handleSuccess();
|
|
10444
10550
|
},
|
|
10445
|
-
onError: (
|
|
10446
|
-
toast.error(
|
|
10551
|
+
onError: (error) => {
|
|
10552
|
+
toast.error(error.message);
|
|
10447
10553
|
}
|
|
10448
10554
|
}
|
|
10449
10555
|
);
|
|
10450
10556
|
});
|
|
10451
|
-
return /* @__PURE__ */ jsx(Form
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
{
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10557
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10558
|
+
KeyboundForm,
|
|
10559
|
+
{
|
|
10560
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10561
|
+
onSubmit,
|
|
10562
|
+
children: [
|
|
10563
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
10564
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10565
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10566
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10567
|
+
] }) })
|
|
10568
|
+
]
|
|
10569
|
+
}
|
|
10570
|
+
) });
|
|
10571
|
+
};
|
|
10572
|
+
const SalesChannelField = ({ control, order }) => {
|
|
10573
|
+
const salesChannels = useComboboxData({
|
|
10574
|
+
queryFn: async (params) => {
|
|
10575
|
+
return await sdk.admin.salesChannel.list(params);
|
|
10576
|
+
},
|
|
10577
|
+
queryKey: ["sales-channels"],
|
|
10578
|
+
getOptions: (data) => {
|
|
10579
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
10580
|
+
label: salesChannel.name,
|
|
10581
|
+
value: salesChannel.id
|
|
10582
|
+
}));
|
|
10583
|
+
},
|
|
10584
|
+
defaultValue: order.sales_channel_id || void 0
|
|
10585
|
+
});
|
|
10586
|
+
return /* @__PURE__ */ jsx(
|
|
10587
|
+
Form$2.Field,
|
|
10588
|
+
{
|
|
10589
|
+
control,
|
|
10590
|
+
name: "sales_channel_id",
|
|
10591
|
+
render: ({ field }) => {
|
|
10592
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10593
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
10594
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10595
|
+
Combobox,
|
|
10596
|
+
{
|
|
10597
|
+
options: salesChannels.options,
|
|
10598
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
10599
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
10600
|
+
searchValue: salesChannels.searchValue,
|
|
10601
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
10602
|
+
placeholder: "Select sales channel",
|
|
10603
|
+
...field
|
|
10604
|
+
}
|
|
10605
|
+
) }),
|
|
10606
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10607
|
+
] });
|
|
10497
10608
|
}
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10609
|
+
}
|
|
10610
|
+
);
|
|
10611
|
+
};
|
|
10612
|
+
const schema$2 = objectType({
|
|
10613
|
+
sales_channel_id: stringType().min(1)
|
|
10614
|
+
});
|
|
10615
|
+
const NumberInput = forwardRef(
|
|
10616
|
+
({
|
|
10617
|
+
value,
|
|
10618
|
+
onChange,
|
|
10619
|
+
size = "base",
|
|
10620
|
+
min = 0,
|
|
10621
|
+
max = 100,
|
|
10622
|
+
step = 1,
|
|
10623
|
+
className,
|
|
10624
|
+
disabled,
|
|
10625
|
+
...props
|
|
10626
|
+
}, ref) => {
|
|
10627
|
+
const handleChange = (event) => {
|
|
10628
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
10629
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
10630
|
+
onChange(newValue);
|
|
10631
|
+
}
|
|
10632
|
+
};
|
|
10633
|
+
const handleIncrement = () => {
|
|
10634
|
+
const newValue = value + step;
|
|
10635
|
+
if (max === void 0 || newValue <= max) {
|
|
10636
|
+
onChange(newValue);
|
|
10637
|
+
}
|
|
10638
|
+
};
|
|
10639
|
+
const handleDecrement = () => {
|
|
10640
|
+
const newValue = value - step;
|
|
10641
|
+
if (min === void 0 || newValue >= min) {
|
|
10642
|
+
onChange(newValue);
|
|
10643
|
+
}
|
|
10644
|
+
};
|
|
10645
|
+
return /* @__PURE__ */ jsxs(
|
|
10646
|
+
"div",
|
|
10501
10647
|
{
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10648
|
+
className: clx(
|
|
10649
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
10650
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
10651
|
+
{
|
|
10652
|
+
"h-7": size === "small",
|
|
10653
|
+
"h-8": size === "base"
|
|
10654
|
+
},
|
|
10655
|
+
className
|
|
10656
|
+
),
|
|
10657
|
+
children: [
|
|
10658
|
+
/* @__PURE__ */ jsx(
|
|
10659
|
+
"input",
|
|
10660
|
+
{
|
|
10661
|
+
ref,
|
|
10662
|
+
type: "number",
|
|
10663
|
+
value,
|
|
10664
|
+
onChange: handleChange,
|
|
10665
|
+
min,
|
|
10666
|
+
max,
|
|
10667
|
+
step,
|
|
10668
|
+
className: clx(
|
|
10669
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
10670
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
10671
|
+
"placeholder:text-ui-fg-muted"
|
|
10672
|
+
),
|
|
10673
|
+
...props
|
|
10674
|
+
}
|
|
10675
|
+
),
|
|
10676
|
+
/* @__PURE__ */ jsxs(
|
|
10677
|
+
"button",
|
|
10678
|
+
{
|
|
10679
|
+
className: clx(
|
|
10680
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
10681
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10682
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
10683
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
10684
|
+
{
|
|
10685
|
+
"size-7": size === "small",
|
|
10686
|
+
"size-8": size === "base"
|
|
10687
|
+
}
|
|
10688
|
+
),
|
|
10689
|
+
type: "button",
|
|
10690
|
+
onClick: handleDecrement,
|
|
10691
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
10692
|
+
children: [
|
|
10693
|
+
/* @__PURE__ */ jsx(Minus, {}),
|
|
10694
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
10695
|
+
]
|
|
10696
|
+
}
|
|
10697
|
+
),
|
|
10698
|
+
/* @__PURE__ */ jsxs(
|
|
10699
|
+
"button",
|
|
10700
|
+
{
|
|
10701
|
+
className: clx(
|
|
10702
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
10703
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10704
|
+
"focus:bg-ui-bg-field-hover",
|
|
10705
|
+
"hover:bg-ui-bg-field-hover",
|
|
10706
|
+
{
|
|
10707
|
+
"size-7": size === "small",
|
|
10708
|
+
"size-8": size === "base"
|
|
10709
|
+
}
|
|
10710
|
+
),
|
|
10711
|
+
type: "button",
|
|
10712
|
+
onClick: handleIncrement,
|
|
10713
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
10714
|
+
children: [
|
|
10715
|
+
/* @__PURE__ */ jsx(Plus, {}),
|
|
10716
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
10717
|
+
]
|
|
10718
|
+
}
|
|
10719
|
+
)
|
|
10720
|
+
]
|
|
10509
10721
|
}
|
|
10510
|
-
)
|
|
10511
|
-
|
|
10722
|
+
);
|
|
10723
|
+
}
|
|
10724
|
+
);
|
|
10725
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
10726
|
+
const productVariantsQueryKeys = {
|
|
10727
|
+
list: (query2) => [
|
|
10728
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
10729
|
+
query2 ? query2 : void 0
|
|
10730
|
+
]
|
|
10512
10731
|
};
|
|
10513
|
-
const
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
setIsOpen(STACKED_MODAL_ID, true);
|
|
10521
|
-
}, [setModalContent, setIsOpen, type]);
|
|
10522
|
-
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
10732
|
+
const useProductVariants = (query2, options) => {
|
|
10733
|
+
const { data, ...rest } = useQuery({
|
|
10734
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
10735
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
10736
|
+
...options
|
|
10737
|
+
});
|
|
10738
|
+
return { ...data, ...rest };
|
|
10523
10739
|
};
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
}, {})
|
|
10542
|
-
);
|
|
10543
|
-
}, [items]);
|
|
10544
|
-
const { q, order, offset } = useQueryParams(
|
|
10545
|
-
["q", "order", "offset"],
|
|
10546
|
-
VARIANT_PREFIX
|
|
10547
|
-
);
|
|
10548
|
-
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10740
|
+
function convertNumber(value) {
|
|
10741
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10742
|
+
}
|
|
10743
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10744
|
+
const Items = () => {
|
|
10745
|
+
const { id } = useParams();
|
|
10746
|
+
const {
|
|
10747
|
+
order: preview,
|
|
10748
|
+
isPending: isPreviewPending,
|
|
10749
|
+
isError: isPreviewError,
|
|
10750
|
+
error: previewError
|
|
10751
|
+
} = useOrderPreview(id, void 0, {
|
|
10752
|
+
placeholderData: keepPreviousData
|
|
10753
|
+
});
|
|
10754
|
+
useInitiateOrderEdit({ preview });
|
|
10755
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10756
|
+
id,
|
|
10549
10757
|
{
|
|
10550
|
-
|
|
10551
|
-
order,
|
|
10552
|
-
offset: offset ? parseInt(offset) : void 0,
|
|
10553
|
-
limit: LIMIT
|
|
10758
|
+
fields: "currency_code"
|
|
10554
10759
|
},
|
|
10555
10760
|
{
|
|
10556
|
-
|
|
10761
|
+
enabled: !!id
|
|
10557
10762
|
}
|
|
10558
10763
|
);
|
|
10559
|
-
const
|
|
10560
|
-
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10561
|
-
const onSubmit = async () => {
|
|
10562
|
-
const ids = Object.keys(rowSelection).filter(
|
|
10563
|
-
(id) => !items.find((i) => i.variant_id === id)
|
|
10564
|
-
);
|
|
10565
|
-
await mutateAsync(
|
|
10566
|
-
{
|
|
10567
|
-
items: ids.map((id) => ({
|
|
10568
|
-
variant_id: id,
|
|
10569
|
-
quantity: 1
|
|
10570
|
-
}))
|
|
10571
|
-
},
|
|
10572
|
-
{
|
|
10573
|
-
onSuccess: () => {
|
|
10574
|
-
setRowSelection({});
|
|
10575
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10576
|
-
},
|
|
10577
|
-
onError: (e) => {
|
|
10578
|
-
toast.error(e.message);
|
|
10579
|
-
}
|
|
10580
|
-
}
|
|
10581
|
-
);
|
|
10582
|
-
};
|
|
10764
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10583
10765
|
if (isError) {
|
|
10584
10766
|
throw error;
|
|
10585
10767
|
}
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10768
|
+
if (isPreviewError) {
|
|
10769
|
+
throw previewError;
|
|
10770
|
+
}
|
|
10771
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
10772
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10773
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
10774
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10775
|
+
] }) });
|
|
10776
|
+
};
|
|
10777
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
10778
|
+
var _a;
|
|
10779
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10780
|
+
const [modalContent, setModalContent] = useState(
|
|
10781
|
+
null
|
|
10782
|
+
);
|
|
10783
|
+
const { handleSuccess } = useRouteModal();
|
|
10784
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
10785
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10786
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10787
|
+
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10788
|
+
const matches = useMemo(() => {
|
|
10789
|
+
return matchSorter(preview.items, query2, {
|
|
10790
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10791
|
+
});
|
|
10792
|
+
}, [preview.items, query2]);
|
|
10793
|
+
const onSubmit = async () => {
|
|
10794
|
+
setIsSubmitting(true);
|
|
10795
|
+
let requestSucceeded = false;
|
|
10796
|
+
await requestOrderEdit(void 0, {
|
|
10797
|
+
onError: (e) => {
|
|
10798
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
10597
10799
|
},
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
{
|
|
10606
|
-
data: variants,
|
|
10607
|
-
columns,
|
|
10608
|
-
isLoading: isPending,
|
|
10609
|
-
getRowId: (row) => row.id,
|
|
10610
|
-
rowCount: count,
|
|
10611
|
-
prefix: VARIANT_PREFIX,
|
|
10612
|
-
layout: "fill",
|
|
10613
|
-
rowSelection: {
|
|
10614
|
-
state: rowSelection,
|
|
10615
|
-
onRowSelectionChange: setRowSelection,
|
|
10616
|
-
enableRowSelection: (row) => {
|
|
10617
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
10618
|
-
}
|
|
10619
|
-
},
|
|
10620
|
-
autoFocusSearch: true
|
|
10621
|
-
}
|
|
10622
|
-
) }),
|
|
10623
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10624
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10625
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
10626
|
-
] }) })
|
|
10627
|
-
]
|
|
10800
|
+
onSuccess: () => {
|
|
10801
|
+
requestSucceeded = true;
|
|
10802
|
+
}
|
|
10803
|
+
});
|
|
10804
|
+
if (!requestSucceeded) {
|
|
10805
|
+
setIsSubmitting(false);
|
|
10806
|
+
return;
|
|
10628
10807
|
}
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
] });
|
|
10650
|
-
},
|
|
10651
|
-
enableSorting: true
|
|
10652
|
-
}),
|
|
10653
|
-
columnHelper.accessor("title", {
|
|
10654
|
-
header: "Variant",
|
|
10655
|
-
enableSorting: true
|
|
10656
|
-
}),
|
|
10657
|
-
columnHelper.accessor("sku", {
|
|
10658
|
-
header: "SKU",
|
|
10659
|
-
cell: ({ getValue }) => {
|
|
10660
|
-
return getValue() ?? "-";
|
|
10661
|
-
},
|
|
10662
|
-
enableSorting: true
|
|
10663
|
-
}),
|
|
10664
|
-
columnHelper.accessor("updated_at", {
|
|
10665
|
-
header: "Updated",
|
|
10666
|
-
cell: ({ getValue }) => {
|
|
10667
|
-
return /* @__PURE__ */ jsx(
|
|
10668
|
-
Tooltip,
|
|
10669
|
-
{
|
|
10670
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10671
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10672
|
-
}
|
|
10673
|
-
);
|
|
10674
|
-
},
|
|
10675
|
-
enableSorting: true,
|
|
10676
|
-
sortAscLabel: "Oldest first",
|
|
10677
|
-
sortDescLabel: "Newest first"
|
|
10678
|
-
}),
|
|
10679
|
-
columnHelper.accessor("created_at", {
|
|
10680
|
-
header: "Created",
|
|
10681
|
-
cell: ({ getValue }) => {
|
|
10682
|
-
return /* @__PURE__ */ jsx(
|
|
10683
|
-
Tooltip,
|
|
10684
|
-
{
|
|
10685
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10686
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10687
|
-
}
|
|
10688
|
-
);
|
|
10689
|
-
},
|
|
10690
|
-
enableSorting: true,
|
|
10691
|
-
sortAscLabel: "Oldest first",
|
|
10692
|
-
sortDescLabel: "Newest first"
|
|
10693
|
-
})
|
|
10694
|
-
];
|
|
10695
|
-
}, []);
|
|
10696
|
-
};
|
|
10697
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10698
|
-
const { setIsOpen } = useStackedModal();
|
|
10699
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10700
|
-
const form = useForm({
|
|
10701
|
-
defaultValues: {
|
|
10702
|
-
title: "",
|
|
10703
|
-
quantity: 1,
|
|
10704
|
-
unit_price: ""
|
|
10808
|
+
await confirmOrderEdit(void 0, {
|
|
10809
|
+
onError: (e) => {
|
|
10810
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10811
|
+
},
|
|
10812
|
+
onSuccess: () => {
|
|
10813
|
+
handleSuccess();
|
|
10814
|
+
},
|
|
10815
|
+
onSettled: () => {
|
|
10816
|
+
setIsSubmitting(false);
|
|
10817
|
+
}
|
|
10818
|
+
});
|
|
10819
|
+
};
|
|
10820
|
+
const onKeyDown = useCallback(
|
|
10821
|
+
(e) => {
|
|
10822
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10823
|
+
if (modalContent || isSubmitting) {
|
|
10824
|
+
return;
|
|
10825
|
+
}
|
|
10826
|
+
onSubmit();
|
|
10827
|
+
}
|
|
10705
10828
|
},
|
|
10706
|
-
|
|
10707
|
-
|
|
10708
|
-
|
|
10709
|
-
|
|
10829
|
+
[modalContent, isSubmitting, onSubmit]
|
|
10830
|
+
);
|
|
10831
|
+
useEffect(() => {
|
|
10832
|
+
document.addEventListener("keydown", onKeyDown);
|
|
10833
|
+
return () => {
|
|
10834
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
10835
|
+
};
|
|
10836
|
+
}, [onKeyDown]);
|
|
10837
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10838
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10839
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
10840
|
+
StackedFocusModal,
|
|
10710
10841
|
{
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
|
|
10714
|
-
|
|
10715
|
-
unit_price: convertNumber(data.unit_price)
|
|
10842
|
+
id: STACKED_MODAL_ID,
|
|
10843
|
+
onOpenChangeCallback: (open) => {
|
|
10844
|
+
if (!open) {
|
|
10845
|
+
setModalContent(null);
|
|
10716
10846
|
}
|
|
10717
|
-
]
|
|
10718
|
-
},
|
|
10719
|
-
{
|
|
10720
|
-
onSuccess: () => {
|
|
10721
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10722
10847
|
},
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
}
|
|
10726
|
-
}
|
|
10727
|
-
);
|
|
10728
|
-
});
|
|
10729
|
-
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
10730
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
10731
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
|
|
10732
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10733
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10734
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
10735
|
-
] }),
|
|
10736
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10737
|
-
/* @__PURE__ */ jsx(
|
|
10738
|
-
Form$2.Field,
|
|
10739
|
-
{
|
|
10740
|
-
control: form.control,
|
|
10741
|
-
name: "title",
|
|
10742
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10848
|
+
children: [
|
|
10849
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
10743
10850
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
10744
|
-
/* @__PURE__ */ jsx(
|
|
10745
|
-
/* @__PURE__ */ jsx(
|
|
10851
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
|
|
10852
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
|
|
10746
10853
|
] }),
|
|
10747
|
-
/* @__PURE__ */
|
|
10748
|
-
|
|
10749
|
-
/* @__PURE__ */
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10854
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10855
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10856
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10857
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10858
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10859
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10860
|
+
] }),
|
|
10861
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10862
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10863
|
+
Input,
|
|
10864
|
+
{
|
|
10865
|
+
type: "search",
|
|
10866
|
+
placeholder: "Search items",
|
|
10867
|
+
value: searchValue,
|
|
10868
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10869
|
+
}
|
|
10870
|
+
) }),
|
|
10871
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10872
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10873
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10874
|
+
/* @__PURE__ */ jsx(
|
|
10875
|
+
StackedModalTrigger$1,
|
|
10876
|
+
{
|
|
10877
|
+
type: "add-items",
|
|
10878
|
+
setModalContent
|
|
10879
|
+
}
|
|
10880
|
+
),
|
|
10881
|
+
/* @__PURE__ */ jsx(
|
|
10882
|
+
StackedModalTrigger$1,
|
|
10883
|
+
{
|
|
10884
|
+
type: "add-custom-item",
|
|
10885
|
+
setModalContent
|
|
10886
|
+
}
|
|
10887
|
+
)
|
|
10888
|
+
] })
|
|
10889
|
+
] })
|
|
10890
|
+
] })
|
|
10891
|
+
] }),
|
|
10892
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10893
|
+
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
|
|
10894
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10895
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10896
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10897
|
+
/* @__PURE__ */ jsx("div", {})
|
|
10898
|
+
] }) }),
|
|
10899
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
10900
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10901
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10902
|
+
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10903
|
+
Item,
|
|
10904
|
+
{
|
|
10905
|
+
item,
|
|
10906
|
+
preview,
|
|
10907
|
+
currencyCode
|
|
10908
|
+
},
|
|
10909
|
+
item.id
|
|
10910
|
+
)) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
10911
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10912
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10913
|
+
'No items found for "',
|
|
10914
|
+
query2,
|
|
10915
|
+
'".'
|
|
10916
|
+
] })
|
|
10917
|
+
] }) })
|
|
10918
|
+
] })
|
|
10764
10919
|
] }),
|
|
10765
|
-
/* @__PURE__ */
|
|
10766
|
-
|
|
10767
|
-
|
|
10920
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10921
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10922
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10923
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10924
|
+
Text,
|
|
10768
10925
|
{
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10926
|
+
size: "small",
|
|
10927
|
+
leading: "compact",
|
|
10928
|
+
className: "text-ui-fg-subtle",
|
|
10929
|
+
children: [
|
|
10930
|
+
itemCount,
|
|
10931
|
+
" ",
|
|
10932
|
+
itemCount === 1 ? "item" : "items"
|
|
10933
|
+
]
|
|
10773
10934
|
}
|
|
10774
10935
|
) }),
|
|
10775
|
-
/* @__PURE__ */ jsx(
|
|
10936
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10776
10937
|
] })
|
|
10777
|
-
] }) })
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
|
|
10938
|
+
] }) }),
|
|
10939
|
+
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10940
|
+
CustomItemForm,
|
|
10941
|
+
{
|
|
10942
|
+
orderId: preview.id,
|
|
10943
|
+
currencyCode
|
|
10944
|
+
}
|
|
10945
|
+
) : null)
|
|
10946
|
+
]
|
|
10947
|
+
}
|
|
10948
|
+
) }),
|
|
10949
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10950
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10781
10951
|
/* @__PURE__ */ jsx(
|
|
10782
|
-
|
|
10952
|
+
Button,
|
|
10783
10953
|
{
|
|
10784
|
-
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10790
|
-
] }),
|
|
10791
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
|
|
10792
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10793
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10794
|
-
] })
|
|
10795
|
-
] }) })
|
|
10954
|
+
size: "small",
|
|
10955
|
+
type: "button",
|
|
10956
|
+
onClick: onSubmit,
|
|
10957
|
+
isLoading: isSubmitting,
|
|
10958
|
+
children: "Save"
|
|
10796
10959
|
}
|
|
10797
10960
|
)
|
|
10798
|
-
] }) }) }),
|
|
10799
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
10800
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10801
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10802
10961
|
] }) })
|
|
10803
|
-
] })
|
|
10804
|
-
};
|
|
10805
|
-
const customItemSchema = objectType({
|
|
10806
|
-
title: stringType().min(1),
|
|
10807
|
-
quantity: numberType(),
|
|
10808
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10809
|
-
});
|
|
10810
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10811
|
-
const promotionsQueryKeys = {
|
|
10812
|
-
list: (query2) => [
|
|
10813
|
-
PROMOTION_QUERY_KEY,
|
|
10814
|
-
query2 ? query2 : void 0
|
|
10815
|
-
],
|
|
10816
|
-
detail: (id, query2) => [
|
|
10817
|
-
PROMOTION_QUERY_KEY,
|
|
10818
|
-
id,
|
|
10819
|
-
query2 ? query2 : void 0
|
|
10820
|
-
]
|
|
10821
|
-
};
|
|
10822
|
-
const usePromotions = (query2, options) => {
|
|
10823
|
-
const { data, ...rest } = useQuery({
|
|
10824
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10825
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10826
|
-
...options
|
|
10827
|
-
});
|
|
10828
|
-
return { ...data, ...rest };
|
|
10962
|
+
] });
|
|
10829
10963
|
};
|
|
10830
|
-
const
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
order: preview,
|
|
10834
|
-
isError: isPreviewError,
|
|
10835
|
-
error: previewError
|
|
10836
|
-
} = useOrderPreview(id, void 0);
|
|
10837
|
-
useInitiateOrderEdit({ preview });
|
|
10838
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10839
|
-
if (isPreviewError) {
|
|
10840
|
-
throw previewError;
|
|
10964
|
+
const Item = ({ item, preview, currencyCode }) => {
|
|
10965
|
+
if (item.variant_id) {
|
|
10966
|
+
return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
|
|
10841
10967
|
}
|
|
10842
|
-
|
|
10843
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10844
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10845
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10846
|
-
] });
|
|
10968
|
+
return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
|
|
10847
10969
|
};
|
|
10848
|
-
const
|
|
10849
|
-
const
|
|
10850
|
-
const
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10854
|
-
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
10855
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10856
|
-
{
|
|
10857
|
-
code: promoCodes
|
|
10970
|
+
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
10971
|
+
const [editing, setEditing] = useState(false);
|
|
10972
|
+
const form = useForm({
|
|
10973
|
+
defaultValues: {
|
|
10974
|
+
quantity: item.quantity,
|
|
10975
|
+
unit_price: item.unit_price
|
|
10858
10976
|
},
|
|
10859
|
-
|
|
10860
|
-
|
|
10977
|
+
resolver: zodResolver(variantItemSchema)
|
|
10978
|
+
});
|
|
10979
|
+
const actionId = useMemo(() => {
|
|
10980
|
+
var _a, _b;
|
|
10981
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10982
|
+
}, [item]);
|
|
10983
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10984
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10985
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10986
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10987
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10988
|
+
setEditing(false);
|
|
10989
|
+
return;
|
|
10861
10990
|
}
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
10991
|
+
if (!actionId) {
|
|
10992
|
+
await updateOriginalItem(
|
|
10993
|
+
{
|
|
10994
|
+
item_id: item.id,
|
|
10995
|
+
quantity: data.quantity,
|
|
10996
|
+
unit_price: convertNumber(data.unit_price)
|
|
10997
|
+
},
|
|
10998
|
+
{
|
|
10999
|
+
onSuccess: () => {
|
|
11000
|
+
setEditing(false);
|
|
11001
|
+
},
|
|
11002
|
+
onError: (e) => {
|
|
11003
|
+
toast.error(e.message);
|
|
11004
|
+
}
|
|
10870
11005
|
}
|
|
10871
|
-
|
|
10872
|
-
},
|
|
10873
|
-
getOptions: (data) => {
|
|
10874
|
-
return data.promotions.map((promotion) => ({
|
|
10875
|
-
label: promotion.code,
|
|
10876
|
-
value: promotion.code
|
|
10877
|
-
}));
|
|
10878
|
-
}
|
|
10879
|
-
});
|
|
10880
|
-
const add = async (value) => {
|
|
10881
|
-
if (!value) {
|
|
11006
|
+
);
|
|
10882
11007
|
return;
|
|
10883
11008
|
}
|
|
10884
|
-
|
|
11009
|
+
await updateActionItem(
|
|
10885
11010
|
{
|
|
10886
|
-
|
|
11011
|
+
action_id: actionId,
|
|
11012
|
+
quantity: data.quantity,
|
|
11013
|
+
unit_price: convertNumber(data.unit_price)
|
|
10887
11014
|
},
|
|
10888
11015
|
{
|
|
10889
|
-
onError: (e) => {
|
|
10890
|
-
toast.error(e.message);
|
|
10891
|
-
comboboxData.onSearchValueChange("");
|
|
10892
|
-
setComboboxValue("");
|
|
10893
|
-
},
|
|
10894
11016
|
onSuccess: () => {
|
|
10895
|
-
|
|
10896
|
-
|
|
11017
|
+
setEditing(false);
|
|
11018
|
+
},
|
|
11019
|
+
onError: (e) => {
|
|
11020
|
+
toast.error(e.message);
|
|
10897
11021
|
}
|
|
10898
11022
|
}
|
|
10899
11023
|
);
|
|
10900
|
-
};
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
setIsSubmitting(false);
|
|
10927
|
-
}
|
|
10928
|
-
});
|
|
10929
|
-
};
|
|
10930
|
-
if (isError) {
|
|
10931
|
-
throw error;
|
|
10932
|
-
}
|
|
10933
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10934
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10935
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10936
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10937
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10938
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11024
|
+
});
|
|
11025
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
|
|
11026
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
|
|
11027
|
+
/* @__PURE__ */ jsx(
|
|
11028
|
+
Thumbnail,
|
|
11029
|
+
{
|
|
11030
|
+
thumbnail: item.thumbnail,
|
|
11031
|
+
alt: item.product_title ?? void 0
|
|
11032
|
+
}
|
|
11033
|
+
),
|
|
11034
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11035
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
11036
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
11037
|
+
/* @__PURE__ */ jsxs(
|
|
11038
|
+
Text,
|
|
11039
|
+
{
|
|
11040
|
+
size: "small",
|
|
11041
|
+
leading: "compact",
|
|
11042
|
+
className: "text-ui-fg-subtle",
|
|
11043
|
+
children: [
|
|
11044
|
+
"(",
|
|
11045
|
+
item.variant_title,
|
|
11046
|
+
")"
|
|
11047
|
+
]
|
|
11048
|
+
}
|
|
11049
|
+
)
|
|
10939
11050
|
] }),
|
|
10940
11051
|
/* @__PURE__ */ jsx(
|
|
10941
|
-
|
|
11052
|
+
Text,
|
|
10942
11053
|
{
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
options: comboboxData.options,
|
|
10948
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10949
|
-
searchValue: comboboxData.searchValue,
|
|
10950
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10951
|
-
onChange: add,
|
|
10952
|
-
value: comboboxValue
|
|
11054
|
+
size: "small",
|
|
11055
|
+
leading: "compact",
|
|
11056
|
+
className: "text-ui-fg-subtle",
|
|
11057
|
+
children: item.variant_sku
|
|
10953
11058
|
}
|
|
10954
11059
|
)
|
|
10955
|
-
] })
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
11060
|
+
] })
|
|
11061
|
+
] }),
|
|
11062
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
|
|
11063
|
+
Form$2.Field,
|
|
11064
|
+
{
|
|
11065
|
+
control: form.control,
|
|
11066
|
+
name: "quantity",
|
|
11067
|
+
render: ({ field }) => {
|
|
11068
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
11069
|
+
}
|
|
11070
|
+
}
|
|
11071
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
11072
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
|
|
11073
|
+
Form$2.Field,
|
|
11074
|
+
{
|
|
11075
|
+
control: form.control,
|
|
11076
|
+
name: "unit_price",
|
|
11077
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
11078
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11079
|
+
CurrencyInput,
|
|
11080
|
+
{
|
|
11081
|
+
...field,
|
|
11082
|
+
symbol: getNativeSymbol(currencyCode),
|
|
11083
|
+
code: currencyCode,
|
|
11084
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
11085
|
+
}
|
|
11086
|
+
) }) });
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
11090
|
+
/* @__PURE__ */ jsx(
|
|
11091
|
+
IconButton,
|
|
11092
|
+
{
|
|
11093
|
+
type: "button",
|
|
11094
|
+
size: "small",
|
|
11095
|
+
onClick: editing ? onSubmit : () => {
|
|
11096
|
+
setEditing(true);
|
|
11097
|
+
},
|
|
11098
|
+
disabled: isPending,
|
|
11099
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
11100
|
+
}
|
|
11101
|
+
)
|
|
11102
|
+
] }) }) });
|
|
11103
|
+
};
|
|
11104
|
+
const variantItemSchema = objectType({
|
|
11105
|
+
quantity: numberType(),
|
|
11106
|
+
unit_price: unionType([numberType(), stringType()])
|
|
11107
|
+
});
|
|
11108
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
11109
|
+
const [editing, setEditing] = useState(false);
|
|
11110
|
+
const { quantity, unit_price, title } = item;
|
|
11111
|
+
const form = useForm({
|
|
11112
|
+
defaultValues: {
|
|
11113
|
+
title,
|
|
11114
|
+
quantity,
|
|
11115
|
+
unit_price
|
|
11116
|
+
},
|
|
11117
|
+
resolver: zodResolver(customItemSchema)
|
|
11118
|
+
});
|
|
11119
|
+
useEffect(() => {
|
|
11120
|
+
form.reset({
|
|
11121
|
+
title,
|
|
11122
|
+
quantity,
|
|
11123
|
+
unit_price
|
|
11124
|
+
});
|
|
11125
|
+
}, [form, title, quantity, unit_price]);
|
|
11126
|
+
const actionId = useMemo(() => {
|
|
11127
|
+
var _a, _b;
|
|
11128
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
11129
|
+
}, [item]);
|
|
11130
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
11131
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
11132
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
11133
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
11134
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11135
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
11136
|
+
setEditing(false);
|
|
11137
|
+
return;
|
|
11138
|
+
}
|
|
11139
|
+
if (!actionId) {
|
|
11140
|
+
await updateOriginalItem(
|
|
10959
11141
|
{
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
11142
|
+
item_id: item.id,
|
|
11143
|
+
quantity: data.quantity,
|
|
11144
|
+
unit_price: convertNumber(data.unit_price)
|
|
10963
11145
|
},
|
|
10964
|
-
promotion.id
|
|
10965
|
-
)) })
|
|
10966
|
-
] }) }),
|
|
10967
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10968
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10969
|
-
/* @__PURE__ */ jsx(
|
|
10970
|
-
Button,
|
|
10971
11146
|
{
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
10975
|
-
|
|
11147
|
+
onSuccess: () => {
|
|
11148
|
+
setEditing(false);
|
|
11149
|
+
},
|
|
11150
|
+
onError: (e) => {
|
|
11151
|
+
toast.error(e.message);
|
|
11152
|
+
}
|
|
10976
11153
|
}
|
|
10977
|
-
)
|
|
10978
|
-
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
11154
|
+
);
|
|
11155
|
+
return;
|
|
11156
|
+
}
|
|
11157
|
+
if (data.quantity === 0) {
|
|
11158
|
+
await removeActionItem(actionId, {
|
|
11159
|
+
onSuccess: () => {
|
|
11160
|
+
setEditing(false);
|
|
11161
|
+
},
|
|
11162
|
+
onError: (e) => {
|
|
11163
|
+
toast.error(e.message);
|
|
11164
|
+
}
|
|
11165
|
+
});
|
|
11166
|
+
return;
|
|
11167
|
+
}
|
|
11168
|
+
await updateActionItem(
|
|
10990
11169
|
{
|
|
10991
|
-
|
|
11170
|
+
action_id: actionId,
|
|
11171
|
+
quantity: data.quantity,
|
|
11172
|
+
unit_price: convertNumber(data.unit_price)
|
|
10992
11173
|
},
|
|
10993
11174
|
{
|
|
11175
|
+
onSuccess: () => {
|
|
11176
|
+
setEditing(false);
|
|
11177
|
+
},
|
|
10994
11178
|
onError: (e) => {
|
|
10995
11179
|
toast.error(e.message);
|
|
10996
11180
|
}
|
|
10997
11181
|
}
|
|
10998
11182
|
);
|
|
10999
|
-
};
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
className: clx(
|
|
11005
|
-
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
11183
|
+
});
|
|
11184
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
|
|
11185
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
11186
|
+
/* @__PURE__ */ jsx(
|
|
11187
|
+
Thumbnail,
|
|
11006
11188
|
{
|
|
11007
|
-
|
|
11189
|
+
thumbnail: item.thumbnail,
|
|
11190
|
+
alt: item.title ?? void 0
|
|
11008
11191
|
}
|
|
11009
11192
|
),
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
] }),
|
|
11018
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11019
|
-
] })
|
|
11020
|
-
] }),
|
|
11021
|
-
/* @__PURE__ */ jsx(
|
|
11022
|
-
IconButton,
|
|
11023
|
-
{
|
|
11024
|
-
size: "small",
|
|
11025
|
-
type: "button",
|
|
11026
|
-
variant: "transparent",
|
|
11027
|
-
onClick: onRemove,
|
|
11028
|
-
isLoading: isPending || isLoading,
|
|
11029
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11193
|
+
editing ? /* @__PURE__ */ jsx(
|
|
11194
|
+
Form$2.Field,
|
|
11195
|
+
{
|
|
11196
|
+
control: form.control,
|
|
11197
|
+
name: "title",
|
|
11198
|
+
render: ({ field }) => {
|
|
11199
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
11030
11200
|
}
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
},
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
return null;
|
|
11042
|
-
}
|
|
11043
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11044
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11045
|
-
if (!currency) {
|
|
11046
|
-
return null;
|
|
11047
|
-
}
|
|
11048
|
-
return getLocaleAmount(value, currency);
|
|
11049
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11050
|
-
return formatPercentage(value);
|
|
11051
|
-
}
|
|
11052
|
-
return null;
|
|
11053
|
-
}
|
|
11054
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11055
|
-
style: "percent",
|
|
11056
|
-
minimumFractionDigits: 2
|
|
11057
|
-
});
|
|
11058
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11059
|
-
let val = value || 0;
|
|
11060
|
-
if (!isPercentageValue) {
|
|
11061
|
-
val = val / 100;
|
|
11062
|
-
}
|
|
11063
|
-
return formatter.format(val);
|
|
11064
|
-
};
|
|
11065
|
-
function getPromotionCodes(items, shippingMethods) {
|
|
11066
|
-
const codes = /* @__PURE__ */ new Set();
|
|
11067
|
-
for (const item of items) {
|
|
11068
|
-
if (item.adjustments) {
|
|
11069
|
-
for (const adjustment of item.adjustments) {
|
|
11070
|
-
if (adjustment.code) {
|
|
11071
|
-
codes.add(adjustment.code);
|
|
11201
|
+
}
|
|
11202
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
11203
|
+
] }),
|
|
11204
|
+
editing ? /* @__PURE__ */ jsx(
|
|
11205
|
+
Form$2.Field,
|
|
11206
|
+
{
|
|
11207
|
+
control: form.control,
|
|
11208
|
+
name: "quantity",
|
|
11209
|
+
render: ({ field }) => {
|
|
11210
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
11072
11211
|
}
|
|
11073
11212
|
}
|
|
11074
|
-
}
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11213
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
11214
|
+
editing ? /* @__PURE__ */ jsx(
|
|
11215
|
+
Form$2.Field,
|
|
11216
|
+
{
|
|
11217
|
+
control: form.control,
|
|
11218
|
+
name: "unit_price",
|
|
11219
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
11220
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11221
|
+
CurrencyInput,
|
|
11222
|
+
{
|
|
11223
|
+
...field,
|
|
11224
|
+
symbol: getNativeSymbol(currencyCode),
|
|
11225
|
+
code: currencyCode,
|
|
11226
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
11227
|
+
}
|
|
11228
|
+
) }) });
|
|
11081
11229
|
}
|
|
11082
11230
|
}
|
|
11083
|
-
}
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11231
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
11232
|
+
/* @__PURE__ */ jsx(
|
|
11233
|
+
IconButton,
|
|
11234
|
+
{
|
|
11235
|
+
type: "button",
|
|
11236
|
+
size: "small",
|
|
11237
|
+
onClick: editing ? onSubmit : () => {
|
|
11238
|
+
setEditing(true);
|
|
11239
|
+
},
|
|
11240
|
+
disabled: isPending,
|
|
11241
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
11242
|
+
}
|
|
11243
|
+
)
|
|
11244
|
+
] }) }) });
|
|
11245
|
+
};
|
|
11246
|
+
const StackedModalTrigger$1 = ({
|
|
11247
|
+
type,
|
|
11248
|
+
setModalContent
|
|
11249
|
+
}) => {
|
|
11250
|
+
const { setIsOpen } = useStackedModal();
|
|
11251
|
+
const onClick = useCallback(() => {
|
|
11252
|
+
setModalContent(type);
|
|
11253
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
11254
|
+
}, [setModalContent, setIsOpen, type]);
|
|
11255
|
+
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
11256
|
+
};
|
|
11257
|
+
const VARIANT_PREFIX = "items";
|
|
11258
|
+
const LIMIT = 50;
|
|
11259
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
11260
|
+
const { setIsOpen } = useStackedModal();
|
|
11261
|
+
const [rowSelection, setRowSelection] = useState(
|
|
11262
|
+
items.reduce((acc, item) => {
|
|
11263
|
+
acc[item.variant_id] = true;
|
|
11264
|
+
return acc;
|
|
11265
|
+
}, {})
|
|
11266
|
+
);
|
|
11267
|
+
useEffect(() => {
|
|
11268
|
+
setRowSelection(
|
|
11269
|
+
items.reduce((acc, item) => {
|
|
11270
|
+
if (item.variant_id) {
|
|
11271
|
+
acc[item.variant_id] = true;
|
|
11272
|
+
}
|
|
11273
|
+
return acc;
|
|
11274
|
+
}, {})
|
|
11275
|
+
);
|
|
11276
|
+
}, [items]);
|
|
11277
|
+
const { q, order, offset } = useQueryParams(
|
|
11278
|
+
["q", "order", "offset"],
|
|
11279
|
+
VARIANT_PREFIX
|
|
11280
|
+
);
|
|
11281
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
11091
11282
|
{
|
|
11092
|
-
|
|
11283
|
+
q,
|
|
11284
|
+
order,
|
|
11285
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
11286
|
+
limit: LIMIT
|
|
11093
11287
|
},
|
|
11094
11288
|
{
|
|
11095
|
-
|
|
11289
|
+
placeholderData: keepPreviousData
|
|
11096
11290
|
}
|
|
11097
11291
|
);
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11105
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11106
|
-
] }),
|
|
11107
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11108
|
-
] });
|
|
11109
|
-
};
|
|
11110
|
-
const SalesChannelForm = ({ order }) => {
|
|
11111
|
-
const form = useForm({
|
|
11112
|
-
defaultValues: {
|
|
11113
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11114
|
-
},
|
|
11115
|
-
resolver: zodResolver(schema$2)
|
|
11116
|
-
});
|
|
11117
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11118
|
-
const { handleSuccess } = useRouteModal();
|
|
11119
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11292
|
+
const columns = useColumns();
|
|
11293
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
11294
|
+
const onSubmit = async () => {
|
|
11295
|
+
const ids = Object.keys(rowSelection).filter(
|
|
11296
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
11297
|
+
);
|
|
11120
11298
|
await mutateAsync(
|
|
11121
11299
|
{
|
|
11122
|
-
|
|
11300
|
+
items: ids.map((id) => ({
|
|
11301
|
+
variant_id: id,
|
|
11302
|
+
quantity: 1
|
|
11303
|
+
}))
|
|
11123
11304
|
},
|
|
11124
11305
|
{
|
|
11125
11306
|
onSuccess: () => {
|
|
11126
|
-
|
|
11127
|
-
|
|
11307
|
+
setRowSelection({});
|
|
11308
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
11128
11309
|
},
|
|
11129
|
-
onError: (
|
|
11130
|
-
toast.error(
|
|
11310
|
+
onError: (e) => {
|
|
11311
|
+
toast.error(e.message);
|
|
11131
11312
|
}
|
|
11132
11313
|
}
|
|
11133
11314
|
);
|
|
11134
|
-
}
|
|
11135
|
-
|
|
11136
|
-
|
|
11315
|
+
};
|
|
11316
|
+
if (isError) {
|
|
11317
|
+
throw error;
|
|
11318
|
+
}
|
|
11319
|
+
return /* @__PURE__ */ jsxs(
|
|
11320
|
+
StackedFocusModal.Content,
|
|
11137
11321
|
{
|
|
11138
|
-
|
|
11139
|
-
|
|
11322
|
+
onOpenAutoFocus: (e) => {
|
|
11323
|
+
e.preventDefault();
|
|
11324
|
+
const searchInput = document.querySelector(
|
|
11325
|
+
"[data-modal-id='modal-search-input']"
|
|
11326
|
+
);
|
|
11327
|
+
if (searchInput) {
|
|
11328
|
+
searchInput.focus();
|
|
11329
|
+
}
|
|
11330
|
+
},
|
|
11140
11331
|
children: [
|
|
11141
|
-
/* @__PURE__ */
|
|
11142
|
-
|
|
11143
|
-
/* @__PURE__ */ jsx(
|
|
11144
|
-
|
|
11332
|
+
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
11333
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
11334
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
11335
|
+
] }),
|
|
11336
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
11337
|
+
DataTable,
|
|
11338
|
+
{
|
|
11339
|
+
data: variants,
|
|
11340
|
+
columns,
|
|
11341
|
+
isLoading: isPending,
|
|
11342
|
+
getRowId: (row) => row.id,
|
|
11343
|
+
rowCount: count,
|
|
11344
|
+
prefix: VARIANT_PREFIX,
|
|
11345
|
+
layout: "fill",
|
|
11346
|
+
rowSelection: {
|
|
11347
|
+
state: rowSelection,
|
|
11348
|
+
onRowSelectionChange: setRowSelection,
|
|
11349
|
+
enableRowSelection: (row) => {
|
|
11350
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
11351
|
+
}
|
|
11352
|
+
},
|
|
11353
|
+
autoFocusSearch: true
|
|
11354
|
+
}
|
|
11355
|
+
) }),
|
|
11356
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
11357
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11358
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
11145
11359
|
] }) })
|
|
11146
11360
|
]
|
|
11147
11361
|
}
|
|
11148
|
-
)
|
|
11362
|
+
);
|
|
11149
11363
|
};
|
|
11150
|
-
const
|
|
11151
|
-
|
|
11152
|
-
|
|
11153
|
-
|
|
11154
|
-
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
|
|
11364
|
+
const columnHelper = createDataTableColumnHelper();
|
|
11365
|
+
const useColumns = () => {
|
|
11366
|
+
return useMemo(() => {
|
|
11367
|
+
return [
|
|
11368
|
+
columnHelper.select(),
|
|
11369
|
+
columnHelper.accessor("product.title", {
|
|
11370
|
+
header: "Product",
|
|
11371
|
+
cell: ({ row }) => {
|
|
11372
|
+
var _a, _b, _c;
|
|
11373
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
11374
|
+
/* @__PURE__ */ jsx(
|
|
11375
|
+
Thumbnail,
|
|
11376
|
+
{
|
|
11377
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
11378
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
11379
|
+
}
|
|
11380
|
+
),
|
|
11381
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
11382
|
+
] });
|
|
11383
|
+
},
|
|
11384
|
+
enableSorting: true
|
|
11385
|
+
}),
|
|
11386
|
+
columnHelper.accessor("title", {
|
|
11387
|
+
header: "Variant",
|
|
11388
|
+
enableSorting: true
|
|
11389
|
+
}),
|
|
11390
|
+
columnHelper.accessor("sku", {
|
|
11391
|
+
header: "SKU",
|
|
11392
|
+
cell: ({ getValue }) => {
|
|
11393
|
+
return getValue() ?? "-";
|
|
11394
|
+
},
|
|
11395
|
+
enableSorting: true
|
|
11396
|
+
}),
|
|
11397
|
+
columnHelper.accessor("updated_at", {
|
|
11398
|
+
header: "Updated",
|
|
11399
|
+
cell: ({ getValue }) => {
|
|
11400
|
+
return /* @__PURE__ */ jsx(
|
|
11401
|
+
Tooltip,
|
|
11174
11402
|
{
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11178
|
-
searchValue: salesChannels.searchValue,
|
|
11179
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11180
|
-
placeholder: "Select sales channel",
|
|
11181
|
-
...field
|
|
11403
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11404
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11182
11405
|
}
|
|
11183
|
-
)
|
|
11184
|
-
|
|
11185
|
-
|
|
11406
|
+
);
|
|
11407
|
+
},
|
|
11408
|
+
enableSorting: true,
|
|
11409
|
+
sortAscLabel: "Oldest first",
|
|
11410
|
+
sortDescLabel: "Newest first"
|
|
11411
|
+
}),
|
|
11412
|
+
columnHelper.accessor("created_at", {
|
|
11413
|
+
header: "Created",
|
|
11414
|
+
cell: ({ getValue }) => {
|
|
11415
|
+
return /* @__PURE__ */ jsx(
|
|
11416
|
+
Tooltip,
|
|
11417
|
+
{
|
|
11418
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11419
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11420
|
+
}
|
|
11421
|
+
);
|
|
11422
|
+
},
|
|
11423
|
+
enableSorting: true,
|
|
11424
|
+
sortAscLabel: "Oldest first",
|
|
11425
|
+
sortDescLabel: "Newest first"
|
|
11426
|
+
})
|
|
11427
|
+
];
|
|
11428
|
+
}, []);
|
|
11429
|
+
};
|
|
11430
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
11431
|
+
const { setIsOpen } = useStackedModal();
|
|
11432
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
11433
|
+
const form = useForm({
|
|
11434
|
+
defaultValues: {
|
|
11435
|
+
title: "",
|
|
11436
|
+
quantity: 1,
|
|
11437
|
+
unit_price: ""
|
|
11438
|
+
},
|
|
11439
|
+
resolver: zodResolver(customItemSchema)
|
|
11440
|
+
});
|
|
11441
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11442
|
+
await addItems(
|
|
11443
|
+
{
|
|
11444
|
+
items: [
|
|
11445
|
+
{
|
|
11446
|
+
title: data.title,
|
|
11447
|
+
quantity: data.quantity,
|
|
11448
|
+
unit_price: convertNumber(data.unit_price)
|
|
11449
|
+
}
|
|
11450
|
+
]
|
|
11451
|
+
},
|
|
11452
|
+
{
|
|
11453
|
+
onSuccess: () => {
|
|
11454
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
11455
|
+
},
|
|
11456
|
+
onError: (e) => {
|
|
11457
|
+
toast.error(e.message);
|
|
11458
|
+
}
|
|
11186
11459
|
}
|
|
11187
|
-
|
|
11188
|
-
);
|
|
11460
|
+
);
|
|
11461
|
+
});
|
|
11462
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
11463
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
11464
|
+
/* @__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: [
|
|
11465
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11466
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
11467
|
+
/* @__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." }) })
|
|
11468
|
+
] }),
|
|
11469
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11470
|
+
/* @__PURE__ */ jsx(
|
|
11471
|
+
Form$2.Field,
|
|
11472
|
+
{
|
|
11473
|
+
control: form.control,
|
|
11474
|
+
name: "title",
|
|
11475
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11476
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11477
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
11478
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
11479
|
+
] }),
|
|
11480
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11481
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11482
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11483
|
+
] })
|
|
11484
|
+
] }) })
|
|
11485
|
+
}
|
|
11486
|
+
),
|
|
11487
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11488
|
+
/* @__PURE__ */ jsx(
|
|
11489
|
+
Form$2.Field,
|
|
11490
|
+
{
|
|
11491
|
+
control: form.control,
|
|
11492
|
+
name: "unit_price",
|
|
11493
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11494
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11495
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
11496
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
11497
|
+
] }),
|
|
11498
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11499
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11500
|
+
CurrencyInput,
|
|
11501
|
+
{
|
|
11502
|
+
symbol: getNativeSymbol(currencyCode),
|
|
11503
|
+
code: currencyCode,
|
|
11504
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
11505
|
+
...field
|
|
11506
|
+
}
|
|
11507
|
+
) }),
|
|
11508
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11509
|
+
] })
|
|
11510
|
+
] }) })
|
|
11511
|
+
}
|
|
11512
|
+
),
|
|
11513
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11514
|
+
/* @__PURE__ */ jsx(
|
|
11515
|
+
Form$2.Field,
|
|
11516
|
+
{
|
|
11517
|
+
control: form.control,
|
|
11518
|
+
name: "quantity",
|
|
11519
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11520
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11521
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
11522
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
11523
|
+
] }),
|
|
11524
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
|
|
11525
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
11526
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11527
|
+
] })
|
|
11528
|
+
] }) })
|
|
11529
|
+
}
|
|
11530
|
+
)
|
|
11531
|
+
] }) }) }),
|
|
11532
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
|
|
11533
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11534
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
11535
|
+
] }) })
|
|
11536
|
+
] }) }) });
|
|
11189
11537
|
};
|
|
11190
|
-
const
|
|
11191
|
-
|
|
11538
|
+
const customItemSchema = objectType({
|
|
11539
|
+
title: stringType().min(1),
|
|
11540
|
+
quantity: numberType(),
|
|
11541
|
+
unit_price: unionType([numberType(), stringType()])
|
|
11192
11542
|
});
|
|
11193
11543
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11194
11544
|
const Shipping = () => {
|
|
@@ -12533,499 +12883,149 @@ const Illustration = () => {
|
|
|
12533
12883
|
height: "3",
|
|
12534
12884
|
rx: "1.5",
|
|
12535
12885
|
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
|
|
12536
|
-
fill: "#A1A1AA"
|
|
12537
|
-
}
|
|
12538
|
-
),
|
|
12539
|
-
/* @__PURE__ */ jsx(
|
|
12540
|
-
"rect",
|
|
12541
|
-
{
|
|
12542
|
-
width: "12",
|
|
12543
|
-
height: "3",
|
|
12544
|
-
rx: "1.5",
|
|
12545
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
12546
|
-
fill: "#A1A1AA"
|
|
12547
|
-
}
|
|
12548
|
-
),
|
|
12549
|
-
/* @__PURE__ */ jsx(
|
|
12550
|
-
"path",
|
|
12551
|
-
{
|
|
12552
|
-
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
12553
|
-
fill: "#52525B"
|
|
12554
|
-
}
|
|
12555
|
-
),
|
|
12556
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12557
|
-
"path",
|
|
12558
|
-
{
|
|
12559
|
-
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12560
|
-
stroke: "#A1A1AA",
|
|
12561
|
-
strokeWidth: "1.5",
|
|
12562
|
-
strokeLinecap: "round",
|
|
12563
|
-
strokeLinejoin: "round"
|
|
12564
|
-
}
|
|
12565
|
-
) }),
|
|
12566
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12567
|
-
"path",
|
|
12568
|
-
{
|
|
12569
|
-
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12570
|
-
stroke: "#A1A1AA",
|
|
12571
|
-
strokeWidth: "1.5",
|
|
12572
|
-
strokeLinecap: "round",
|
|
12573
|
-
strokeLinejoin: "round"
|
|
12574
|
-
}
|
|
12575
|
-
) }),
|
|
12576
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12577
|
-
"path",
|
|
12578
|
-
{
|
|
12579
|
-
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12580
|
-
stroke: "#A1A1AA",
|
|
12581
|
-
strokeWidth: "1.5",
|
|
12582
|
-
strokeLinecap: "round",
|
|
12583
|
-
strokeLinejoin: "round"
|
|
12584
|
-
}
|
|
12585
|
-
) }),
|
|
12586
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12587
|
-
"path",
|
|
12588
|
-
{
|
|
12589
|
-
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12590
|
-
stroke: "#A1A1AA",
|
|
12591
|
-
strokeWidth: "1.5",
|
|
12592
|
-
strokeLinecap: "round",
|
|
12593
|
-
strokeLinejoin: "round"
|
|
12594
|
-
}
|
|
12595
|
-
) }),
|
|
12596
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12597
|
-
"path",
|
|
12598
|
-
{
|
|
12599
|
-
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12600
|
-
stroke: "#A1A1AA",
|
|
12601
|
-
strokeWidth: "1.5",
|
|
12602
|
-
strokeLinecap: "round",
|
|
12603
|
-
strokeLinejoin: "round"
|
|
12604
|
-
}
|
|
12605
|
-
) }),
|
|
12606
|
-
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12607
|
-
"path",
|
|
12608
|
-
{
|
|
12609
|
-
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12610
|
-
stroke: "#A1A1AA",
|
|
12611
|
-
strokeWidth: "1.5",
|
|
12612
|
-
strokeLinecap: "round",
|
|
12613
|
-
strokeLinejoin: "round"
|
|
12614
|
-
}
|
|
12615
|
-
) }),
|
|
12616
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12617
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12618
|
-
"rect",
|
|
12619
|
-
{
|
|
12620
|
-
width: "12",
|
|
12621
|
-
height: "12",
|
|
12622
|
-
fill: "white",
|
|
12623
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12624
|
-
}
|
|
12625
|
-
) }),
|
|
12626
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12627
|
-
"rect",
|
|
12628
|
-
{
|
|
12629
|
-
width: "12",
|
|
12630
|
-
height: "12",
|
|
12631
|
-
fill: "white",
|
|
12632
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12633
|
-
}
|
|
12634
|
-
) }),
|
|
12635
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12636
|
-
"rect",
|
|
12637
|
-
{
|
|
12638
|
-
width: "12",
|
|
12639
|
-
height: "12",
|
|
12640
|
-
fill: "white",
|
|
12641
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12642
|
-
}
|
|
12643
|
-
) }),
|
|
12644
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12645
|
-
"rect",
|
|
12646
|
-
{
|
|
12647
|
-
width: "12",
|
|
12648
|
-
height: "12",
|
|
12649
|
-
fill: "white",
|
|
12650
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12651
|
-
}
|
|
12652
|
-
) }),
|
|
12653
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12654
|
-
"rect",
|
|
12655
|
-
{
|
|
12656
|
-
width: "12",
|
|
12657
|
-
height: "12",
|
|
12658
|
-
fill: "white",
|
|
12659
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12660
|
-
}
|
|
12661
|
-
) }),
|
|
12662
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12663
|
-
"rect",
|
|
12664
|
-
{
|
|
12665
|
-
width: "12",
|
|
12666
|
-
height: "12",
|
|
12667
|
-
fill: "white",
|
|
12668
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12669
|
-
}
|
|
12670
|
-
) })
|
|
12671
|
-
] })
|
|
12672
|
-
]
|
|
12673
|
-
}
|
|
12674
|
-
);
|
|
12675
|
-
};
|
|
12676
|
-
const schema = objectType({
|
|
12677
|
-
customer_id: stringType().min(1)
|
|
12678
|
-
});
|
|
12679
|
-
const InlineTip = forwardRef(
|
|
12680
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12681
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12682
|
-
return /* @__PURE__ */ jsxs(
|
|
12683
|
-
"div",
|
|
12684
|
-
{
|
|
12685
|
-
ref,
|
|
12686
|
-
className: clx(
|
|
12687
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12688
|
-
className
|
|
12689
|
-
),
|
|
12690
|
-
...props,
|
|
12691
|
-
children: [
|
|
12692
|
-
/* @__PURE__ */ jsx(
|
|
12693
|
-
"div",
|
|
12694
|
-
{
|
|
12695
|
-
role: "presentation",
|
|
12696
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12697
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12698
|
-
})
|
|
12699
|
-
}
|
|
12700
|
-
),
|
|
12701
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
12702
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12703
|
-
labelValue,
|
|
12704
|
-
":"
|
|
12705
|
-
] }),
|
|
12706
|
-
" ",
|
|
12707
|
-
children
|
|
12708
|
-
] })
|
|
12709
|
-
]
|
|
12710
|
-
}
|
|
12711
|
-
);
|
|
12712
|
-
}
|
|
12713
|
-
);
|
|
12714
|
-
InlineTip.displayName = "InlineTip";
|
|
12715
|
-
const MetadataFieldSchema = objectType({
|
|
12716
|
-
key: stringType(),
|
|
12717
|
-
disabled: booleanType().optional(),
|
|
12718
|
-
value: anyType()
|
|
12719
|
-
});
|
|
12720
|
-
const MetadataSchema = objectType({
|
|
12721
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
12722
|
-
});
|
|
12723
|
-
const Metadata = () => {
|
|
12724
|
-
const { id } = useParams();
|
|
12725
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12726
|
-
fields: "metadata"
|
|
12727
|
-
});
|
|
12728
|
-
if (isError) {
|
|
12729
|
-
throw error;
|
|
12730
|
-
}
|
|
12731
|
-
const isReady = !isPending && !!order;
|
|
12732
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12733
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12734
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
12735
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12736
|
-
] }),
|
|
12737
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12738
|
-
] });
|
|
12739
|
-
};
|
|
12740
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12741
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12742
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
12743
|
-
const { handleSuccess } = useRouteModal();
|
|
12744
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12745
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12746
|
-
const form = useForm({
|
|
12747
|
-
defaultValues: {
|
|
12748
|
-
metadata: getDefaultValues(metadata)
|
|
12749
|
-
},
|
|
12750
|
-
resolver: zodResolver(MetadataSchema)
|
|
12751
|
-
});
|
|
12752
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12753
|
-
const parsedData = parseValues(data);
|
|
12754
|
-
await mutateAsync(
|
|
12755
|
-
{
|
|
12756
|
-
metadata: parsedData
|
|
12757
|
-
},
|
|
12758
|
-
{
|
|
12759
|
-
onSuccess: () => {
|
|
12760
|
-
toast.success("Metadata updated");
|
|
12761
|
-
handleSuccess();
|
|
12762
|
-
},
|
|
12763
|
-
onError: (error) => {
|
|
12764
|
-
toast.error(error.message);
|
|
12765
|
-
}
|
|
12766
|
-
}
|
|
12767
|
-
);
|
|
12768
|
-
});
|
|
12769
|
-
const { fields, insert, remove } = useFieldArray({
|
|
12770
|
-
control: form.control,
|
|
12771
|
-
name: "metadata"
|
|
12772
|
-
});
|
|
12773
|
-
function deleteRow(index) {
|
|
12774
|
-
remove(index);
|
|
12775
|
-
if (fields.length === 1) {
|
|
12776
|
-
insert(0, {
|
|
12777
|
-
key: "",
|
|
12778
|
-
value: "",
|
|
12779
|
-
disabled: false
|
|
12780
|
-
});
|
|
12781
|
-
}
|
|
12782
|
-
}
|
|
12783
|
-
function insertRow(index, position) {
|
|
12784
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
12785
|
-
key: "",
|
|
12786
|
-
value: "",
|
|
12787
|
-
disabled: false
|
|
12788
|
-
});
|
|
12789
|
-
}
|
|
12790
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12791
|
-
KeyboundForm,
|
|
12792
|
-
{
|
|
12793
|
-
onSubmit: handleSubmit,
|
|
12794
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12795
|
-
children: [
|
|
12796
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12797
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12798
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12799
|
-
/* @__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" }) }),
|
|
12800
|
-
/* @__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" }) })
|
|
12801
|
-
] }),
|
|
12802
|
-
fields.map((field, index) => {
|
|
12803
|
-
const isDisabled = field.disabled || false;
|
|
12804
|
-
let placeholder = "-";
|
|
12805
|
-
if (typeof field.value === "object") {
|
|
12806
|
-
placeholder = "{ ... }";
|
|
12807
|
-
}
|
|
12808
|
-
if (Array.isArray(field.value)) {
|
|
12809
|
-
placeholder = "[ ... ]";
|
|
12810
|
-
}
|
|
12811
|
-
return /* @__PURE__ */ jsx(
|
|
12812
|
-
ConditionalTooltip,
|
|
12813
|
-
{
|
|
12814
|
-
showTooltip: isDisabled,
|
|
12815
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
12816
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
12817
|
-
/* @__PURE__ */ jsxs(
|
|
12818
|
-
"div",
|
|
12819
|
-
{
|
|
12820
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
12821
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12822
|
-
}),
|
|
12823
|
-
children: [
|
|
12824
|
-
/* @__PURE__ */ jsx(
|
|
12825
|
-
Form$2.Field,
|
|
12826
|
-
{
|
|
12827
|
-
control: form.control,
|
|
12828
|
-
name: `metadata.${index}.key`,
|
|
12829
|
-
render: ({ field: field2 }) => {
|
|
12830
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12831
|
-
GridInput,
|
|
12832
|
-
{
|
|
12833
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12834
|
-
...field2,
|
|
12835
|
-
disabled: isDisabled,
|
|
12836
|
-
placeholder: "Key"
|
|
12837
|
-
}
|
|
12838
|
-
) }) });
|
|
12839
|
-
}
|
|
12840
|
-
}
|
|
12841
|
-
),
|
|
12842
|
-
/* @__PURE__ */ jsx(
|
|
12843
|
-
Form$2.Field,
|
|
12844
|
-
{
|
|
12845
|
-
control: form.control,
|
|
12846
|
-
name: `metadata.${index}.value`,
|
|
12847
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
12848
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12849
|
-
GridInput,
|
|
12850
|
-
{
|
|
12851
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12852
|
-
...field2,
|
|
12853
|
-
value: isDisabled ? placeholder : value,
|
|
12854
|
-
disabled: isDisabled,
|
|
12855
|
-
placeholder: "Value"
|
|
12856
|
-
}
|
|
12857
|
-
) }) });
|
|
12858
|
-
}
|
|
12859
|
-
}
|
|
12860
|
-
)
|
|
12861
|
-
]
|
|
12862
|
-
}
|
|
12863
|
-
),
|
|
12864
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12865
|
-
/* @__PURE__ */ jsx(
|
|
12866
|
-
DropdownMenu.Trigger,
|
|
12867
|
-
{
|
|
12868
|
-
className: clx(
|
|
12869
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12870
|
-
{
|
|
12871
|
-
hidden: isDisabled
|
|
12872
|
-
}
|
|
12873
|
-
),
|
|
12874
|
-
disabled: isDisabled,
|
|
12875
|
-
asChild: true,
|
|
12876
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
12877
|
-
}
|
|
12878
|
-
),
|
|
12879
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12880
|
-
/* @__PURE__ */ jsxs(
|
|
12881
|
-
DropdownMenu.Item,
|
|
12882
|
-
{
|
|
12883
|
-
className: "gap-x-2",
|
|
12884
|
-
onClick: () => insertRow(index, "above"),
|
|
12885
|
-
children: [
|
|
12886
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12887
|
-
"Insert row above"
|
|
12888
|
-
]
|
|
12889
|
-
}
|
|
12890
|
-
),
|
|
12891
|
-
/* @__PURE__ */ jsxs(
|
|
12892
|
-
DropdownMenu.Item,
|
|
12893
|
-
{
|
|
12894
|
-
className: "gap-x-2",
|
|
12895
|
-
onClick: () => insertRow(index, "below"),
|
|
12896
|
-
children: [
|
|
12897
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12898
|
-
"Insert row below"
|
|
12899
|
-
]
|
|
12900
|
-
}
|
|
12901
|
-
),
|
|
12902
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
12903
|
-
/* @__PURE__ */ jsxs(
|
|
12904
|
-
DropdownMenu.Item,
|
|
12905
|
-
{
|
|
12906
|
-
className: "gap-x-2",
|
|
12907
|
-
onClick: () => deleteRow(index),
|
|
12908
|
-
children: [
|
|
12909
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
12910
|
-
"Delete row"
|
|
12911
|
-
]
|
|
12912
|
-
}
|
|
12913
|
-
)
|
|
12914
|
-
] })
|
|
12915
|
-
] })
|
|
12916
|
-
] })
|
|
12917
|
-
},
|
|
12918
|
-
field.id
|
|
12919
|
-
);
|
|
12920
|
-
})
|
|
12921
|
-
] }),
|
|
12922
|
-
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." })
|
|
12923
|
-
] }),
|
|
12924
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12925
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12926
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12927
|
-
] }) })
|
|
12886
|
+
fill: "#A1A1AA"
|
|
12887
|
+
}
|
|
12888
|
+
),
|
|
12889
|
+
/* @__PURE__ */ jsx(
|
|
12890
|
+
"rect",
|
|
12891
|
+
{
|
|
12892
|
+
width: "12",
|
|
12893
|
+
height: "3",
|
|
12894
|
+
rx: "1.5",
|
|
12895
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
|
|
12896
|
+
fill: "#A1A1AA"
|
|
12897
|
+
}
|
|
12898
|
+
),
|
|
12899
|
+
/* @__PURE__ */ jsx(
|
|
12900
|
+
"path",
|
|
12901
|
+
{
|
|
12902
|
+
d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
|
|
12903
|
+
fill: "#52525B"
|
|
12904
|
+
}
|
|
12905
|
+
),
|
|
12906
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12907
|
+
"path",
|
|
12908
|
+
{
|
|
12909
|
+
d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
|
|
12910
|
+
stroke: "#A1A1AA",
|
|
12911
|
+
strokeWidth: "1.5",
|
|
12912
|
+
strokeLinecap: "round",
|
|
12913
|
+
strokeLinejoin: "round"
|
|
12914
|
+
}
|
|
12915
|
+
) }),
|
|
12916
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12917
|
+
"path",
|
|
12918
|
+
{
|
|
12919
|
+
d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
|
|
12920
|
+
stroke: "#A1A1AA",
|
|
12921
|
+
strokeWidth: "1.5",
|
|
12922
|
+
strokeLinecap: "round",
|
|
12923
|
+
strokeLinejoin: "round"
|
|
12924
|
+
}
|
|
12925
|
+
) }),
|
|
12926
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12927
|
+
"path",
|
|
12928
|
+
{
|
|
12929
|
+
d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
|
|
12930
|
+
stroke: "#A1A1AA",
|
|
12931
|
+
strokeWidth: "1.5",
|
|
12932
|
+
strokeLinecap: "round",
|
|
12933
|
+
strokeLinejoin: "round"
|
|
12934
|
+
}
|
|
12935
|
+
) }),
|
|
12936
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12937
|
+
"path",
|
|
12938
|
+
{
|
|
12939
|
+
d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
|
|
12940
|
+
stroke: "#A1A1AA",
|
|
12941
|
+
strokeWidth: "1.5",
|
|
12942
|
+
strokeLinecap: "round",
|
|
12943
|
+
strokeLinejoin: "round"
|
|
12944
|
+
}
|
|
12945
|
+
) }),
|
|
12946
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12947
|
+
"path",
|
|
12948
|
+
{
|
|
12949
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12950
|
+
stroke: "#A1A1AA",
|
|
12951
|
+
strokeWidth: "1.5",
|
|
12952
|
+
strokeLinecap: "round",
|
|
12953
|
+
strokeLinejoin: "round"
|
|
12954
|
+
}
|
|
12955
|
+
) }),
|
|
12956
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12957
|
+
"path",
|
|
12958
|
+
{
|
|
12959
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12960
|
+
stroke: "#A1A1AA",
|
|
12961
|
+
strokeWidth: "1.5",
|
|
12962
|
+
strokeLinecap: "round",
|
|
12963
|
+
strokeLinejoin: "round"
|
|
12964
|
+
}
|
|
12965
|
+
) }),
|
|
12966
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12967
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12968
|
+
"rect",
|
|
12969
|
+
{
|
|
12970
|
+
width: "12",
|
|
12971
|
+
height: "12",
|
|
12972
|
+
fill: "white",
|
|
12973
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12974
|
+
}
|
|
12975
|
+
) }),
|
|
12976
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12977
|
+
"rect",
|
|
12978
|
+
{
|
|
12979
|
+
width: "12",
|
|
12980
|
+
height: "12",
|
|
12981
|
+
fill: "white",
|
|
12982
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12983
|
+
}
|
|
12984
|
+
) }),
|
|
12985
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12986
|
+
"rect",
|
|
12987
|
+
{
|
|
12988
|
+
width: "12",
|
|
12989
|
+
height: "12",
|
|
12990
|
+
fill: "white",
|
|
12991
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12992
|
+
}
|
|
12993
|
+
) }),
|
|
12994
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12995
|
+
"rect",
|
|
12996
|
+
{
|
|
12997
|
+
width: "12",
|
|
12998
|
+
height: "12",
|
|
12999
|
+
fill: "white",
|
|
13000
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13001
|
+
}
|
|
13002
|
+
) }),
|
|
13003
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13004
|
+
"rect",
|
|
13005
|
+
{
|
|
13006
|
+
width: "12",
|
|
13007
|
+
height: "12",
|
|
13008
|
+
fill: "white",
|
|
13009
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13010
|
+
}
|
|
13011
|
+
) }),
|
|
13012
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13013
|
+
"rect",
|
|
13014
|
+
{
|
|
13015
|
+
width: "12",
|
|
13016
|
+
height: "12",
|
|
13017
|
+
fill: "white",
|
|
13018
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13019
|
+
}
|
|
13020
|
+
) })
|
|
13021
|
+
] })
|
|
12928
13022
|
]
|
|
12929
13023
|
}
|
|
12930
|
-
) });
|
|
12931
|
-
};
|
|
12932
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
12933
|
-
return /* @__PURE__ */ jsx(
|
|
12934
|
-
"input",
|
|
12935
|
-
{
|
|
12936
|
-
ref,
|
|
12937
|
-
...props,
|
|
12938
|
-
autoComplete: "off",
|
|
12939
|
-
className: clx(
|
|
12940
|
-
"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",
|
|
12941
|
-
className
|
|
12942
|
-
)
|
|
12943
|
-
}
|
|
12944
13024
|
);
|
|
12945
|
-
});
|
|
12946
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
12947
|
-
const PlaceholderInner = () => {
|
|
12948
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12949
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12950
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12951
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12952
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12953
|
-
] }) })
|
|
12954
|
-
] });
|
|
12955
13025
|
};
|
|
12956
|
-
const
|
|
12957
|
-
|
|
12958
|
-
|
|
12959
|
-
return [
|
|
12960
|
-
{
|
|
12961
|
-
key: "",
|
|
12962
|
-
value: "",
|
|
12963
|
-
disabled: false
|
|
12964
|
-
}
|
|
12965
|
-
];
|
|
12966
|
-
}
|
|
12967
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
12968
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
12969
|
-
return {
|
|
12970
|
-
key,
|
|
12971
|
-
value,
|
|
12972
|
-
disabled: true
|
|
12973
|
-
};
|
|
12974
|
-
}
|
|
12975
|
-
let stringValue = value;
|
|
12976
|
-
if (typeof value !== "string") {
|
|
12977
|
-
stringValue = JSON.stringify(value);
|
|
12978
|
-
}
|
|
12979
|
-
return {
|
|
12980
|
-
key,
|
|
12981
|
-
value: stringValue,
|
|
12982
|
-
original_key: key
|
|
12983
|
-
};
|
|
12984
|
-
});
|
|
12985
|
-
}
|
|
12986
|
-
function parseValues(values) {
|
|
12987
|
-
const metadata = values.metadata;
|
|
12988
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
12989
|
-
if (isEmpty) {
|
|
12990
|
-
return null;
|
|
12991
|
-
}
|
|
12992
|
-
const update = {};
|
|
12993
|
-
metadata.forEach((field) => {
|
|
12994
|
-
let key = field.key;
|
|
12995
|
-
let value = field.value;
|
|
12996
|
-
const disabled = field.disabled;
|
|
12997
|
-
if (!key || !value) {
|
|
12998
|
-
return;
|
|
12999
|
-
}
|
|
13000
|
-
if (disabled) {
|
|
13001
|
-
update[key] = value;
|
|
13002
|
-
return;
|
|
13003
|
-
}
|
|
13004
|
-
key = key.trim();
|
|
13005
|
-
value = value.trim();
|
|
13006
|
-
if (value === "true") {
|
|
13007
|
-
update[key] = true;
|
|
13008
|
-
} else if (value === "false") {
|
|
13009
|
-
update[key] = false;
|
|
13010
|
-
} else {
|
|
13011
|
-
const parsedNumber = parseFloat(value);
|
|
13012
|
-
if (!isNaN(parsedNumber)) {
|
|
13013
|
-
update[key] = parsedNumber;
|
|
13014
|
-
} else {
|
|
13015
|
-
update[key] = value;
|
|
13016
|
-
}
|
|
13017
|
-
}
|
|
13018
|
-
});
|
|
13019
|
-
return update;
|
|
13020
|
-
}
|
|
13021
|
-
function getHasUneditableRows(metadata) {
|
|
13022
|
-
if (!metadata) {
|
|
13023
|
-
return false;
|
|
13024
|
-
}
|
|
13025
|
-
return Object.values(metadata).some(
|
|
13026
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
13027
|
-
);
|
|
13028
|
-
}
|
|
13026
|
+
const schema = objectType({
|
|
13027
|
+
customer_id: stringType().min(1)
|
|
13028
|
+
});
|
|
13029
13029
|
const widgetModule = { widgets: [] };
|
|
13030
13030
|
const routeModule = {
|
|
13031
13031
|
routes: [
|
|
@@ -13047,20 +13047,20 @@ const routeModule = {
|
|
|
13047
13047
|
loader,
|
|
13048
13048
|
children: [
|
|
13049
13049
|
{
|
|
13050
|
-
Component:
|
|
13051
|
-
path: "/draft-orders/:id/
|
|
13050
|
+
Component: Email,
|
|
13051
|
+
path: "/draft-orders/:id/email"
|
|
13052
13052
|
},
|
|
13053
13053
|
{
|
|
13054
13054
|
Component: CustomItems,
|
|
13055
13055
|
path: "/draft-orders/:id/custom-items"
|
|
13056
13056
|
},
|
|
13057
13057
|
{
|
|
13058
|
-
Component:
|
|
13059
|
-
path: "/draft-orders/:id/
|
|
13058
|
+
Component: BillingAddress,
|
|
13059
|
+
path: "/draft-orders/:id/billing-address"
|
|
13060
13060
|
},
|
|
13061
13061
|
{
|
|
13062
|
-
Component:
|
|
13063
|
-
path: "/draft-orders/:id/
|
|
13062
|
+
Component: Metadata,
|
|
13063
|
+
path: "/draft-orders/:id/metadata"
|
|
13064
13064
|
},
|
|
13065
13065
|
{
|
|
13066
13066
|
Component: Promotions,
|
|
@@ -13070,6 +13070,10 @@ const routeModule = {
|
|
|
13070
13070
|
Component: SalesChannel,
|
|
13071
13071
|
path: "/draft-orders/:id/sales-channel"
|
|
13072
13072
|
},
|
|
13073
|
+
{
|
|
13074
|
+
Component: Items,
|
|
13075
|
+
path: "/draft-orders/:id/items"
|
|
13076
|
+
},
|
|
13073
13077
|
{
|
|
13074
13078
|
Component: Shipping,
|
|
13075
13079
|
path: "/draft-orders/:id/shipping"
|
|
@@ -13081,10 +13085,6 @@ const routeModule = {
|
|
|
13081
13085
|
{
|
|
13082
13086
|
Component: TransferOwnership,
|
|
13083
13087
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13084
|
-
},
|
|
13085
|
-
{
|
|
13086
|
-
Component: Metadata,
|
|
13087
|
-
path: "/draft-orders/:id/metadata"
|
|
13088
13088
|
}
|
|
13089
13089
|
]
|
|
13090
13090
|
}
|