@medusajs/draft-order 2.10.4-preview-20250926120205 → 2.10.4-preview-20250926150202

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9567,6 +9567,27 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
+ const CustomItems = () => {
9571
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9574
+ ] });
9575
+ };
9576
+ const CustomItemsForm = () => {
9577
+ const form = useForm({
9578
+ resolver: zodResolver(schema$5)
9579
+ });
9580
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
+ ] }) })
9586
+ ] }) });
9587
+ };
9588
+ const schema$5 = objectType({
9589
+ email: stringType().email()
9590
+ });
9570
9591
  const BillingAddress = () => {
9571
9592
  const { id } = useParams();
9572
9593
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9599,7 +9620,7 @@ const BillingAddressForm = ({ order }) => {
9599
9620
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
9621
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
9622
  },
9602
- resolver: zodResolver(schema$5)
9623
+ resolver: zodResolver(schema$4)
9603
9624
  });
9604
9625
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
9626
  const { handleSuccess } = useRouteModal();
@@ -9756,28 +9777,7 @@ const BillingAddressForm = ({ order }) => {
9756
9777
  }
9757
9778
  ) });
9758
9779
  };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9780
+ const schema$4 = addressSchema;
9781
9781
  const Email = () => {
9782
9782
  const { id } = useParams();
9783
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9846,494 +9846,144 @@ const EmailForm = ({ order }) => {
9846
9846
  const schema$3 = objectType({
9847
9847
  email: stringType().email()
9848
9848
  });
9849
- const InlineTip = forwardRef(
9850
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9851
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9849
+ const NumberInput = forwardRef(
9850
+ ({
9851
+ value,
9852
+ onChange,
9853
+ size = "base",
9854
+ min = 0,
9855
+ max = 100,
9856
+ step = 1,
9857
+ className,
9858
+ disabled,
9859
+ ...props
9860
+ }, ref) => {
9861
+ const handleChange = (event) => {
9862
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
+ onChange(newValue);
9865
+ }
9866
+ };
9867
+ const handleIncrement = () => {
9868
+ const newValue = value + step;
9869
+ if (max === void 0 || newValue <= max) {
9870
+ onChange(newValue);
9871
+ }
9872
+ };
9873
+ const handleDecrement = () => {
9874
+ const newValue = value - step;
9875
+ if (min === void 0 || newValue >= min) {
9876
+ onChange(newValue);
9877
+ }
9878
+ };
9852
9879
  return /* @__PURE__ */ jsxs(
9853
9880
  "div",
9854
9881
  {
9855
- ref,
9856
9882
  className: clx(
9857
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9883
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
+ {
9886
+ "h-7": size === "small",
9887
+ "h-8": size === "base"
9888
+ },
9858
9889
  className
9859
9890
  ),
9860
- ...props,
9861
9891
  children: [
9862
9892
  /* @__PURE__ */ jsx(
9863
- "div",
9893
+ "input",
9864
9894
  {
9865
- role: "presentation",
9866
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9867
- "bg-ui-tag-orange-icon": variant === "warning"
9868
- })
9895
+ ref,
9896
+ type: "number",
9897
+ value,
9898
+ onChange: handleChange,
9899
+ min,
9900
+ max,
9901
+ step,
9902
+ className: clx(
9903
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9904
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9905
+ "placeholder:text-ui-fg-muted"
9906
+ ),
9907
+ ...props
9869
9908
  }
9870
9909
  ),
9871
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9872
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9873
- labelValue,
9874
- ":"
9875
- ] }),
9876
- " ",
9877
- children
9878
- ] })
9910
+ /* @__PURE__ */ jsxs(
9911
+ "button",
9912
+ {
9913
+ className: clx(
9914
+ "flex items-center justify-center outline-none transition-fg",
9915
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9916
+ "focus:bg-ui-bg-field-component-hover",
9917
+ "hover:bg-ui-bg-field-component-hover",
9918
+ {
9919
+ "size-7": size === "small",
9920
+ "size-8": size === "base"
9921
+ }
9922
+ ),
9923
+ type: "button",
9924
+ onClick: handleDecrement,
9925
+ disabled: min !== void 0 && value <= min || disabled,
9926
+ children: [
9927
+ /* @__PURE__ */ jsx(Minus, {}),
9928
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9929
+ ]
9930
+ }
9931
+ ),
9932
+ /* @__PURE__ */ jsxs(
9933
+ "button",
9934
+ {
9935
+ className: clx(
9936
+ "flex items-center justify-center outline-none transition-fg",
9937
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9938
+ "focus:bg-ui-bg-field-hover",
9939
+ "hover:bg-ui-bg-field-hover",
9940
+ {
9941
+ "size-7": size === "small",
9942
+ "size-8": size === "base"
9943
+ }
9944
+ ),
9945
+ type: "button",
9946
+ onClick: handleIncrement,
9947
+ disabled: max !== void 0 && value >= max || disabled,
9948
+ children: [
9949
+ /* @__PURE__ */ jsx(Plus, {}),
9950
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9951
+ ]
9952
+ }
9953
+ )
9879
9954
  ]
9880
9955
  }
9881
9956
  );
9882
9957
  }
9883
9958
  );
9884
- InlineTip.displayName = "InlineTip";
9885
- const MetadataFieldSchema = objectType({
9886
- key: stringType(),
9887
- disabled: booleanType().optional(),
9888
- value: anyType()
9889
- });
9890
- const MetadataSchema = objectType({
9891
- metadata: arrayType(MetadataFieldSchema)
9892
- });
9893
- const Metadata = () => {
9894
- const { id } = useParams();
9895
- const { order, isPending, isError, error } = useOrder(id, {
9896
- fields: "metadata"
9897
- });
9898
- if (isError) {
9899
- throw error;
9900
- }
9901
- const isReady = !isPending && !!order;
9902
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9903
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9904
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9905
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9906
- ] }),
9907
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9908
- ] });
9959
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
+ const productVariantsQueryKeys = {
9961
+ list: (query2) => [
9962
+ PRODUCT_VARIANTS_QUERY_KEY,
9963
+ query2 ? query2 : void 0
9964
+ ]
9909
9965
  };
9910
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9911
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9912
- const MetadataForm = ({ orderId, metadata }) => {
9913
- const { handleSuccess } = useRouteModal();
9914
- const hasUneditableRows = getHasUneditableRows(metadata);
9915
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9916
- const form = useForm({
9917
- defaultValues: {
9918
- metadata: getDefaultValues(metadata)
9919
- },
9920
- resolver: zodResolver(MetadataSchema)
9966
+ const useProductVariants = (query2, options) => {
9967
+ const { data, ...rest } = useQuery({
9968
+ queryKey: productVariantsQueryKeys.list(query2),
9969
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9970
+ ...options
9921
9971
  });
9922
- const handleSubmit = form.handleSubmit(async (data) => {
9923
- const parsedData = parseValues(data);
9924
- await mutateAsync(
9925
- {
9926
- metadata: parsedData
9972
+ return { ...data, ...rest };
9973
+ };
9974
+ const useCancelOrderEdit = ({ preview }) => {
9975
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9976
+ const onCancel = useCallback(async () => {
9977
+ if (!preview) {
9978
+ return true;
9979
+ }
9980
+ let res = false;
9981
+ await cancelOrderEdit(void 0, {
9982
+ onError: (e) => {
9983
+ toast.error(e.message);
9927
9984
  },
9928
- {
9929
- onSuccess: () => {
9930
- toast.success("Metadata updated");
9931
- handleSuccess();
9932
- },
9933
- onError: (error) => {
9934
- toast.error(error.message);
9935
- }
9936
- }
9937
- );
9938
- });
9939
- const { fields, insert, remove } = useFieldArray({
9940
- control: form.control,
9941
- name: "metadata"
9942
- });
9943
- function deleteRow(index) {
9944
- remove(index);
9945
- if (fields.length === 1) {
9946
- insert(0, {
9947
- key: "",
9948
- value: "",
9949
- disabled: false
9950
- });
9951
- }
9952
- }
9953
- function insertRow(index, position) {
9954
- insert(index + (position === "above" ? 0 : 1), {
9955
- key: "",
9956
- value: "",
9957
- disabled: false
9958
- });
9959
- }
9960
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9961
- KeyboundForm,
9962
- {
9963
- onSubmit: handleSubmit,
9964
- className: "flex flex-1 flex-col overflow-hidden",
9965
- children: [
9966
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9967
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9968
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9969
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9970
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9971
- ] }),
9972
- fields.map((field, index) => {
9973
- const isDisabled = field.disabled || false;
9974
- let placeholder = "-";
9975
- if (typeof field.value === "object") {
9976
- placeholder = "{ ... }";
9977
- }
9978
- if (Array.isArray(field.value)) {
9979
- placeholder = "[ ... ]";
9980
- }
9981
- return /* @__PURE__ */ jsx(
9982
- ConditionalTooltip,
9983
- {
9984
- showTooltip: isDisabled,
9985
- content: "This row is disabled because it contains non-primitive data.",
9986
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9987
- /* @__PURE__ */ jsxs(
9988
- "div",
9989
- {
9990
- className: clx("grid grid-cols-2 divide-x", {
9991
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9992
- }),
9993
- children: [
9994
- /* @__PURE__ */ jsx(
9995
- Form$2.Field,
9996
- {
9997
- control: form.control,
9998
- name: `metadata.${index}.key`,
9999
- render: ({ field: field2 }) => {
10000
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10001
- GridInput,
10002
- {
10003
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10004
- ...field2,
10005
- disabled: isDisabled,
10006
- placeholder: "Key"
10007
- }
10008
- ) }) });
10009
- }
10010
- }
10011
- ),
10012
- /* @__PURE__ */ jsx(
10013
- Form$2.Field,
10014
- {
10015
- control: form.control,
10016
- name: `metadata.${index}.value`,
10017
- render: ({ field: { value, ...field2 } }) => {
10018
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10019
- GridInput,
10020
- {
10021
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10022
- ...field2,
10023
- value: isDisabled ? placeholder : value,
10024
- disabled: isDisabled,
10025
- placeholder: "Value"
10026
- }
10027
- ) }) });
10028
- }
10029
- }
10030
- )
10031
- ]
10032
- }
10033
- ),
10034
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10035
- /* @__PURE__ */ jsx(
10036
- DropdownMenu.Trigger,
10037
- {
10038
- className: clx(
10039
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10040
- {
10041
- hidden: isDisabled
10042
- }
10043
- ),
10044
- disabled: isDisabled,
10045
- asChild: true,
10046
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10047
- }
10048
- ),
10049
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10050
- /* @__PURE__ */ jsxs(
10051
- DropdownMenu.Item,
10052
- {
10053
- className: "gap-x-2",
10054
- onClick: () => insertRow(index, "above"),
10055
- children: [
10056
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10057
- "Insert row above"
10058
- ]
10059
- }
10060
- ),
10061
- /* @__PURE__ */ jsxs(
10062
- DropdownMenu.Item,
10063
- {
10064
- className: "gap-x-2",
10065
- onClick: () => insertRow(index, "below"),
10066
- children: [
10067
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10068
- "Insert row below"
10069
- ]
10070
- }
10071
- ),
10072
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10073
- /* @__PURE__ */ jsxs(
10074
- DropdownMenu.Item,
10075
- {
10076
- className: "gap-x-2",
10077
- onClick: () => deleteRow(index),
10078
- children: [
10079
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10080
- "Delete row"
10081
- ]
10082
- }
10083
- )
10084
- ] })
10085
- ] })
10086
- ] })
10087
- },
10088
- field.id
10089
- );
10090
- })
10091
- ] }),
10092
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10093
- ] }),
10094
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10095
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10096
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10097
- ] }) })
10098
- ]
10099
- }
10100
- ) });
10101
- };
10102
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10103
- return /* @__PURE__ */ jsx(
10104
- "input",
10105
- {
10106
- ref,
10107
- ...props,
10108
- autoComplete: "off",
10109
- className: clx(
10110
- "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",
10111
- className
10112
- )
10113
- }
10114
- );
10115
- });
10116
- GridInput.displayName = "MetadataForm.GridInput";
10117
- const PlaceholderInner = () => {
10118
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10119
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10120
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10121
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10122
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10123
- ] }) })
10124
- ] });
10125
- };
10126
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10127
- function getDefaultValues(metadata) {
10128
- if (!metadata || !Object.keys(metadata).length) {
10129
- return [
10130
- {
10131
- key: "",
10132
- value: "",
10133
- disabled: false
10134
- }
10135
- ];
10136
- }
10137
- return Object.entries(metadata).map(([key, value]) => {
10138
- if (!EDITABLE_TYPES.includes(typeof value)) {
10139
- return {
10140
- key,
10141
- value,
10142
- disabled: true
10143
- };
10144
- }
10145
- let stringValue = value;
10146
- if (typeof value !== "string") {
10147
- stringValue = JSON.stringify(value);
10148
- }
10149
- return {
10150
- key,
10151
- value: stringValue,
10152
- original_key: key
10153
- };
10154
- });
10155
- }
10156
- function parseValues(values) {
10157
- const metadata = values.metadata;
10158
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10159
- if (isEmpty) {
10160
- return null;
10161
- }
10162
- const update = {};
10163
- metadata.forEach((field) => {
10164
- let key = field.key;
10165
- let value = field.value;
10166
- const disabled = field.disabled;
10167
- if (!key || !value) {
10168
- return;
10169
- }
10170
- if (disabled) {
10171
- update[key] = value;
10172
- return;
10173
- }
10174
- key = key.trim();
10175
- value = value.trim();
10176
- if (value === "true") {
10177
- update[key] = true;
10178
- } else if (value === "false") {
10179
- update[key] = false;
10180
- } else {
10181
- const parsedNumber = parseFloat(value);
10182
- if (!isNaN(parsedNumber)) {
10183
- update[key] = parsedNumber;
10184
- } else {
10185
- update[key] = value;
10186
- }
10187
- }
10188
- });
10189
- return update;
10190
- }
10191
- function getHasUneditableRows(metadata) {
10192
- if (!metadata) {
10193
- return false;
10194
- }
10195
- return Object.values(metadata).some(
10196
- (value) => !EDITABLE_TYPES.includes(typeof value)
10197
- );
10198
- }
10199
- const NumberInput = forwardRef(
10200
- ({
10201
- value,
10202
- onChange,
10203
- size = "base",
10204
- min = 0,
10205
- max = 100,
10206
- step = 1,
10207
- className,
10208
- disabled,
10209
- ...props
10210
- }, ref) => {
10211
- const handleChange = (event) => {
10212
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10213
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10214
- onChange(newValue);
10215
- }
10216
- };
10217
- const handleIncrement = () => {
10218
- const newValue = value + step;
10219
- if (max === void 0 || newValue <= max) {
10220
- onChange(newValue);
10221
- }
10222
- };
10223
- const handleDecrement = () => {
10224
- const newValue = value - step;
10225
- if (min === void 0 || newValue >= min) {
10226
- onChange(newValue);
10227
- }
10228
- };
10229
- return /* @__PURE__ */ jsxs(
10230
- "div",
10231
- {
10232
- className: clx(
10233
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10234
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10235
- {
10236
- "h-7": size === "small",
10237
- "h-8": size === "base"
10238
- },
10239
- className
10240
- ),
10241
- children: [
10242
- /* @__PURE__ */ jsx(
10243
- "input",
10244
- {
10245
- ref,
10246
- type: "number",
10247
- value,
10248
- onChange: handleChange,
10249
- min,
10250
- max,
10251
- step,
10252
- className: clx(
10253
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10254
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10255
- "placeholder:text-ui-fg-muted"
10256
- ),
10257
- ...props
10258
- }
10259
- ),
10260
- /* @__PURE__ */ jsxs(
10261
- "button",
10262
- {
10263
- className: clx(
10264
- "flex items-center justify-center outline-none transition-fg",
10265
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10266
- "focus:bg-ui-bg-field-component-hover",
10267
- "hover:bg-ui-bg-field-component-hover",
10268
- {
10269
- "size-7": size === "small",
10270
- "size-8": size === "base"
10271
- }
10272
- ),
10273
- type: "button",
10274
- onClick: handleDecrement,
10275
- disabled: min !== void 0 && value <= min || disabled,
10276
- children: [
10277
- /* @__PURE__ */ jsx(Minus, {}),
10278
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10279
- ]
10280
- }
10281
- ),
10282
- /* @__PURE__ */ jsxs(
10283
- "button",
10284
- {
10285
- className: clx(
10286
- "flex items-center justify-center outline-none transition-fg",
10287
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10288
- "focus:bg-ui-bg-field-hover",
10289
- "hover:bg-ui-bg-field-hover",
10290
- {
10291
- "size-7": size === "small",
10292
- "size-8": size === "base"
10293
- }
10294
- ),
10295
- type: "button",
10296
- onClick: handleIncrement,
10297
- disabled: max !== void 0 && value >= max || disabled,
10298
- children: [
10299
- /* @__PURE__ */ jsx(Plus, {}),
10300
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10301
- ]
10302
- }
10303
- )
10304
- ]
10305
- }
10306
- );
10307
- }
10308
- );
10309
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10310
- const productVariantsQueryKeys = {
10311
- list: (query2) => [
10312
- PRODUCT_VARIANTS_QUERY_KEY,
10313
- query2 ? query2 : void 0
10314
- ]
10315
- };
10316
- const useProductVariants = (query2, options) => {
10317
- const { data, ...rest } = useQuery({
10318
- queryKey: productVariantsQueryKeys.list(query2),
10319
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10320
- ...options
10321
- });
10322
- return { ...data, ...rest };
10323
- };
10324
- const useCancelOrderEdit = ({ preview }) => {
10325
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10326
- const onCancel = useCallback(async () => {
10327
- if (!preview) {
10328
- return true;
10329
- }
10330
- let res = false;
10331
- await cancelOrderEdit(void 0, {
10332
- onError: (e) => {
10333
- toast.error(e.message);
10334
- },
10335
- onSuccess: () => {
10336
- res = true;
9985
+ onSuccess: () => {
9986
+ res = true;
10337
9987
  }
10338
9988
  });
10339
9989
  return res;
@@ -11369,83 +11019,433 @@ const PromotionItem = ({
11369
11019
  {
11370
11020
  "animate-pulse": isLoading
11371
11021
  }
11372
- ),
11022
+ ),
11023
+ children: [
11024
+ /* @__PURE__ */ jsxs("div", { children: [
11025
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11026
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11027
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11028
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11029
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11030
+ ] }),
11031
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11032
+ ] })
11033
+ ] }),
11034
+ /* @__PURE__ */ jsx(
11035
+ IconButton,
11036
+ {
11037
+ size: "small",
11038
+ type: "button",
11039
+ variant: "transparent",
11040
+ onClick: onRemove,
11041
+ isLoading: isPending || isLoading,
11042
+ children: /* @__PURE__ */ jsx(XMark, {})
11043
+ }
11044
+ )
11045
+ ]
11046
+ },
11047
+ promotion.id
11048
+ );
11049
+ };
11050
+ function getDisplayValue(promotion) {
11051
+ var _a, _b, _c, _d;
11052
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11053
+ if (!value) {
11054
+ return null;
11055
+ }
11056
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11057
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11058
+ if (!currency) {
11059
+ return null;
11060
+ }
11061
+ return getLocaleAmount(value, currency);
11062
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11063
+ return formatPercentage(value);
11064
+ }
11065
+ return null;
11066
+ }
11067
+ const formatter = new Intl.NumberFormat([], {
11068
+ style: "percent",
11069
+ minimumFractionDigits: 2
11070
+ });
11071
+ const formatPercentage = (value, isPercentageValue = false) => {
11072
+ let val = value || 0;
11073
+ if (!isPercentageValue) {
11074
+ val = val / 100;
11075
+ }
11076
+ return formatter.format(val);
11077
+ };
11078
+ function getPromotionIds(items, shippingMethods) {
11079
+ const promotionIds = /* @__PURE__ */ new Set();
11080
+ for (const item of items) {
11081
+ if (item.adjustments) {
11082
+ for (const adjustment of item.adjustments) {
11083
+ if (adjustment.promotion_id) {
11084
+ promotionIds.add(adjustment.promotion_id);
11085
+ }
11086
+ }
11087
+ }
11088
+ }
11089
+ for (const shippingMethod of shippingMethods) {
11090
+ if (shippingMethod.adjustments) {
11091
+ for (const adjustment of shippingMethod.adjustments) {
11092
+ if (adjustment.promotion_id) {
11093
+ promotionIds.add(adjustment.promotion_id);
11094
+ }
11095
+ }
11096
+ }
11097
+ }
11098
+ return Array.from(promotionIds);
11099
+ }
11100
+ const InlineTip = forwardRef(
11101
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11102
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11103
+ return /* @__PURE__ */ jsxs(
11104
+ "div",
11105
+ {
11106
+ ref,
11107
+ className: clx(
11108
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11109
+ className
11110
+ ),
11111
+ ...props,
11112
+ children: [
11113
+ /* @__PURE__ */ jsx(
11114
+ "div",
11115
+ {
11116
+ role: "presentation",
11117
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11118
+ "bg-ui-tag-orange-icon": variant === "warning"
11119
+ })
11120
+ }
11121
+ ),
11122
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11123
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11124
+ labelValue,
11125
+ ":"
11126
+ ] }),
11127
+ " ",
11128
+ children
11129
+ ] })
11130
+ ]
11131
+ }
11132
+ );
11133
+ }
11134
+ );
11135
+ InlineTip.displayName = "InlineTip";
11136
+ const MetadataFieldSchema = objectType({
11137
+ key: stringType(),
11138
+ disabled: booleanType().optional(),
11139
+ value: anyType()
11140
+ });
11141
+ const MetadataSchema = objectType({
11142
+ metadata: arrayType(MetadataFieldSchema)
11143
+ });
11144
+ const Metadata = () => {
11145
+ const { id } = useParams();
11146
+ const { order, isPending, isError, error } = useOrder(id, {
11147
+ fields: "metadata"
11148
+ });
11149
+ if (isError) {
11150
+ throw error;
11151
+ }
11152
+ const isReady = !isPending && !!order;
11153
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11155
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11156
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11157
+ ] }),
11158
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11159
+ ] });
11160
+ };
11161
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11162
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11163
+ const MetadataForm = ({ orderId, metadata }) => {
11164
+ const { handleSuccess } = useRouteModal();
11165
+ const hasUneditableRows = getHasUneditableRows(metadata);
11166
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11167
+ const form = useForm({
11168
+ defaultValues: {
11169
+ metadata: getDefaultValues(metadata)
11170
+ },
11171
+ resolver: zodResolver(MetadataSchema)
11172
+ });
11173
+ const handleSubmit = form.handleSubmit(async (data) => {
11174
+ const parsedData = parseValues(data);
11175
+ await mutateAsync(
11176
+ {
11177
+ metadata: parsedData
11178
+ },
11179
+ {
11180
+ onSuccess: () => {
11181
+ toast.success("Metadata updated");
11182
+ handleSuccess();
11183
+ },
11184
+ onError: (error) => {
11185
+ toast.error(error.message);
11186
+ }
11187
+ }
11188
+ );
11189
+ });
11190
+ const { fields, insert, remove } = useFieldArray({
11191
+ control: form.control,
11192
+ name: "metadata"
11193
+ });
11194
+ function deleteRow(index) {
11195
+ remove(index);
11196
+ if (fields.length === 1) {
11197
+ insert(0, {
11198
+ key: "",
11199
+ value: "",
11200
+ disabled: false
11201
+ });
11202
+ }
11203
+ }
11204
+ function insertRow(index, position) {
11205
+ insert(index + (position === "above" ? 0 : 1), {
11206
+ key: "",
11207
+ value: "",
11208
+ disabled: false
11209
+ });
11210
+ }
11211
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11212
+ KeyboundForm,
11213
+ {
11214
+ onSubmit: handleSubmit,
11215
+ className: "flex flex-1 flex-col overflow-hidden",
11373
11216
  children: [
11374
- /* @__PURE__ */ jsxs("div", { children: [
11375
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11217
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11218
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11219
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11220
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11221
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11380
11222
  ] }),
11381
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
- ] })
11223
+ fields.map((field, index) => {
11224
+ const isDisabled = field.disabled || false;
11225
+ let placeholder = "-";
11226
+ if (typeof field.value === "object") {
11227
+ placeholder = "{ ... }";
11228
+ }
11229
+ if (Array.isArray(field.value)) {
11230
+ placeholder = "[ ... ]";
11231
+ }
11232
+ return /* @__PURE__ */ jsx(
11233
+ ConditionalTooltip,
11234
+ {
11235
+ showTooltip: isDisabled,
11236
+ content: "This row is disabled because it contains non-primitive data.",
11237
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11238
+ /* @__PURE__ */ jsxs(
11239
+ "div",
11240
+ {
11241
+ className: clx("grid grid-cols-2 divide-x", {
11242
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11243
+ }),
11244
+ children: [
11245
+ /* @__PURE__ */ jsx(
11246
+ Form$2.Field,
11247
+ {
11248
+ control: form.control,
11249
+ name: `metadata.${index}.key`,
11250
+ render: ({ field: field2 }) => {
11251
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11252
+ GridInput,
11253
+ {
11254
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11255
+ ...field2,
11256
+ disabled: isDisabled,
11257
+ placeholder: "Key"
11258
+ }
11259
+ ) }) });
11260
+ }
11261
+ }
11262
+ ),
11263
+ /* @__PURE__ */ jsx(
11264
+ Form$2.Field,
11265
+ {
11266
+ control: form.control,
11267
+ name: `metadata.${index}.value`,
11268
+ render: ({ field: { value, ...field2 } }) => {
11269
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11270
+ GridInput,
11271
+ {
11272
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11273
+ ...field2,
11274
+ value: isDisabled ? placeholder : value,
11275
+ disabled: isDisabled,
11276
+ placeholder: "Value"
11277
+ }
11278
+ ) }) });
11279
+ }
11280
+ }
11281
+ )
11282
+ ]
11283
+ }
11284
+ ),
11285
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11286
+ /* @__PURE__ */ jsx(
11287
+ DropdownMenu.Trigger,
11288
+ {
11289
+ className: clx(
11290
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11291
+ {
11292
+ hidden: isDisabled
11293
+ }
11294
+ ),
11295
+ disabled: isDisabled,
11296
+ asChild: true,
11297
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11298
+ }
11299
+ ),
11300
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11301
+ /* @__PURE__ */ jsxs(
11302
+ DropdownMenu.Item,
11303
+ {
11304
+ className: "gap-x-2",
11305
+ onClick: () => insertRow(index, "above"),
11306
+ children: [
11307
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11308
+ "Insert row above"
11309
+ ]
11310
+ }
11311
+ ),
11312
+ /* @__PURE__ */ jsxs(
11313
+ DropdownMenu.Item,
11314
+ {
11315
+ className: "gap-x-2",
11316
+ onClick: () => insertRow(index, "below"),
11317
+ children: [
11318
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11319
+ "Insert row below"
11320
+ ]
11321
+ }
11322
+ ),
11323
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11324
+ /* @__PURE__ */ jsxs(
11325
+ DropdownMenu.Item,
11326
+ {
11327
+ className: "gap-x-2",
11328
+ onClick: () => deleteRow(index),
11329
+ children: [
11330
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11331
+ "Delete row"
11332
+ ]
11333
+ }
11334
+ )
11335
+ ] })
11336
+ ] })
11337
+ ] })
11338
+ },
11339
+ field.id
11340
+ );
11341
+ })
11342
+ ] }),
11343
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11383
11344
  ] }),
11384
- /* @__PURE__ */ jsx(
11385
- IconButton,
11386
- {
11387
- size: "small",
11388
- type: "button",
11389
- variant: "transparent",
11390
- onClick: onRemove,
11391
- isLoading: isPending || isLoading,
11392
- children: /* @__PURE__ */ jsx(XMark, {})
11393
- }
11394
- )
11345
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11346
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11347
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11348
+ ] }) })
11395
11349
  ]
11396
- },
11397
- promotion.id
11398
- );
11350
+ }
11351
+ ) });
11399
11352
  };
11400
- function getDisplayValue(promotion) {
11401
- var _a, _b, _c, _d;
11402
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
- if (!value) {
11404
- return null;
11405
- }
11406
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
- if (!currency) {
11409
- return null;
11353
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11354
+ return /* @__PURE__ */ jsx(
11355
+ "input",
11356
+ {
11357
+ ref,
11358
+ ...props,
11359
+ autoComplete: "off",
11360
+ className: clx(
11361
+ "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",
11362
+ className
11363
+ )
11410
11364
  }
11411
- return getLocaleAmount(value, currency);
11412
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
- return formatPercentage(value);
11414
- }
11415
- return null;
11416
- }
11417
- const formatter = new Intl.NumberFormat([], {
11418
- style: "percent",
11419
- minimumFractionDigits: 2
11365
+ );
11420
11366
  });
11421
- const formatPercentage = (value, isPercentageValue = false) => {
11422
- let val = value || 0;
11423
- if (!isPercentageValue) {
11424
- val = val / 100;
11425
- }
11426
- return formatter.format(val);
11367
+ GridInput.displayName = "MetadataForm.GridInput";
11368
+ const PlaceholderInner = () => {
11369
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11370
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11371
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11372
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11373
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11374
+ ] }) })
11375
+ ] });
11427
11376
  };
11428
- function getPromotionIds(items, shippingMethods) {
11429
- const promotionIds = /* @__PURE__ */ new Set();
11430
- for (const item of items) {
11431
- if (item.adjustments) {
11432
- for (const adjustment of item.adjustments) {
11433
- if (adjustment.promotion_id) {
11434
- promotionIds.add(adjustment.promotion_id);
11435
- }
11377
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11378
+ function getDefaultValues(metadata) {
11379
+ if (!metadata || !Object.keys(metadata).length) {
11380
+ return [
11381
+ {
11382
+ key: "",
11383
+ value: "",
11384
+ disabled: false
11436
11385
  }
11386
+ ];
11387
+ }
11388
+ return Object.entries(metadata).map(([key, value]) => {
11389
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11390
+ return {
11391
+ key,
11392
+ value,
11393
+ disabled: true
11394
+ };
11437
11395
  }
11396
+ let stringValue = value;
11397
+ if (typeof value !== "string") {
11398
+ stringValue = JSON.stringify(value);
11399
+ }
11400
+ return {
11401
+ key,
11402
+ value: stringValue,
11403
+ original_key: key
11404
+ };
11405
+ });
11406
+ }
11407
+ function parseValues(values) {
11408
+ const metadata = values.metadata;
11409
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11410
+ if (isEmpty) {
11411
+ return null;
11438
11412
  }
11439
- for (const shippingMethod of shippingMethods) {
11440
- if (shippingMethod.adjustments) {
11441
- for (const adjustment of shippingMethod.adjustments) {
11442
- if (adjustment.promotion_id) {
11443
- promotionIds.add(adjustment.promotion_id);
11444
- }
11413
+ const update = {};
11414
+ metadata.forEach((field) => {
11415
+ let key = field.key;
11416
+ let value = field.value;
11417
+ const disabled = field.disabled;
11418
+ if (!key || !value) {
11419
+ return;
11420
+ }
11421
+ if (disabled) {
11422
+ update[key] = value;
11423
+ return;
11424
+ }
11425
+ key = key.trim();
11426
+ value = value.trim();
11427
+ if (value === "true") {
11428
+ update[key] = true;
11429
+ } else if (value === "false") {
11430
+ update[key] = false;
11431
+ } else {
11432
+ const parsedNumber = parseFloat(value);
11433
+ if (!isNaN(parsedNumber)) {
11434
+ update[key] = parsedNumber;
11435
+ } else {
11436
+ update[key] = value;
11445
11437
  }
11446
11438
  }
11439
+ });
11440
+ return update;
11441
+ }
11442
+ function getHasUneditableRows(metadata) {
11443
+ if (!metadata) {
11444
+ return false;
11447
11445
  }
11448
- return Array.from(promotionIds);
11446
+ return Object.values(metadata).some(
11447
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11448
+ );
11449
11449
  }
11450
11450
  const SalesChannel = () => {
11451
11451
  const { id } = useParams();
@@ -12343,226 +12343,23 @@ const CustomAmountField = ({
12343
12343
  render: ({ field: { onChange, ...field } }) => {
12344
12344
  return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
12345
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
- ] }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
- CurrencyInput,
12351
- {
12352
- ...field,
12353
- onValueChange: (value) => onChange(value),
12354
- symbol: getNativeSymbol(currencyCode),
12355
- code: currencyCode
12356
- }
12357
- ) })
12358
- ] });
12359
- }
12360
- }
12361
- );
12362
- };
12363
- const ShippingAddress = () => {
12364
- const { id } = useParams();
12365
- const { order, isPending, isError, error } = useOrder(id, {
12366
- fields: "+shipping_address"
12367
- });
12368
- if (isError) {
12369
- throw error;
12370
- }
12371
- const isReady = !isPending && !!order;
12372
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
- ] }),
12377
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
- ] });
12379
- };
12380
- const ShippingAddressForm = ({ order }) => {
12381
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12382
- const form = useForm({
12383
- defaultValues: {
12384
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
- },
12395
- resolver: zodResolver(schema$1)
12396
- });
12397
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
- const { handleSuccess } = useRouteModal();
12399
- const onSubmit = form.handleSubmit(async (data) => {
12400
- await mutateAsync(
12401
- {
12402
- shipping_address: {
12403
- first_name: data.first_name,
12404
- last_name: data.last_name,
12405
- company: data.company,
12406
- address_1: data.address_1,
12407
- address_2: data.address_2,
12408
- city: data.city,
12409
- province: data.province,
12410
- country_code: data.country_code,
12411
- postal_code: data.postal_code,
12412
- phone: data.phone
12413
- }
12414
- },
12415
- {
12416
- onSuccess: () => {
12417
- handleSuccess();
12418
- },
12419
- onError: (error) => {
12420
- toast.error(error.message);
12421
- }
12422
- }
12423
- );
12424
- });
12425
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
- KeyboundForm,
12427
- {
12428
- className: "flex flex-1 flex-col overflow-hidden",
12429
- onSubmit,
12430
- children: [
12431
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "country_code",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
- /* @__PURE__ */ jsx(
12446
- Form$2.Field,
12447
- {
12448
- control: form.control,
12449
- name: "first_name",
12450
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
- ] })
12455
- }
12456
- ),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "last_name",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- )
12469
- ] }),
12470
- /* @__PURE__ */ jsx(
12471
- Form$2.Field,
12472
- {
12473
- control: form.control,
12474
- name: "company",
12475
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
- ] })
12480
- }
12481
- ),
12482
- /* @__PURE__ */ jsx(
12483
- Form$2.Field,
12484
- {
12485
- control: form.control,
12486
- name: "address_1",
12487
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
- ] })
12492
- }
12493
- ),
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "address_2",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
- /* @__PURE__ */ jsx(
12508
- Form$2.Field,
12509
- {
12510
- control: form.control,
12511
- name: "postal_code",
12512
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
- ] })
12517
- }
12518
- ),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "city",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- )
12531
- ] }),
12532
- /* @__PURE__ */ jsx(
12533
- Form$2.Field,
12534
- {
12535
- control: form.control,
12536
- name: "province",
12537
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
- ] })
12542
- }
12543
- ),
12544
- /* @__PURE__ */ jsx(
12545
- Form$2.Field,
12346
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
+ ] }),
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
+ CurrencyInput,
12546
12351
  {
12547
- control: form.control,
12548
- name: "phone",
12549
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
- ] })
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12554
12356
  }
12555
- )
12556
- ] }) }),
12557
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
- ] }) })
12561
- ]
12357
+ ) })
12358
+ ] });
12359
+ }
12562
12360
  }
12563
- ) });
12361
+ );
12564
12362
  };
12565
- const schema$1 = addressSchema;
12566
12363
  const TransferOwnership = () => {
12567
12364
  const { id } = useParams();
12568
12365
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12586,7 +12383,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
12383
  defaultValues: {
12587
12384
  customer_id: order.customer_id || ""
12588
12385
  },
12589
- resolver: zodResolver(schema)
12386
+ resolver: zodResolver(schema$1)
12590
12387
  });
12591
12388
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
12389
  const { handleSuccess } = useRouteModal();
@@ -13036,9 +12833,212 @@ const Illustration = () => {
13036
12833
  }
13037
12834
  );
13038
12835
  };
13039
- const schema = objectType({
12836
+ const schema$1 = objectType({
13040
12837
  customer_id: stringType().min(1)
13041
12838
  });
12839
+ const ShippingAddress = () => {
12840
+ const { id } = useParams();
12841
+ const { order, isPending, isError, error } = useOrder(id, {
12842
+ fields: "+shipping_address"
12843
+ });
12844
+ if (isError) {
12845
+ throw error;
12846
+ }
12847
+ const isReady = !isPending && !!order;
12848
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12851
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12852
+ ] }),
12853
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12854
+ ] });
12855
+ };
12856
+ const ShippingAddressForm = ({ order }) => {
12857
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
+ const form = useForm({
12859
+ defaultValues: {
12860
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12861
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12862
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12863
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12864
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12865
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12866
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12867
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12868
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12869
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12870
+ },
12871
+ resolver: zodResolver(schema)
12872
+ });
12873
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12874
+ const { handleSuccess } = useRouteModal();
12875
+ const onSubmit = form.handleSubmit(async (data) => {
12876
+ await mutateAsync(
12877
+ {
12878
+ shipping_address: {
12879
+ first_name: data.first_name,
12880
+ last_name: data.last_name,
12881
+ company: data.company,
12882
+ address_1: data.address_1,
12883
+ address_2: data.address_2,
12884
+ city: data.city,
12885
+ province: data.province,
12886
+ country_code: data.country_code,
12887
+ postal_code: data.postal_code,
12888
+ phone: data.phone
12889
+ }
12890
+ },
12891
+ {
12892
+ onSuccess: () => {
12893
+ handleSuccess();
12894
+ },
12895
+ onError: (error) => {
12896
+ toast.error(error.message);
12897
+ }
12898
+ }
12899
+ );
12900
+ });
12901
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
+ KeyboundForm,
12903
+ {
12904
+ className: "flex flex-1 flex-col overflow-hidden",
12905
+ onSubmit,
12906
+ children: [
12907
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "country_code",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
+ /* @__PURE__ */ jsx(
12922
+ Form$2.Field,
12923
+ {
12924
+ control: form.control,
12925
+ name: "first_name",
12926
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
+ ] })
12931
+ }
12932
+ ),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "last_name",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ )
12945
+ ] }),
12946
+ /* @__PURE__ */ jsx(
12947
+ Form$2.Field,
12948
+ {
12949
+ control: form.control,
12950
+ name: "company",
12951
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
+ ] })
12956
+ }
12957
+ ),
12958
+ /* @__PURE__ */ jsx(
12959
+ Form$2.Field,
12960
+ {
12961
+ control: form.control,
12962
+ name: "address_1",
12963
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
+ ] })
12968
+ }
12969
+ ),
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "address_2",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
+ /* @__PURE__ */ jsx(
12984
+ Form$2.Field,
12985
+ {
12986
+ control: form.control,
12987
+ name: "postal_code",
12988
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
+ ] })
12993
+ }
12994
+ ),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "city",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ )
13007
+ ] }),
13008
+ /* @__PURE__ */ jsx(
13009
+ Form$2.Field,
13010
+ {
13011
+ control: form.control,
13012
+ name: "province",
13013
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
+ ] })
13018
+ }
13019
+ ),
13020
+ /* @__PURE__ */ jsx(
13021
+ Form$2.Field,
13022
+ {
13023
+ control: form.control,
13024
+ name: "phone",
13025
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
+ ] })
13030
+ }
13031
+ )
13032
+ ] }) }),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
+ ] }) })
13037
+ ]
13038
+ }
13039
+ ) });
13040
+ };
13041
+ const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,21 +13059,17 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
13062
  {
13067
13063
  Component: CustomItems,
13068
13064
  path: "/draft-orders/:id/custom-items"
13069
13065
  },
13070
13066
  {
13071
- Component: Email,
13072
- path: "/draft-orders/:id/email"
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13073
13069
  },
13074
13070
  {
13075
- Component: Metadata,
13076
- path: "/draft-orders/:id/metadata"
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13077
13073
  },
13078
13074
  {
13079
13075
  Component: Items,
@@ -13083,6 +13079,10 @@ const routeModule = {
13083
13079
  Component: Promotions,
13084
13080
  path: "/draft-orders/:id/promotions"
13085
13081
  },
13082
+ {
13083
+ Component: Metadata,
13084
+ path: "/draft-orders/:id/metadata"
13085
+ },
13086
13086
  {
13087
13087
  Component: SalesChannel,
13088
13088
  path: "/draft-orders/:id/sales-channel"
@@ -13091,13 +13091,13 @@ const routeModule = {
13091
13091
  Component: Shipping,
13092
13092
  path: "/draft-orders/:id/shipping"
13093
13093
  },
13094
- {
13095
- Component: ShippingAddress,
13096
- path: "/draft-orders/:id/shipping-address"
13097
- },
13098
13094
  {
13099
13095
  Component: TransferOwnership,
13100
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
+ },
13098
+ {
13099
+ Component: ShippingAddress,
13100
+ path: "/draft-orders/:id/shipping-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }