@medusajs/draft-order 2.10.0-snapshot-20250828080217 → 2.10.0-snapshot-20250828112445

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.
@@ -9560,27 +9560,6 @@ const ID = () => {
9560
9560
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9561
9561
  ] });
9562
9562
  };
9563
- const CustomItems = () => {
9564
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9565
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9566
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9567
- ] });
9568
- };
9569
- const CustomItemsForm = () => {
9570
- const form = reactHookForm.useForm({
9571
- resolver: zod.zodResolver(schema$5)
9572
- });
9573
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9574
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9575
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9576
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9577
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9578
- ] }) })
9579
- ] }) });
9580
- };
9581
- const schema$5 = objectType({
9582
- email: stringType().email()
9583
- });
9584
9563
  const BillingAddress = () => {
9585
9564
  const { id } = reactRouterDom.useParams();
9586
9565
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9613,7 +9592,7 @@ const BillingAddressForm = ({ order }) => {
9613
9592
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9614
9593
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9615
9594
  },
9616
- resolver: zod.zodResolver(schema$4)
9595
+ resolver: zod.zodResolver(schema$5)
9617
9596
  });
9618
9597
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9619
9598
  const { handleSuccess } = useRouteModal();
@@ -9770,11 +9749,76 @@ const BillingAddressForm = ({ order }) => {
9770
9749
  }
9771
9750
  ) });
9772
9751
  };
9773
- const schema$4 = addressSchema;
9774
- const Email = () => {
9752
+ const schema$5 = addressSchema;
9753
+ const CustomItems = () => {
9754
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9756
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9757
+ ] });
9758
+ };
9759
+ const CustomItemsForm = () => {
9760
+ const form = reactHookForm.useForm({
9761
+ resolver: zod.zodResolver(schema$4)
9762
+ });
9763
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9764
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9765
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9766
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9767
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9768
+ ] }) })
9769
+ ] }) });
9770
+ };
9771
+ const schema$4 = objectType({
9772
+ email: stringType().email()
9773
+ });
9774
+ const InlineTip = React.forwardRef(
9775
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9776
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9777
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9778
+ "div",
9779
+ {
9780
+ ref,
9781
+ className: ui.clx(
9782
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9783
+ className
9784
+ ),
9785
+ ...props,
9786
+ children: [
9787
+ /* @__PURE__ */ jsxRuntime.jsx(
9788
+ "div",
9789
+ {
9790
+ role: "presentation",
9791
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9792
+ "bg-ui-tag-orange-icon": variant === "warning"
9793
+ })
9794
+ }
9795
+ ),
9796
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9798
+ labelValue,
9799
+ ":"
9800
+ ] }),
9801
+ " ",
9802
+ children
9803
+ ] })
9804
+ ]
9805
+ }
9806
+ );
9807
+ }
9808
+ );
9809
+ InlineTip.displayName = "InlineTip";
9810
+ const MetadataFieldSchema = objectType({
9811
+ key: stringType(),
9812
+ disabled: booleanType().optional(),
9813
+ value: anyType()
9814
+ });
9815
+ const MetadataSchema = objectType({
9816
+ metadata: arrayType(MetadataFieldSchema)
9817
+ });
9818
+ const Metadata = () => {
9775
9819
  const { id } = reactRouterDom.useParams();
9776
9820
  const { order, isPending, isError, error } = useOrder(id, {
9777
- fields: "+email"
9821
+ fields: "metadata"
9778
9822
  });
9779
9823
  if (isError) {
9780
9824
  throw error;
@@ -9782,26 +9826,33 @@ const Email = () => {
9782
9826
  const isReady = !isPending && !!order;
9783
9827
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9784
9828
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9785
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9786
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9829
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9830
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9787
9831
  ] }),
9788
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9832
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9789
9833
  ] });
9790
9834
  };
9791
- const EmailForm = ({ order }) => {
9835
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9836
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9837
+ const MetadataForm = ({ orderId, metadata }) => {
9838
+ const { handleSuccess } = useRouteModal();
9839
+ const hasUneditableRows = getHasUneditableRows(metadata);
9840
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9792
9841
  const form = reactHookForm.useForm({
9793
9842
  defaultValues: {
9794
- email: order.email ?? ""
9843
+ metadata: getDefaultValues(metadata)
9795
9844
  },
9796
- resolver: zod.zodResolver(schema$3)
9845
+ resolver: zod.zodResolver(MetadataSchema)
9797
9846
  });
9798
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9799
- const { handleSuccess } = useRouteModal();
9800
- const onSubmit = form.handleSubmit(async (data) => {
9847
+ const handleSubmit = form.handleSubmit(async (data) => {
9848
+ const parsedData = parseValues(data);
9801
9849
  await mutateAsync(
9802
- { email: data.email },
9850
+ {
9851
+ metadata: parsedData
9852
+ },
9803
9853
  {
9804
9854
  onSuccess: () => {
9855
+ ui.toast.success("Metadata updated");
9805
9856
  handleSuccess();
9806
9857
  },
9807
9858
  onError: (error) => {
@@ -9810,113 +9861,344 @@ const EmailForm = ({ order }) => {
9810
9861
  }
9811
9862
  );
9812
9863
  });
9864
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9865
+ control: form.control,
9866
+ name: "metadata"
9867
+ });
9868
+ function deleteRow(index) {
9869
+ remove(index);
9870
+ if (fields.length === 1) {
9871
+ insert(0, {
9872
+ key: "",
9873
+ value: "",
9874
+ disabled: false
9875
+ });
9876
+ }
9877
+ }
9878
+ function insertRow(index, position) {
9879
+ insert(index + (position === "above" ? 0 : 1), {
9880
+ key: "",
9881
+ value: "",
9882
+ disabled: false
9883
+ });
9884
+ }
9813
9885
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9814
9886
  KeyboundForm,
9815
9887
  {
9888
+ onSubmit: handleSubmit,
9816
9889
  className: "flex flex-1 flex-col overflow-hidden",
9817
- onSubmit,
9818
9890
  children: [
9819
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9820
- Form$2.Field,
9821
- {
9822
- control: form.control,
9823
- name: "email",
9824
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9826
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
- ] })
9829
- }
9830
- ) }),
9831
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9833
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9834
- ] }) })
9835
- ]
9836
- }
9837
- ) });
9838
- };
9839
- const schema$3 = objectType({
9840
- email: stringType().email()
9841
- });
9842
- const NumberInput = React.forwardRef(
9843
- ({
9844
- value,
9845
- onChange,
9846
- size = "base",
9847
- min = 0,
9848
- max = 100,
9849
- step = 1,
9850
- className,
9851
- disabled,
9852
- ...props
9853
- }, ref) => {
9854
- const handleChange = (event) => {
9855
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9856
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9857
- onChange(newValue);
9858
- }
9859
- };
9860
- const handleIncrement = () => {
9861
- const newValue = value + step;
9862
- if (max === void 0 || newValue <= max) {
9863
- onChange(newValue);
9864
- }
9865
- };
9866
- const handleDecrement = () => {
9867
- const newValue = value - step;
9868
- if (min === void 0 || newValue >= min) {
9869
- onChange(newValue);
9870
- }
9871
- };
9872
- return /* @__PURE__ */ jsxRuntime.jsxs(
9873
- "div",
9874
- {
9875
- className: ui.clx(
9876
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9877
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9878
- {
9879
- "h-7": size === "small",
9880
- "h-8": size === "base"
9881
- },
9882
- className
9883
- ),
9884
- children: [
9885
- /* @__PURE__ */ jsxRuntime.jsx(
9886
- "input",
9887
- {
9888
- ref,
9889
- type: "number",
9890
- value,
9891
- onChange: handleChange,
9892
- min,
9893
- max,
9894
- step,
9895
- className: ui.clx(
9896
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9897
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9898
- "placeholder:text-ui-fg-muted"
9899
- ),
9900
- ...props
9901
- }
9902
- ),
9903
- /* @__PURE__ */ jsxRuntime.jsxs(
9904
- "button",
9905
- {
9906
- className: ui.clx(
9907
- "flex items-center justify-center outline-none transition-fg",
9908
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9909
- "focus:bg-ui-bg-field-component-hover",
9910
- "hover:bg-ui-bg-field-component-hover",
9891
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9892
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9893
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9894
+ /* @__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" }) }),
9895
+ /* @__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" }) })
9896
+ ] }),
9897
+ fields.map((field, index) => {
9898
+ const isDisabled = field.disabled || false;
9899
+ let placeholder = "-";
9900
+ if (typeof field.value === "object") {
9901
+ placeholder = "{ ... }";
9902
+ }
9903
+ if (Array.isArray(field.value)) {
9904
+ placeholder = "[ ... ]";
9905
+ }
9906
+ return /* @__PURE__ */ jsxRuntime.jsx(
9907
+ ConditionalTooltip,
9911
9908
  {
9912
- "size-7": size === "small",
9913
- "size-8": size === "base"
9914
- }
9915
- ),
9916
- type: "button",
9917
- onClick: handleDecrement,
9918
- disabled: min !== void 0 && value <= min || disabled,
9919
- children: [
9909
+ showTooltip: isDisabled,
9910
+ content: "This row is disabled because it contains non-primitive data.",
9911
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9912
+ /* @__PURE__ */ jsxRuntime.jsxs(
9913
+ "div",
9914
+ {
9915
+ className: ui.clx("grid grid-cols-2 divide-x", {
9916
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9917
+ }),
9918
+ children: [
9919
+ /* @__PURE__ */ jsxRuntime.jsx(
9920
+ Form$2.Field,
9921
+ {
9922
+ control: form.control,
9923
+ name: `metadata.${index}.key`,
9924
+ render: ({ field: field2 }) => {
9925
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9926
+ GridInput,
9927
+ {
9928
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9929
+ ...field2,
9930
+ disabled: isDisabled,
9931
+ placeholder: "Key"
9932
+ }
9933
+ ) }) });
9934
+ }
9935
+ }
9936
+ ),
9937
+ /* @__PURE__ */ jsxRuntime.jsx(
9938
+ Form$2.Field,
9939
+ {
9940
+ control: form.control,
9941
+ name: `metadata.${index}.value`,
9942
+ render: ({ field: { value, ...field2 } }) => {
9943
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9944
+ GridInput,
9945
+ {
9946
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9947
+ ...field2,
9948
+ value: isDisabled ? placeholder : value,
9949
+ disabled: isDisabled,
9950
+ placeholder: "Value"
9951
+ }
9952
+ ) }) });
9953
+ }
9954
+ }
9955
+ )
9956
+ ]
9957
+ }
9958
+ ),
9959
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9960
+ /* @__PURE__ */ jsxRuntime.jsx(
9961
+ ui.DropdownMenu.Trigger,
9962
+ {
9963
+ className: ui.clx(
9964
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9965
+ {
9966
+ hidden: isDisabled
9967
+ }
9968
+ ),
9969
+ disabled: isDisabled,
9970
+ asChild: true,
9971
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9972
+ }
9973
+ ),
9974
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9975
+ /* @__PURE__ */ jsxRuntime.jsxs(
9976
+ ui.DropdownMenu.Item,
9977
+ {
9978
+ className: "gap-x-2",
9979
+ onClick: () => insertRow(index, "above"),
9980
+ children: [
9981
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9982
+ "Insert row above"
9983
+ ]
9984
+ }
9985
+ ),
9986
+ /* @__PURE__ */ jsxRuntime.jsxs(
9987
+ ui.DropdownMenu.Item,
9988
+ {
9989
+ className: "gap-x-2",
9990
+ onClick: () => insertRow(index, "below"),
9991
+ children: [
9992
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9993
+ "Insert row below"
9994
+ ]
9995
+ }
9996
+ ),
9997
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9998
+ /* @__PURE__ */ jsxRuntime.jsxs(
9999
+ ui.DropdownMenu.Item,
10000
+ {
10001
+ className: "gap-x-2",
10002
+ onClick: () => deleteRow(index),
10003
+ children: [
10004
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10005
+ "Delete row"
10006
+ ]
10007
+ }
10008
+ )
10009
+ ] })
10010
+ ] })
10011
+ ] })
10012
+ },
10013
+ field.id
10014
+ );
10015
+ })
10016
+ ] }),
10017
+ 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." })
10018
+ ] }),
10019
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10020
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10021
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10022
+ ] }) })
10023
+ ]
10024
+ }
10025
+ ) });
10026
+ };
10027
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10028
+ return /* @__PURE__ */ jsxRuntime.jsx(
10029
+ "input",
10030
+ {
10031
+ ref,
10032
+ ...props,
10033
+ autoComplete: "off",
10034
+ className: ui.clx(
10035
+ "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",
10036
+ className
10037
+ )
10038
+ }
10039
+ );
10040
+ });
10041
+ GridInput.displayName = "MetadataForm.GridInput";
10042
+ const PlaceholderInner = () => {
10043
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10044
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10045
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10046
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10047
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10048
+ ] }) })
10049
+ ] });
10050
+ };
10051
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10052
+ function getDefaultValues(metadata) {
10053
+ if (!metadata || !Object.keys(metadata).length) {
10054
+ return [
10055
+ {
10056
+ key: "",
10057
+ value: "",
10058
+ disabled: false
10059
+ }
10060
+ ];
10061
+ }
10062
+ return Object.entries(metadata).map(([key, value]) => {
10063
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10064
+ return {
10065
+ key,
10066
+ value,
10067
+ disabled: true
10068
+ };
10069
+ }
10070
+ let stringValue = value;
10071
+ if (typeof value !== "string") {
10072
+ stringValue = JSON.stringify(value);
10073
+ }
10074
+ return {
10075
+ key,
10076
+ value: stringValue,
10077
+ original_key: key
10078
+ };
10079
+ });
10080
+ }
10081
+ function parseValues(values) {
10082
+ const metadata = values.metadata;
10083
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10084
+ if (isEmpty) {
10085
+ return null;
10086
+ }
10087
+ const update = {};
10088
+ metadata.forEach((field) => {
10089
+ let key = field.key;
10090
+ let value = field.value;
10091
+ const disabled = field.disabled;
10092
+ if (!key || !value) {
10093
+ return;
10094
+ }
10095
+ if (disabled) {
10096
+ update[key] = value;
10097
+ return;
10098
+ }
10099
+ key = key.trim();
10100
+ value = value.trim();
10101
+ if (value === "true") {
10102
+ update[key] = true;
10103
+ } else if (value === "false") {
10104
+ update[key] = false;
10105
+ } else {
10106
+ const parsedNumber = parseFloat(value);
10107
+ if (!isNaN(parsedNumber)) {
10108
+ update[key] = parsedNumber;
10109
+ } else {
10110
+ update[key] = value;
10111
+ }
10112
+ }
10113
+ });
10114
+ return update;
10115
+ }
10116
+ function getHasUneditableRows(metadata) {
10117
+ if (!metadata) {
10118
+ return false;
10119
+ }
10120
+ return Object.values(metadata).some(
10121
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10122
+ );
10123
+ }
10124
+ const NumberInput = React.forwardRef(
10125
+ ({
10126
+ value,
10127
+ onChange,
10128
+ size = "base",
10129
+ min = 0,
10130
+ max = 100,
10131
+ step = 1,
10132
+ className,
10133
+ disabled,
10134
+ ...props
10135
+ }, ref) => {
10136
+ const handleChange = (event) => {
10137
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10138
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10139
+ onChange(newValue);
10140
+ }
10141
+ };
10142
+ const handleIncrement = () => {
10143
+ const newValue = value + step;
10144
+ if (max === void 0 || newValue <= max) {
10145
+ onChange(newValue);
10146
+ }
10147
+ };
10148
+ const handleDecrement = () => {
10149
+ const newValue = value - step;
10150
+ if (min === void 0 || newValue >= min) {
10151
+ onChange(newValue);
10152
+ }
10153
+ };
10154
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10155
+ "div",
10156
+ {
10157
+ className: ui.clx(
10158
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10159
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10160
+ {
10161
+ "h-7": size === "small",
10162
+ "h-8": size === "base"
10163
+ },
10164
+ className
10165
+ ),
10166
+ children: [
10167
+ /* @__PURE__ */ jsxRuntime.jsx(
10168
+ "input",
10169
+ {
10170
+ ref,
10171
+ type: "number",
10172
+ value,
10173
+ onChange: handleChange,
10174
+ min,
10175
+ max,
10176
+ step,
10177
+ className: ui.clx(
10178
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10179
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10180
+ "placeholder:text-ui-fg-muted"
10181
+ ),
10182
+ ...props
10183
+ }
10184
+ ),
10185
+ /* @__PURE__ */ jsxRuntime.jsxs(
10186
+ "button",
10187
+ {
10188
+ className: ui.clx(
10189
+ "flex items-center justify-center outline-none transition-fg",
10190
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10191
+ "focus:bg-ui-bg-field-component-hover",
10192
+ "hover:bg-ui-bg-field-component-hover",
10193
+ {
10194
+ "size-7": size === "small",
10195
+ "size-8": size === "base"
10196
+ }
10197
+ ),
10198
+ type: "button",
10199
+ onClick: handleDecrement,
10200
+ disabled: min !== void 0 && value <= min || disabled,
10201
+ children: [
9920
10202
  /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9921
10203
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9922
10204
  ]
@@ -10695,474 +10977,124 @@ const useColumns = () => {
10695
10977
  },
10696
10978
  enableSorting: true,
10697
10979
  sortAscLabel: "Oldest first",
10698
- sortDescLabel: "Newest first"
10699
- })
10700
- ];
10701
- }, []);
10702
- };
10703
- const CustomItemForm = ({ orderId, currencyCode }) => {
10704
- const { setIsOpen } = useStackedModal();
10705
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10706
- const form = reactHookForm.useForm({
10707
- defaultValues: {
10708
- title: "",
10709
- quantity: 1,
10710
- unit_price: ""
10711
- },
10712
- resolver: zod.zodResolver(customItemSchema)
10713
- });
10714
- const onSubmit = form.handleSubmit(async (data) => {
10715
- await addItems(
10716
- {
10717
- items: [
10718
- {
10719
- title: data.title,
10720
- quantity: data.quantity,
10721
- unit_price: convertNumber(data.unit_price)
10722
- }
10723
- ]
10724
- },
10725
- {
10726
- onSuccess: () => {
10727
- setIsOpen(STACKED_MODAL_ID, false);
10728
- },
10729
- onError: (e) => {
10730
- ui.toast.error(e.message);
10731
- }
10732
- }
10733
- );
10734
- });
10735
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10736
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10737
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10738
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10739
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10740
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10741
- ] }),
10742
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10743
- /* @__PURE__ */ jsxRuntime.jsx(
10744
- Form$2.Field,
10745
- {
10746
- control: form.control,
10747
- name: "title",
10748
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10749
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10752
- ] }),
10753
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10754
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10755
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10756
- ] })
10757
- ] }) })
10758
- }
10759
- ),
10760
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10761
- /* @__PURE__ */ jsxRuntime.jsx(
10762
- Form$2.Field,
10763
- {
10764
- control: form.control,
10765
- name: "unit_price",
10766
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10767
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10768
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10769
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10770
- ] }),
10771
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10772
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10773
- ui.CurrencyInput,
10774
- {
10775
- symbol: getNativeSymbol(currencyCode),
10776
- code: currencyCode,
10777
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10778
- ...field
10779
- }
10780
- ) }),
10781
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10782
- ] })
10783
- ] }) })
10784
- }
10785
- ),
10786
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10787
- /* @__PURE__ */ jsxRuntime.jsx(
10788
- Form$2.Field,
10789
- {
10790
- control: form.control,
10791
- name: "quantity",
10792
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10793
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10794
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10795
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10796
- ] }),
10797
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
10798
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10799
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10800
- ] })
10801
- ] }) })
10802
- }
10803
- )
10804
- ] }) }) }),
10805
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10806
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10807
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10808
- ] }) })
10809
- ] }) }) });
10810
- };
10811
- const customItemSchema = objectType({
10812
- title: stringType().min(1),
10813
- quantity: numberType(),
10814
- unit_price: unionType([numberType(), stringType()])
10815
- });
10816
- const InlineTip = React.forwardRef(
10817
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10818
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10819
- return /* @__PURE__ */ jsxRuntime.jsxs(
10820
- "div",
10821
- {
10822
- ref,
10823
- className: ui.clx(
10824
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10825
- className
10826
- ),
10827
- ...props,
10828
- children: [
10829
- /* @__PURE__ */ jsxRuntime.jsx(
10830
- "div",
10831
- {
10832
- role: "presentation",
10833
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10834
- "bg-ui-tag-orange-icon": variant === "warning"
10835
- })
10836
- }
10837
- ),
10838
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10839
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10840
- labelValue,
10841
- ":"
10842
- ] }),
10843
- " ",
10844
- children
10845
- ] })
10846
- ]
10847
- }
10848
- );
10849
- }
10850
- );
10851
- InlineTip.displayName = "InlineTip";
10852
- const MetadataFieldSchema = objectType({
10853
- key: stringType(),
10854
- disabled: booleanType().optional(),
10855
- value: anyType()
10856
- });
10857
- const MetadataSchema = objectType({
10858
- metadata: arrayType(MetadataFieldSchema)
10859
- });
10860
- const Metadata = () => {
10861
- const { id } = reactRouterDom.useParams();
10862
- const { order, isPending, isError, error } = useOrder(id, {
10863
- fields: "metadata"
10864
- });
10865
- if (isError) {
10866
- throw error;
10867
- }
10868
- const isReady = !isPending && !!order;
10869
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10870
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10871
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10872
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10873
- ] }),
10874
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10875
- ] });
10876
- };
10877
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10878
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10879
- const MetadataForm = ({ orderId, metadata }) => {
10880
- const { handleSuccess } = useRouteModal();
10881
- const hasUneditableRows = getHasUneditableRows(metadata);
10882
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10980
+ sortDescLabel: "Newest first"
10981
+ })
10982
+ ];
10983
+ }, []);
10984
+ };
10985
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10986
+ const { setIsOpen } = useStackedModal();
10987
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10883
10988
  const form = reactHookForm.useForm({
10884
10989
  defaultValues: {
10885
- metadata: getDefaultValues(metadata)
10990
+ title: "",
10991
+ quantity: 1,
10992
+ unit_price: ""
10886
10993
  },
10887
- resolver: zod.zodResolver(MetadataSchema)
10994
+ resolver: zod.zodResolver(customItemSchema)
10888
10995
  });
10889
- const handleSubmit = form.handleSubmit(async (data) => {
10890
- const parsedData = parseValues(data);
10891
- await mutateAsync(
10996
+ const onSubmit = form.handleSubmit(async (data) => {
10997
+ await addItems(
10892
10998
  {
10893
- metadata: parsedData
10999
+ items: [
11000
+ {
11001
+ title: data.title,
11002
+ quantity: data.quantity,
11003
+ unit_price: convertNumber(data.unit_price)
11004
+ }
11005
+ ]
10894
11006
  },
10895
11007
  {
10896
11008
  onSuccess: () => {
10897
- ui.toast.success("Metadata updated");
10898
- handleSuccess();
11009
+ setIsOpen(STACKED_MODAL_ID, false);
10899
11010
  },
10900
- onError: (error) => {
10901
- ui.toast.error(error.message);
11011
+ onError: (e) => {
11012
+ ui.toast.error(e.message);
10902
11013
  }
10903
11014
  }
10904
11015
  );
10905
11016
  });
10906
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10907
- control: form.control,
10908
- name: "metadata"
10909
- });
10910
- function deleteRow(index) {
10911
- remove(index);
10912
- if (fields.length === 1) {
10913
- insert(0, {
10914
- key: "",
10915
- value: "",
10916
- disabled: false
10917
- });
10918
- }
10919
- }
10920
- function insertRow(index, position) {
10921
- insert(index + (position === "above" ? 0 : 1), {
10922
- key: "",
10923
- value: "",
10924
- disabled: false
10925
- });
10926
- }
10927
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10928
- KeyboundForm,
10929
- {
10930
- onSubmit: handleSubmit,
10931
- className: "flex flex-1 flex-col overflow-hidden",
10932
- children: [
10933
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10934
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10935
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10936
- /* @__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" }) }),
10937
- /* @__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" }) })
11017
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11018
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11019
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
11020
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11021
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11022
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11023
+ ] }),
11024
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11025
+ /* @__PURE__ */ jsxRuntime.jsx(
11026
+ Form$2.Field,
11027
+ {
11028
+ control: form.control,
11029
+ name: "title",
11030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11031
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10938
11034
  ] }),
10939
- fields.map((field, index) => {
10940
- const isDisabled = field.disabled || false;
10941
- let placeholder = "-";
10942
- if (typeof field.value === "object") {
10943
- placeholder = "{ ... }";
10944
- }
10945
- if (Array.isArray(field.value)) {
10946
- placeholder = "[ ... ]";
10947
- }
10948
- return /* @__PURE__ */ jsxRuntime.jsx(
10949
- ConditionalTooltip,
11035
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11036
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11037
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11038
+ ] })
11039
+ ] }) })
11040
+ }
11041
+ ),
11042
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11043
+ /* @__PURE__ */ jsxRuntime.jsx(
11044
+ Form$2.Field,
11045
+ {
11046
+ control: form.control,
11047
+ name: "unit_price",
11048
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11049
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11050
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11051
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11052
+ ] }),
11053
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11054
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11055
+ ui.CurrencyInput,
10950
11056
  {
10951
- showTooltip: isDisabled,
10952
- content: "This row is disabled because it contains non-primitive data.",
10953
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsxs(
10955
- "div",
10956
- {
10957
- className: ui.clx("grid grid-cols-2 divide-x", {
10958
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10959
- }),
10960
- children: [
10961
- /* @__PURE__ */ jsxRuntime.jsx(
10962
- Form$2.Field,
10963
- {
10964
- control: form.control,
10965
- name: `metadata.${index}.key`,
10966
- render: ({ field: field2 }) => {
10967
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10968
- GridInput,
10969
- {
10970
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10971
- ...field2,
10972
- disabled: isDisabled,
10973
- placeholder: "Key"
10974
- }
10975
- ) }) });
10976
- }
10977
- }
10978
- ),
10979
- /* @__PURE__ */ jsxRuntime.jsx(
10980
- Form$2.Field,
10981
- {
10982
- control: form.control,
10983
- name: `metadata.${index}.value`,
10984
- render: ({ field: { value, ...field2 } }) => {
10985
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10986
- GridInput,
10987
- {
10988
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10989
- ...field2,
10990
- value: isDisabled ? placeholder : value,
10991
- disabled: isDisabled,
10992
- placeholder: "Value"
10993
- }
10994
- ) }) });
10995
- }
10996
- }
10997
- )
10998
- ]
10999
- }
11000
- ),
11001
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11002
- /* @__PURE__ */ jsxRuntime.jsx(
11003
- ui.DropdownMenu.Trigger,
11004
- {
11005
- className: ui.clx(
11006
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11007
- {
11008
- hidden: isDisabled
11009
- }
11010
- ),
11011
- disabled: isDisabled,
11012
- asChild: true,
11013
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11014
- }
11015
- ),
11016
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11017
- /* @__PURE__ */ jsxRuntime.jsxs(
11018
- ui.DropdownMenu.Item,
11019
- {
11020
- className: "gap-x-2",
11021
- onClick: () => insertRow(index, "above"),
11022
- children: [
11023
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11024
- "Insert row above"
11025
- ]
11026
- }
11027
- ),
11028
- /* @__PURE__ */ jsxRuntime.jsxs(
11029
- ui.DropdownMenu.Item,
11030
- {
11031
- className: "gap-x-2",
11032
- onClick: () => insertRow(index, "below"),
11033
- children: [
11034
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11035
- "Insert row below"
11036
- ]
11037
- }
11038
- ),
11039
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11040
- /* @__PURE__ */ jsxRuntime.jsxs(
11041
- ui.DropdownMenu.Item,
11042
- {
11043
- className: "gap-x-2",
11044
- onClick: () => deleteRow(index),
11045
- children: [
11046
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11047
- "Delete row"
11048
- ]
11049
- }
11050
- )
11051
- ] })
11052
- ] })
11053
- ] })
11054
- },
11055
- field.id
11056
- );
11057
- })
11058
- ] }),
11059
- 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." })
11060
- ] }),
11061
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11062
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11063
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11064
- ] }) })
11065
- ]
11066
- }
11067
- ) });
11068
- };
11069
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11070
- return /* @__PURE__ */ jsxRuntime.jsx(
11071
- "input",
11072
- {
11073
- ref,
11074
- ...props,
11075
- autoComplete: "off",
11076
- className: ui.clx(
11077
- "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",
11078
- className
11057
+ symbol: getNativeSymbol(currencyCode),
11058
+ code: currencyCode,
11059
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11060
+ ...field
11061
+ }
11062
+ ) }),
11063
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11064
+ ] })
11065
+ ] }) })
11066
+ }
11067
+ ),
11068
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11069
+ /* @__PURE__ */ jsxRuntime.jsx(
11070
+ Form$2.Field,
11071
+ {
11072
+ control: form.control,
11073
+ name: "quantity",
11074
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11075
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11076
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11077
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11078
+ ] }),
11079
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
11080
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11081
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11082
+ ] })
11083
+ ] }) })
11084
+ }
11079
11085
  )
11080
- }
11081
- );
11082
- });
11083
- GridInput.displayName = "MetadataForm.GridInput";
11084
- const PlaceholderInner = () => {
11085
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11086
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11087
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11088
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11089
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11086
+ ] }) }) }),
11087
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11088
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11089
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11090
11090
  ] }) })
11091
- ] });
11091
+ ] }) }) });
11092
11092
  };
11093
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11094
- function getDefaultValues(metadata) {
11095
- if (!metadata || !Object.keys(metadata).length) {
11096
- return [
11097
- {
11098
- key: "",
11099
- value: "",
11100
- disabled: false
11101
- }
11102
- ];
11103
- }
11104
- return Object.entries(metadata).map(([key, value]) => {
11105
- if (!EDITABLE_TYPES.includes(typeof value)) {
11106
- return {
11107
- key,
11108
- value,
11109
- disabled: true
11110
- };
11111
- }
11112
- let stringValue = value;
11113
- if (typeof value !== "string") {
11114
- stringValue = JSON.stringify(value);
11115
- }
11116
- return {
11117
- key,
11118
- value: stringValue,
11119
- original_key: key
11120
- };
11121
- });
11122
- }
11123
- function parseValues(values) {
11124
- const metadata = values.metadata;
11125
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11126
- if (isEmpty) {
11127
- return null;
11128
- }
11129
- const update = {};
11130
- metadata.forEach((field) => {
11131
- let key = field.key;
11132
- let value = field.value;
11133
- const disabled = field.disabled;
11134
- if (!key || !value) {
11135
- return;
11136
- }
11137
- if (disabled) {
11138
- update[key] = value;
11139
- return;
11140
- }
11141
- key = key.trim();
11142
- value = value.trim();
11143
- if (value === "true") {
11144
- update[key] = true;
11145
- } else if (value === "false") {
11146
- update[key] = false;
11147
- } else {
11148
- const parsedNumber = parseFloat(value);
11149
- if (!isNaN(parsedNumber)) {
11150
- update[key] = parsedNumber;
11151
- } else {
11152
- update[key] = value;
11153
- }
11154
- }
11155
- });
11156
- return update;
11157
- }
11158
- function getHasUneditableRows(metadata) {
11159
- if (!metadata) {
11160
- return false;
11161
- }
11162
- return Object.values(metadata).some(
11163
- (value) => !EDITABLE_TYPES.includes(typeof value)
11164
- );
11165
- }
11093
+ const customItemSchema = objectType({
11094
+ title: stringType().min(1),
11095
+ quantity: numberType(),
11096
+ unit_price: unionType([numberType(), stringType()])
11097
+ });
11166
11098
  const PROMOTION_QUERY_KEY = "promotions";
11167
11099
  const promotionsQueryKeys = {
11168
11100
  list: (query2) => [
@@ -11393,159 +11325,53 @@ const PromotionItem = ({
11393
11325
  function getDisplayValue(promotion) {
11394
11326
  var _a, _b, _c, _d;
11395
11327
  const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11396
- if (!value) {
11397
- return null;
11398
- }
11399
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11400
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11401
- if (!currency) {
11402
- return null;
11403
- }
11404
- return getLocaleAmount(value, currency);
11405
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11406
- return formatPercentage(value);
11407
- }
11408
- return null;
11409
- }
11410
- const formatter = new Intl.NumberFormat([], {
11411
- style: "percent",
11412
- minimumFractionDigits: 2
11413
- });
11414
- const formatPercentage = (value, isPercentageValue = false) => {
11415
- let val = value || 0;
11416
- if (!isPercentageValue) {
11417
- val = val / 100;
11418
- }
11419
- return formatter.format(val);
11420
- };
11421
- function getPromotionCodes(items, shippingMethods) {
11422
- const codes = /* @__PURE__ */ new Set();
11423
- for (const item of items) {
11424
- if (item.adjustments) {
11425
- for (const adjustment of item.adjustments) {
11426
- if (adjustment.code) {
11427
- codes.add(adjustment.code);
11428
- }
11429
- }
11430
- }
11431
- }
11432
- for (const shippingMethod of shippingMethods) {
11433
- if (shippingMethod.adjustments) {
11434
- for (const adjustment of shippingMethod.adjustments) {
11435
- if (adjustment.code) {
11436
- codes.add(adjustment.code);
11437
- }
11438
- }
11439
- }
11440
- }
11441
- return Array.from(codes);
11442
- }
11443
- const SalesChannel = () => {
11444
- const { id } = reactRouterDom.useParams();
11445
- const { draft_order, isPending, isError, error } = useDraftOrder(
11446
- id,
11447
- {
11448
- fields: "+sales_channel_id"
11449
- },
11450
- {
11451
- enabled: !!id
11452
- }
11453
- );
11454
- if (isError) {
11455
- throw error;
11456
- }
11457
- const ISrEADY = !!draft_order && !isPending;
11458
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11462
- ] }),
11463
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11464
- ] });
11465
- };
11466
- const SalesChannelForm = ({ order }) => {
11467
- const form = reactHookForm.useForm({
11468
- defaultValues: {
11469
- sales_channel_id: order.sales_channel_id || ""
11470
- },
11471
- resolver: zod.zodResolver(schema$2)
11472
- });
11473
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11474
- const { handleSuccess } = useRouteModal();
11475
- const onSubmit = form.handleSubmit(async (data) => {
11476
- await mutateAsync(
11477
- {
11478
- sales_channel_id: data.sales_channel_id
11479
- },
11480
- {
11481
- onSuccess: () => {
11482
- ui.toast.success("Sales channel updated");
11483
- handleSuccess();
11484
- },
11485
- onError: (error) => {
11486
- ui.toast.error(error.message);
11487
- }
11488
- }
11489
- );
11490
- });
11491
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
- KeyboundForm,
11493
- {
11494
- className: "flex flex-1 flex-col overflow-hidden",
11495
- onSubmit,
11496
- children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11500
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
- ] }) })
11502
- ]
11503
- }
11504
- ) });
11505
- };
11506
- const SalesChannelField = ({ control, order }) => {
11507
- const salesChannels = useComboboxData({
11508
- queryFn: async (params) => {
11509
- return await sdk.admin.salesChannel.list(params);
11510
- },
11511
- queryKey: ["sales-channels"],
11512
- getOptions: (data) => {
11513
- return data.sales_channels.map((salesChannel) => ({
11514
- label: salesChannel.name,
11515
- value: salesChannel.id
11516
- }));
11517
- },
11518
- defaultValue: order.sales_channel_id || void 0
11519
- });
11520
- return /* @__PURE__ */ jsxRuntime.jsx(
11521
- Form$2.Field,
11522
- {
11523
- control,
11524
- name: "sales_channel_id",
11525
- render: ({ field }) => {
11526
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
- Combobox,
11530
- {
11531
- options: salesChannels.options,
11532
- fetchNextPage: salesChannels.fetchNextPage,
11533
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
- searchValue: salesChannels.searchValue,
11535
- onSearchValueChange: salesChannels.onSearchValueChange,
11536
- placeholder: "Select sales channel",
11537
- ...field
11538
- }
11539
- ) }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
- ] });
11542
- }
11328
+ if (!value) {
11329
+ return null;
11330
+ }
11331
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11332
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11333
+ if (!currency) {
11334
+ return null;
11543
11335
  }
11544
- );
11545
- };
11546
- const schema$2 = objectType({
11547
- sales_channel_id: stringType().min(1)
11336
+ return getLocaleAmount(value, currency);
11337
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11338
+ return formatPercentage(value);
11339
+ }
11340
+ return null;
11341
+ }
11342
+ const formatter = new Intl.NumberFormat([], {
11343
+ style: "percent",
11344
+ minimumFractionDigits: 2
11548
11345
  });
11346
+ const formatPercentage = (value, isPercentageValue = false) => {
11347
+ let val = value || 0;
11348
+ if (!isPercentageValue) {
11349
+ val = val / 100;
11350
+ }
11351
+ return formatter.format(val);
11352
+ };
11353
+ function getPromotionCodes(items, shippingMethods) {
11354
+ const codes = /* @__PURE__ */ new Set();
11355
+ for (const item of items) {
11356
+ if (item.adjustments) {
11357
+ for (const adjustment of item.adjustments) {
11358
+ if (adjustment.code) {
11359
+ codes.add(adjustment.code);
11360
+ }
11361
+ }
11362
+ }
11363
+ }
11364
+ for (const shippingMethod of shippingMethods) {
11365
+ if (shippingMethod.adjustments) {
11366
+ for (const adjustment of shippingMethod.adjustments) {
11367
+ if (adjustment.code) {
11368
+ codes.add(adjustment.code);
11369
+ }
11370
+ }
11371
+ }
11372
+ }
11373
+ return Array.from(codes);
11374
+ }
11549
11375
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
11376
  const Shipping = () => {
11551
11377
  var _a;
@@ -12385,7 +12211,7 @@ const ShippingAddressForm = ({ order }) => {
12385
12211
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12386
12212
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12387
12213
  },
12388
- resolver: zod.zodResolver(schema$1)
12214
+ resolver: zod.zodResolver(schema$3)
12389
12215
  });
12390
12216
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12391
12217
  const { handleSuccess } = useRouteModal();
@@ -12555,7 +12381,7 @@ const ShippingAddressForm = ({ order }) => {
12555
12381
  }
12556
12382
  ) });
12557
12383
  };
12558
- const schema$1 = addressSchema;
12384
+ const schema$3 = addressSchema;
12559
12385
  const TransferOwnership = () => {
12560
12386
  const { id } = reactRouterDom.useParams();
12561
12387
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12579,7 +12405,7 @@ const TransferOwnershipForm = ({ order }) => {
12579
12405
  defaultValues: {
12580
12406
  customer_id: order.customer_id || ""
12581
12407
  },
12582
- resolver: zod.zodResolver(schema)
12408
+ resolver: zod.zodResolver(schema$2)
12583
12409
  });
12584
12410
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12585
12411
  const { handleSuccess } = useRouteModal();
@@ -13029,9 +12855,183 @@ const Illustration = () => {
13029
12855
  }
13030
12856
  );
13031
12857
  };
13032
- const schema = objectType({
12858
+ const schema$2 = objectType({
13033
12859
  customer_id: stringType().min(1)
13034
12860
  });
12861
+ const SalesChannel = () => {
12862
+ const { id } = reactRouterDom.useParams();
12863
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12864
+ id,
12865
+ {
12866
+ fields: "+sales_channel_id"
12867
+ },
12868
+ {
12869
+ enabled: !!id
12870
+ }
12871
+ );
12872
+ if (isError) {
12873
+ throw error;
12874
+ }
12875
+ const ISrEADY = !!draft_order && !isPending;
12876
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12877
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12878
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12879
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12880
+ ] }),
12881
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12882
+ ] });
12883
+ };
12884
+ const SalesChannelForm = ({ order }) => {
12885
+ const form = reactHookForm.useForm({
12886
+ defaultValues: {
12887
+ sales_channel_id: order.sales_channel_id || ""
12888
+ },
12889
+ resolver: zod.zodResolver(schema$1)
12890
+ });
12891
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12892
+ const { handleSuccess } = useRouteModal();
12893
+ const onSubmit = form.handleSubmit(async (data) => {
12894
+ await mutateAsync(
12895
+ {
12896
+ sales_channel_id: data.sales_channel_id
12897
+ },
12898
+ {
12899
+ onSuccess: () => {
12900
+ ui.toast.success("Sales channel updated");
12901
+ handleSuccess();
12902
+ },
12903
+ onError: (error) => {
12904
+ ui.toast.error(error.message);
12905
+ }
12906
+ }
12907
+ );
12908
+ });
12909
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12910
+ KeyboundForm,
12911
+ {
12912
+ className: "flex flex-1 flex-col overflow-hidden",
12913
+ onSubmit,
12914
+ children: [
12915
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12917
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12918
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12919
+ ] }) })
12920
+ ]
12921
+ }
12922
+ ) });
12923
+ };
12924
+ const SalesChannelField = ({ control, order }) => {
12925
+ const salesChannels = useComboboxData({
12926
+ queryFn: async (params) => {
12927
+ return await sdk.admin.salesChannel.list(params);
12928
+ },
12929
+ queryKey: ["sales-channels"],
12930
+ getOptions: (data) => {
12931
+ return data.sales_channels.map((salesChannel) => ({
12932
+ label: salesChannel.name,
12933
+ value: salesChannel.id
12934
+ }));
12935
+ },
12936
+ defaultValue: order.sales_channel_id || void 0
12937
+ });
12938
+ return /* @__PURE__ */ jsxRuntime.jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control,
12942
+ name: "sales_channel_id",
12943
+ render: ({ field }) => {
12944
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12947
+ Combobox,
12948
+ {
12949
+ options: salesChannels.options,
12950
+ fetchNextPage: salesChannels.fetchNextPage,
12951
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12952
+ searchValue: salesChannels.searchValue,
12953
+ onSearchValueChange: salesChannels.onSearchValueChange,
12954
+ placeholder: "Select sales channel",
12955
+ ...field
12956
+ }
12957
+ ) }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
+ ] });
12960
+ }
12961
+ }
12962
+ );
12963
+ };
12964
+ const schema$1 = objectType({
12965
+ sales_channel_id: stringType().min(1)
12966
+ });
12967
+ const Email = () => {
12968
+ const { id } = reactRouterDom.useParams();
12969
+ const { order, isPending, isError, error } = useOrder(id, {
12970
+ fields: "+email"
12971
+ });
12972
+ if (isError) {
12973
+ throw error;
12974
+ }
12975
+ const isReady = !isPending && !!order;
12976
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12977
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12978
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12979
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12980
+ ] }),
12981
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12982
+ ] });
12983
+ };
12984
+ const EmailForm = ({ order }) => {
12985
+ const form = reactHookForm.useForm({
12986
+ defaultValues: {
12987
+ email: order.email ?? ""
12988
+ },
12989
+ resolver: zod.zodResolver(schema)
12990
+ });
12991
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12992
+ const { handleSuccess } = useRouteModal();
12993
+ const onSubmit = form.handleSubmit(async (data) => {
12994
+ await mutateAsync(
12995
+ { email: data.email },
12996
+ {
12997
+ onSuccess: () => {
12998
+ handleSuccess();
12999
+ },
13000
+ onError: (error) => {
13001
+ ui.toast.error(error.message);
13002
+ }
13003
+ }
13004
+ );
13005
+ });
13006
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13007
+ KeyboundForm,
13008
+ {
13009
+ className: "flex flex-1 flex-col overflow-hidden",
13010
+ onSubmit,
13011
+ children: [
13012
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13013
+ Form$2.Field,
13014
+ {
13015
+ control: form.control,
13016
+ name: "email",
13017
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
+ ] })
13022
+ }
13023
+ ) }),
13024
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13027
+ ] }) })
13028
+ ]
13029
+ }
13030
+ ) });
13031
+ };
13032
+ const schema = objectType({
13033
+ email: stringType().email()
13034
+ });
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13052,33 +13052,25 @@ const routeModule = {
13052
13052
  handle,
13053
13053
  loader,
13054
13054
  children: [
13055
- {
13056
- Component: CustomItems,
13057
- path: "/draft-orders/:id/custom-items"
13058
- },
13059
13055
  {
13060
13056
  Component: BillingAddress,
13061
13057
  path: "/draft-orders/:id/billing-address"
13062
13058
  },
13063
13059
  {
13064
- Component: Email,
13065
- path: "/draft-orders/:id/email"
13066
- },
13067
- {
13068
- Component: Items,
13069
- path: "/draft-orders/:id/items"
13060
+ Component: CustomItems,
13061
+ path: "/draft-orders/:id/custom-items"
13070
13062
  },
13071
13063
  {
13072
13064
  Component: Metadata,
13073
13065
  path: "/draft-orders/:id/metadata"
13074
13066
  },
13075
13067
  {
13076
- Component: Promotions,
13077
- path: "/draft-orders/:id/promotions"
13068
+ Component: Items,
13069
+ path: "/draft-orders/:id/items"
13078
13070
  },
13079
13071
  {
13080
- Component: SalesChannel,
13081
- path: "/draft-orders/:id/sales-channel"
13072
+ Component: Promotions,
13073
+ path: "/draft-orders/:id/promotions"
13082
13074
  },
13083
13075
  {
13084
13076
  Component: Shipping,
@@ -13091,6 +13083,14 @@ const routeModule = {
13091
13083
  {
13092
13084
  Component: TransferOwnership,
13093
13085
  path: "/draft-orders/:id/transfer-ownership"
13086
+ },
13087
+ {
13088
+ Component: SalesChannel,
13089
+ path: "/draft-orders/:id/sales-channel"
13090
+ },
13091
+ {
13092
+ Component: Email,
13093
+ path: "/draft-orders/:id/email"
13094
13094
  }
13095
13095
  ]
13096
13096
  }