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