@medusajs/draft-order 2.11.4-preview-20251116180137 → 2.11.4-preview-20251116210130
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 +1264 -1264
- package/.medusa/server/src/admin/index.mjs +1265 -1265
- package/package.json +16 -16
|
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
|
|
|
4
4
|
import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
|
|
6
6
|
import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
|
|
7
|
-
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent,
|
|
7
|
+
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
|
|
8
8
|
import Medusa from "@medusajs/js-sdk";
|
|
9
9
|
import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
|
|
10
10
|
import { enUS } from "date-fns/locale";
|
|
@@ -9755,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9755
9755
|
) });
|
|
9756
9756
|
};
|
|
9757
9757
|
const schema$5 = addressSchema;
|
|
9758
|
+
const CustomItems = () => {
|
|
9759
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9760
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9761
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9762
|
+
] });
|
|
9763
|
+
};
|
|
9764
|
+
const CustomItemsForm = () => {
|
|
9765
|
+
const form = useForm({
|
|
9766
|
+
resolver: zodResolver(schema$4)
|
|
9767
|
+
});
|
|
9768
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9769
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9770
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9771
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9772
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9773
|
+
] }) })
|
|
9774
|
+
] }) });
|
|
9775
|
+
};
|
|
9776
|
+
const schema$4 = objectType({
|
|
9777
|
+
email: stringType().email()
|
|
9778
|
+
});
|
|
9758
9779
|
const Email = () => {
|
|
9759
9780
|
const { id } = useParams();
|
|
9760
9781
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9777,7 +9798,7 @@ const EmailForm = ({ order }) => {
|
|
|
9777
9798
|
defaultValues: {
|
|
9778
9799
|
email: order.email ?? ""
|
|
9779
9800
|
},
|
|
9780
|
-
resolver: zodResolver(schema$
|
|
9801
|
+
resolver: zodResolver(schema$3)
|
|
9781
9802
|
});
|
|
9782
9803
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9783
9804
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9820,576 +9841,778 @@ const EmailForm = ({ order }) => {
|
|
|
9820
9841
|
}
|
|
9821
9842
|
) });
|
|
9822
9843
|
};
|
|
9823
|
-
const schema$
|
|
9844
|
+
const schema$3 = objectType({
|
|
9824
9845
|
email: stringType().email()
|
|
9825
9846
|
});
|
|
9826
|
-
const
|
|
9827
|
-
({
|
|
9828
|
-
|
|
9829
|
-
onChange,
|
|
9830
|
-
size = "base",
|
|
9831
|
-
min = 0,
|
|
9832
|
-
max = 100,
|
|
9833
|
-
step = 1,
|
|
9834
|
-
className,
|
|
9835
|
-
disabled,
|
|
9836
|
-
...props
|
|
9837
|
-
}, ref) => {
|
|
9838
|
-
const handleChange = (event) => {
|
|
9839
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9840
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9841
|
-
onChange(newValue);
|
|
9842
|
-
}
|
|
9843
|
-
};
|
|
9844
|
-
const handleIncrement = () => {
|
|
9845
|
-
const newValue = value + step;
|
|
9846
|
-
if (max === void 0 || newValue <= max) {
|
|
9847
|
-
onChange(newValue);
|
|
9848
|
-
}
|
|
9849
|
-
};
|
|
9850
|
-
const handleDecrement = () => {
|
|
9851
|
-
const newValue = value - step;
|
|
9852
|
-
if (min === void 0 || newValue >= min) {
|
|
9853
|
-
onChange(newValue);
|
|
9854
|
-
}
|
|
9855
|
-
};
|
|
9847
|
+
const InlineTip = forwardRef(
|
|
9848
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9849
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9856
9850
|
return /* @__PURE__ */ jsxs(
|
|
9857
9851
|
"div",
|
|
9858
9852
|
{
|
|
9853
|
+
ref,
|
|
9859
9854
|
className: clx(
|
|
9860
|
-
"
|
|
9861
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9862
|
-
{
|
|
9863
|
-
"h-7": size === "small",
|
|
9864
|
-
"h-8": size === "base"
|
|
9865
|
-
},
|
|
9855
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9866
9856
|
className
|
|
9867
9857
|
),
|
|
9858
|
+
...props,
|
|
9868
9859
|
children: [
|
|
9869
9860
|
/* @__PURE__ */ jsx(
|
|
9870
|
-
"
|
|
9871
|
-
{
|
|
9872
|
-
ref,
|
|
9873
|
-
type: "number",
|
|
9874
|
-
value,
|
|
9875
|
-
onChange: handleChange,
|
|
9876
|
-
min,
|
|
9877
|
-
max,
|
|
9878
|
-
step,
|
|
9879
|
-
className: clx(
|
|
9880
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
9881
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
9882
|
-
"placeholder:text-ui-fg-muted"
|
|
9883
|
-
),
|
|
9884
|
-
...props
|
|
9885
|
-
}
|
|
9886
|
-
),
|
|
9887
|
-
/* @__PURE__ */ jsxs(
|
|
9888
|
-
"button",
|
|
9861
|
+
"div",
|
|
9889
9862
|
{
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
"
|
|
9893
|
-
|
|
9894
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
9895
|
-
{
|
|
9896
|
-
"size-7": size === "small",
|
|
9897
|
-
"size-8": size === "base"
|
|
9898
|
-
}
|
|
9899
|
-
),
|
|
9900
|
-
type: "button",
|
|
9901
|
-
onClick: handleDecrement,
|
|
9902
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
9903
|
-
children: [
|
|
9904
|
-
/* @__PURE__ */ jsx(Minus, {}),
|
|
9905
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9906
|
-
]
|
|
9863
|
+
role: "presentation",
|
|
9864
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9865
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9866
|
+
})
|
|
9907
9867
|
}
|
|
9908
9868
|
),
|
|
9909
|
-
/* @__PURE__ */ jsxs(
|
|
9910
|
-
"
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
{
|
|
9918
|
-
"size-7": size === "small",
|
|
9919
|
-
"size-8": size === "base"
|
|
9920
|
-
}
|
|
9921
|
-
),
|
|
9922
|
-
type: "button",
|
|
9923
|
-
onClick: handleIncrement,
|
|
9924
|
-
disabled: max !== void 0 && value >= max || disabled,
|
|
9925
|
-
children: [
|
|
9926
|
-
/* @__PURE__ */ jsx(Plus, {}),
|
|
9927
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
9928
|
-
]
|
|
9929
|
-
}
|
|
9930
|
-
)
|
|
9869
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9870
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9871
|
+
labelValue,
|
|
9872
|
+
":"
|
|
9873
|
+
] }),
|
|
9874
|
+
" ",
|
|
9875
|
+
children
|
|
9876
|
+
] })
|
|
9931
9877
|
]
|
|
9932
9878
|
}
|
|
9933
9879
|
);
|
|
9934
9880
|
}
|
|
9935
9881
|
);
|
|
9936
|
-
|
|
9937
|
-
const
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
9947
|
-
...options
|
|
9948
|
-
});
|
|
9949
|
-
return { ...data, ...rest };
|
|
9950
|
-
};
|
|
9951
|
-
const useCancelOrderEdit = ({ preview }) => {
|
|
9952
|
-
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
9953
|
-
const onCancel = useCallback(async () => {
|
|
9954
|
-
if (!preview) {
|
|
9955
|
-
return true;
|
|
9956
|
-
}
|
|
9957
|
-
let res = false;
|
|
9958
|
-
await cancelOrderEdit(void 0, {
|
|
9959
|
-
onError: (e) => {
|
|
9960
|
-
toast.error(e.message);
|
|
9961
|
-
},
|
|
9962
|
-
onSuccess: () => {
|
|
9963
|
-
res = true;
|
|
9964
|
-
}
|
|
9965
|
-
});
|
|
9966
|
-
return res;
|
|
9967
|
-
}, [preview, cancelOrderEdit]);
|
|
9968
|
-
return { onCancel };
|
|
9969
|
-
};
|
|
9970
|
-
let IS_REQUEST_RUNNING = false;
|
|
9971
|
-
const useInitiateOrderEdit = ({
|
|
9972
|
-
preview
|
|
9973
|
-
}) => {
|
|
9974
|
-
const navigate = useNavigate();
|
|
9975
|
-
const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
|
|
9976
|
-
useEffect(() => {
|
|
9977
|
-
async function run() {
|
|
9978
|
-
if (IS_REQUEST_RUNNING || !preview) {
|
|
9979
|
-
return;
|
|
9980
|
-
}
|
|
9981
|
-
if (preview.order_change) {
|
|
9982
|
-
return;
|
|
9983
|
-
}
|
|
9984
|
-
IS_REQUEST_RUNNING = true;
|
|
9985
|
-
await mutateAsync(void 0, {
|
|
9986
|
-
onError: (e) => {
|
|
9987
|
-
toast.error(e.message);
|
|
9988
|
-
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
9989
|
-
return;
|
|
9990
|
-
}
|
|
9991
|
-
});
|
|
9992
|
-
IS_REQUEST_RUNNING = false;
|
|
9993
|
-
}
|
|
9994
|
-
run();
|
|
9995
|
-
}, [preview, navigate, mutateAsync]);
|
|
9996
|
-
};
|
|
9997
|
-
function convertNumber(value) {
|
|
9998
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
9999
|
-
}
|
|
10000
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10001
|
-
const Items = () => {
|
|
9882
|
+
InlineTip.displayName = "InlineTip";
|
|
9883
|
+
const MetadataFieldSchema = objectType({
|
|
9884
|
+
key: stringType(),
|
|
9885
|
+
disabled: booleanType().optional(),
|
|
9886
|
+
value: anyType()
|
|
9887
|
+
});
|
|
9888
|
+
const MetadataSchema = objectType({
|
|
9889
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
9890
|
+
});
|
|
9891
|
+
const Metadata = () => {
|
|
10002
9892
|
const { id } = useParams();
|
|
10003
|
-
const {
|
|
10004
|
-
|
|
10005
|
-
isPending: isPreviewPending,
|
|
10006
|
-
isError: isPreviewError,
|
|
10007
|
-
error: previewError
|
|
10008
|
-
} = useOrderPreview(id, void 0, {
|
|
10009
|
-
placeholderData: keepPreviousData
|
|
9893
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9894
|
+
fields: "metadata"
|
|
10010
9895
|
});
|
|
10011
|
-
useInitiateOrderEdit({ preview });
|
|
10012
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10013
|
-
id,
|
|
10014
|
-
{
|
|
10015
|
-
fields: "currency_code"
|
|
10016
|
-
},
|
|
10017
|
-
{
|
|
10018
|
-
enabled: !!id
|
|
10019
|
-
}
|
|
10020
|
-
);
|
|
10021
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10022
9896
|
if (isError) {
|
|
10023
9897
|
throw error;
|
|
10024
9898
|
}
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
/* @__PURE__ */ jsx(
|
|
10032
|
-
] })
|
|
9899
|
+
const isReady = !isPending && !!order;
|
|
9900
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9901
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9902
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
9903
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9904
|
+
] }),
|
|
9905
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
9906
|
+
] });
|
|
10033
9907
|
};
|
|
10034
|
-
const
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
const [modalContent, setModalContent] = useState(
|
|
10038
|
-
null
|
|
10039
|
-
);
|
|
9908
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9909
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9910
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10040
9911
|
const { handleSuccess } = useRouteModal();
|
|
10041
|
-
const
|
|
10042
|
-
const { mutateAsync
|
|
10043
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10044
|
-
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10045
|
-
const matches = useMemo(() => {
|
|
10046
|
-
return matchSorter(preview.items, query2, {
|
|
10047
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10048
|
-
});
|
|
10049
|
-
}, [preview.items, query2]);
|
|
10050
|
-
const onSubmit = async () => {
|
|
10051
|
-
setIsSubmitting(true);
|
|
10052
|
-
let requestSucceeded = false;
|
|
10053
|
-
await requestOrderEdit(void 0, {
|
|
10054
|
-
onError: (e) => {
|
|
10055
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
10056
|
-
},
|
|
10057
|
-
onSuccess: () => {
|
|
10058
|
-
requestSucceeded = true;
|
|
10059
|
-
}
|
|
10060
|
-
});
|
|
10061
|
-
if (!requestSucceeded) {
|
|
10062
|
-
setIsSubmitting(false);
|
|
10063
|
-
return;
|
|
10064
|
-
}
|
|
10065
|
-
await confirmOrderEdit(void 0, {
|
|
10066
|
-
onError: (e) => {
|
|
10067
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10068
|
-
},
|
|
10069
|
-
onSuccess: () => {
|
|
10070
|
-
handleSuccess();
|
|
10071
|
-
},
|
|
10072
|
-
onSettled: () => {
|
|
10073
|
-
setIsSubmitting(false);
|
|
10074
|
-
}
|
|
10075
|
-
});
|
|
10076
|
-
};
|
|
10077
|
-
const onKeyDown = useCallback(
|
|
10078
|
-
(e) => {
|
|
10079
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10080
|
-
if (modalContent || isSubmitting) {
|
|
10081
|
-
return;
|
|
10082
|
-
}
|
|
10083
|
-
onSubmit();
|
|
10084
|
-
}
|
|
10085
|
-
},
|
|
10086
|
-
[modalContent, isSubmitting, onSubmit]
|
|
10087
|
-
);
|
|
10088
|
-
useEffect(() => {
|
|
10089
|
-
document.addEventListener("keydown", onKeyDown);
|
|
10090
|
-
return () => {
|
|
10091
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
10092
|
-
};
|
|
10093
|
-
}, [onKeyDown]);
|
|
10094
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10095
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10096
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
10097
|
-
StackedFocusModal,
|
|
10098
|
-
{
|
|
10099
|
-
id: STACKED_MODAL_ID,
|
|
10100
|
-
onOpenChangeCallback: (open) => {
|
|
10101
|
-
if (!open) {
|
|
10102
|
-
setModalContent(null);
|
|
10103
|
-
}
|
|
10104
|
-
},
|
|
10105
|
-
children: [
|
|
10106
|
-
/* @__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: [
|
|
10107
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10108
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
|
|
10109
|
-
/* @__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" }) })
|
|
10110
|
-
] }),
|
|
10111
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10112
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10113
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10114
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10115
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10116
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10117
|
-
] }),
|
|
10118
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10119
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10120
|
-
Input,
|
|
10121
|
-
{
|
|
10122
|
-
type: "search",
|
|
10123
|
-
placeholder: "Search items",
|
|
10124
|
-
value: searchValue,
|
|
10125
|
-
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10126
|
-
}
|
|
10127
|
-
) }),
|
|
10128
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10129
|
-
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10130
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10131
|
-
/* @__PURE__ */ jsx(
|
|
10132
|
-
StackedModalTrigger$1,
|
|
10133
|
-
{
|
|
10134
|
-
type: "add-items",
|
|
10135
|
-
setModalContent
|
|
10136
|
-
}
|
|
10137
|
-
),
|
|
10138
|
-
/* @__PURE__ */ jsx(
|
|
10139
|
-
StackedModalTrigger$1,
|
|
10140
|
-
{
|
|
10141
|
-
type: "add-custom-item",
|
|
10142
|
-
setModalContent
|
|
10143
|
-
}
|
|
10144
|
-
)
|
|
10145
|
-
] })
|
|
10146
|
-
] })
|
|
10147
|
-
] })
|
|
10148
|
-
] }),
|
|
10149
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10150
|
-
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
10151
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10152
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10153
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10154
|
-
/* @__PURE__ */ jsx("div", {})
|
|
10155
|
-
] }) }),
|
|
10156
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10157
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10158
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10159
|
-
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10160
|
-
Item,
|
|
10161
|
-
{
|
|
10162
|
-
item,
|
|
10163
|
-
preview,
|
|
10164
|
-
currencyCode
|
|
10165
|
-
},
|
|
10166
|
-
item.id
|
|
10167
|
-
)) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10168
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10169
|
-
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10170
|
-
'No items found for "',
|
|
10171
|
-
query2,
|
|
10172
|
-
'".'
|
|
10173
|
-
] })
|
|
10174
|
-
] }) })
|
|
10175
|
-
] })
|
|
10176
|
-
] }),
|
|
10177
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10178
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10179
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10180
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10181
|
-
Text,
|
|
10182
|
-
{
|
|
10183
|
-
size: "small",
|
|
10184
|
-
leading: "compact",
|
|
10185
|
-
className: "text-ui-fg-subtle",
|
|
10186
|
-
children: [
|
|
10187
|
-
itemCount,
|
|
10188
|
-
" ",
|
|
10189
|
-
itemCount === 1 ? "item" : "items"
|
|
10190
|
-
]
|
|
10191
|
-
}
|
|
10192
|
-
) }),
|
|
10193
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10194
|
-
] })
|
|
10195
|
-
] }) }),
|
|
10196
|
-
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10197
|
-
CustomItemForm,
|
|
10198
|
-
{
|
|
10199
|
-
orderId: preview.id,
|
|
10200
|
-
currencyCode
|
|
10201
|
-
}
|
|
10202
|
-
) : null)
|
|
10203
|
-
]
|
|
10204
|
-
}
|
|
10205
|
-
) }),
|
|
10206
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10207
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10208
|
-
/* @__PURE__ */ jsx(
|
|
10209
|
-
Button,
|
|
10210
|
-
{
|
|
10211
|
-
size: "small",
|
|
10212
|
-
type: "button",
|
|
10213
|
-
onClick: onSubmit,
|
|
10214
|
-
isLoading: isSubmitting,
|
|
10215
|
-
children: "Save"
|
|
10216
|
-
}
|
|
10217
|
-
)
|
|
10218
|
-
] }) })
|
|
10219
|
-
] });
|
|
10220
|
-
};
|
|
10221
|
-
const Item = ({ item, preview, currencyCode }) => {
|
|
10222
|
-
if (item.variant_id) {
|
|
10223
|
-
return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
|
|
10224
|
-
}
|
|
10225
|
-
return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
|
|
10226
|
-
};
|
|
10227
|
-
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
10228
|
-
const [editing, setEditing] = useState(false);
|
|
9912
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9913
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10229
9914
|
const form = useForm({
|
|
10230
9915
|
defaultValues: {
|
|
10231
|
-
|
|
10232
|
-
unit_price: item.unit_price
|
|
9916
|
+
metadata: getDefaultValues(metadata)
|
|
10233
9917
|
},
|
|
10234
|
-
resolver: zodResolver(
|
|
9918
|
+
resolver: zodResolver(MetadataSchema)
|
|
10235
9919
|
});
|
|
10236
|
-
const
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
}, [item]);
|
|
10240
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10241
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10242
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10243
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10244
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10245
|
-
setEditing(false);
|
|
10246
|
-
return;
|
|
10247
|
-
}
|
|
10248
|
-
if (!actionId) {
|
|
10249
|
-
await updateOriginalItem(
|
|
10250
|
-
{
|
|
10251
|
-
item_id: item.id,
|
|
10252
|
-
quantity: data.quantity,
|
|
10253
|
-
unit_price: convertNumber(data.unit_price)
|
|
10254
|
-
},
|
|
10255
|
-
{
|
|
10256
|
-
onSuccess: () => {
|
|
10257
|
-
setEditing(false);
|
|
10258
|
-
},
|
|
10259
|
-
onError: (e) => {
|
|
10260
|
-
toast.error(e.message);
|
|
10261
|
-
}
|
|
10262
|
-
}
|
|
10263
|
-
);
|
|
10264
|
-
return;
|
|
10265
|
-
}
|
|
10266
|
-
await updateActionItem(
|
|
9920
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9921
|
+
const parsedData = parseValues(data);
|
|
9922
|
+
await mutateAsync(
|
|
10267
9923
|
{
|
|
10268
|
-
|
|
10269
|
-
quantity: data.quantity,
|
|
10270
|
-
unit_price: convertNumber(data.unit_price)
|
|
9924
|
+
metadata: parsedData
|
|
10271
9925
|
},
|
|
10272
9926
|
{
|
|
10273
9927
|
onSuccess: () => {
|
|
10274
|
-
|
|
9928
|
+
toast.success("Metadata updated");
|
|
9929
|
+
handleSuccess();
|
|
10275
9930
|
},
|
|
10276
|
-
onError: (
|
|
10277
|
-
toast.error(
|
|
9931
|
+
onError: (error) => {
|
|
9932
|
+
toast.error(error.message);
|
|
10278
9933
|
}
|
|
10279
9934
|
}
|
|
10280
9935
|
);
|
|
10281
9936
|
});
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
9937
|
+
const { fields, insert, remove } = useFieldArray({
|
|
9938
|
+
control: form.control,
|
|
9939
|
+
name: "metadata"
|
|
9940
|
+
});
|
|
9941
|
+
function deleteRow(index) {
|
|
9942
|
+
remove(index);
|
|
9943
|
+
if (fields.length === 1) {
|
|
9944
|
+
insert(0, {
|
|
9945
|
+
key: "",
|
|
9946
|
+
value: "",
|
|
9947
|
+
disabled: false
|
|
9948
|
+
});
|
|
9949
|
+
}
|
|
9950
|
+
}
|
|
9951
|
+
function insertRow(index, position) {
|
|
9952
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9953
|
+
key: "",
|
|
9954
|
+
value: "",
|
|
9955
|
+
disabled: false
|
|
9956
|
+
});
|
|
9957
|
+
}
|
|
9958
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9959
|
+
KeyboundForm,
|
|
9960
|
+
{
|
|
9961
|
+
onSubmit: handleSubmit,
|
|
9962
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9963
|
+
children: [
|
|
9964
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9965
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9966
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9967
|
+
/* @__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" }) }),
|
|
9968
|
+
/* @__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" }) })
|
|
9969
|
+
] }),
|
|
9970
|
+
fields.map((field, index) => {
|
|
9971
|
+
const isDisabled = field.disabled || false;
|
|
9972
|
+
let placeholder = "-";
|
|
9973
|
+
if (typeof field.value === "object") {
|
|
9974
|
+
placeholder = "{ ... }";
|
|
9975
|
+
}
|
|
9976
|
+
if (Array.isArray(field.value)) {
|
|
9977
|
+
placeholder = "[ ... ]";
|
|
9978
|
+
}
|
|
9979
|
+
return /* @__PURE__ */ jsx(
|
|
9980
|
+
ConditionalTooltip,
|
|
9981
|
+
{
|
|
9982
|
+
showTooltip: isDisabled,
|
|
9983
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9984
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9985
|
+
/* @__PURE__ */ jsxs(
|
|
9986
|
+
"div",
|
|
9987
|
+
{
|
|
9988
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
9989
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9990
|
+
}),
|
|
9991
|
+
children: [
|
|
9992
|
+
/* @__PURE__ */ jsx(
|
|
9993
|
+
Form$2.Field,
|
|
9994
|
+
{
|
|
9995
|
+
control: form.control,
|
|
9996
|
+
name: `metadata.${index}.key`,
|
|
9997
|
+
render: ({ field: field2 }) => {
|
|
9998
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9999
|
+
GridInput,
|
|
10000
|
+
{
|
|
10001
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10002
|
+
...field2,
|
|
10003
|
+
disabled: isDisabled,
|
|
10004
|
+
placeholder: "Key"
|
|
10005
|
+
}
|
|
10006
|
+
) }) });
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
),
|
|
10010
|
+
/* @__PURE__ */ jsx(
|
|
10011
|
+
Form$2.Field,
|
|
10012
|
+
{
|
|
10013
|
+
control: form.control,
|
|
10014
|
+
name: `metadata.${index}.value`,
|
|
10015
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10016
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10017
|
+
GridInput,
|
|
10018
|
+
{
|
|
10019
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10020
|
+
...field2,
|
|
10021
|
+
value: isDisabled ? placeholder : value,
|
|
10022
|
+
disabled: isDisabled,
|
|
10023
|
+
placeholder: "Value"
|
|
10024
|
+
}
|
|
10025
|
+
) }) });
|
|
10026
|
+
}
|
|
10027
|
+
}
|
|
10028
|
+
)
|
|
10029
|
+
]
|
|
10030
|
+
}
|
|
10031
|
+
),
|
|
10032
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10033
|
+
/* @__PURE__ */ jsx(
|
|
10034
|
+
DropdownMenu.Trigger,
|
|
10035
|
+
{
|
|
10036
|
+
className: clx(
|
|
10037
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10038
|
+
{
|
|
10039
|
+
hidden: isDisabled
|
|
10040
|
+
}
|
|
10041
|
+
),
|
|
10042
|
+
disabled: isDisabled,
|
|
10043
|
+
asChild: true,
|
|
10044
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
10045
|
+
}
|
|
10046
|
+
),
|
|
10047
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10048
|
+
/* @__PURE__ */ jsxs(
|
|
10049
|
+
DropdownMenu.Item,
|
|
10050
|
+
{
|
|
10051
|
+
className: "gap-x-2",
|
|
10052
|
+
onClick: () => insertRow(index, "above"),
|
|
10053
|
+
children: [
|
|
10054
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
10055
|
+
"Insert row above"
|
|
10056
|
+
]
|
|
10057
|
+
}
|
|
10058
|
+
),
|
|
10059
|
+
/* @__PURE__ */ jsxs(
|
|
10060
|
+
DropdownMenu.Item,
|
|
10061
|
+
{
|
|
10062
|
+
className: "gap-x-2",
|
|
10063
|
+
onClick: () => insertRow(index, "below"),
|
|
10064
|
+
children: [
|
|
10065
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
10066
|
+
"Insert row below"
|
|
10067
|
+
]
|
|
10068
|
+
}
|
|
10069
|
+
),
|
|
10070
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
10071
|
+
/* @__PURE__ */ jsxs(
|
|
10072
|
+
DropdownMenu.Item,
|
|
10073
|
+
{
|
|
10074
|
+
className: "gap-x-2",
|
|
10075
|
+
onClick: () => deleteRow(index),
|
|
10076
|
+
children: [
|
|
10077
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
10078
|
+
"Delete row"
|
|
10079
|
+
]
|
|
10080
|
+
}
|
|
10081
|
+
)
|
|
10082
|
+
] })
|
|
10083
|
+
] })
|
|
10084
|
+
] })
|
|
10085
|
+
},
|
|
10086
|
+
field.id
|
|
10087
|
+
);
|
|
10088
|
+
})
|
|
10089
|
+
] }),
|
|
10090
|
+
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." })
|
|
10091
|
+
] }),
|
|
10092
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10093
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10094
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10095
|
+
] }) })
|
|
10096
|
+
]
|
|
10097
|
+
}
|
|
10098
|
+
) });
|
|
10099
|
+
};
|
|
10100
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
10101
|
+
return /* @__PURE__ */ jsx(
|
|
10102
|
+
"input",
|
|
10103
|
+
{
|
|
10104
|
+
ref,
|
|
10105
|
+
...props,
|
|
10106
|
+
autoComplete: "off",
|
|
10107
|
+
className: clx(
|
|
10108
|
+
"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",
|
|
10109
|
+
className
|
|
10110
|
+
)
|
|
10111
|
+
}
|
|
10112
|
+
);
|
|
10113
|
+
});
|
|
10114
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
10115
|
+
const PlaceholderInner = () => {
|
|
10116
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10117
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10118
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10119
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10120
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10121
|
+
] }) })
|
|
10122
|
+
] });
|
|
10123
|
+
};
|
|
10124
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10125
|
+
function getDefaultValues(metadata) {
|
|
10126
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
10127
|
+
return [
|
|
10128
|
+
{
|
|
10129
|
+
key: "",
|
|
10130
|
+
value: "",
|
|
10131
|
+
disabled: false
|
|
10132
|
+
}
|
|
10133
|
+
];
|
|
10134
|
+
}
|
|
10135
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
10136
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10137
|
+
return {
|
|
10138
|
+
key,
|
|
10139
|
+
value,
|
|
10140
|
+
disabled: true
|
|
10141
|
+
};
|
|
10142
|
+
}
|
|
10143
|
+
let stringValue = value;
|
|
10144
|
+
if (typeof value !== "string") {
|
|
10145
|
+
stringValue = JSON.stringify(value);
|
|
10146
|
+
}
|
|
10147
|
+
return {
|
|
10148
|
+
key,
|
|
10149
|
+
value: stringValue,
|
|
10150
|
+
original_key: key
|
|
10151
|
+
};
|
|
10152
|
+
});
|
|
10153
|
+
}
|
|
10154
|
+
function parseValues(values) {
|
|
10155
|
+
const metadata = values.metadata;
|
|
10156
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10157
|
+
if (isEmpty) {
|
|
10158
|
+
return null;
|
|
10159
|
+
}
|
|
10160
|
+
const update = {};
|
|
10161
|
+
metadata.forEach((field) => {
|
|
10162
|
+
let key = field.key;
|
|
10163
|
+
let value = field.value;
|
|
10164
|
+
const disabled = field.disabled;
|
|
10165
|
+
if (!key || !value) {
|
|
10166
|
+
return;
|
|
10167
|
+
}
|
|
10168
|
+
if (disabled) {
|
|
10169
|
+
update[key] = value;
|
|
10170
|
+
return;
|
|
10171
|
+
}
|
|
10172
|
+
key = key.trim();
|
|
10173
|
+
value = value.trim();
|
|
10174
|
+
if (value === "true") {
|
|
10175
|
+
update[key] = true;
|
|
10176
|
+
} else if (value === "false") {
|
|
10177
|
+
update[key] = false;
|
|
10178
|
+
} else {
|
|
10179
|
+
const parsedNumber = parseFloat(value);
|
|
10180
|
+
if (!isNaN(parsedNumber)) {
|
|
10181
|
+
update[key] = parsedNumber;
|
|
10182
|
+
} else {
|
|
10183
|
+
update[key] = value;
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10186
|
+
});
|
|
10187
|
+
return update;
|
|
10188
|
+
}
|
|
10189
|
+
function getHasUneditableRows(metadata) {
|
|
10190
|
+
if (!metadata) {
|
|
10191
|
+
return false;
|
|
10192
|
+
}
|
|
10193
|
+
return Object.values(metadata).some(
|
|
10194
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10195
|
+
);
|
|
10196
|
+
}
|
|
10197
|
+
const NumberInput = forwardRef(
|
|
10198
|
+
({
|
|
10199
|
+
value,
|
|
10200
|
+
onChange,
|
|
10201
|
+
size = "base",
|
|
10202
|
+
min = 0,
|
|
10203
|
+
max = 100,
|
|
10204
|
+
step = 1,
|
|
10205
|
+
className,
|
|
10206
|
+
disabled,
|
|
10207
|
+
...props
|
|
10208
|
+
}, ref) => {
|
|
10209
|
+
const handleChange = (event) => {
|
|
10210
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
10211
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
10212
|
+
onChange(newValue);
|
|
10213
|
+
}
|
|
10214
|
+
};
|
|
10215
|
+
const handleIncrement = () => {
|
|
10216
|
+
const newValue = value + step;
|
|
10217
|
+
if (max === void 0 || newValue <= max) {
|
|
10218
|
+
onChange(newValue);
|
|
10219
|
+
}
|
|
10220
|
+
};
|
|
10221
|
+
const handleDecrement = () => {
|
|
10222
|
+
const newValue = value - step;
|
|
10223
|
+
if (min === void 0 || newValue >= min) {
|
|
10224
|
+
onChange(newValue);
|
|
10225
|
+
}
|
|
10226
|
+
};
|
|
10227
|
+
return /* @__PURE__ */ jsxs(
|
|
10228
|
+
"div",
|
|
10229
|
+
{
|
|
10230
|
+
className: clx(
|
|
10231
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
10232
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
10233
|
+
{
|
|
10234
|
+
"h-7": size === "small",
|
|
10235
|
+
"h-8": size === "base"
|
|
10236
|
+
},
|
|
10237
|
+
className
|
|
10238
|
+
),
|
|
10239
|
+
children: [
|
|
10240
|
+
/* @__PURE__ */ jsx(
|
|
10241
|
+
"input",
|
|
10296
10242
|
{
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10243
|
+
ref,
|
|
10244
|
+
type: "number",
|
|
10245
|
+
value,
|
|
10246
|
+
onChange: handleChange,
|
|
10247
|
+
min,
|
|
10248
|
+
max,
|
|
10249
|
+
step,
|
|
10250
|
+
className: clx(
|
|
10251
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
10252
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
10253
|
+
"placeholder:text-ui-fg-muted"
|
|
10254
|
+
),
|
|
10255
|
+
...props
|
|
10256
|
+
}
|
|
10257
|
+
),
|
|
10258
|
+
/* @__PURE__ */ jsxs(
|
|
10259
|
+
"button",
|
|
10260
|
+
{
|
|
10261
|
+
className: clx(
|
|
10262
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
10263
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10264
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
10265
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
10266
|
+
{
|
|
10267
|
+
"size-7": size === "small",
|
|
10268
|
+
"size-8": size === "base"
|
|
10269
|
+
}
|
|
10270
|
+
),
|
|
10271
|
+
type: "button",
|
|
10272
|
+
onClick: handleDecrement,
|
|
10273
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
10300
10274
|
children: [
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10275
|
+
/* @__PURE__ */ jsx(Minus, {}),
|
|
10276
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
10277
|
+
]
|
|
10278
|
+
}
|
|
10279
|
+
),
|
|
10280
|
+
/* @__PURE__ */ jsxs(
|
|
10281
|
+
"button",
|
|
10282
|
+
{
|
|
10283
|
+
className: clx(
|
|
10284
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
10285
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
10286
|
+
"focus:bg-ui-bg-field-hover",
|
|
10287
|
+
"hover:bg-ui-bg-field-hover",
|
|
10288
|
+
{
|
|
10289
|
+
"size-7": size === "small",
|
|
10290
|
+
"size-8": size === "base"
|
|
10291
|
+
}
|
|
10292
|
+
),
|
|
10293
|
+
type: "button",
|
|
10294
|
+
onClick: handleIncrement,
|
|
10295
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
10296
|
+
children: [
|
|
10297
|
+
/* @__PURE__ */ jsx(Plus, {}),
|
|
10298
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
10304
10299
|
]
|
|
10305
10300
|
}
|
|
10306
10301
|
)
|
|
10307
|
-
]
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10302
|
+
]
|
|
10303
|
+
}
|
|
10304
|
+
);
|
|
10305
|
+
}
|
|
10306
|
+
);
|
|
10307
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
10308
|
+
const productVariantsQueryKeys = {
|
|
10309
|
+
list: (query2) => [
|
|
10310
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
10311
|
+
query2 ? query2 : void 0
|
|
10312
|
+
]
|
|
10313
|
+
};
|
|
10314
|
+
const useProductVariants = (query2, options) => {
|
|
10315
|
+
const { data, ...rest } = useQuery({
|
|
10316
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
10317
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
10318
|
+
...options
|
|
10319
|
+
});
|
|
10320
|
+
return { ...data, ...rest };
|
|
10321
|
+
};
|
|
10322
|
+
const useCancelOrderEdit = ({ preview }) => {
|
|
10323
|
+
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
10324
|
+
const onCancel = useCallback(async () => {
|
|
10325
|
+
if (!preview) {
|
|
10326
|
+
return true;
|
|
10327
|
+
}
|
|
10328
|
+
let res = false;
|
|
10329
|
+
await cancelOrderEdit(void 0, {
|
|
10330
|
+
onError: (e) => {
|
|
10331
|
+
toast.error(e.message);
|
|
10332
|
+
},
|
|
10333
|
+
onSuccess: () => {
|
|
10334
|
+
res = true;
|
|
10335
|
+
}
|
|
10336
|
+
});
|
|
10337
|
+
return res;
|
|
10338
|
+
}, [preview, cancelOrderEdit]);
|
|
10339
|
+
return { onCancel };
|
|
10340
|
+
};
|
|
10341
|
+
let IS_REQUEST_RUNNING = false;
|
|
10342
|
+
const useInitiateOrderEdit = ({
|
|
10343
|
+
preview
|
|
10344
|
+
}) => {
|
|
10345
|
+
const navigate = useNavigate();
|
|
10346
|
+
const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
|
|
10347
|
+
useEffect(() => {
|
|
10348
|
+
async function run() {
|
|
10349
|
+
if (IS_REQUEST_RUNNING || !preview) {
|
|
10350
|
+
return;
|
|
10351
|
+
}
|
|
10352
|
+
if (preview.order_change) {
|
|
10353
|
+
return;
|
|
10354
|
+
}
|
|
10355
|
+
IS_REQUEST_RUNNING = true;
|
|
10356
|
+
await mutateAsync(void 0, {
|
|
10357
|
+
onError: (e) => {
|
|
10358
|
+
toast.error(e.message);
|
|
10359
|
+
navigate(`/draft-orders/${preview.id}`, { replace: true });
|
|
10360
|
+
return;
|
|
10326
10361
|
}
|
|
10362
|
+
});
|
|
10363
|
+
IS_REQUEST_RUNNING = false;
|
|
10364
|
+
}
|
|
10365
|
+
run();
|
|
10366
|
+
}, [preview, navigate, mutateAsync]);
|
|
10367
|
+
};
|
|
10368
|
+
function convertNumber(value) {
|
|
10369
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10370
|
+
}
|
|
10371
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10372
|
+
const Items = () => {
|
|
10373
|
+
const { id } = useParams();
|
|
10374
|
+
const {
|
|
10375
|
+
order: preview,
|
|
10376
|
+
isPending: isPreviewPending,
|
|
10377
|
+
isError: isPreviewError,
|
|
10378
|
+
error: previewError
|
|
10379
|
+
} = useOrderPreview(id, void 0, {
|
|
10380
|
+
placeholderData: keepPreviousData
|
|
10381
|
+
});
|
|
10382
|
+
useInitiateOrderEdit({ preview });
|
|
10383
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10384
|
+
id,
|
|
10385
|
+
{
|
|
10386
|
+
fields: "currency_code"
|
|
10387
|
+
},
|
|
10388
|
+
{
|
|
10389
|
+
enabled: !!id
|
|
10390
|
+
}
|
|
10391
|
+
);
|
|
10392
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10393
|
+
if (isError) {
|
|
10394
|
+
throw error;
|
|
10395
|
+
}
|
|
10396
|
+
if (isPreviewError) {
|
|
10397
|
+
throw previewError;
|
|
10398
|
+
}
|
|
10399
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
10400
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10401
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
10402
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10403
|
+
] }) });
|
|
10404
|
+
};
|
|
10405
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
10406
|
+
var _a;
|
|
10407
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10408
|
+
const [modalContent, setModalContent] = useState(
|
|
10409
|
+
null
|
|
10410
|
+
);
|
|
10411
|
+
const { handleSuccess } = useRouteModal();
|
|
10412
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
10413
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10414
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10415
|
+
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10416
|
+
const matches = useMemo(() => {
|
|
10417
|
+
return matchSorter(preview.items, query2, {
|
|
10418
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10419
|
+
});
|
|
10420
|
+
}, [preview.items, query2]);
|
|
10421
|
+
const onSubmit = async () => {
|
|
10422
|
+
setIsSubmitting(true);
|
|
10423
|
+
let requestSucceeded = false;
|
|
10424
|
+
await requestOrderEdit(void 0, {
|
|
10425
|
+
onError: (e) => {
|
|
10426
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
10427
|
+
},
|
|
10428
|
+
onSuccess: () => {
|
|
10429
|
+
requestSucceeded = true;
|
|
10327
10430
|
}
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10431
|
+
});
|
|
10432
|
+
if (!requestSucceeded) {
|
|
10433
|
+
setIsSubmitting(false);
|
|
10434
|
+
return;
|
|
10435
|
+
}
|
|
10436
|
+
await confirmOrderEdit(void 0, {
|
|
10437
|
+
onError: (e) => {
|
|
10438
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10439
|
+
},
|
|
10440
|
+
onSuccess: () => {
|
|
10441
|
+
handleSuccess();
|
|
10442
|
+
},
|
|
10443
|
+
onSettled: () => {
|
|
10444
|
+
setIsSubmitting(false);
|
|
10445
|
+
}
|
|
10446
|
+
});
|
|
10447
|
+
};
|
|
10448
|
+
const onKeyDown = useCallback(
|
|
10449
|
+
(e) => {
|
|
10450
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10451
|
+
if (modalContent || isSubmitting) {
|
|
10452
|
+
return;
|
|
10344
10453
|
}
|
|
10454
|
+
onSubmit();
|
|
10345
10455
|
}
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10456
|
+
},
|
|
10457
|
+
[modalContent, isSubmitting, onSubmit]
|
|
10458
|
+
);
|
|
10459
|
+
useEffect(() => {
|
|
10460
|
+
document.addEventListener("keydown", onKeyDown);
|
|
10461
|
+
return () => {
|
|
10462
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
10463
|
+
};
|
|
10464
|
+
}, [onKeyDown]);
|
|
10465
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10466
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10467
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
10468
|
+
StackedFocusModal,
|
|
10349
10469
|
{
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10470
|
+
id: STACKED_MODAL_ID,
|
|
10471
|
+
onOpenChangeCallback: (open) => {
|
|
10472
|
+
if (!open) {
|
|
10473
|
+
setModalContent(null);
|
|
10474
|
+
}
|
|
10354
10475
|
},
|
|
10355
|
-
|
|
10356
|
-
|
|
10476
|
+
children: [
|
|
10477
|
+
/* @__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: [
|
|
10478
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10479
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
|
|
10480
|
+
/* @__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" }) })
|
|
10481
|
+
] }),
|
|
10482
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10483
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10484
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10485
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10486
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10487
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10488
|
+
] }),
|
|
10489
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10490
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10491
|
+
Input,
|
|
10492
|
+
{
|
|
10493
|
+
type: "search",
|
|
10494
|
+
placeholder: "Search items",
|
|
10495
|
+
value: searchValue,
|
|
10496
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10497
|
+
}
|
|
10498
|
+
) }),
|
|
10499
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10500
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10501
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10502
|
+
/* @__PURE__ */ jsx(
|
|
10503
|
+
StackedModalTrigger$1,
|
|
10504
|
+
{
|
|
10505
|
+
type: "add-items",
|
|
10506
|
+
setModalContent
|
|
10507
|
+
}
|
|
10508
|
+
),
|
|
10509
|
+
/* @__PURE__ */ jsx(
|
|
10510
|
+
StackedModalTrigger$1,
|
|
10511
|
+
{
|
|
10512
|
+
type: "add-custom-item",
|
|
10513
|
+
setModalContent
|
|
10514
|
+
}
|
|
10515
|
+
)
|
|
10516
|
+
] })
|
|
10517
|
+
] })
|
|
10518
|
+
] })
|
|
10519
|
+
] }),
|
|
10520
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10521
|
+
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
10522
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10523
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10524
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10525
|
+
/* @__PURE__ */ jsx("div", {})
|
|
10526
|
+
] }) }),
|
|
10527
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10528
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10529
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10530
|
+
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10531
|
+
Item,
|
|
10532
|
+
{
|
|
10533
|
+
item,
|
|
10534
|
+
preview,
|
|
10535
|
+
currencyCode
|
|
10536
|
+
},
|
|
10537
|
+
item.id
|
|
10538
|
+
)) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10539
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10540
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10541
|
+
'No items found for "',
|
|
10542
|
+
query2,
|
|
10543
|
+
'".'
|
|
10544
|
+
] })
|
|
10545
|
+
] }) })
|
|
10546
|
+
] })
|
|
10547
|
+
] }),
|
|
10548
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10549
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10550
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10551
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10552
|
+
Text,
|
|
10553
|
+
{
|
|
10554
|
+
size: "small",
|
|
10555
|
+
leading: "compact",
|
|
10556
|
+
className: "text-ui-fg-subtle",
|
|
10557
|
+
children: [
|
|
10558
|
+
itemCount,
|
|
10559
|
+
" ",
|
|
10560
|
+
itemCount === 1 ? "item" : "items"
|
|
10561
|
+
]
|
|
10562
|
+
}
|
|
10563
|
+
) }),
|
|
10564
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10565
|
+
] })
|
|
10566
|
+
] }) }),
|
|
10567
|
+
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10568
|
+
CustomItemForm,
|
|
10569
|
+
{
|
|
10570
|
+
orderId: preview.id,
|
|
10571
|
+
currencyCode
|
|
10572
|
+
}
|
|
10573
|
+
) : null)
|
|
10574
|
+
]
|
|
10357
10575
|
}
|
|
10358
|
-
)
|
|
10359
|
-
|
|
10576
|
+
) }),
|
|
10577
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10578
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10579
|
+
/* @__PURE__ */ jsx(
|
|
10580
|
+
Button,
|
|
10581
|
+
{
|
|
10582
|
+
size: "small",
|
|
10583
|
+
type: "button",
|
|
10584
|
+
onClick: onSubmit,
|
|
10585
|
+
isLoading: isSubmitting,
|
|
10586
|
+
children: "Save"
|
|
10587
|
+
}
|
|
10588
|
+
)
|
|
10589
|
+
] }) })
|
|
10590
|
+
] });
|
|
10360
10591
|
};
|
|
10361
|
-
const
|
|
10362
|
-
|
|
10363
|
-
|
|
10364
|
-
}
|
|
10365
|
-
|
|
10592
|
+
const Item = ({ item, preview, currencyCode }) => {
|
|
10593
|
+
if (item.variant_id) {
|
|
10594
|
+
return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
|
|
10595
|
+
}
|
|
10596
|
+
return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
|
|
10597
|
+
};
|
|
10598
|
+
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
10366
10599
|
const [editing, setEditing] = useState(false);
|
|
10367
|
-
const { quantity, unit_price, title } = item;
|
|
10368
10600
|
const form = useForm({
|
|
10369
10601
|
defaultValues: {
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
unit_price
|
|
10602
|
+
quantity: item.quantity,
|
|
10603
|
+
unit_price: item.unit_price
|
|
10373
10604
|
},
|
|
10374
|
-
resolver: zodResolver(
|
|
10605
|
+
resolver: zodResolver(variantItemSchema)
|
|
10375
10606
|
});
|
|
10376
|
-
useEffect(() => {
|
|
10377
|
-
form.reset({
|
|
10378
|
-
title,
|
|
10379
|
-
quantity,
|
|
10380
|
-
unit_price
|
|
10381
|
-
});
|
|
10382
|
-
}, [form, title, quantity, unit_price]);
|
|
10383
10607
|
const actionId = useMemo(() => {
|
|
10384
10608
|
var _a, _b;
|
|
10385
10609
|
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10386
10610
|
}, [item]);
|
|
10387
10611
|
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10388
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10389
10612
|
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10390
10613
|
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10391
10614
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10392
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity
|
|
10615
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10393
10616
|
setEditing(false);
|
|
10394
10617
|
return;
|
|
10395
10618
|
}
|
|
@@ -10411,17 +10634,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10411
10634
|
);
|
|
10412
10635
|
return;
|
|
10413
10636
|
}
|
|
10414
|
-
if (data.quantity === 0) {
|
|
10415
|
-
await removeActionItem(actionId, {
|
|
10416
|
-
onSuccess: () => {
|
|
10417
|
-
setEditing(false);
|
|
10418
|
-
},
|
|
10419
|
-
onError: (e) => {
|
|
10420
|
-
toast.error(e.message);
|
|
10421
|
-
}
|
|
10422
|
-
});
|
|
10423
|
-
return;
|
|
10424
|
-
}
|
|
10425
10637
|
await updateActionItem(
|
|
10426
10638
|
{
|
|
10427
10639
|
action_id: actionId,
|
|
@@ -10439,26 +10651,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10439
10651
|
);
|
|
10440
10652
|
});
|
|
10441
10653
|
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
10442
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
10654
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
|
|
10443
10655
|
/* @__PURE__ */ jsx(
|
|
10444
10656
|
Thumbnail,
|
|
10445
10657
|
{
|
|
10446
10658
|
thumbnail: item.thumbnail,
|
|
10447
|
-
alt: item.
|
|
10659
|
+
alt: item.product_title ?? void 0
|
|
10448
10660
|
}
|
|
10449
10661
|
),
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
|
|
10455
|
-
|
|
10456
|
-
|
|
10662
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10663
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
10664
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
10665
|
+
/* @__PURE__ */ jsxs(
|
|
10666
|
+
Text,
|
|
10667
|
+
{
|
|
10668
|
+
size: "small",
|
|
10669
|
+
leading: "compact",
|
|
10670
|
+
className: "text-ui-fg-subtle",
|
|
10671
|
+
children: [
|
|
10672
|
+
"(",
|
|
10673
|
+
item.variant_title,
|
|
10674
|
+
")"
|
|
10675
|
+
]
|
|
10676
|
+
}
|
|
10677
|
+
)
|
|
10678
|
+
] }),
|
|
10679
|
+
/* @__PURE__ */ jsx(
|
|
10680
|
+
Text,
|
|
10681
|
+
{
|
|
10682
|
+
size: "small",
|
|
10683
|
+
leading: "compact",
|
|
10684
|
+
className: "text-ui-fg-subtle",
|
|
10685
|
+
children: item.variant_sku
|
|
10457
10686
|
}
|
|
10458
|
-
|
|
10459
|
-
|
|
10687
|
+
)
|
|
10688
|
+
] })
|
|
10460
10689
|
] }),
|
|
10461
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10690
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
10462
10691
|
Form$2.Field,
|
|
10463
10692
|
{
|
|
10464
10693
|
control: form.control,
|
|
@@ -10467,8 +10696,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10467
10696
|
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
10468
10697
|
}
|
|
10469
10698
|
}
|
|
10470
|
-
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
10471
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10699
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
10700
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
10472
10701
|
Form$2.Field,
|
|
10473
10702
|
{
|
|
10474
10703
|
control: form.control,
|
|
@@ -10485,7 +10714,7 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10485
10714
|
) }) });
|
|
10486
10715
|
}
|
|
10487
10716
|
}
|
|
10488
|
-
) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10717
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10489
10718
|
/* @__PURE__ */ jsx(
|
|
10490
10719
|
IconButton,
|
|
10491
10720
|
{
|
|
@@ -10500,215 +10729,79 @@ const CustomItem = ({ item, preview, currencyCode }) => {
|
|
|
10500
10729
|
)
|
|
10501
10730
|
] }) }) });
|
|
10502
10731
|
};
|
|
10503
|
-
const
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
})
|
|
10507
|
-
|
|
10508
|
-
const
|
|
10509
|
-
|
|
10510
|
-
setIsOpen(STACKED_MODAL_ID, true);
|
|
10511
|
-
}, [setModalContent, setIsOpen, type]);
|
|
10512
|
-
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
10513
|
-
};
|
|
10514
|
-
const VARIANT_PREFIX = "items";
|
|
10515
|
-
const LIMIT = 50;
|
|
10516
|
-
const ExistingItemsForm = ({ orderId, items }) => {
|
|
10517
|
-
const { setIsOpen } = useStackedModal();
|
|
10518
|
-
const [rowSelection, setRowSelection] = useState(
|
|
10519
|
-
items.reduce((acc, item) => {
|
|
10520
|
-
acc[item.variant_id] = true;
|
|
10521
|
-
return acc;
|
|
10522
|
-
}, {})
|
|
10523
|
-
);
|
|
10524
|
-
useEffect(() => {
|
|
10525
|
-
setRowSelection(
|
|
10526
|
-
items.reduce((acc, item) => {
|
|
10527
|
-
if (item.variant_id) {
|
|
10528
|
-
acc[item.variant_id] = true;
|
|
10529
|
-
}
|
|
10530
|
-
return acc;
|
|
10531
|
-
}, {})
|
|
10532
|
-
);
|
|
10533
|
-
}, [items]);
|
|
10534
|
-
const { q, order, offset } = useQueryParams(
|
|
10535
|
-
["q", "order", "offset"],
|
|
10536
|
-
VARIANT_PREFIX
|
|
10537
|
-
);
|
|
10538
|
-
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10539
|
-
{
|
|
10540
|
-
q,
|
|
10541
|
-
order,
|
|
10542
|
-
offset: offset ? parseInt(offset) : void 0,
|
|
10543
|
-
limit: LIMIT
|
|
10544
|
-
},
|
|
10545
|
-
{
|
|
10546
|
-
placeholderData: keepPreviousData
|
|
10547
|
-
}
|
|
10548
|
-
);
|
|
10549
|
-
const columns = useColumns();
|
|
10550
|
-
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10551
|
-
const onSubmit = async () => {
|
|
10552
|
-
const ids = Object.keys(rowSelection).filter(
|
|
10553
|
-
(id) => !items.find((i) => i.variant_id === id)
|
|
10554
|
-
);
|
|
10555
|
-
await mutateAsync(
|
|
10556
|
-
{
|
|
10557
|
-
items: ids.map((id) => ({
|
|
10558
|
-
variant_id: id,
|
|
10559
|
-
quantity: 1
|
|
10560
|
-
}))
|
|
10561
|
-
},
|
|
10562
|
-
{
|
|
10563
|
-
onSuccess: () => {
|
|
10564
|
-
setRowSelection({});
|
|
10565
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10566
|
-
},
|
|
10567
|
-
onError: (e) => {
|
|
10568
|
-
toast.error(e.message);
|
|
10569
|
-
}
|
|
10570
|
-
}
|
|
10571
|
-
);
|
|
10572
|
-
};
|
|
10573
|
-
if (isError) {
|
|
10574
|
-
throw error;
|
|
10575
|
-
}
|
|
10576
|
-
return /* @__PURE__ */ jsxs(
|
|
10577
|
-
StackedFocusModal.Content,
|
|
10578
|
-
{
|
|
10579
|
-
onOpenAutoFocus: (e) => {
|
|
10580
|
-
e.preventDefault();
|
|
10581
|
-
const searchInput = document.querySelector(
|
|
10582
|
-
"[data-modal-id='modal-search-input']"
|
|
10583
|
-
);
|
|
10584
|
-
if (searchInput) {
|
|
10585
|
-
searchInput.focus();
|
|
10586
|
-
}
|
|
10587
|
-
},
|
|
10588
|
-
children: [
|
|
10589
|
-
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
10590
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
10591
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
10592
|
-
] }),
|
|
10593
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
10594
|
-
DataTable,
|
|
10595
|
-
{
|
|
10596
|
-
data: variants,
|
|
10597
|
-
columns,
|
|
10598
|
-
isLoading: isPending,
|
|
10599
|
-
getRowId: (row) => row.id,
|
|
10600
|
-
rowCount: count,
|
|
10601
|
-
prefix: VARIANT_PREFIX,
|
|
10602
|
-
layout: "fill",
|
|
10603
|
-
rowSelection: {
|
|
10604
|
-
state: rowSelection,
|
|
10605
|
-
onRowSelectionChange: setRowSelection,
|
|
10606
|
-
enableRowSelection: (row) => {
|
|
10607
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
10608
|
-
}
|
|
10609
|
-
},
|
|
10610
|
-
autoFocusSearch: true
|
|
10611
|
-
}
|
|
10612
|
-
) }),
|
|
10613
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10614
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10615
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
10616
|
-
] }) })
|
|
10617
|
-
]
|
|
10618
|
-
}
|
|
10619
|
-
);
|
|
10620
|
-
};
|
|
10621
|
-
const columnHelper = createDataTableColumnHelper();
|
|
10622
|
-
const useColumns = () => {
|
|
10623
|
-
return useMemo(() => {
|
|
10624
|
-
return [
|
|
10625
|
-
columnHelper.select(),
|
|
10626
|
-
columnHelper.accessor("product.title", {
|
|
10627
|
-
header: "Product",
|
|
10628
|
-
cell: ({ row }) => {
|
|
10629
|
-
var _a, _b, _c;
|
|
10630
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10631
|
-
/* @__PURE__ */ jsx(
|
|
10632
|
-
Thumbnail,
|
|
10633
|
-
{
|
|
10634
|
-
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
10635
|
-
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
10636
|
-
}
|
|
10637
|
-
),
|
|
10638
|
-
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10639
|
-
] });
|
|
10640
|
-
},
|
|
10641
|
-
enableSorting: true
|
|
10642
|
-
}),
|
|
10643
|
-
columnHelper.accessor("title", {
|
|
10644
|
-
header: "Variant",
|
|
10645
|
-
enableSorting: true
|
|
10646
|
-
}),
|
|
10647
|
-
columnHelper.accessor("sku", {
|
|
10648
|
-
header: "SKU",
|
|
10649
|
-
cell: ({ getValue }) => {
|
|
10650
|
-
return getValue() ?? "-";
|
|
10651
|
-
},
|
|
10652
|
-
enableSorting: true
|
|
10653
|
-
}),
|
|
10654
|
-
columnHelper.accessor("updated_at", {
|
|
10655
|
-
header: "Updated",
|
|
10656
|
-
cell: ({ getValue }) => {
|
|
10657
|
-
return /* @__PURE__ */ jsx(
|
|
10658
|
-
Tooltip,
|
|
10659
|
-
{
|
|
10660
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10661
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10662
|
-
}
|
|
10663
|
-
);
|
|
10664
|
-
},
|
|
10665
|
-
enableSorting: true,
|
|
10666
|
-
sortAscLabel: "Oldest first",
|
|
10667
|
-
sortDescLabel: "Newest first"
|
|
10668
|
-
}),
|
|
10669
|
-
columnHelper.accessor("created_at", {
|
|
10670
|
-
header: "Created",
|
|
10671
|
-
cell: ({ getValue }) => {
|
|
10672
|
-
return /* @__PURE__ */ jsx(
|
|
10673
|
-
Tooltip,
|
|
10674
|
-
{
|
|
10675
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10676
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10677
|
-
}
|
|
10678
|
-
);
|
|
10679
|
-
},
|
|
10680
|
-
enableSorting: true,
|
|
10681
|
-
sortAscLabel: "Oldest first",
|
|
10682
|
-
sortDescLabel: "Newest first"
|
|
10683
|
-
})
|
|
10684
|
-
];
|
|
10685
|
-
}, []);
|
|
10686
|
-
};
|
|
10687
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10688
|
-
const { setIsOpen } = useStackedModal();
|
|
10689
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10732
|
+
const variantItemSchema = objectType({
|
|
10733
|
+
quantity: numberType(),
|
|
10734
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10735
|
+
});
|
|
10736
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
10737
|
+
const [editing, setEditing] = useState(false);
|
|
10738
|
+
const { quantity, unit_price, title } = item;
|
|
10690
10739
|
const form = useForm({
|
|
10691
10740
|
defaultValues: {
|
|
10692
|
-
title
|
|
10693
|
-
quantity
|
|
10694
|
-
unit_price
|
|
10741
|
+
title,
|
|
10742
|
+
quantity,
|
|
10743
|
+
unit_price
|
|
10695
10744
|
},
|
|
10696
10745
|
resolver: zodResolver(customItemSchema)
|
|
10697
10746
|
});
|
|
10747
|
+
useEffect(() => {
|
|
10748
|
+
form.reset({
|
|
10749
|
+
title,
|
|
10750
|
+
quantity,
|
|
10751
|
+
unit_price
|
|
10752
|
+
});
|
|
10753
|
+
}, [form, title, quantity, unit_price]);
|
|
10754
|
+
const actionId = useMemo(() => {
|
|
10755
|
+
var _a, _b;
|
|
10756
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10757
|
+
}, [item]);
|
|
10758
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10759
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10760
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10761
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10698
10762
|
const onSubmit = form.handleSubmit(async (data) => {
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10705
|
-
|
|
10763
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
10764
|
+
setEditing(false);
|
|
10765
|
+
return;
|
|
10766
|
+
}
|
|
10767
|
+
if (!actionId) {
|
|
10768
|
+
await updateOriginalItem(
|
|
10769
|
+
{
|
|
10770
|
+
item_id: item.id,
|
|
10771
|
+
quantity: data.quantity,
|
|
10772
|
+
unit_price: convertNumber(data.unit_price)
|
|
10773
|
+
},
|
|
10774
|
+
{
|
|
10775
|
+
onSuccess: () => {
|
|
10776
|
+
setEditing(false);
|
|
10777
|
+
},
|
|
10778
|
+
onError: (e) => {
|
|
10779
|
+
toast.error(e.message);
|
|
10706
10780
|
}
|
|
10707
|
-
|
|
10781
|
+
}
|
|
10782
|
+
);
|
|
10783
|
+
return;
|
|
10784
|
+
}
|
|
10785
|
+
if (data.quantity === 0) {
|
|
10786
|
+
await removeActionItem(actionId, {
|
|
10787
|
+
onSuccess: () => {
|
|
10788
|
+
setEditing(false);
|
|
10789
|
+
},
|
|
10790
|
+
onError: (e) => {
|
|
10791
|
+
toast.error(e.message);
|
|
10792
|
+
}
|
|
10793
|
+
});
|
|
10794
|
+
return;
|
|
10795
|
+
}
|
|
10796
|
+
await updateActionItem(
|
|
10797
|
+
{
|
|
10798
|
+
action_id: actionId,
|
|
10799
|
+
quantity: data.quantity,
|
|
10800
|
+
unit_price: convertNumber(data.unit_price)
|
|
10708
10801
|
},
|
|
10709
10802
|
{
|
|
10710
10803
|
onSuccess: () => {
|
|
10711
|
-
|
|
10804
|
+
setEditing(false);
|
|
10712
10805
|
},
|
|
10713
10806
|
onError: (e) => {
|
|
10714
10807
|
toast.error(e.message);
|
|
@@ -10716,458 +10809,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
|
10716
10809
|
}
|
|
10717
10810
|
);
|
|
10718
10811
|
});
|
|
10719
|
-
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(
|
|
10720
|
-
/* @__PURE__ */
|
|
10721
|
-
/* @__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: [
|
|
10722
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10723
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10724
|
-
/* @__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." }) })
|
|
10725
|
-
] }),
|
|
10726
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10812
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
10813
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
10727
10814
|
/* @__PURE__ */ jsx(
|
|
10728
|
-
|
|
10815
|
+
Thumbnail,
|
|
10729
10816
|
{
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10733
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10734
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
10735
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10736
|
-
] }),
|
|
10737
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10738
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10739
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10740
|
-
] })
|
|
10741
|
-
] }) })
|
|
10817
|
+
thumbnail: item.thumbnail,
|
|
10818
|
+
alt: item.title ?? void 0
|
|
10742
10819
|
}
|
|
10743
10820
|
),
|
|
10744
|
-
/* @__PURE__ */ jsx(
|
|
10745
|
-
/* @__PURE__ */ jsx(
|
|
10821
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10746
10822
|
Form$2.Field,
|
|
10747
10823
|
{
|
|
10748
10824
|
control: form.control,
|
|
10749
|
-
name: "
|
|
10750
|
-
render: ({ field
|
|
10751
|
-
/* @__PURE__ */
|
|
10752
|
-
|
|
10753
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10754
|
-
] }),
|
|
10755
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10756
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10757
|
-
CurrencyInput,
|
|
10758
|
-
{
|
|
10759
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10760
|
-
code: currencyCode,
|
|
10761
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10762
|
-
...field
|
|
10763
|
-
}
|
|
10764
|
-
) }),
|
|
10765
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10766
|
-
] })
|
|
10767
|
-
] }) })
|
|
10825
|
+
name: "title",
|
|
10826
|
+
render: ({ field }) => {
|
|
10827
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
10828
|
+
}
|
|
10768
10829
|
}
|
|
10769
|
-
),
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
|
|
10778
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10779
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10780
|
-
] }),
|
|
10781
|
-
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
10782
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10783
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10784
|
-
] })
|
|
10785
|
-
] }) })
|
|
10830
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
10831
|
+
] }),
|
|
10832
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10833
|
+
Form$2.Field,
|
|
10834
|
+
{
|
|
10835
|
+
control: form.control,
|
|
10836
|
+
name: "quantity",
|
|
10837
|
+
render: ({ field }) => {
|
|
10838
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
10786
10839
|
}
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10792
|
-
] }) })
|
|
10793
|
-
] }) }) });
|
|
10794
|
-
};
|
|
10795
|
-
const customItemSchema = objectType({
|
|
10796
|
-
title: stringType().min(1),
|
|
10797
|
-
quantity: numberType(),
|
|
10798
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10799
|
-
});
|
|
10800
|
-
const CustomItems = () => {
|
|
10801
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10802
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
10803
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
10804
|
-
] });
|
|
10805
|
-
};
|
|
10806
|
-
const CustomItemsForm = () => {
|
|
10807
|
-
const form = useForm({
|
|
10808
|
-
resolver: zodResolver(schema$3)
|
|
10809
|
-
});
|
|
10810
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
10811
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
10812
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10813
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10814
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
10815
|
-
] }) })
|
|
10816
|
-
] }) });
|
|
10817
|
-
};
|
|
10818
|
-
const schema$3 = objectType({
|
|
10819
|
-
email: stringType().email()
|
|
10820
|
-
});
|
|
10821
|
-
const InlineTip = forwardRef(
|
|
10822
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10823
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10824
|
-
return /* @__PURE__ */ jsxs(
|
|
10825
|
-
"div",
|
|
10840
|
+
}
|
|
10841
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
10842
|
+
editing ? /* @__PURE__ */ jsx(
|
|
10843
|
+
Form$2.Field,
|
|
10826
10844
|
{
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
...props,
|
|
10833
|
-
children: [
|
|
10834
|
-
/* @__PURE__ */ jsx(
|
|
10835
|
-
"div",
|
|
10845
|
+
control: form.control,
|
|
10846
|
+
name: "unit_price",
|
|
10847
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
10848
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10849
|
+
CurrencyInput,
|
|
10836
10850
|
{
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10851
|
+
...field,
|
|
10852
|
+
symbol: getNativeSymbol(currencyCode),
|
|
10853
|
+
code: currencyCode,
|
|
10854
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10841
10855
|
}
|
|
10842
|
-
)
|
|
10843
|
-
|
|
10844
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10845
|
-
labelValue,
|
|
10846
|
-
":"
|
|
10847
|
-
] }),
|
|
10848
|
-
" ",
|
|
10849
|
-
children
|
|
10850
|
-
] })
|
|
10851
|
-
]
|
|
10856
|
+
) }) });
|
|
10857
|
+
}
|
|
10852
10858
|
}
|
|
10853
|
-
)
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
}
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
}
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
}
|
|
10873
|
-
const
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
] }),
|
|
10879
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10880
|
-
] });
|
|
10859
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10860
|
+
/* @__PURE__ */ jsx(
|
|
10861
|
+
IconButton,
|
|
10862
|
+
{
|
|
10863
|
+
type: "button",
|
|
10864
|
+
size: "small",
|
|
10865
|
+
onClick: editing ? onSubmit : () => {
|
|
10866
|
+
setEditing(true);
|
|
10867
|
+
},
|
|
10868
|
+
disabled: isPending,
|
|
10869
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10870
|
+
}
|
|
10871
|
+
)
|
|
10872
|
+
] }) }) });
|
|
10873
|
+
};
|
|
10874
|
+
const StackedModalTrigger$1 = ({
|
|
10875
|
+
type,
|
|
10876
|
+
setModalContent
|
|
10877
|
+
}) => {
|
|
10878
|
+
const { setIsOpen } = useStackedModal();
|
|
10879
|
+
const onClick = useCallback(() => {
|
|
10880
|
+
setModalContent(type);
|
|
10881
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
10882
|
+
}, [setModalContent, setIsOpen, type]);
|
|
10883
|
+
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
10881
10884
|
};
|
|
10882
|
-
const
|
|
10883
|
-
const
|
|
10884
|
-
const
|
|
10885
|
-
const {
|
|
10886
|
-
const
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10885
|
+
const VARIANT_PREFIX = "items";
|
|
10886
|
+
const LIMIT = 50;
|
|
10887
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
10888
|
+
const { setIsOpen } = useStackedModal();
|
|
10889
|
+
const [rowSelection, setRowSelection] = useState(
|
|
10890
|
+
items.reduce((acc, item) => {
|
|
10891
|
+
acc[item.variant_id] = true;
|
|
10892
|
+
return acc;
|
|
10893
|
+
}, {})
|
|
10894
|
+
);
|
|
10895
|
+
useEffect(() => {
|
|
10896
|
+
setRowSelection(
|
|
10897
|
+
items.reduce((acc, item) => {
|
|
10898
|
+
if (item.variant_id) {
|
|
10899
|
+
acc[item.variant_id] = true;
|
|
10900
|
+
}
|
|
10901
|
+
return acc;
|
|
10902
|
+
}, {})
|
|
10903
|
+
);
|
|
10904
|
+
}, [items]);
|
|
10905
|
+
const { q, order, offset } = useQueryParams(
|
|
10906
|
+
["q", "order", "offset"],
|
|
10907
|
+
VARIANT_PREFIX
|
|
10908
|
+
);
|
|
10909
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10910
|
+
{
|
|
10911
|
+
q,
|
|
10912
|
+
order,
|
|
10913
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
10914
|
+
limit: LIMIT
|
|
10891
10915
|
},
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10916
|
+
{
|
|
10917
|
+
placeholderData: keepPreviousData
|
|
10918
|
+
}
|
|
10919
|
+
);
|
|
10920
|
+
const columns = useColumns();
|
|
10921
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10922
|
+
const onSubmit = async () => {
|
|
10923
|
+
const ids = Object.keys(rowSelection).filter(
|
|
10924
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
10925
|
+
);
|
|
10896
10926
|
await mutateAsync(
|
|
10897
10927
|
{
|
|
10898
|
-
|
|
10928
|
+
items: ids.map((id) => ({
|
|
10929
|
+
variant_id: id,
|
|
10930
|
+
quantity: 1
|
|
10931
|
+
}))
|
|
10899
10932
|
},
|
|
10900
10933
|
{
|
|
10901
10934
|
onSuccess: () => {
|
|
10902
|
-
|
|
10903
|
-
|
|
10935
|
+
setRowSelection({});
|
|
10936
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
10904
10937
|
},
|
|
10905
|
-
onError: (
|
|
10906
|
-
toast.error(
|
|
10938
|
+
onError: (e) => {
|
|
10939
|
+
toast.error(e.message);
|
|
10907
10940
|
}
|
|
10908
10941
|
}
|
|
10909
10942
|
);
|
|
10910
|
-
}
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
name: "metadata"
|
|
10914
|
-
});
|
|
10915
|
-
function deleteRow(index) {
|
|
10916
|
-
remove(index);
|
|
10917
|
-
if (fields.length === 1) {
|
|
10918
|
-
insert(0, {
|
|
10919
|
-
key: "",
|
|
10920
|
-
value: "",
|
|
10921
|
-
disabled: false
|
|
10922
|
-
});
|
|
10923
|
-
}
|
|
10924
|
-
}
|
|
10925
|
-
function insertRow(index, position) {
|
|
10926
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10927
|
-
key: "",
|
|
10928
|
-
value: "",
|
|
10929
|
-
disabled: false
|
|
10930
|
-
});
|
|
10943
|
+
};
|
|
10944
|
+
if (isError) {
|
|
10945
|
+
throw error;
|
|
10931
10946
|
}
|
|
10932
|
-
return /* @__PURE__ */
|
|
10933
|
-
|
|
10947
|
+
return /* @__PURE__ */ jsxs(
|
|
10948
|
+
StackedFocusModal.Content,
|
|
10934
10949
|
{
|
|
10935
|
-
|
|
10936
|
-
|
|
10950
|
+
onOpenAutoFocus: (e) => {
|
|
10951
|
+
e.preventDefault();
|
|
10952
|
+
const searchInput = document.querySelector(
|
|
10953
|
+
"[data-modal-id='modal-search-input']"
|
|
10954
|
+
);
|
|
10955
|
+
if (searchInput) {
|
|
10956
|
+
searchInput.focus();
|
|
10957
|
+
}
|
|
10958
|
+
},
|
|
10937
10959
|
children: [
|
|
10938
|
-
/* @__PURE__ */ jsxs(
|
|
10939
|
-
/* @__PURE__ */
|
|
10940
|
-
|
|
10941
|
-
/* @__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" }) }),
|
|
10942
|
-
/* @__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" }) })
|
|
10943
|
-
] }),
|
|
10944
|
-
fields.map((field, index) => {
|
|
10945
|
-
const isDisabled = field.disabled || false;
|
|
10946
|
-
let placeholder = "-";
|
|
10947
|
-
if (typeof field.value === "object") {
|
|
10948
|
-
placeholder = "{ ... }";
|
|
10949
|
-
}
|
|
10950
|
-
if (Array.isArray(field.value)) {
|
|
10951
|
-
placeholder = "[ ... ]";
|
|
10952
|
-
}
|
|
10953
|
-
return /* @__PURE__ */ jsx(
|
|
10954
|
-
ConditionalTooltip,
|
|
10955
|
-
{
|
|
10956
|
-
showTooltip: isDisabled,
|
|
10957
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
10958
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10959
|
-
/* @__PURE__ */ jsxs(
|
|
10960
|
-
"div",
|
|
10961
|
-
{
|
|
10962
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
10963
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10964
|
-
}),
|
|
10965
|
-
children: [
|
|
10966
|
-
/* @__PURE__ */ jsx(
|
|
10967
|
-
Form$2.Field,
|
|
10968
|
-
{
|
|
10969
|
-
control: form.control,
|
|
10970
|
-
name: `metadata.${index}.key`,
|
|
10971
|
-
render: ({ field: field2 }) => {
|
|
10972
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10973
|
-
GridInput,
|
|
10974
|
-
{
|
|
10975
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10976
|
-
...field2,
|
|
10977
|
-
disabled: isDisabled,
|
|
10978
|
-
placeholder: "Key"
|
|
10979
|
-
}
|
|
10980
|
-
) }) });
|
|
10981
|
-
}
|
|
10982
|
-
}
|
|
10983
|
-
),
|
|
10984
|
-
/* @__PURE__ */ jsx(
|
|
10985
|
-
Form$2.Field,
|
|
10986
|
-
{
|
|
10987
|
-
control: form.control,
|
|
10988
|
-
name: `metadata.${index}.value`,
|
|
10989
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
10990
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10991
|
-
GridInput,
|
|
10992
|
-
{
|
|
10993
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10994
|
-
...field2,
|
|
10995
|
-
value: isDisabled ? placeholder : value,
|
|
10996
|
-
disabled: isDisabled,
|
|
10997
|
-
placeholder: "Value"
|
|
10998
|
-
}
|
|
10999
|
-
) }) });
|
|
11000
|
-
}
|
|
11001
|
-
}
|
|
11002
|
-
)
|
|
11003
|
-
]
|
|
11004
|
-
}
|
|
11005
|
-
),
|
|
11006
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11007
|
-
/* @__PURE__ */ jsx(
|
|
11008
|
-
DropdownMenu.Trigger,
|
|
11009
|
-
{
|
|
11010
|
-
className: clx(
|
|
11011
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11012
|
-
{
|
|
11013
|
-
hidden: isDisabled
|
|
11014
|
-
}
|
|
11015
|
-
),
|
|
11016
|
-
disabled: isDisabled,
|
|
11017
|
-
asChild: true,
|
|
11018
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11019
|
-
}
|
|
11020
|
-
),
|
|
11021
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11022
|
-
/* @__PURE__ */ jsxs(
|
|
11023
|
-
DropdownMenu.Item,
|
|
11024
|
-
{
|
|
11025
|
-
className: "gap-x-2",
|
|
11026
|
-
onClick: () => insertRow(index, "above"),
|
|
11027
|
-
children: [
|
|
11028
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11029
|
-
"Insert row above"
|
|
11030
|
-
]
|
|
11031
|
-
}
|
|
11032
|
-
),
|
|
11033
|
-
/* @__PURE__ */ jsxs(
|
|
11034
|
-
DropdownMenu.Item,
|
|
11035
|
-
{
|
|
11036
|
-
className: "gap-x-2",
|
|
11037
|
-
onClick: () => insertRow(index, "below"),
|
|
11038
|
-
children: [
|
|
11039
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11040
|
-
"Insert row below"
|
|
11041
|
-
]
|
|
11042
|
-
}
|
|
11043
|
-
),
|
|
11044
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11045
|
-
/* @__PURE__ */ jsxs(
|
|
11046
|
-
DropdownMenu.Item,
|
|
11047
|
-
{
|
|
11048
|
-
className: "gap-x-2",
|
|
11049
|
-
onClick: () => deleteRow(index),
|
|
11050
|
-
children: [
|
|
11051
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11052
|
-
"Delete row"
|
|
11053
|
-
]
|
|
11054
|
-
}
|
|
11055
|
-
)
|
|
11056
|
-
] })
|
|
11057
|
-
] })
|
|
11058
|
-
] })
|
|
11059
|
-
},
|
|
11060
|
-
field.id
|
|
11061
|
-
);
|
|
11062
|
-
})
|
|
11063
|
-
] }),
|
|
11064
|
-
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." })
|
|
10960
|
+
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
10961
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
10962
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
11065
10963
|
] }),
|
|
11066
|
-
/* @__PURE__ */ jsx(
|
|
11067
|
-
|
|
11068
|
-
|
|
10964
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
10965
|
+
DataTable,
|
|
10966
|
+
{
|
|
10967
|
+
data: variants,
|
|
10968
|
+
columns,
|
|
10969
|
+
isLoading: isPending,
|
|
10970
|
+
getRowId: (row) => row.id,
|
|
10971
|
+
rowCount: count,
|
|
10972
|
+
prefix: VARIANT_PREFIX,
|
|
10973
|
+
layout: "fill",
|
|
10974
|
+
rowSelection: {
|
|
10975
|
+
state: rowSelection,
|
|
10976
|
+
onRowSelectionChange: setRowSelection,
|
|
10977
|
+
enableRowSelection: (row) => {
|
|
10978
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
10979
|
+
}
|
|
10980
|
+
},
|
|
10981
|
+
autoFocusSearch: true
|
|
10982
|
+
}
|
|
10983
|
+
) }),
|
|
10984
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10985
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10986
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
11069
10987
|
] }) })
|
|
11070
10988
|
]
|
|
11071
10989
|
}
|
|
11072
|
-
) });
|
|
11073
|
-
};
|
|
11074
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11075
|
-
return /* @__PURE__ */ jsx(
|
|
11076
|
-
"input",
|
|
11077
|
-
{
|
|
11078
|
-
ref,
|
|
11079
|
-
...props,
|
|
11080
|
-
autoComplete: "off",
|
|
11081
|
-
className: clx(
|
|
11082
|
-
"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",
|
|
11083
|
-
className
|
|
11084
|
-
)
|
|
11085
|
-
}
|
|
11086
10990
|
);
|
|
11087
|
-
});
|
|
11088
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11089
|
-
const PlaceholderInner = () => {
|
|
11090
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11091
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11092
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11093
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11094
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11095
|
-
] }) })
|
|
11096
|
-
] });
|
|
11097
10991
|
};
|
|
11098
|
-
const
|
|
11099
|
-
|
|
11100
|
-
|
|
10992
|
+
const columnHelper = createDataTableColumnHelper();
|
|
10993
|
+
const useColumns = () => {
|
|
10994
|
+
return useMemo(() => {
|
|
11101
10995
|
return [
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
10996
|
+
columnHelper.select(),
|
|
10997
|
+
columnHelper.accessor("product.title", {
|
|
10998
|
+
header: "Product",
|
|
10999
|
+
cell: ({ row }) => {
|
|
11000
|
+
var _a, _b, _c;
|
|
11001
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
11002
|
+
/* @__PURE__ */ jsx(
|
|
11003
|
+
Thumbnail,
|
|
11004
|
+
{
|
|
11005
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
11006
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
11007
|
+
}
|
|
11008
|
+
),
|
|
11009
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
11010
|
+
] });
|
|
11011
|
+
},
|
|
11012
|
+
enableSorting: true
|
|
11013
|
+
}),
|
|
11014
|
+
columnHelper.accessor("title", {
|
|
11015
|
+
header: "Variant",
|
|
11016
|
+
enableSorting: true
|
|
11017
|
+
}),
|
|
11018
|
+
columnHelper.accessor("sku", {
|
|
11019
|
+
header: "SKU",
|
|
11020
|
+
cell: ({ getValue }) => {
|
|
11021
|
+
return getValue() ?? "-";
|
|
11022
|
+
},
|
|
11023
|
+
enableSorting: true
|
|
11024
|
+
}),
|
|
11025
|
+
columnHelper.accessor("updated_at", {
|
|
11026
|
+
header: "Updated",
|
|
11027
|
+
cell: ({ getValue }) => {
|
|
11028
|
+
return /* @__PURE__ */ jsx(
|
|
11029
|
+
Tooltip,
|
|
11030
|
+
{
|
|
11031
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11032
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11033
|
+
}
|
|
11034
|
+
);
|
|
11035
|
+
},
|
|
11036
|
+
enableSorting: true,
|
|
11037
|
+
sortAscLabel: "Oldest first",
|
|
11038
|
+
sortDescLabel: "Newest first"
|
|
11039
|
+
}),
|
|
11040
|
+
columnHelper.accessor("created_at", {
|
|
11041
|
+
header: "Created",
|
|
11042
|
+
cell: ({ getValue }) => {
|
|
11043
|
+
return /* @__PURE__ */ jsx(
|
|
11044
|
+
Tooltip,
|
|
11045
|
+
{
|
|
11046
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
11047
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
11048
|
+
}
|
|
11049
|
+
);
|
|
11050
|
+
},
|
|
11051
|
+
enableSorting: true,
|
|
11052
|
+
sortAscLabel: "Oldest first",
|
|
11053
|
+
sortDescLabel: "Newest first"
|
|
11054
|
+
})
|
|
11107
11055
|
];
|
|
11108
|
-
}
|
|
11109
|
-
|
|
11110
|
-
|
|
11111
|
-
|
|
11112
|
-
|
|
11113
|
-
|
|
11114
|
-
|
|
11115
|
-
|
|
11116
|
-
|
|
11117
|
-
|
|
11118
|
-
|
|
11119
|
-
|
|
11120
|
-
}
|
|
11121
|
-
return {
|
|
11122
|
-
key,
|
|
11123
|
-
value: stringValue,
|
|
11124
|
-
original_key: key
|
|
11125
|
-
};
|
|
11056
|
+
}, []);
|
|
11057
|
+
};
|
|
11058
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
11059
|
+
const { setIsOpen } = useStackedModal();
|
|
11060
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
11061
|
+
const form = useForm({
|
|
11062
|
+
defaultValues: {
|
|
11063
|
+
title: "",
|
|
11064
|
+
quantity: 1,
|
|
11065
|
+
unit_price: ""
|
|
11066
|
+
},
|
|
11067
|
+
resolver: zodResolver(customItemSchema)
|
|
11126
11068
|
});
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
}
|
|
11146
|
-
key = key.trim();
|
|
11147
|
-
value = value.trim();
|
|
11148
|
-
if (value === "true") {
|
|
11149
|
-
update[key] = true;
|
|
11150
|
-
} else if (value === "false") {
|
|
11151
|
-
update[key] = false;
|
|
11152
|
-
} else {
|
|
11153
|
-
const parsedNumber = parseFloat(value);
|
|
11154
|
-
if (!isNaN(parsedNumber)) {
|
|
11155
|
-
update[key] = parsedNumber;
|
|
11156
|
-
} else {
|
|
11157
|
-
update[key] = value;
|
|
11069
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11070
|
+
await addItems(
|
|
11071
|
+
{
|
|
11072
|
+
items: [
|
|
11073
|
+
{
|
|
11074
|
+
title: data.title,
|
|
11075
|
+
quantity: data.quantity,
|
|
11076
|
+
unit_price: convertNumber(data.unit_price)
|
|
11077
|
+
}
|
|
11078
|
+
]
|
|
11079
|
+
},
|
|
11080
|
+
{
|
|
11081
|
+
onSuccess: () => {
|
|
11082
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
11083
|
+
},
|
|
11084
|
+
onError: (e) => {
|
|
11085
|
+
toast.error(e.message);
|
|
11086
|
+
}
|
|
11158
11087
|
}
|
|
11159
|
-
|
|
11088
|
+
);
|
|
11160
11089
|
});
|
|
11161
|
-
return
|
|
11162
|
-
}
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11090
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
11091
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
11092
|
+
/* @__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: [
|
|
11093
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11094
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
11095
|
+
/* @__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." }) })
|
|
11096
|
+
] }),
|
|
11097
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11098
|
+
/* @__PURE__ */ jsx(
|
|
11099
|
+
Form$2.Field,
|
|
11100
|
+
{
|
|
11101
|
+
control: form.control,
|
|
11102
|
+
name: "title",
|
|
11103
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11104
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11105
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
11106
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
11107
|
+
] }),
|
|
11108
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11109
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11110
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11111
|
+
] })
|
|
11112
|
+
] }) })
|
|
11113
|
+
}
|
|
11114
|
+
),
|
|
11115
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11116
|
+
/* @__PURE__ */ jsx(
|
|
11117
|
+
Form$2.Field,
|
|
11118
|
+
{
|
|
11119
|
+
control: form.control,
|
|
11120
|
+
name: "unit_price",
|
|
11121
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11122
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11123
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
11124
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
11125
|
+
] }),
|
|
11126
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11127
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11128
|
+
CurrencyInput,
|
|
11129
|
+
{
|
|
11130
|
+
symbol: getNativeSymbol(currencyCode),
|
|
11131
|
+
code: currencyCode,
|
|
11132
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
11133
|
+
...field
|
|
11134
|
+
}
|
|
11135
|
+
) }),
|
|
11136
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11137
|
+
] })
|
|
11138
|
+
] }) })
|
|
11139
|
+
}
|
|
11140
|
+
),
|
|
11141
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11142
|
+
/* @__PURE__ */ jsx(
|
|
11143
|
+
Form$2.Field,
|
|
11144
|
+
{
|
|
11145
|
+
control: form.control,
|
|
11146
|
+
name: "quantity",
|
|
11147
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11148
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11149
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
11150
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
11151
|
+
] }),
|
|
11152
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
11153
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
11154
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11155
|
+
] })
|
|
11156
|
+
] }) })
|
|
11157
|
+
}
|
|
11158
|
+
)
|
|
11159
|
+
] }) }) }),
|
|
11160
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11161
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11162
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
11163
|
+
] }) })
|
|
11164
|
+
] }) }) });
|
|
11165
|
+
};
|
|
11166
|
+
const customItemSchema = objectType({
|
|
11167
|
+
title: stringType().min(1),
|
|
11168
|
+
quantity: numberType(),
|
|
11169
|
+
unit_price: unionType([numberType(), stringType()])
|
|
11170
|
+
});
|
|
11171
11171
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11172
11172
|
const promotionsQueryKeys = {
|
|
11173
11173
|
list: (query2) => [
|
|
@@ -11445,6 +11445,112 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11445
11445
|
}
|
|
11446
11446
|
return Array.from(promotionIds);
|
|
11447
11447
|
}
|
|
11448
|
+
const SalesChannel = () => {
|
|
11449
|
+
const { id } = useParams();
|
|
11450
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11451
|
+
id,
|
|
11452
|
+
{
|
|
11453
|
+
fields: "+sales_channel_id"
|
|
11454
|
+
},
|
|
11455
|
+
{
|
|
11456
|
+
enabled: !!id
|
|
11457
|
+
}
|
|
11458
|
+
);
|
|
11459
|
+
if (isError) {
|
|
11460
|
+
throw error;
|
|
11461
|
+
}
|
|
11462
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11463
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11464
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11465
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11466
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11467
|
+
] }),
|
|
11468
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11469
|
+
] });
|
|
11470
|
+
};
|
|
11471
|
+
const SalesChannelForm = ({ order }) => {
|
|
11472
|
+
const form = useForm({
|
|
11473
|
+
defaultValues: {
|
|
11474
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11475
|
+
},
|
|
11476
|
+
resolver: zodResolver(schema$2)
|
|
11477
|
+
});
|
|
11478
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11479
|
+
const { handleSuccess } = useRouteModal();
|
|
11480
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11481
|
+
await mutateAsync(
|
|
11482
|
+
{
|
|
11483
|
+
sales_channel_id: data.sales_channel_id
|
|
11484
|
+
},
|
|
11485
|
+
{
|
|
11486
|
+
onSuccess: () => {
|
|
11487
|
+
toast.success("Sales channel updated");
|
|
11488
|
+
handleSuccess();
|
|
11489
|
+
},
|
|
11490
|
+
onError: (error) => {
|
|
11491
|
+
toast.error(error.message);
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
11494
|
+
);
|
|
11495
|
+
});
|
|
11496
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11497
|
+
KeyboundForm,
|
|
11498
|
+
{
|
|
11499
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11500
|
+
onSubmit,
|
|
11501
|
+
children: [
|
|
11502
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11503
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11504
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11505
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11506
|
+
] }) })
|
|
11507
|
+
]
|
|
11508
|
+
}
|
|
11509
|
+
) });
|
|
11510
|
+
};
|
|
11511
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11512
|
+
const salesChannels = useComboboxData({
|
|
11513
|
+
queryFn: async (params) => {
|
|
11514
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11515
|
+
},
|
|
11516
|
+
queryKey: ["sales-channels"],
|
|
11517
|
+
getOptions: (data) => {
|
|
11518
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11519
|
+
label: salesChannel.name,
|
|
11520
|
+
value: salesChannel.id
|
|
11521
|
+
}));
|
|
11522
|
+
},
|
|
11523
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11524
|
+
});
|
|
11525
|
+
return /* @__PURE__ */ jsx(
|
|
11526
|
+
Form$2.Field,
|
|
11527
|
+
{
|
|
11528
|
+
control,
|
|
11529
|
+
name: "sales_channel_id",
|
|
11530
|
+
render: ({ field }) => {
|
|
11531
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11532
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11533
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11534
|
+
Combobox,
|
|
11535
|
+
{
|
|
11536
|
+
options: salesChannels.options,
|
|
11537
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11538
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11539
|
+
searchValue: salesChannels.searchValue,
|
|
11540
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11541
|
+
placeholder: "Select sales channel",
|
|
11542
|
+
...field
|
|
11543
|
+
}
|
|
11544
|
+
) }),
|
|
11545
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11546
|
+
] });
|
|
11547
|
+
}
|
|
11548
|
+
}
|
|
11549
|
+
);
|
|
11550
|
+
};
|
|
11551
|
+
const schema$2 = objectType({
|
|
11552
|
+
sales_channel_id: stringType().min(1)
|
|
11553
|
+
});
|
|
11448
11554
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11449
11555
|
const Shipping = () => {
|
|
11450
11556
|
var _a;
|
|
@@ -12252,112 +12358,6 @@ const CustomAmountField = ({
|
|
|
12252
12358
|
}
|
|
12253
12359
|
);
|
|
12254
12360
|
};
|
|
12255
|
-
const SalesChannel = () => {
|
|
12256
|
-
const { id } = useParams();
|
|
12257
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12258
|
-
id,
|
|
12259
|
-
{
|
|
12260
|
-
fields: "+sales_channel_id"
|
|
12261
|
-
},
|
|
12262
|
-
{
|
|
12263
|
-
enabled: !!id
|
|
12264
|
-
}
|
|
12265
|
-
);
|
|
12266
|
-
if (isError) {
|
|
12267
|
-
throw error;
|
|
12268
|
-
}
|
|
12269
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12270
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12271
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12272
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12273
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12274
|
-
] }),
|
|
12275
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12276
|
-
] });
|
|
12277
|
-
};
|
|
12278
|
-
const SalesChannelForm = ({ order }) => {
|
|
12279
|
-
const form = useForm({
|
|
12280
|
-
defaultValues: {
|
|
12281
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12282
|
-
},
|
|
12283
|
-
resolver: zodResolver(schema$2)
|
|
12284
|
-
});
|
|
12285
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12286
|
-
const { handleSuccess } = useRouteModal();
|
|
12287
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12288
|
-
await mutateAsync(
|
|
12289
|
-
{
|
|
12290
|
-
sales_channel_id: data.sales_channel_id
|
|
12291
|
-
},
|
|
12292
|
-
{
|
|
12293
|
-
onSuccess: () => {
|
|
12294
|
-
toast.success("Sales channel updated");
|
|
12295
|
-
handleSuccess();
|
|
12296
|
-
},
|
|
12297
|
-
onError: (error) => {
|
|
12298
|
-
toast.error(error.message);
|
|
12299
|
-
}
|
|
12300
|
-
}
|
|
12301
|
-
);
|
|
12302
|
-
});
|
|
12303
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12304
|
-
KeyboundForm,
|
|
12305
|
-
{
|
|
12306
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12307
|
-
onSubmit,
|
|
12308
|
-
children: [
|
|
12309
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12310
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12311
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12312
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12313
|
-
] }) })
|
|
12314
|
-
]
|
|
12315
|
-
}
|
|
12316
|
-
) });
|
|
12317
|
-
};
|
|
12318
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12319
|
-
const salesChannels = useComboboxData({
|
|
12320
|
-
queryFn: async (params) => {
|
|
12321
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12322
|
-
},
|
|
12323
|
-
queryKey: ["sales-channels"],
|
|
12324
|
-
getOptions: (data) => {
|
|
12325
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12326
|
-
label: salesChannel.name,
|
|
12327
|
-
value: salesChannel.id
|
|
12328
|
-
}));
|
|
12329
|
-
},
|
|
12330
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12331
|
-
});
|
|
12332
|
-
return /* @__PURE__ */ jsx(
|
|
12333
|
-
Form$2.Field,
|
|
12334
|
-
{
|
|
12335
|
-
control,
|
|
12336
|
-
name: "sales_channel_id",
|
|
12337
|
-
render: ({ field }) => {
|
|
12338
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12339
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12340
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12341
|
-
Combobox,
|
|
12342
|
-
{
|
|
12343
|
-
options: salesChannels.options,
|
|
12344
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
12345
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12346
|
-
searchValue: salesChannels.searchValue,
|
|
12347
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12348
|
-
placeholder: "Select sales channel",
|
|
12349
|
-
...field
|
|
12350
|
-
}
|
|
12351
|
-
) }),
|
|
12352
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12353
|
-
] });
|
|
12354
|
-
}
|
|
12355
|
-
}
|
|
12356
|
-
);
|
|
12357
|
-
};
|
|
12358
|
-
const schema$2 = objectType({
|
|
12359
|
-
sales_channel_id: stringType().min(1)
|
|
12360
|
-
});
|
|
12361
12361
|
const ShippingAddress = () => {
|
|
12362
12362
|
const { id } = useParams();
|
|
12363
12363
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -13061,34 +13061,34 @@ const routeModule = {
|
|
|
13061
13061
|
Component: BillingAddress,
|
|
13062
13062
|
path: "/draft-orders/:id/billing-address"
|
|
13063
13063
|
},
|
|
13064
|
-
{
|
|
13065
|
-
Component: Email,
|
|
13066
|
-
path: "/draft-orders/:id/email"
|
|
13067
|
-
},
|
|
13068
|
-
{
|
|
13069
|
-
Component: Items,
|
|
13070
|
-
path: "/draft-orders/:id/items"
|
|
13071
|
-
},
|
|
13072
13064
|
{
|
|
13073
13065
|
Component: CustomItems,
|
|
13074
13066
|
path: "/draft-orders/:id/custom-items"
|
|
13075
13067
|
},
|
|
13068
|
+
{
|
|
13069
|
+
Component: Email,
|
|
13070
|
+
path: "/draft-orders/:id/email"
|
|
13071
|
+
},
|
|
13076
13072
|
{
|
|
13077
13073
|
Component: Metadata,
|
|
13078
13074
|
path: "/draft-orders/:id/metadata"
|
|
13079
13075
|
},
|
|
13080
13076
|
{
|
|
13081
|
-
Component:
|
|
13082
|
-
path: "/draft-orders/:id/
|
|
13077
|
+
Component: Items,
|
|
13078
|
+
path: "/draft-orders/:id/items"
|
|
13083
13079
|
},
|
|
13084
13080
|
{
|
|
13085
|
-
Component:
|
|
13086
|
-
path: "/draft-orders/:id/
|
|
13081
|
+
Component: Promotions,
|
|
13082
|
+
path: "/draft-orders/:id/promotions"
|
|
13087
13083
|
},
|
|
13088
13084
|
{
|
|
13089
13085
|
Component: SalesChannel,
|
|
13090
13086
|
path: "/draft-orders/:id/sales-channel"
|
|
13091
13087
|
},
|
|
13088
|
+
{
|
|
13089
|
+
Component: Shipping,
|
|
13090
|
+
path: "/draft-orders/:id/shipping"
|
|
13091
|
+
},
|
|
13092
13092
|
{
|
|
13093
13093
|
Component: ShippingAddress,
|
|
13094
13094
|
path: "/draft-orders/:id/shipping-address"
|