@medusajs/draft-order 3.0.0-preview-20260222000310 → 3.0.0-preview-20260222061113

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.
@@ -9853,573 +9853,775 @@ const EmailForm = ({ order }) => {
9853
9853
  const schema$3 = objectType({
9854
9854
  email: stringType().email()
9855
9855
  });
9856
- const NumberInput = React.forwardRef(
9857
- ({
9858
- value,
9859
- onChange,
9860
- size = "base",
9861
- min = 0,
9862
- max = 100,
9863
- step = 1,
9864
- className,
9865
- disabled,
9866
- ...props
9867
- }, ref) => {
9868
- const handleChange = (event) => {
9869
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9870
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9871
- onChange(newValue);
9872
- }
9873
- };
9874
- const handleIncrement = () => {
9875
- const newValue = value + step;
9876
- if (max === void 0 || newValue <= max) {
9877
- onChange(newValue);
9878
- }
9879
- };
9880
- const handleDecrement = () => {
9881
- const newValue = value - step;
9882
- if (min === void 0 || newValue >= min) {
9883
- onChange(newValue);
9884
- }
9885
- };
9856
+ const InlineTip = React.forwardRef(
9857
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9858
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9886
9859
  return /* @__PURE__ */ jsxRuntime.jsxs(
9887
9860
  "div",
9888
9861
  {
9862
+ ref,
9889
9863
  className: ui.clx(
9890
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9891
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9892
- {
9893
- "h-7": size === "small",
9894
- "h-8": size === "base"
9895
- },
9864
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9896
9865
  className
9897
9866
  ),
9867
+ ...props,
9898
9868
  children: [
9899
9869
  /* @__PURE__ */ jsxRuntime.jsx(
9900
- "input",
9901
- {
9902
- ref,
9903
- type: "number",
9904
- value,
9905
- onChange: handleChange,
9906
- min,
9907
- max,
9908
- step,
9909
- className: ui.clx(
9910
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9911
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9912
- "placeholder:text-ui-fg-muted"
9913
- ),
9914
- ...props
9915
- }
9916
- ),
9917
- /* @__PURE__ */ jsxRuntime.jsxs(
9918
- "button",
9870
+ "div",
9919
9871
  {
9920
- className: ui.clx(
9921
- "flex items-center justify-center outline-none transition-fg",
9922
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9923
- "focus:bg-ui-bg-field-component-hover",
9924
- "hover:bg-ui-bg-field-component-hover",
9925
- {
9926
- "size-7": size === "small",
9927
- "size-8": size === "base"
9928
- }
9929
- ),
9930
- type: "button",
9931
- onClick: handleDecrement,
9932
- disabled: min !== void 0 && value <= min || disabled,
9933
- children: [
9934
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9935
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9936
- ]
9872
+ role: "presentation",
9873
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9874
+ "bg-ui-tag-orange-icon": variant === "warning"
9875
+ })
9937
9876
  }
9938
9877
  ),
9939
- /* @__PURE__ */ jsxRuntime.jsxs(
9940
- "button",
9941
- {
9942
- className: ui.clx(
9943
- "flex items-center justify-center outline-none transition-fg",
9944
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9945
- "focus:bg-ui-bg-field-hover",
9946
- "hover:bg-ui-bg-field-hover",
9947
- {
9948
- "size-7": size === "small",
9949
- "size-8": size === "base"
9950
- }
9951
- ),
9952
- type: "button",
9953
- onClick: handleIncrement,
9954
- disabled: max !== void 0 && value >= max || disabled,
9955
- children: [
9956
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9957
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9958
- ]
9959
- }
9960
- )
9878
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9879
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9880
+ labelValue,
9881
+ ":"
9882
+ ] }),
9883
+ " ",
9884
+ children
9885
+ ] })
9961
9886
  ]
9962
9887
  }
9963
9888
  );
9964
9889
  }
9965
9890
  );
9966
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9967
- const productVariantsQueryKeys = {
9968
- list: (query2) => [
9969
- PRODUCT_VARIANTS_QUERY_KEY,
9970
- query2 ? query2 : void 0
9971
- ]
9972
- };
9973
- const useProductVariants = (query2, options) => {
9974
- const { data, ...rest } = reactQuery.useQuery({
9975
- queryKey: productVariantsQueryKeys.list(query2),
9976
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9977
- ...options
9978
- });
9979
- return { ...data, ...rest };
9980
- };
9981
- const useCancelOrderEdit = ({ preview }) => {
9982
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9983
- const onCancel = React.useCallback(async () => {
9984
- if (!preview) {
9985
- return true;
9986
- }
9987
- let res = false;
9988
- await cancelOrderEdit(void 0, {
9989
- onError: (e) => {
9990
- ui.toast.error(e.message);
9991
- },
9992
- onSuccess: () => {
9993
- res = true;
9994
- }
9995
- });
9996
- return res;
9997
- }, [preview, cancelOrderEdit]);
9998
- return { onCancel };
9999
- };
10000
- let IS_REQUEST_RUNNING = false;
10001
- const useInitiateOrderEdit = ({
10002
- preview
10003
- }) => {
10004
- const navigate = reactRouterDom.useNavigate();
10005
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10006
- React.useEffect(() => {
10007
- async function run() {
10008
- if (IS_REQUEST_RUNNING || !preview) {
10009
- return;
10010
- }
10011
- if (preview.order_change) {
10012
- return;
10013
- }
10014
- IS_REQUEST_RUNNING = true;
10015
- await mutateAsync(void 0, {
10016
- onError: (e) => {
10017
- ui.toast.error(e.message);
10018
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10019
- return;
10020
- }
10021
- });
10022
- IS_REQUEST_RUNNING = false;
10023
- }
10024
- run();
10025
- }, [preview, navigate, mutateAsync]);
10026
- };
10027
- function convertNumber(value) {
10028
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10029
- }
10030
- const STACKED_MODAL_ID = "items_stacked_modal";
10031
- const Items = () => {
9891
+ InlineTip.displayName = "InlineTip";
9892
+ const MetadataFieldSchema = objectType({
9893
+ key: stringType(),
9894
+ disabled: booleanType().optional(),
9895
+ value: anyType()
9896
+ });
9897
+ const MetadataSchema = objectType({
9898
+ metadata: arrayType(MetadataFieldSchema)
9899
+ });
9900
+ const Metadata = () => {
10032
9901
  const { id } = reactRouterDom.useParams();
10033
- const {
10034
- order: preview,
10035
- isPending: isPreviewPending,
10036
- isError: isPreviewError,
10037
- error: previewError
10038
- } = useOrderPreview(id, void 0, {
10039
- placeholderData: reactQuery.keepPreviousData
9902
+ const { order, isPending, isError, error } = useOrder(id, {
9903
+ fields: "metadata"
10040
9904
  });
10041
- useInitiateOrderEdit({ preview });
10042
- const { draft_order, isPending, isError, error } = useDraftOrder(
10043
- id,
10044
- {
10045
- fields: "currency_code"
10046
- },
10047
- {
10048
- enabled: !!id
10049
- }
10050
- );
10051
- const { onCancel } = useCancelOrderEdit({ preview });
10052
9905
  if (isError) {
10053
9906
  throw error;
10054
9907
  }
10055
- if (isPreviewError) {
10056
- throw previewError;
10057
- }
10058
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10059
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10060
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10061
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10062
- ] }) });
9908
+ const isReady = !isPending && !!order;
9909
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9910
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9912
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9913
+ ] }),
9914
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9915
+ ] });
10063
9916
  };
10064
- const ItemsForm = ({ preview, currencyCode }) => {
10065
- var _a;
10066
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10067
- const [modalContent, setModalContent] = React.useState(
10068
- null
10069
- );
9917
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9918
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9919
+ const MetadataForm = ({ orderId, metadata }) => {
10070
9920
  const { handleSuccess } = useRouteModal();
10071
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10072
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10073
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10074
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10075
- const matches = React.useMemo(() => {
10076
- return matchSorter.matchSorter(preview.items, query2, {
10077
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10078
- });
10079
- }, [preview.items, query2]);
10080
- const onSubmit = async () => {
10081
- setIsSubmitting(true);
10082
- let requestSucceeded = false;
10083
- await requestOrderEdit(void 0, {
10084
- onError: (e) => {
10085
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10086
- },
10087
- onSuccess: () => {
10088
- requestSucceeded = true;
10089
- }
10090
- });
10091
- if (!requestSucceeded) {
10092
- setIsSubmitting(false);
10093
- return;
10094
- }
10095
- await confirmOrderEdit(void 0, {
10096
- onError: (e) => {
10097
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10098
- },
10099
- onSuccess: () => {
10100
- handleSuccess();
10101
- },
10102
- onSettled: () => {
10103
- setIsSubmitting(false);
10104
- }
10105
- });
10106
- };
10107
- const onKeyDown = React.useCallback(
10108
- (e) => {
10109
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10110
- if (modalContent || isSubmitting) {
10111
- return;
10112
- }
10113
- onSubmit();
10114
- }
10115
- },
10116
- [modalContent, isSubmitting, onSubmit]
10117
- );
10118
- React.useEffect(() => {
10119
- document.addEventListener("keydown", onKeyDown);
10120
- return () => {
10121
- document.removeEventListener("keydown", onKeyDown);
10122
- };
10123
- }, [onKeyDown]);
10124
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10125
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10126
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10127
- StackedFocusModal,
10128
- {
10129
- id: STACKED_MODAL_ID,
10130
- onOpenChangeCallback: (open) => {
10131
- if (!open) {
10132
- setModalContent(null);
10133
- }
10134
- },
10135
- children: [
10136
- /* @__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: [
10137
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10138
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10139
- /* @__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" }) })
10140
- ] }),
10141
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10142
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10143
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10144
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10145
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10146
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10147
- ] }),
10148
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10149
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10150
- ui.Input,
10151
- {
10152
- type: "search",
10153
- placeholder: "Search items",
10154
- value: searchValue,
10155
- onChange: (e) => onSearchValueChange(e.target.value)
10156
- }
10157
- ) }),
10158
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10159
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10160
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10161
- /* @__PURE__ */ jsxRuntime.jsx(
10162
- StackedModalTrigger$1,
10163
- {
10164
- type: "add-items",
10165
- setModalContent
10166
- }
10167
- ),
10168
- /* @__PURE__ */ jsxRuntime.jsx(
10169
- StackedModalTrigger$1,
10170
- {
10171
- type: "add-custom-item",
10172
- setModalContent
10173
- }
10174
- )
10175
- ] })
10176
- ] })
10177
- ] })
10178
- ] }),
10179
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10180
- /* @__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: [
10181
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10182
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10183
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10184
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10185
- ] }) }),
10186
- /* @__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: [
10187
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10188
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10189
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10190
- Item,
10191
- {
10192
- item,
10193
- preview,
10194
- currencyCode
10195
- },
10196
- item.id
10197
- )) : /* @__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: [
10198
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10199
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10200
- 'No items found for "',
10201
- query2,
10202
- '".'
10203
- ] })
10204
- ] }) })
10205
- ] })
10206
- ] }),
10207
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10208
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10209
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10210
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10211
- ui.Text,
10212
- {
10213
- size: "small",
10214
- leading: "compact",
10215
- className: "text-ui-fg-subtle",
10216
- children: [
10217
- itemCount,
10218
- " ",
10219
- itemCount === 1 ? "item" : "items"
10220
- ]
10221
- }
10222
- ) }),
10223
- /* @__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) }) })
10224
- ] })
10225
- ] }) }),
10226
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10227
- CustomItemForm,
10228
- {
10229
- orderId: preview.id,
10230
- currencyCode
10231
- }
10232
- ) : null)
10233
- ]
10234
- }
10235
- ) }),
10236
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10237
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10238
- /* @__PURE__ */ jsxRuntime.jsx(
10239
- ui.Button,
10240
- {
10241
- size: "small",
10242
- type: "button",
10243
- onClick: onSubmit,
10244
- isLoading: isSubmitting,
10245
- children: "Save"
10246
- }
10247
- )
10248
- ] }) })
10249
- ] });
10250
- };
10251
- const Item = ({ item, preview, currencyCode }) => {
10252
- if (item.variant_id) {
10253
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10254
- }
10255
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10256
- };
10257
- const VariantItem = ({ item, preview, currencyCode }) => {
10258
- const [editing, setEditing] = React.useState(false);
9921
+ const hasUneditableRows = getHasUneditableRows(metadata);
9922
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10259
9923
  const form = reactHookForm.useForm({
10260
9924
  defaultValues: {
10261
- quantity: item.quantity,
10262
- unit_price: item.unit_price
9925
+ metadata: getDefaultValues(metadata)
10263
9926
  },
10264
- resolver: zod.zodResolver(variantItemSchema)
9927
+ resolver: zod.zodResolver(MetadataSchema)
10265
9928
  });
10266
- const actionId = React.useMemo(() => {
10267
- var _a, _b;
10268
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10269
- }, [item]);
10270
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10271
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10272
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10273
- const onSubmit = form.handleSubmit(async (data) => {
10274
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10275
- setEditing(false);
10276
- return;
10277
- }
10278
- if (!actionId) {
10279
- await updateOriginalItem(
10280
- {
10281
- item_id: item.id,
10282
- quantity: data.quantity,
10283
- unit_price: convertNumber(data.unit_price)
10284
- },
10285
- {
10286
- onSuccess: () => {
10287
- setEditing(false);
10288
- },
10289
- onError: (e) => {
10290
- ui.toast.error(e.message);
10291
- }
10292
- }
10293
- );
10294
- return;
10295
- }
10296
- await updateActionItem(
9929
+ const handleSubmit = form.handleSubmit(async (data) => {
9930
+ const parsedData = parseValues(data);
9931
+ await mutateAsync(
10297
9932
  {
10298
- action_id: actionId,
10299
- quantity: data.quantity,
10300
- unit_price: convertNumber(data.unit_price)
9933
+ metadata: parsedData
10301
9934
  },
10302
9935
  {
10303
9936
  onSuccess: () => {
10304
- setEditing(false);
9937
+ ui.toast.success("Metadata updated");
9938
+ handleSuccess();
10305
9939
  },
10306
- onError: (e) => {
10307
- ui.toast.error(e.message);
9940
+ onError: (error) => {
9941
+ ui.toast.error(error.message);
10308
9942
  }
10309
9943
  }
10310
9944
  );
10311
9945
  });
10312
- 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: [
10313
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10314
- /* @__PURE__ */ jsxRuntime.jsx(
10315
- Thumbnail,
10316
- {
10317
- thumbnail: item.thumbnail,
10318
- alt: item.product_title ?? void 0
10319
- }
10320
- ),
10321
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10322
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10324
- /* @__PURE__ */ jsxRuntime.jsxs(
10325
- ui.Text,
10326
- {
10327
- size: "small",
10328
- leading: "compact",
10329
- className: "text-ui-fg-subtle",
10330
- children: [
10331
- "(",
10332
- item.variant_title,
10333
- ")"
10334
- ]
10335
- }
10336
- )
10337
- ] }),
10338
- /* @__PURE__ */ jsxRuntime.jsx(
10339
- ui.Text,
10340
- {
10341
- size: "small",
10342
- leading: "compact",
10343
- className: "text-ui-fg-subtle",
10344
- children: item.variant_sku
10345
- }
10346
- )
10347
- ] })
10348
- ] }),
10349
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10350
- Form$2.Field,
9946
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9947
+ control: form.control,
9948
+ name: "metadata"
9949
+ });
9950
+ function deleteRow(index) {
9951
+ remove(index);
9952
+ if (fields.length === 1) {
9953
+ insert(0, {
9954
+ key: "",
9955
+ value: "",
9956
+ disabled: false
9957
+ });
9958
+ }
9959
+ }
9960
+ function insertRow(index, position) {
9961
+ insert(index + (position === "above" ? 0 : 1), {
9962
+ key: "",
9963
+ value: "",
9964
+ disabled: false
9965
+ });
9966
+ }
9967
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9968
+ KeyboundForm,
9969
+ {
9970
+ onSubmit: handleSubmit,
9971
+ className: "flex flex-1 flex-col overflow-hidden",
9972
+ children: [
9973
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9974
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9975
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9976
+ /* @__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" }) }),
9977
+ /* @__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" }) })
9978
+ ] }),
9979
+ fields.map((field, index) => {
9980
+ const isDisabled = field.disabled || false;
9981
+ let placeholder = "-";
9982
+ if (typeof field.value === "object") {
9983
+ placeholder = "{ ... }";
9984
+ }
9985
+ if (Array.isArray(field.value)) {
9986
+ placeholder = "[ ... ]";
9987
+ }
9988
+ return /* @__PURE__ */ jsxRuntime.jsx(
9989
+ ConditionalTooltip,
9990
+ {
9991
+ showTooltip: isDisabled,
9992
+ content: "This row is disabled because it contains non-primitive data.",
9993
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9994
+ /* @__PURE__ */ jsxRuntime.jsxs(
9995
+ "div",
9996
+ {
9997
+ className: ui.clx("grid grid-cols-2 divide-x", {
9998
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9999
+ }),
10000
+ children: [
10001
+ /* @__PURE__ */ jsxRuntime.jsx(
10002
+ Form$2.Field,
10003
+ {
10004
+ control: form.control,
10005
+ name: `metadata.${index}.key`,
10006
+ render: ({ field: field2 }) => {
10007
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10008
+ GridInput,
10009
+ {
10010
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10011
+ ...field2,
10012
+ disabled: isDisabled,
10013
+ placeholder: "Key"
10014
+ }
10015
+ ) }) });
10016
+ }
10017
+ }
10018
+ ),
10019
+ /* @__PURE__ */ jsxRuntime.jsx(
10020
+ Form$2.Field,
10021
+ {
10022
+ control: form.control,
10023
+ name: `metadata.${index}.value`,
10024
+ render: ({ field: { value, ...field2 } }) => {
10025
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10026
+ GridInput,
10027
+ {
10028
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10029
+ ...field2,
10030
+ value: isDisabled ? placeholder : value,
10031
+ disabled: isDisabled,
10032
+ placeholder: "Value"
10033
+ }
10034
+ ) }) });
10035
+ }
10036
+ }
10037
+ )
10038
+ ]
10039
+ }
10040
+ ),
10041
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10042
+ /* @__PURE__ */ jsxRuntime.jsx(
10043
+ ui.DropdownMenu.Trigger,
10044
+ {
10045
+ className: ui.clx(
10046
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10047
+ {
10048
+ hidden: isDisabled
10049
+ }
10050
+ ),
10051
+ disabled: isDisabled,
10052
+ asChild: true,
10053
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10054
+ }
10055
+ ),
10056
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10057
+ /* @__PURE__ */ jsxRuntime.jsxs(
10058
+ ui.DropdownMenu.Item,
10059
+ {
10060
+ className: "gap-x-2",
10061
+ onClick: () => insertRow(index, "above"),
10062
+ children: [
10063
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10064
+ "Insert row above"
10065
+ ]
10066
+ }
10067
+ ),
10068
+ /* @__PURE__ */ jsxRuntime.jsxs(
10069
+ ui.DropdownMenu.Item,
10070
+ {
10071
+ className: "gap-x-2",
10072
+ onClick: () => insertRow(index, "below"),
10073
+ children: [
10074
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10075
+ "Insert row below"
10076
+ ]
10077
+ }
10078
+ ),
10079
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10080
+ /* @__PURE__ */ jsxRuntime.jsxs(
10081
+ ui.DropdownMenu.Item,
10082
+ {
10083
+ className: "gap-x-2",
10084
+ onClick: () => deleteRow(index),
10085
+ children: [
10086
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10087
+ "Delete row"
10088
+ ]
10089
+ }
10090
+ )
10091
+ ] })
10092
+ ] })
10093
+ ] })
10094
+ },
10095
+ field.id
10096
+ );
10097
+ })
10098
+ ] }),
10099
+ 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." })
10100
+ ] }),
10101
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10102
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10103
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10104
+ ] }) })
10105
+ ]
10106
+ }
10107
+ ) });
10108
+ };
10109
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10110
+ return /* @__PURE__ */ jsxRuntime.jsx(
10111
+ "input",
10112
+ {
10113
+ ref,
10114
+ ...props,
10115
+ autoComplete: "off",
10116
+ className: ui.clx(
10117
+ "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",
10118
+ className
10119
+ )
10120
+ }
10121
+ );
10122
+ });
10123
+ GridInput.displayName = "MetadataForm.GridInput";
10124
+ const PlaceholderInner = () => {
10125
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10126
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10127
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10128
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10129
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10130
+ ] }) })
10131
+ ] });
10132
+ };
10133
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10134
+ function getDefaultValues(metadata) {
10135
+ if (!metadata || !Object.keys(metadata).length) {
10136
+ return [
10351
10137
  {
10352
- control: form.control,
10353
- name: "quantity",
10354
- render: ({ field }) => {
10355
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10138
+ key: "",
10139
+ value: "",
10140
+ disabled: false
10141
+ }
10142
+ ];
10143
+ }
10144
+ return Object.entries(metadata).map(([key, value]) => {
10145
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10146
+ return {
10147
+ key,
10148
+ value,
10149
+ disabled: true
10150
+ };
10151
+ }
10152
+ let stringValue = value;
10153
+ if (typeof value !== "string") {
10154
+ stringValue = JSON.stringify(value);
10155
+ }
10156
+ return {
10157
+ key,
10158
+ value: stringValue,
10159
+ original_key: key
10160
+ };
10161
+ });
10162
+ }
10163
+ function parseValues(values) {
10164
+ const metadata = values.metadata;
10165
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10166
+ if (isEmpty) {
10167
+ return null;
10168
+ }
10169
+ const update = {};
10170
+ metadata.forEach((field) => {
10171
+ let key = field.key;
10172
+ let value = field.value;
10173
+ const disabled = field.disabled;
10174
+ if (!key || !value) {
10175
+ return;
10176
+ }
10177
+ if (disabled) {
10178
+ update[key] = value;
10179
+ return;
10180
+ }
10181
+ key = key.trim();
10182
+ value = value.trim();
10183
+ if (value === "true") {
10184
+ update[key] = true;
10185
+ } else if (value === "false") {
10186
+ update[key] = false;
10187
+ } else {
10188
+ const parsedNumber = parseFloat(value);
10189
+ if (!isNaN(parsedNumber)) {
10190
+ update[key] = parsedNumber;
10191
+ } else {
10192
+ update[key] = value;
10193
+ }
10194
+ }
10195
+ });
10196
+ return update;
10197
+ }
10198
+ function getHasUneditableRows(metadata) {
10199
+ if (!metadata) {
10200
+ return false;
10201
+ }
10202
+ return Object.values(metadata).some(
10203
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10204
+ );
10205
+ }
10206
+ const NumberInput = React.forwardRef(
10207
+ ({
10208
+ value,
10209
+ onChange,
10210
+ size = "base",
10211
+ min = 0,
10212
+ max = 100,
10213
+ step = 1,
10214
+ className,
10215
+ disabled,
10216
+ ...props
10217
+ }, ref) => {
10218
+ const handleChange = (event) => {
10219
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10220
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10221
+ onChange(newValue);
10222
+ }
10223
+ };
10224
+ const handleIncrement = () => {
10225
+ const newValue = value + step;
10226
+ if (max === void 0 || newValue <= max) {
10227
+ onChange(newValue);
10228
+ }
10229
+ };
10230
+ const handleDecrement = () => {
10231
+ const newValue = value - step;
10232
+ if (min === void 0 || newValue >= min) {
10233
+ onChange(newValue);
10234
+ }
10235
+ };
10236
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10237
+ "div",
10238
+ {
10239
+ className: ui.clx(
10240
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10241
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10242
+ {
10243
+ "h-7": size === "small",
10244
+ "h-8": size === "base"
10245
+ },
10246
+ className
10247
+ ),
10248
+ children: [
10249
+ /* @__PURE__ */ jsxRuntime.jsx(
10250
+ "input",
10251
+ {
10252
+ ref,
10253
+ type: "number",
10254
+ value,
10255
+ onChange: handleChange,
10256
+ min,
10257
+ max,
10258
+ step,
10259
+ className: ui.clx(
10260
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10261
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10262
+ "placeholder:text-ui-fg-muted"
10263
+ ),
10264
+ ...props
10265
+ }
10266
+ ),
10267
+ /* @__PURE__ */ jsxRuntime.jsxs(
10268
+ "button",
10269
+ {
10270
+ className: ui.clx(
10271
+ "flex items-center justify-center outline-none transition-fg",
10272
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10273
+ "focus:bg-ui-bg-field-component-hover",
10274
+ "hover:bg-ui-bg-field-component-hover",
10275
+ {
10276
+ "size-7": size === "small",
10277
+ "size-8": size === "base"
10278
+ }
10279
+ ),
10280
+ type: "button",
10281
+ onClick: handleDecrement,
10282
+ disabled: min !== void 0 && value <= min || disabled,
10283
+ children: [
10284
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10285
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10286
+ ]
10287
+ }
10288
+ ),
10289
+ /* @__PURE__ */ jsxRuntime.jsxs(
10290
+ "button",
10291
+ {
10292
+ className: ui.clx(
10293
+ "flex items-center justify-center outline-none transition-fg",
10294
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10295
+ "focus:bg-ui-bg-field-hover",
10296
+ "hover:bg-ui-bg-field-hover",
10297
+ {
10298
+ "size-7": size === "small",
10299
+ "size-8": size === "base"
10300
+ }
10301
+ ),
10302
+ type: "button",
10303
+ onClick: handleIncrement,
10304
+ disabled: max !== void 0 && value >= max || disabled,
10305
+ children: [
10306
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10307
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10308
+ ]
10309
+ }
10310
+ )
10311
+ ]
10312
+ }
10313
+ );
10314
+ }
10315
+ );
10316
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10317
+ const productVariantsQueryKeys = {
10318
+ list: (query2) => [
10319
+ PRODUCT_VARIANTS_QUERY_KEY,
10320
+ query2 ? query2 : void 0
10321
+ ]
10322
+ };
10323
+ const useProductVariants = (query2, options) => {
10324
+ const { data, ...rest } = reactQuery.useQuery({
10325
+ queryKey: productVariantsQueryKeys.list(query2),
10326
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10327
+ ...options
10328
+ });
10329
+ return { ...data, ...rest };
10330
+ };
10331
+ const useCancelOrderEdit = ({ preview }) => {
10332
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10333
+ const onCancel = React.useCallback(async () => {
10334
+ if (!preview) {
10335
+ return true;
10336
+ }
10337
+ let res = false;
10338
+ await cancelOrderEdit(void 0, {
10339
+ onError: (e) => {
10340
+ ui.toast.error(e.message);
10341
+ },
10342
+ onSuccess: () => {
10343
+ res = true;
10344
+ }
10345
+ });
10346
+ return res;
10347
+ }, [preview, cancelOrderEdit]);
10348
+ return { onCancel };
10349
+ };
10350
+ let IS_REQUEST_RUNNING = false;
10351
+ const useInitiateOrderEdit = ({
10352
+ preview
10353
+ }) => {
10354
+ const navigate = reactRouterDom.useNavigate();
10355
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10356
+ React.useEffect(() => {
10357
+ async function run() {
10358
+ if (IS_REQUEST_RUNNING || !preview) {
10359
+ return;
10360
+ }
10361
+ if (preview.order_change) {
10362
+ return;
10363
+ }
10364
+ IS_REQUEST_RUNNING = true;
10365
+ await mutateAsync(void 0, {
10366
+ onError: (e) => {
10367
+ ui.toast.error(e.message);
10368
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10369
+ return;
10356
10370
  }
10371
+ });
10372
+ IS_REQUEST_RUNNING = false;
10373
+ }
10374
+ run();
10375
+ }, [preview, navigate, mutateAsync]);
10376
+ };
10377
+ function convertNumber(value) {
10378
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10379
+ }
10380
+ const STACKED_MODAL_ID = "items_stacked_modal";
10381
+ const Items = () => {
10382
+ const { id } = reactRouterDom.useParams();
10383
+ const {
10384
+ order: preview,
10385
+ isPending: isPreviewPending,
10386
+ isError: isPreviewError,
10387
+ error: previewError
10388
+ } = useOrderPreview(id, void 0, {
10389
+ placeholderData: reactQuery.keepPreviousData
10390
+ });
10391
+ useInitiateOrderEdit({ preview });
10392
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10393
+ id,
10394
+ {
10395
+ fields: "currency_code"
10396
+ },
10397
+ {
10398
+ enabled: !!id
10399
+ }
10400
+ );
10401
+ const { onCancel } = useCancelOrderEdit({ preview });
10402
+ if (isError) {
10403
+ throw error;
10404
+ }
10405
+ if (isPreviewError) {
10406
+ throw previewError;
10407
+ }
10408
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10409
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10410
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10411
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10412
+ ] }) });
10413
+ };
10414
+ const ItemsForm = ({ preview, currencyCode }) => {
10415
+ var _a;
10416
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10417
+ const [modalContent, setModalContent] = React.useState(
10418
+ null
10419
+ );
10420
+ const { handleSuccess } = useRouteModal();
10421
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10422
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10423
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10424
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10425
+ const matches = React.useMemo(() => {
10426
+ return matchSorter.matchSorter(preview.items, query2, {
10427
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10428
+ });
10429
+ }, [preview.items, query2]);
10430
+ const onSubmit = async () => {
10431
+ setIsSubmitting(true);
10432
+ let requestSucceeded = false;
10433
+ await requestOrderEdit(void 0, {
10434
+ onError: (e) => {
10435
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10436
+ },
10437
+ onSuccess: () => {
10438
+ requestSucceeded = true;
10357
10439
  }
10358
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10359
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10360
- Form$2.Field,
10361
- {
10362
- control: form.control,
10363
- name: "unit_price",
10364
- render: ({ field: { onChange, ...field } }) => {
10365
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10366
- ui.CurrencyInput,
10367
- {
10368
- ...field,
10369
- symbol: getNativeSymbol(currencyCode),
10370
- code: currencyCode,
10371
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10372
- }
10373
- ) }) });
10440
+ });
10441
+ if (!requestSucceeded) {
10442
+ setIsSubmitting(false);
10443
+ return;
10444
+ }
10445
+ await confirmOrderEdit(void 0, {
10446
+ onError: (e) => {
10447
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10448
+ },
10449
+ onSuccess: () => {
10450
+ handleSuccess();
10451
+ },
10452
+ onSettled: () => {
10453
+ setIsSubmitting(false);
10454
+ }
10455
+ });
10456
+ };
10457
+ const onKeyDown = React.useCallback(
10458
+ (e) => {
10459
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10460
+ if (modalContent || isSubmitting) {
10461
+ return;
10374
10462
  }
10463
+ onSubmit();
10375
10464
  }
10376
- ) }) : /* @__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) }) }),
10377
- /* @__PURE__ */ jsxRuntime.jsx(
10378
- ui.IconButton,
10465
+ },
10466
+ [modalContent, isSubmitting, onSubmit]
10467
+ );
10468
+ React.useEffect(() => {
10469
+ document.addEventListener("keydown", onKeyDown);
10470
+ return () => {
10471
+ document.removeEventListener("keydown", onKeyDown);
10472
+ };
10473
+ }, [onKeyDown]);
10474
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10475
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10476
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10477
+ StackedFocusModal,
10379
10478
  {
10380
- type: "button",
10381
- size: "small",
10382
- onClick: editing ? onSubmit : () => {
10383
- setEditing(true);
10479
+ id: STACKED_MODAL_ID,
10480
+ onOpenChangeCallback: (open) => {
10481
+ if (!open) {
10482
+ setModalContent(null);
10483
+ }
10384
10484
  },
10385
- disabled: isPending,
10386
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10485
+ children: [
10486
+ /* @__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: [
10487
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10488
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10489
+ /* @__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" }) })
10490
+ ] }),
10491
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10492
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10493
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10494
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10495
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10496
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10497
+ ] }),
10498
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10499
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10500
+ ui.Input,
10501
+ {
10502
+ type: "search",
10503
+ placeholder: "Search items",
10504
+ value: searchValue,
10505
+ onChange: (e) => onSearchValueChange(e.target.value)
10506
+ }
10507
+ ) }),
10508
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10509
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10510
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10511
+ /* @__PURE__ */ jsxRuntime.jsx(
10512
+ StackedModalTrigger$1,
10513
+ {
10514
+ type: "add-items",
10515
+ setModalContent
10516
+ }
10517
+ ),
10518
+ /* @__PURE__ */ jsxRuntime.jsx(
10519
+ StackedModalTrigger$1,
10520
+ {
10521
+ type: "add-custom-item",
10522
+ setModalContent
10523
+ }
10524
+ )
10525
+ ] })
10526
+ ] })
10527
+ ] })
10528
+ ] }),
10529
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10530
+ /* @__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: [
10531
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10532
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10533
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10534
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10535
+ ] }) }),
10536
+ /* @__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: [
10537
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10538
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10539
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10540
+ Item,
10541
+ {
10542
+ item,
10543
+ preview,
10544
+ currencyCode
10545
+ },
10546
+ item.id
10547
+ )) : /* @__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: [
10548
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10549
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10550
+ 'No items found for "',
10551
+ query2,
10552
+ '".'
10553
+ ] })
10554
+ ] }) })
10555
+ ] })
10556
+ ] }),
10557
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10558
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10559
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10560
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10561
+ ui.Text,
10562
+ {
10563
+ size: "small",
10564
+ leading: "compact",
10565
+ className: "text-ui-fg-subtle",
10566
+ children: [
10567
+ itemCount,
10568
+ " ",
10569
+ itemCount === 1 ? "item" : "items"
10570
+ ]
10571
+ }
10572
+ ) }),
10573
+ /* @__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) }) })
10574
+ ] })
10575
+ ] }) }),
10576
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10577
+ CustomItemForm,
10578
+ {
10579
+ orderId: preview.id,
10580
+ currencyCode
10581
+ }
10582
+ ) : null)
10583
+ ]
10387
10584
  }
10388
- )
10389
- ] }) }) });
10585
+ ) }),
10586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10588
+ /* @__PURE__ */ jsxRuntime.jsx(
10589
+ ui.Button,
10590
+ {
10591
+ size: "small",
10592
+ type: "button",
10593
+ onClick: onSubmit,
10594
+ isLoading: isSubmitting,
10595
+ children: "Save"
10596
+ }
10597
+ )
10598
+ ] }) })
10599
+ ] });
10390
10600
  };
10391
- const variantItemSchema = objectType({
10392
- quantity: numberType(),
10393
- unit_price: unionType([numberType(), stringType()])
10394
- });
10395
- const CustomItem = ({ item, preview, currencyCode }) => {
10601
+ const Item = ({ item, preview, currencyCode }) => {
10602
+ if (item.variant_id) {
10603
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10604
+ }
10605
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10606
+ };
10607
+ const VariantItem = ({ item, preview, currencyCode }) => {
10396
10608
  const [editing, setEditing] = React.useState(false);
10397
- const { quantity, unit_price, title } = item;
10398
10609
  const form = reactHookForm.useForm({
10399
10610
  defaultValues: {
10400
- title,
10401
- quantity,
10402
- unit_price
10403
- },
10404
- resolver: zod.zodResolver(customItemSchema)
10405
- });
10406
- React.useEffect(() => {
10407
- form.reset({
10408
- title,
10409
- quantity,
10410
- unit_price
10411
- });
10412
- }, [form, title, quantity, unit_price]);
10611
+ quantity: item.quantity,
10612
+ unit_price: item.unit_price
10613
+ },
10614
+ resolver: zod.zodResolver(variantItemSchema)
10615
+ });
10413
10616
  const actionId = React.useMemo(() => {
10414
10617
  var _a, _b;
10415
10618
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10416
10619
  }, [item]);
10417
10620
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10418
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10419
10621
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10420
10622
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10421
10623
  const onSubmit = form.handleSubmit(async (data) => {
10422
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10624
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10423
10625
  setEditing(false);
10424
10626
  return;
10425
10627
  }
@@ -10441,17 +10643,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10441
10643
  );
10442
10644
  return;
10443
10645
  }
10444
- if (data.quantity === 0) {
10445
- await removeActionItem(actionId, {
10446
- onSuccess: () => {
10447
- setEditing(false);
10448
- },
10449
- onError: (e) => {
10450
- ui.toast.error(e.message);
10451
- }
10452
- });
10453
- return;
10454
- }
10455
10646
  await updateActionItem(
10456
10647
  {
10457
10648
  action_id: actionId,
@@ -10469,26 +10660,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10469
10660
  );
10470
10661
  });
10471
10662
  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: [
10472
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10663
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10473
10664
  /* @__PURE__ */ jsxRuntime.jsx(
10474
10665
  Thumbnail,
10475
10666
  {
10476
10667
  thumbnail: item.thumbnail,
10477
- alt: item.title ?? void 0
10668
+ alt: item.product_title ?? void 0
10478
10669
  }
10479
10670
  ),
10480
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10481
- Form$2.Field,
10482
- {
10483
- control: form.control,
10484
- name: "title",
10485
- render: ({ field }) => {
10486
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10671
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10672
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10673
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10674
+ /* @__PURE__ */ jsxRuntime.jsxs(
10675
+ ui.Text,
10676
+ {
10677
+ size: "small",
10678
+ leading: "compact",
10679
+ className: "text-ui-fg-subtle",
10680
+ children: [
10681
+ "(",
10682
+ item.variant_title,
10683
+ ")"
10684
+ ]
10685
+ }
10686
+ )
10687
+ ] }),
10688
+ /* @__PURE__ */ jsxRuntime.jsx(
10689
+ ui.Text,
10690
+ {
10691
+ size: "small",
10692
+ leading: "compact",
10693
+ className: "text-ui-fg-subtle",
10694
+ children: item.variant_sku
10487
10695
  }
10488
- }
10489
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10696
+ )
10697
+ ] })
10490
10698
  ] }),
10491
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10699
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10492
10700
  Form$2.Field,
10493
10701
  {
10494
10702
  control: form.control,
@@ -10497,8 +10705,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10497
10705
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10498
10706
  }
10499
10707
  }
10500
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10501
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10708
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10709
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10502
10710
  Form$2.Field,
10503
10711
  {
10504
10712
  control: form.control,
@@ -10514,231 +10722,95 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10514
10722
  }
10515
10723
  ) }) });
10516
10724
  }
10517
- }
10518
- ) : /* @__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) }) }),
10519
- /* @__PURE__ */ jsxRuntime.jsx(
10520
- ui.IconButton,
10521
- {
10522
- type: "button",
10523
- size: "small",
10524
- onClick: editing ? onSubmit : () => {
10525
- setEditing(true);
10526
- },
10527
- disabled: isPending,
10528
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10529
- }
10530
- )
10531
- ] }) }) });
10532
- };
10533
- const StackedModalTrigger$1 = ({
10534
- type,
10535
- setModalContent
10536
- }) => {
10537
- const { setIsOpen } = useStackedModal();
10538
- const onClick = React.useCallback(() => {
10539
- setModalContent(type);
10540
- setIsOpen(STACKED_MODAL_ID, true);
10541
- }, [setModalContent, setIsOpen, type]);
10542
- 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" }) });
10543
- };
10544
- const VARIANT_PREFIX = "items";
10545
- const LIMIT = 50;
10546
- const ExistingItemsForm = ({ orderId, items }) => {
10547
- const { setIsOpen } = useStackedModal();
10548
- const [rowSelection, setRowSelection] = React.useState(
10549
- items.reduce((acc, item) => {
10550
- acc[item.variant_id] = true;
10551
- return acc;
10552
- }, {})
10553
- );
10554
- React.useEffect(() => {
10555
- setRowSelection(
10556
- items.reduce((acc, item) => {
10557
- if (item.variant_id) {
10558
- acc[item.variant_id] = true;
10559
- }
10560
- return acc;
10561
- }, {})
10562
- );
10563
- }, [items]);
10564
- const { q, order, offset } = useQueryParams(
10565
- ["q", "order", "offset"],
10566
- VARIANT_PREFIX
10567
- );
10568
- const { variants, count, isPending, isError, error } = useProductVariants(
10569
- {
10570
- q,
10571
- order,
10572
- offset: offset ? parseInt(offset) : void 0,
10573
- limit: LIMIT
10574
- },
10575
- {
10576
- placeholderData: reactQuery.keepPreviousData
10577
- }
10578
- );
10579
- const columns = useColumns();
10580
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10581
- const onSubmit = async () => {
10582
- const ids = Object.keys(rowSelection).filter(
10583
- (id) => !items.find((i) => i.variant_id === id)
10584
- );
10585
- await mutateAsync(
10586
- {
10587
- items: ids.map((id) => ({
10588
- variant_id: id,
10589
- quantity: 1
10590
- }))
10591
- },
10592
- {
10593
- onSuccess: () => {
10594
- setRowSelection({});
10595
- setIsOpen(STACKED_MODAL_ID, false);
10596
- },
10597
- onError: (e) => {
10598
- ui.toast.error(e.message);
10599
- }
10600
- }
10601
- );
10602
- };
10603
- if (isError) {
10604
- throw error;
10605
- }
10606
- return /* @__PURE__ */ jsxRuntime.jsxs(
10607
- StackedFocusModal.Content,
10608
- {
10609
- onOpenAutoFocus: (e) => {
10610
- e.preventDefault();
10611
- const searchInput = document.querySelector(
10612
- "[data-modal-id='modal-search-input']"
10613
- );
10614
- if (searchInput) {
10615
- searchInput.focus();
10616
- }
10617
- },
10618
- children: [
10619
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10620
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10621
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10622
- ] }),
10623
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10624
- DataTable,
10625
- {
10626
- data: variants,
10627
- columns,
10628
- isLoading: isPending,
10629
- getRowId: (row) => row.id,
10630
- rowCount: count,
10631
- prefix: VARIANT_PREFIX,
10632
- layout: "fill",
10633
- rowSelection: {
10634
- state: rowSelection,
10635
- onRowSelectionChange: setRowSelection,
10636
- enableRowSelection: (row) => {
10637
- return !items.find((i) => i.variant_id === row.original.id);
10638
- }
10639
- },
10640
- autoFocusSearch: true
10641
- }
10642
- ) }),
10643
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10644
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10645
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10646
- ] }) })
10647
- ]
10648
- }
10649
- );
10650
- };
10651
- const columnHelper = ui.createDataTableColumnHelper();
10652
- const useColumns = () => {
10653
- return React.useMemo(() => {
10654
- return [
10655
- columnHelper.select(),
10656
- columnHelper.accessor("product.title", {
10657
- header: "Product",
10658
- cell: ({ row }) => {
10659
- var _a, _b, _c;
10660
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10661
- /* @__PURE__ */ jsxRuntime.jsx(
10662
- Thumbnail,
10663
- {
10664
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10665
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10666
- }
10667
- ),
10668
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10669
- ] });
10670
- },
10671
- enableSorting: true
10672
- }),
10673
- columnHelper.accessor("title", {
10674
- header: "Variant",
10675
- enableSorting: true
10676
- }),
10677
- columnHelper.accessor("sku", {
10678
- header: "SKU",
10679
- cell: ({ getValue }) => {
10680
- return getValue() ?? "-";
10681
- },
10682
- enableSorting: true
10683
- }),
10684
- columnHelper.accessor("updated_at", {
10685
- header: "Updated",
10686
- cell: ({ getValue }) => {
10687
- return /* @__PURE__ */ jsxRuntime.jsx(
10688
- ui.Tooltip,
10689
- {
10690
- content: getFullDate({ date: getValue(), includeTime: true }),
10691
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10692
- }
10693
- );
10694
- },
10695
- enableSorting: true,
10696
- sortAscLabel: "Oldest first",
10697
- sortDescLabel: "Newest first"
10698
- }),
10699
- columnHelper.accessor("created_at", {
10700
- header: "Created",
10701
- cell: ({ getValue }) => {
10702
- return /* @__PURE__ */ jsxRuntime.jsx(
10703
- ui.Tooltip,
10704
- {
10705
- content: getFullDate({ date: getValue(), includeTime: true }),
10706
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10707
- }
10708
- );
10725
+ }
10726
+ ) }) : /* @__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) }) }),
10727
+ /* @__PURE__ */ jsxRuntime.jsx(
10728
+ ui.IconButton,
10729
+ {
10730
+ type: "button",
10731
+ size: "small",
10732
+ onClick: editing ? onSubmit : () => {
10733
+ setEditing(true);
10709
10734
  },
10710
- enableSorting: true,
10711
- sortAscLabel: "Oldest first",
10712
- sortDescLabel: "Newest first"
10713
- })
10714
- ];
10715
- }, []);
10735
+ disabled: isPending,
10736
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10737
+ }
10738
+ )
10739
+ ] }) }) });
10716
10740
  };
10717
- const CustomItemForm = ({ orderId, currencyCode }) => {
10718
- const { setIsOpen } = useStackedModal();
10719
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10741
+ const variantItemSchema = objectType({
10742
+ quantity: numberType(),
10743
+ unit_price: unionType([numberType(), stringType()])
10744
+ });
10745
+ const CustomItem = ({ item, preview, currencyCode }) => {
10746
+ const [editing, setEditing] = React.useState(false);
10747
+ const { quantity, unit_price, title } = item;
10720
10748
  const form = reactHookForm.useForm({
10721
10749
  defaultValues: {
10722
- title: "",
10723
- quantity: 1,
10724
- unit_price: ""
10750
+ title,
10751
+ quantity,
10752
+ unit_price
10725
10753
  },
10726
10754
  resolver: zod.zodResolver(customItemSchema)
10727
10755
  });
10756
+ React.useEffect(() => {
10757
+ form.reset({
10758
+ title,
10759
+ quantity,
10760
+ unit_price
10761
+ });
10762
+ }, [form, title, quantity, unit_price]);
10763
+ const actionId = React.useMemo(() => {
10764
+ var _a, _b;
10765
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10766
+ }, [item]);
10767
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10768
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10769
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10770
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10728
10771
  const onSubmit = form.handleSubmit(async (data) => {
10729
- await addItems(
10730
- {
10731
- items: [
10732
- {
10733
- title: data.title,
10734
- quantity: data.quantity,
10735
- unit_price: convertNumber(data.unit_price)
10772
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10773
+ setEditing(false);
10774
+ return;
10775
+ }
10776
+ if (!actionId) {
10777
+ await updateOriginalItem(
10778
+ {
10779
+ item_id: item.id,
10780
+ quantity: data.quantity,
10781
+ unit_price: convertNumber(data.unit_price)
10782
+ },
10783
+ {
10784
+ onSuccess: () => {
10785
+ setEditing(false);
10786
+ },
10787
+ onError: (e) => {
10788
+ ui.toast.error(e.message);
10736
10789
  }
10737
- ]
10790
+ }
10791
+ );
10792
+ return;
10793
+ }
10794
+ if (data.quantity === 0) {
10795
+ await removeActionItem(actionId, {
10796
+ onSuccess: () => {
10797
+ setEditing(false);
10798
+ },
10799
+ onError: (e) => {
10800
+ ui.toast.error(e.message);
10801
+ }
10802
+ });
10803
+ return;
10804
+ }
10805
+ await updateActionItem(
10806
+ {
10807
+ action_id: actionId,
10808
+ quantity: data.quantity,
10809
+ unit_price: convertNumber(data.unit_price)
10738
10810
  },
10739
10811
  {
10740
10812
  onSuccess: () => {
10741
- setIsOpen(STACKED_MODAL_ID, false);
10813
+ setEditing(false);
10742
10814
  },
10743
10815
  onError: (e) => {
10744
10816
  ui.toast.error(e.message);
@@ -10746,437 +10818,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10746
10818
  }
10747
10819
  );
10748
10820
  });
10749
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10750
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10751
- /* @__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: [
10752
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10753
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10754
- /* @__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." }) })
10755
- ] }),
10756
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10821
+ 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: [
10822
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10757
10823
  /* @__PURE__ */ jsxRuntime.jsx(
10758
- Form$2.Field,
10824
+ Thumbnail,
10759
10825
  {
10760
- control: form.control,
10761
- name: "title",
10762
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10763
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10765
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10766
- ] }),
10767
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10768
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10769
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10770
- ] })
10771
- ] }) })
10826
+ thumbnail: item.thumbnail,
10827
+ alt: item.title ?? void 0
10772
10828
  }
10773
10829
  ),
10774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10775
- /* @__PURE__ */ jsxRuntime.jsx(
10830
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10776
10831
  Form$2.Field,
10777
10832
  {
10778
10833
  control: form.control,
10779
- name: "unit_price",
10780
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10781
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10782
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10783
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10784
- ] }),
10785
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10786
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10787
- ui.CurrencyInput,
10788
- {
10789
- symbol: getNativeSymbol(currencyCode),
10790
- code: currencyCode,
10791
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10792
- ...field
10793
- }
10794
- ) }),
10795
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10796
- ] })
10797
- ] }) })
10834
+ name: "title",
10835
+ render: ({ field }) => {
10836
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10837
+ }
10798
10838
  }
10799
- ),
10800
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10801
- /* @__PURE__ */ jsxRuntime.jsx(
10802
- Form$2.Field,
10803
- {
10804
- control: form.control,
10805
- name: "quantity",
10806
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10807
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10808
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10809
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10810
- ] }),
10811
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10812
- /* @__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" }) }) }),
10813
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10814
- ] })
10815
- ] }) })
10839
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10840
+ ] }),
10841
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10842
+ Form$2.Field,
10843
+ {
10844
+ control: form.control,
10845
+ name: "quantity",
10846
+ render: ({ field }) => {
10847
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10816
10848
  }
10817
- )
10818
- ] }) }) }),
10819
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10820
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10821
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10822
- ] }) })
10823
- ] }) }) });
10824
- };
10825
- const customItemSchema = objectType({
10826
- title: stringType().min(1),
10827
- quantity: numberType(),
10828
- unit_price: unionType([numberType(), stringType()])
10829
- });
10830
- const InlineTip = React.forwardRef(
10831
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10832
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10833
- return /* @__PURE__ */ jsxRuntime.jsxs(
10834
- "div",
10849
+ }
10850
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10851
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10852
+ Form$2.Field,
10835
10853
  {
10836
- ref,
10837
- className: ui.clx(
10838
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10839
- className
10840
- ),
10841
- ...props,
10842
- children: [
10843
- /* @__PURE__ */ jsxRuntime.jsx(
10844
- "div",
10854
+ control: form.control,
10855
+ name: "unit_price",
10856
+ render: ({ field: { onChange, ...field } }) => {
10857
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10858
+ ui.CurrencyInput,
10845
10859
  {
10846
- role: "presentation",
10847
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10848
- "bg-ui-tag-orange-icon": variant === "warning"
10849
- })
10850
- }
10851
- ),
10852
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10853
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10854
- labelValue,
10855
- ":"
10856
- ] }),
10857
- " ",
10858
- children
10859
- ] })
10860
- ]
10861
- }
10862
- );
10863
- }
10864
- );
10865
- InlineTip.displayName = "InlineTip";
10866
- const MetadataFieldSchema = objectType({
10867
- key: stringType(),
10868
- disabled: booleanType().optional(),
10869
- value: anyType()
10870
- });
10871
- const MetadataSchema = objectType({
10872
- metadata: arrayType(MetadataFieldSchema)
10873
- });
10874
- const Metadata = () => {
10875
- const { id } = reactRouterDom.useParams();
10876
- const { order, isPending, isError, error } = useOrder(id, {
10877
- fields: "metadata"
10878
- });
10879
- if (isError) {
10880
- throw error;
10881
- }
10882
- const isReady = !isPending && !!order;
10883
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10884
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10885
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10886
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10887
- ] }),
10888
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10889
- ] });
10860
+ ...field,
10861
+ symbol: getNativeSymbol(currencyCode),
10862
+ code: currencyCode,
10863
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10864
+ }
10865
+ ) }) });
10866
+ }
10867
+ }
10868
+ ) : /* @__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) }) }),
10869
+ /* @__PURE__ */ jsxRuntime.jsx(
10870
+ ui.IconButton,
10871
+ {
10872
+ type: "button",
10873
+ size: "small",
10874
+ onClick: editing ? onSubmit : () => {
10875
+ setEditing(true);
10876
+ },
10877
+ disabled: isPending,
10878
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10879
+ }
10880
+ )
10881
+ ] }) }) });
10890
10882
  };
10891
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10892
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10893
- const MetadataForm = ({ orderId, metadata }) => {
10894
- const { handleSuccess } = useRouteModal();
10895
- const hasUneditableRows = getHasUneditableRows(metadata);
10896
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10897
- const form = reactHookForm.useForm({
10898
- defaultValues: {
10899
- metadata: getDefaultValues(metadata)
10883
+ const StackedModalTrigger$1 = ({
10884
+ type,
10885
+ setModalContent
10886
+ }) => {
10887
+ const { setIsOpen } = useStackedModal();
10888
+ const onClick = React.useCallback(() => {
10889
+ setModalContent(type);
10890
+ setIsOpen(STACKED_MODAL_ID, true);
10891
+ }, [setModalContent, setIsOpen, type]);
10892
+ 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" }) });
10893
+ };
10894
+ const VARIANT_PREFIX = "items";
10895
+ const LIMIT = 50;
10896
+ const ExistingItemsForm = ({ orderId, items }) => {
10897
+ const { setIsOpen } = useStackedModal();
10898
+ const [rowSelection, setRowSelection] = React.useState(
10899
+ items.reduce((acc, item) => {
10900
+ acc[item.variant_id] = true;
10901
+ return acc;
10902
+ }, {})
10903
+ );
10904
+ React.useEffect(() => {
10905
+ setRowSelection(
10906
+ items.reduce((acc, item) => {
10907
+ if (item.variant_id) {
10908
+ acc[item.variant_id] = true;
10909
+ }
10910
+ return acc;
10911
+ }, {})
10912
+ );
10913
+ }, [items]);
10914
+ const { q, order, offset } = useQueryParams(
10915
+ ["q", "order", "offset"],
10916
+ VARIANT_PREFIX
10917
+ );
10918
+ const { variants, count, isPending, isError, error } = useProductVariants(
10919
+ {
10920
+ q,
10921
+ order,
10922
+ offset: offset ? parseInt(offset) : void 0,
10923
+ limit: LIMIT
10900
10924
  },
10901
- resolver: zod.zodResolver(MetadataSchema)
10902
- });
10903
- const handleSubmit = form.handleSubmit(async (data) => {
10904
- const parsedData = parseValues(data);
10925
+ {
10926
+ placeholderData: reactQuery.keepPreviousData
10927
+ }
10928
+ );
10929
+ const columns = useColumns();
10930
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10931
+ const onSubmit = async () => {
10932
+ const ids = Object.keys(rowSelection).filter(
10933
+ (id) => !items.find((i) => i.variant_id === id)
10934
+ );
10905
10935
  await mutateAsync(
10906
10936
  {
10907
- metadata: parsedData
10937
+ items: ids.map((id) => ({
10938
+ variant_id: id,
10939
+ quantity: 1
10940
+ }))
10908
10941
  },
10909
10942
  {
10910
10943
  onSuccess: () => {
10911
- ui.toast.success("Metadata updated");
10912
- handleSuccess();
10944
+ setRowSelection({});
10945
+ setIsOpen(STACKED_MODAL_ID, false);
10913
10946
  },
10914
- onError: (error) => {
10915
- ui.toast.error(error.message);
10916
- }
10917
- }
10918
- );
10919
- });
10920
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10921
- control: form.control,
10922
- name: "metadata"
10923
- });
10924
- function deleteRow(index) {
10925
- remove(index);
10926
- if (fields.length === 1) {
10927
- insert(0, {
10928
- key: "",
10929
- value: "",
10930
- disabled: false
10931
- });
10932
- }
10933
- }
10934
- function insertRow(index, position) {
10935
- insert(index + (position === "above" ? 0 : 1), {
10936
- key: "",
10937
- value: "",
10938
- disabled: false
10939
- });
10940
- }
10941
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10942
- KeyboundForm,
10943
- {
10944
- onSubmit: handleSubmit,
10945
- className: "flex flex-1 flex-col overflow-hidden",
10946
- children: [
10947
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10948
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10949
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10950
- /* @__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" }) }),
10951
- /* @__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" }) })
10952
- ] }),
10953
- fields.map((field, index) => {
10954
- const isDisabled = field.disabled || false;
10955
- let placeholder = "-";
10956
- if (typeof field.value === "object") {
10957
- placeholder = "{ ... }";
10958
- }
10959
- if (Array.isArray(field.value)) {
10960
- placeholder = "[ ... ]";
10961
- }
10962
- return /* @__PURE__ */ jsxRuntime.jsx(
10963
- ConditionalTooltip,
10964
- {
10965
- showTooltip: isDisabled,
10966
- content: "This row is disabled because it contains non-primitive data.",
10967
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10968
- /* @__PURE__ */ jsxRuntime.jsxs(
10969
- "div",
10970
- {
10971
- className: ui.clx("grid grid-cols-2 divide-x", {
10972
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10973
- }),
10974
- children: [
10975
- /* @__PURE__ */ jsxRuntime.jsx(
10976
- Form$2.Field,
10977
- {
10978
- control: form.control,
10979
- name: `metadata.${index}.key`,
10980
- render: ({ field: field2 }) => {
10981
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10982
- GridInput,
10983
- {
10984
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10985
- ...field2,
10986
- disabled: isDisabled,
10987
- placeholder: "Key"
10988
- }
10989
- ) }) });
10990
- }
10991
- }
10992
- ),
10993
- /* @__PURE__ */ jsxRuntime.jsx(
10994
- Form$2.Field,
10995
- {
10996
- control: form.control,
10997
- name: `metadata.${index}.value`,
10998
- render: ({ field: { value, ...field2 } }) => {
10999
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11000
- GridInput,
11001
- {
11002
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11003
- ...field2,
11004
- value: isDisabled ? placeholder : value,
11005
- disabled: isDisabled,
11006
- placeholder: "Value"
11007
- }
11008
- ) }) });
11009
- }
11010
- }
11011
- )
11012
- ]
11013
- }
11014
- ),
11015
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11016
- /* @__PURE__ */ jsxRuntime.jsx(
11017
- ui.DropdownMenu.Trigger,
11018
- {
11019
- className: ui.clx(
11020
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11021
- {
11022
- hidden: isDisabled
11023
- }
11024
- ),
11025
- disabled: isDisabled,
11026
- asChild: true,
11027
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11028
- }
11029
- ),
11030
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11031
- /* @__PURE__ */ jsxRuntime.jsxs(
11032
- ui.DropdownMenu.Item,
11033
- {
11034
- className: "gap-x-2",
11035
- onClick: () => insertRow(index, "above"),
11036
- children: [
11037
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11038
- "Insert row above"
11039
- ]
11040
- }
11041
- ),
11042
- /* @__PURE__ */ jsxRuntime.jsxs(
11043
- ui.DropdownMenu.Item,
11044
- {
11045
- className: "gap-x-2",
11046
- onClick: () => insertRow(index, "below"),
11047
- children: [
11048
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11049
- "Insert row below"
11050
- ]
11051
- }
11052
- ),
11053
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11054
- /* @__PURE__ */ jsxRuntime.jsxs(
11055
- ui.DropdownMenu.Item,
11056
- {
11057
- className: "gap-x-2",
11058
- onClick: () => deleteRow(index),
11059
- children: [
11060
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11061
- "Delete row"
11062
- ]
11063
- }
11064
- )
11065
- ] })
11066
- ] })
11067
- ] })
11068
- },
11069
- field.id
11070
- );
11071
- })
11072
- ] }),
11073
- 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." })
10947
+ onError: (e) => {
10948
+ ui.toast.error(e.message);
10949
+ }
10950
+ }
10951
+ );
10952
+ };
10953
+ if (isError) {
10954
+ throw error;
10955
+ }
10956
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10957
+ StackedFocusModal.Content,
10958
+ {
10959
+ onOpenAutoFocus: (e) => {
10960
+ e.preventDefault();
10961
+ const searchInput = document.querySelector(
10962
+ "[data-modal-id='modal-search-input']"
10963
+ );
10964
+ if (searchInput) {
10965
+ searchInput.focus();
10966
+ }
10967
+ },
10968
+ children: [
10969
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10970
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10971
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11074
10972
  ] }),
11075
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11076
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11077
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10973
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10974
+ DataTable,
10975
+ {
10976
+ data: variants,
10977
+ columns,
10978
+ isLoading: isPending,
10979
+ getRowId: (row) => row.id,
10980
+ rowCount: count,
10981
+ prefix: VARIANT_PREFIX,
10982
+ layout: "fill",
10983
+ rowSelection: {
10984
+ state: rowSelection,
10985
+ onRowSelectionChange: setRowSelection,
10986
+ enableRowSelection: (row) => {
10987
+ return !items.find((i) => i.variant_id === row.original.id);
10988
+ }
10989
+ },
10990
+ autoFocusSearch: true
10991
+ }
10992
+ ) }),
10993
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10994
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10995
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11078
10996
  ] }) })
11079
10997
  ]
11080
10998
  }
11081
- ) });
11082
- };
11083
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11084
- return /* @__PURE__ */ jsxRuntime.jsx(
11085
- "input",
11086
- {
11087
- ref,
11088
- ...props,
11089
- autoComplete: "off",
11090
- className: ui.clx(
11091
- "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",
11092
- className
11093
- )
11094
- }
11095
10999
  );
11096
- });
11097
- GridInput.displayName = "MetadataForm.GridInput";
11098
- const PlaceholderInner = () => {
11099
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11100
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11101
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11102
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11103
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11104
- ] }) })
11105
- ] });
11106
11000
  };
11107
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11108
- function getDefaultValues(metadata) {
11109
- if (!metadata || !Object.keys(metadata).length) {
11001
+ const columnHelper = ui.createDataTableColumnHelper();
11002
+ const useColumns = () => {
11003
+ return React.useMemo(() => {
11110
11004
  return [
11111
- {
11112
- key: "",
11113
- value: "",
11114
- disabled: false
11115
- }
11005
+ columnHelper.select(),
11006
+ columnHelper.accessor("product.title", {
11007
+ header: "Product",
11008
+ cell: ({ row }) => {
11009
+ var _a, _b, _c;
11010
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
11011
+ /* @__PURE__ */ jsxRuntime.jsx(
11012
+ Thumbnail,
11013
+ {
11014
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11015
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11016
+ }
11017
+ ),
11018
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11019
+ ] });
11020
+ },
11021
+ enableSorting: true
11022
+ }),
11023
+ columnHelper.accessor("title", {
11024
+ header: "Variant",
11025
+ enableSorting: true
11026
+ }),
11027
+ columnHelper.accessor("sku", {
11028
+ header: "SKU",
11029
+ cell: ({ getValue }) => {
11030
+ return getValue() ?? "-";
11031
+ },
11032
+ enableSorting: true
11033
+ }),
11034
+ columnHelper.accessor("updated_at", {
11035
+ header: "Updated",
11036
+ cell: ({ getValue }) => {
11037
+ return /* @__PURE__ */ jsxRuntime.jsx(
11038
+ ui.Tooltip,
11039
+ {
11040
+ content: getFullDate({ date: getValue(), includeTime: true }),
11041
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11042
+ }
11043
+ );
11044
+ },
11045
+ enableSorting: true,
11046
+ sortAscLabel: "Oldest first",
11047
+ sortDescLabel: "Newest first"
11048
+ }),
11049
+ columnHelper.accessor("created_at", {
11050
+ header: "Created",
11051
+ cell: ({ getValue }) => {
11052
+ return /* @__PURE__ */ jsxRuntime.jsx(
11053
+ ui.Tooltip,
11054
+ {
11055
+ content: getFullDate({ date: getValue(), includeTime: true }),
11056
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11057
+ }
11058
+ );
11059
+ },
11060
+ enableSorting: true,
11061
+ sortAscLabel: "Oldest first",
11062
+ sortDescLabel: "Newest first"
11063
+ })
11116
11064
  ];
11117
- }
11118
- return Object.entries(metadata).map(([key, value]) => {
11119
- if (!EDITABLE_TYPES.includes(typeof value)) {
11120
- return {
11121
- key,
11122
- value,
11123
- disabled: true
11124
- };
11125
- }
11126
- let stringValue = value;
11127
- if (typeof value !== "string") {
11128
- stringValue = JSON.stringify(value);
11129
- }
11130
- return {
11131
- key,
11132
- value: stringValue,
11133
- original_key: key
11134
- };
11065
+ }, []);
11066
+ };
11067
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11068
+ const { setIsOpen } = useStackedModal();
11069
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11070
+ const form = reactHookForm.useForm({
11071
+ defaultValues: {
11072
+ title: "",
11073
+ quantity: 1,
11074
+ unit_price: ""
11075
+ },
11076
+ resolver: zod.zodResolver(customItemSchema)
11135
11077
  });
11136
- }
11137
- function parseValues(values) {
11138
- const metadata = values.metadata;
11139
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11140
- if (isEmpty) {
11141
- return null;
11142
- }
11143
- const update = {};
11144
- metadata.forEach((field) => {
11145
- let key = field.key;
11146
- let value = field.value;
11147
- const disabled = field.disabled;
11148
- if (!key || !value) {
11149
- return;
11150
- }
11151
- if (disabled) {
11152
- update[key] = value;
11153
- return;
11154
- }
11155
- key = key.trim();
11156
- value = value.trim();
11157
- if (value === "true") {
11158
- update[key] = true;
11159
- } else if (value === "false") {
11160
- update[key] = false;
11161
- } else {
11162
- const parsedNumber = parseFloat(value);
11163
- if (!isNaN(parsedNumber)) {
11164
- update[key] = parsedNumber;
11165
- } else {
11166
- update[key] = value;
11078
+ const onSubmit = form.handleSubmit(async (data) => {
11079
+ await addItems(
11080
+ {
11081
+ items: [
11082
+ {
11083
+ title: data.title,
11084
+ quantity: data.quantity,
11085
+ unit_price: convertNumber(data.unit_price)
11086
+ }
11087
+ ]
11088
+ },
11089
+ {
11090
+ onSuccess: () => {
11091
+ setIsOpen(STACKED_MODAL_ID, false);
11092
+ },
11093
+ onError: (e) => {
11094
+ ui.toast.error(e.message);
11095
+ }
11167
11096
  }
11168
- }
11097
+ );
11169
11098
  });
11170
- return update;
11171
- }
11172
- function getHasUneditableRows(metadata) {
11173
- if (!metadata) {
11174
- return false;
11175
- }
11176
- return Object.values(metadata).some(
11177
- (value) => !EDITABLE_TYPES.includes(typeof value)
11178
- );
11179
- }
11099
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11100
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11101
+ /* @__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: [
11102
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11103
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11104
+ /* @__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." }) })
11105
+ ] }),
11106
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11107
+ /* @__PURE__ */ jsxRuntime.jsx(
11108
+ Form$2.Field,
11109
+ {
11110
+ control: form.control,
11111
+ name: "title",
11112
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11113
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11115
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
11116
+ ] }),
11117
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11118
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11119
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11120
+ ] })
11121
+ ] }) })
11122
+ }
11123
+ ),
11124
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11125
+ /* @__PURE__ */ jsxRuntime.jsx(
11126
+ Form$2.Field,
11127
+ {
11128
+ control: form.control,
11129
+ name: "unit_price",
11130
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11131
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11132
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11133
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11134
+ ] }),
11135
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11136
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11137
+ ui.CurrencyInput,
11138
+ {
11139
+ symbol: getNativeSymbol(currencyCode),
11140
+ code: currencyCode,
11141
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11142
+ ...field
11143
+ }
11144
+ ) }),
11145
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11146
+ ] })
11147
+ ] }) })
11148
+ }
11149
+ ),
11150
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11151
+ /* @__PURE__ */ jsxRuntime.jsx(
11152
+ Form$2.Field,
11153
+ {
11154
+ control: form.control,
11155
+ name: "quantity",
11156
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11157
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11158
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11159
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11160
+ ] }),
11161
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
11162
+ /* @__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" }) }) }),
11163
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11164
+ ] })
11165
+ ] }) })
11166
+ }
11167
+ )
11168
+ ] }) }) }),
11169
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11170
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11171
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11172
+ ] }) })
11173
+ ] }) }) });
11174
+ };
11175
+ const customItemSchema = objectType({
11176
+ title: stringType().min(1),
11177
+ quantity: numberType(),
11178
+ unit_price: unionType([numberType(), stringType()])
11179
+ });
11180
11180
  const PROMOTION_QUERY_KEY = "promotions";
11181
11181
  const promotionsQueryKeys = {
11182
11182
  list: (query2) => [
@@ -11542,24 +11542,227 @@ const SalesChannelField = ({ control, order }) => {
11542
11542
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11543
11543
  Combobox,
11544
11544
  {
11545
- options: salesChannels.options,
11546
- fetchNextPage: salesChannels.fetchNextPage,
11547
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11548
- searchValue: salesChannels.searchValue,
11549
- onSearchValueChange: salesChannels.onSearchValueChange,
11550
- placeholder: "Select sales channel",
11551
- ...field
11545
+ options: salesChannels.options,
11546
+ fetchNextPage: salesChannels.fetchNextPage,
11547
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11548
+ searchValue: salesChannels.searchValue,
11549
+ onSearchValueChange: salesChannels.onSearchValueChange,
11550
+ placeholder: "Select sales channel",
11551
+ ...field
11552
+ }
11553
+ ) }),
11554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11555
+ ] });
11556
+ }
11557
+ }
11558
+ );
11559
+ };
11560
+ const schema$2 = objectType({
11561
+ sales_channel_id: stringType().min(1)
11562
+ });
11563
+ const ShippingAddress = () => {
11564
+ const { id } = reactRouterDom.useParams();
11565
+ const { order, isPending, isError, error } = useOrder(id, {
11566
+ fields: "+shipping_address"
11567
+ });
11568
+ if (isError) {
11569
+ throw error;
11570
+ }
11571
+ const isReady = !isPending && !!order;
11572
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11573
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11574
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11575
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11576
+ ] }),
11577
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11578
+ ] });
11579
+ };
11580
+ const ShippingAddressForm = ({ order }) => {
11581
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11582
+ const form = reactHookForm.useForm({
11583
+ defaultValues: {
11584
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11585
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11586
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11587
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11588
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11589
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11590
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11591
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11592
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11593
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11594
+ },
11595
+ resolver: zod.zodResolver(schema$1)
11596
+ });
11597
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11598
+ const { handleSuccess } = useRouteModal();
11599
+ const onSubmit = form.handleSubmit(async (data) => {
11600
+ await mutateAsync(
11601
+ {
11602
+ shipping_address: {
11603
+ first_name: data.first_name,
11604
+ last_name: data.last_name,
11605
+ company: data.company,
11606
+ address_1: data.address_1,
11607
+ address_2: data.address_2,
11608
+ city: data.city,
11609
+ province: data.province,
11610
+ country_code: data.country_code,
11611
+ postal_code: data.postal_code,
11612
+ phone: data.phone
11613
+ }
11614
+ },
11615
+ {
11616
+ onSuccess: () => {
11617
+ handleSuccess();
11618
+ },
11619
+ onError: (error) => {
11620
+ ui.toast.error(error.message);
11621
+ }
11622
+ }
11623
+ );
11624
+ });
11625
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11626
+ KeyboundForm,
11627
+ {
11628
+ className: "flex flex-1 flex-col overflow-hidden",
11629
+ onSubmit,
11630
+ children: [
11631
+ /* @__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: [
11632
+ /* @__PURE__ */ jsxRuntime.jsx(
11633
+ Form$2.Field,
11634
+ {
11635
+ control: form.control,
11636
+ name: "country_code",
11637
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11640
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11641
+ ] })
11642
+ }
11643
+ ),
11644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11645
+ /* @__PURE__ */ jsxRuntime.jsx(
11646
+ Form$2.Field,
11647
+ {
11648
+ control: form.control,
11649
+ name: "first_name",
11650
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11653
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11654
+ ] })
11655
+ }
11656
+ ),
11657
+ /* @__PURE__ */ jsxRuntime.jsx(
11658
+ Form$2.Field,
11659
+ {
11660
+ control: form.control,
11661
+ name: "last_name",
11662
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11665
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11666
+ ] })
11667
+ }
11668
+ )
11669
+ ] }),
11670
+ /* @__PURE__ */ jsxRuntime.jsx(
11671
+ Form$2.Field,
11672
+ {
11673
+ control: form.control,
11674
+ name: "company",
11675
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11679
+ ] })
11680
+ }
11681
+ ),
11682
+ /* @__PURE__ */ jsxRuntime.jsx(
11683
+ Form$2.Field,
11684
+ {
11685
+ control: form.control,
11686
+ name: "address_1",
11687
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11690
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11691
+ ] })
11692
+ }
11693
+ ),
11694
+ /* @__PURE__ */ jsxRuntime.jsx(
11695
+ Form$2.Field,
11696
+ {
11697
+ control: form.control,
11698
+ name: "address_2",
11699
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11703
+ ] })
11704
+ }
11705
+ ),
11706
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11707
+ /* @__PURE__ */ jsxRuntime.jsx(
11708
+ Form$2.Field,
11709
+ {
11710
+ control: form.control,
11711
+ name: "postal_code",
11712
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11715
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11716
+ ] })
11717
+ }
11718
+ ),
11719
+ /* @__PURE__ */ jsxRuntime.jsx(
11720
+ Form$2.Field,
11721
+ {
11722
+ control: form.control,
11723
+ name: "city",
11724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11728
+ ] })
11729
+ }
11730
+ )
11731
+ ] }),
11732
+ /* @__PURE__ */ jsxRuntime.jsx(
11733
+ Form$2.Field,
11734
+ {
11735
+ control: form.control,
11736
+ name: "province",
11737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11740
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11741
+ ] })
11742
+ }
11743
+ ),
11744
+ /* @__PURE__ */ jsxRuntime.jsx(
11745
+ Form$2.Field,
11746
+ {
11747
+ control: form.control,
11748
+ name: "phone",
11749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11753
+ ] })
11552
11754
  }
11553
- ) }),
11554
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11555
- ] });
11556
- }
11755
+ )
11756
+ ] }) }),
11757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11758
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11759
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11760
+ ] }) })
11761
+ ]
11557
11762
  }
11558
- );
11763
+ ) });
11559
11764
  };
11560
- const schema$2 = objectType({
11561
- sales_channel_id: stringType().min(1)
11562
- });
11765
+ const schema$1 = addressSchema;
11563
11766
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11564
11767
  const Shipping = () => {
11565
11768
  var _a;
@@ -12367,209 +12570,6 @@ const CustomAmountField = ({
12367
12570
  }
12368
12571
  );
12369
12572
  };
12370
- const ShippingAddress = () => {
12371
- const { id } = reactRouterDom.useParams();
12372
- const { order, isPending, isError, error } = useOrder(id, {
12373
- fields: "+shipping_address"
12374
- });
12375
- if (isError) {
12376
- throw error;
12377
- }
12378
- const isReady = !isPending && !!order;
12379
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12380
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12381
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12382
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12383
- ] }),
12384
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12385
- ] });
12386
- };
12387
- const ShippingAddressForm = ({ order }) => {
12388
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12389
- const form = reactHookForm.useForm({
12390
- defaultValues: {
12391
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12392
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12393
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12394
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12395
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12396
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12397
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12398
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12399
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12400
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12401
- },
12402
- resolver: zod.zodResolver(schema$1)
12403
- });
12404
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12405
- const { handleSuccess } = useRouteModal();
12406
- const onSubmit = form.handleSubmit(async (data) => {
12407
- await mutateAsync(
12408
- {
12409
- shipping_address: {
12410
- first_name: data.first_name,
12411
- last_name: data.last_name,
12412
- company: data.company,
12413
- address_1: data.address_1,
12414
- address_2: data.address_2,
12415
- city: data.city,
12416
- province: data.province,
12417
- country_code: data.country_code,
12418
- postal_code: data.postal_code,
12419
- phone: data.phone
12420
- }
12421
- },
12422
- {
12423
- onSuccess: () => {
12424
- handleSuccess();
12425
- },
12426
- onError: (error) => {
12427
- ui.toast.error(error.message);
12428
- }
12429
- }
12430
- );
12431
- });
12432
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12433
- KeyboundForm,
12434
- {
12435
- className: "flex flex-1 flex-col overflow-hidden",
12436
- onSubmit,
12437
- children: [
12438
- /* @__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: [
12439
- /* @__PURE__ */ jsxRuntime.jsx(
12440
- Form$2.Field,
12441
- {
12442
- control: form.control,
12443
- name: "country_code",
12444
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12446
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12448
- ] })
12449
- }
12450
- ),
12451
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12452
- /* @__PURE__ */ jsxRuntime.jsx(
12453
- Form$2.Field,
12454
- {
12455
- control: form.control,
12456
- name: "first_name",
12457
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12461
- ] })
12462
- }
12463
- ),
12464
- /* @__PURE__ */ jsxRuntime.jsx(
12465
- Form$2.Field,
12466
- {
12467
- control: form.control,
12468
- name: "last_name",
12469
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12473
- ] })
12474
- }
12475
- )
12476
- ] }),
12477
- /* @__PURE__ */ jsxRuntime.jsx(
12478
- Form$2.Field,
12479
- {
12480
- control: form.control,
12481
- name: "company",
12482
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
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.jsx(
12490
- Form$2.Field,
12491
- {
12492
- control: form.control,
12493
- name: "address_1",
12494
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12496
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12498
- ] })
12499
- }
12500
- ),
12501
- /* @__PURE__ */ jsxRuntime.jsx(
12502
- Form$2.Field,
12503
- {
12504
- control: form.control,
12505
- name: "address_2",
12506
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12510
- ] })
12511
- }
12512
- ),
12513
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12514
- /* @__PURE__ */ jsxRuntime.jsx(
12515
- Form$2.Field,
12516
- {
12517
- control: form.control,
12518
- name: "postal_code",
12519
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12523
- ] })
12524
- }
12525
- ),
12526
- /* @__PURE__ */ jsxRuntime.jsx(
12527
- Form$2.Field,
12528
- {
12529
- control: form.control,
12530
- name: "city",
12531
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12535
- ] })
12536
- }
12537
- )
12538
- ] }),
12539
- /* @__PURE__ */ jsxRuntime.jsx(
12540
- Form$2.Field,
12541
- {
12542
- control: form.control,
12543
- name: "province",
12544
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12548
- ] })
12549
- }
12550
- ),
12551
- /* @__PURE__ */ jsxRuntime.jsx(
12552
- Form$2.Field,
12553
- {
12554
- control: form.control,
12555
- name: "phone",
12556
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12560
- ] })
12561
- }
12562
- )
12563
- ] }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12565
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12566
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12567
- ] }) })
12568
- ]
12569
- }
12570
- ) });
12571
- };
12572
- const schema$1 = addressSchema;
12573
12573
  const TransferOwnership = () => {
12574
12574
  const { id } = reactRouterDom.useParams();
12575
12575
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13078,14 +13078,14 @@ const routeModule = {
13078
13078
  Component: Email,
13079
13079
  path: "/draft-orders/:id/email"
13080
13080
  },
13081
- {
13082
- Component: Items,
13083
- path: "/draft-orders/:id/items"
13084
- },
13085
13081
  {
13086
13082
  Component: Metadata,
13087
13083
  path: "/draft-orders/:id/metadata"
13088
13084
  },
13085
+ {
13086
+ Component: Items,
13087
+ path: "/draft-orders/:id/items"
13088
+ },
13089
13089
  {
13090
13090
  Component: Promotions,
13091
13091
  path: "/draft-orders/:id/promotions"
@@ -13094,14 +13094,14 @@ const routeModule = {
13094
13094
  Component: SalesChannel,
13095
13095
  path: "/draft-orders/:id/sales-channel"
13096
13096
  },
13097
- {
13098
- Component: Shipping,
13099
- path: "/draft-orders/:id/shipping"
13100
- },
13101
13097
  {
13102
13098
  Component: ShippingAddress,
13103
13099
  path: "/draft-orders/:id/shipping-address"
13104
13100
  },
13101
+ {
13102
+ Component: Shipping,
13103
+ path: "/draft-orders/:id/shipping"
13104
+ },
13105
13105
  {
13106
13106
  Component: TransferOwnership,
13107
13107
  path: "/draft-orders/:id/transfer-ownership"