@medusajs/draft-order 2.11.2-preview-20251026120206 → 2.11.2-preview-20251026150203

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