@medusajs/draft-order 2.11.4-preview-20251106120154 → 2.11.4-snapshot-20251106121614

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.
@@ -9568,27 +9568,6 @@ const ID = () => {
9568
9568
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9569
9569
  ] });
9570
9570
  };
9571
- const CustomItems = () => {
9572
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9574
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9575
- ] });
9576
- };
9577
- const CustomItemsForm = () => {
9578
- const form = reactHookForm.useForm({
9579
- resolver: zod.zodResolver(schema$5)
9580
- });
9581
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9583
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9584
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9585
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9586
- ] }) })
9587
- ] }) });
9588
- };
9589
- const schema$5 = objectType({
9590
- email: stringType().email()
9591
- });
9592
9571
  const BillingAddress = () => {
9593
9572
  const { id } = reactRouterDom.useParams();
9594
9573
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9621,7 +9600,7 @@ const BillingAddressForm = ({ order }) => {
9621
9600
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9622
9601
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9623
9602
  },
9624
- resolver: zod.zodResolver(schema$4)
9603
+ resolver: zod.zodResolver(schema$5)
9625
9604
  });
9626
9605
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9627
9606
  const { handleSuccess } = useRouteModal();
@@ -9778,11 +9757,76 @@ const BillingAddressForm = ({ order }) => {
9778
9757
  }
9779
9758
  ) });
9780
9759
  };
9781
- const schema$4 = addressSchema;
9782
- const Email = () => {
9760
+ const schema$5 = addressSchema;
9761
+ const CustomItems = () => {
9762
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9763
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9764
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9765
+ ] });
9766
+ };
9767
+ const CustomItemsForm = () => {
9768
+ const form = reactHookForm.useForm({
9769
+ resolver: zod.zodResolver(schema$4)
9770
+ });
9771
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9772
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9773
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9774
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9775
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9776
+ ] }) })
9777
+ ] }) });
9778
+ };
9779
+ const schema$4 = objectType({
9780
+ email: stringType().email()
9781
+ });
9782
+ const InlineTip = React.forwardRef(
9783
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9784
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9785
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9786
+ "div",
9787
+ {
9788
+ ref,
9789
+ className: ui.clx(
9790
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9791
+ className
9792
+ ),
9793
+ ...props,
9794
+ children: [
9795
+ /* @__PURE__ */ jsxRuntime.jsx(
9796
+ "div",
9797
+ {
9798
+ role: "presentation",
9799
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9800
+ "bg-ui-tag-orange-icon": variant === "warning"
9801
+ })
9802
+ }
9803
+ ),
9804
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9805
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9806
+ labelValue,
9807
+ ":"
9808
+ ] }),
9809
+ " ",
9810
+ children
9811
+ ] })
9812
+ ]
9813
+ }
9814
+ );
9815
+ }
9816
+ );
9817
+ InlineTip.displayName = "InlineTip";
9818
+ const MetadataFieldSchema = objectType({
9819
+ key: stringType(),
9820
+ disabled: booleanType().optional(),
9821
+ value: anyType()
9822
+ });
9823
+ const MetadataSchema = objectType({
9824
+ metadata: arrayType(MetadataFieldSchema)
9825
+ });
9826
+ const Metadata = () => {
9783
9827
  const { id } = reactRouterDom.useParams();
9784
9828
  const { order, isPending, isError, error } = useOrder(id, {
9785
- fields: "+email"
9829
+ fields: "metadata"
9786
9830
  });
9787
9831
  if (isError) {
9788
9832
  throw error;
@@ -9790,26 +9834,33 @@ const Email = () => {
9790
9834
  const isReady = !isPending && !!order;
9791
9835
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9792
9836
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9793
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9794
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9837
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9795
9839
  ] }),
9796
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9840
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9797
9841
  ] });
9798
9842
  };
9799
- const EmailForm = ({ order }) => {
9843
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9844
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9845
+ const MetadataForm = ({ orderId, metadata }) => {
9846
+ const { handleSuccess } = useRouteModal();
9847
+ const hasUneditableRows = getHasUneditableRows(metadata);
9848
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9800
9849
  const form = reactHookForm.useForm({
9801
9850
  defaultValues: {
9802
- email: order.email ?? ""
9851
+ metadata: getDefaultValues(metadata)
9803
9852
  },
9804
- resolver: zod.zodResolver(schema$3)
9853
+ resolver: zod.zodResolver(MetadataSchema)
9805
9854
  });
9806
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9807
- const { handleSuccess } = useRouteModal();
9808
- const onSubmit = form.handleSubmit(async (data) => {
9855
+ const handleSubmit = form.handleSubmit(async (data) => {
9856
+ const parsedData = parseValues(data);
9809
9857
  await mutateAsync(
9810
- { email: data.email },
9858
+ {
9859
+ metadata: parsedData
9860
+ },
9811
9861
  {
9812
9862
  onSuccess: () => {
9863
+ ui.toast.success("Metadata updated");
9813
9864
  handleSuccess();
9814
9865
  },
9815
9866
  onError: (error) => {
@@ -9818,112 +9869,411 @@ const EmailForm = ({ order }) => {
9818
9869
  }
9819
9870
  );
9820
9871
  });
9872
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9873
+ control: form.control,
9874
+ name: "metadata"
9875
+ });
9876
+ function deleteRow(index) {
9877
+ remove(index);
9878
+ if (fields.length === 1) {
9879
+ insert(0, {
9880
+ key: "",
9881
+ value: "",
9882
+ disabled: false
9883
+ });
9884
+ }
9885
+ }
9886
+ function insertRow(index, position) {
9887
+ insert(index + (position === "above" ? 0 : 1), {
9888
+ key: "",
9889
+ value: "",
9890
+ disabled: false
9891
+ });
9892
+ }
9821
9893
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9822
9894
  KeyboundForm,
9823
9895
  {
9896
+ onSubmit: handleSubmit,
9824
9897
  className: "flex flex-1 flex-col overflow-hidden",
9825
- onSubmit,
9826
9898
  children: [
9827
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9828
- Form$2.Field,
9829
- {
9830
- control: form.control,
9831
- name: "email",
9832
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9833
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9834
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9835
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9836
- ] })
9837
- }
9838
- ) }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9840
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9841
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9842
- ] }) })
9843
- ]
9844
- }
9845
- ) });
9846
- };
9847
- const schema$3 = objectType({
9848
- email: stringType().email()
9849
- });
9850
- const NumberInput = React.forwardRef(
9851
- ({
9852
- value,
9853
- onChange,
9854
- size = "base",
9855
- min = 0,
9856
- max = 100,
9857
- step = 1,
9858
- className,
9859
- disabled,
9860
- ...props
9861
- }, ref) => {
9862
- const handleChange = (event) => {
9863
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9864
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9865
- onChange(newValue);
9866
- }
9867
- };
9868
- const handleIncrement = () => {
9869
- const newValue = value + step;
9870
- if (max === void 0 || newValue <= max) {
9871
- onChange(newValue);
9872
- }
9873
- };
9874
- const handleDecrement = () => {
9875
- const newValue = value - step;
9876
- if (min === void 0 || newValue >= min) {
9877
- onChange(newValue);
9878
- }
9879
- };
9880
- return /* @__PURE__ */ jsxRuntime.jsxs(
9881
- "div",
9882
- {
9883
- className: ui.clx(
9884
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9885
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9886
- {
9887
- "h-7": size === "small",
9888
- "h-8": size === "base"
9889
- },
9890
- className
9891
- ),
9892
- children: [
9893
- /* @__PURE__ */ jsxRuntime.jsx(
9894
- "input",
9895
- {
9896
- ref,
9897
- type: "number",
9898
- value,
9899
- onChange: handleChange,
9900
- min,
9901
- max,
9902
- step,
9903
- className: ui.clx(
9904
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9905
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9906
- "placeholder:text-ui-fg-muted"
9907
- ),
9908
- ...props
9909
- }
9910
- ),
9911
- /* @__PURE__ */ jsxRuntime.jsxs(
9912
- "button",
9913
- {
9914
- className: ui.clx(
9915
- "flex items-center justify-center outline-none transition-fg",
9916
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9917
- "focus:bg-ui-bg-field-component-hover",
9918
- "hover:bg-ui-bg-field-component-hover",
9899
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9900
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9901
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9902
+ /* @__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" }) }),
9903
+ /* @__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" }) })
9904
+ ] }),
9905
+ fields.map((field, index) => {
9906
+ const isDisabled = field.disabled || false;
9907
+ let placeholder = "-";
9908
+ if (typeof field.value === "object") {
9909
+ placeholder = "{ ... }";
9910
+ }
9911
+ if (Array.isArray(field.value)) {
9912
+ placeholder = "[ ... ]";
9913
+ }
9914
+ return /* @__PURE__ */ jsxRuntime.jsx(
9915
+ ConditionalTooltip,
9919
9916
  {
9920
- "size-7": size === "small",
9921
- "size-8": size === "base"
9922
- }
9923
- ),
9924
- type: "button",
9925
- onClick: handleDecrement,
9926
- disabled: min !== void 0 && value <= min || disabled,
9917
+ showTooltip: isDisabled,
9918
+ content: "This row is disabled because it contains non-primitive data.",
9919
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9920
+ /* @__PURE__ */ jsxRuntime.jsxs(
9921
+ "div",
9922
+ {
9923
+ className: ui.clx("grid grid-cols-2 divide-x", {
9924
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9925
+ }),
9926
+ children: [
9927
+ /* @__PURE__ */ jsxRuntime.jsx(
9928
+ Form$2.Field,
9929
+ {
9930
+ control: form.control,
9931
+ name: `metadata.${index}.key`,
9932
+ render: ({ field: field2 }) => {
9933
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9934
+ GridInput,
9935
+ {
9936
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9937
+ ...field2,
9938
+ disabled: isDisabled,
9939
+ placeholder: "Key"
9940
+ }
9941
+ ) }) });
9942
+ }
9943
+ }
9944
+ ),
9945
+ /* @__PURE__ */ jsxRuntime.jsx(
9946
+ Form$2.Field,
9947
+ {
9948
+ control: form.control,
9949
+ name: `metadata.${index}.value`,
9950
+ render: ({ field: { value, ...field2 } }) => {
9951
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9952
+ GridInput,
9953
+ {
9954
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9955
+ ...field2,
9956
+ value: isDisabled ? placeholder : value,
9957
+ disabled: isDisabled,
9958
+ placeholder: "Value"
9959
+ }
9960
+ ) }) });
9961
+ }
9962
+ }
9963
+ )
9964
+ ]
9965
+ }
9966
+ ),
9967
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9968
+ /* @__PURE__ */ jsxRuntime.jsx(
9969
+ ui.DropdownMenu.Trigger,
9970
+ {
9971
+ className: ui.clx(
9972
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9973
+ {
9974
+ hidden: isDisabled
9975
+ }
9976
+ ),
9977
+ disabled: isDisabled,
9978
+ asChild: true,
9979
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9980
+ }
9981
+ ),
9982
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9983
+ /* @__PURE__ */ jsxRuntime.jsxs(
9984
+ ui.DropdownMenu.Item,
9985
+ {
9986
+ className: "gap-x-2",
9987
+ onClick: () => insertRow(index, "above"),
9988
+ children: [
9989
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9990
+ "Insert row above"
9991
+ ]
9992
+ }
9993
+ ),
9994
+ /* @__PURE__ */ jsxRuntime.jsxs(
9995
+ ui.DropdownMenu.Item,
9996
+ {
9997
+ className: "gap-x-2",
9998
+ onClick: () => insertRow(index, "below"),
9999
+ children: [
10000
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10001
+ "Insert row below"
10002
+ ]
10003
+ }
10004
+ ),
10005
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10006
+ /* @__PURE__ */ jsxRuntime.jsxs(
10007
+ ui.DropdownMenu.Item,
10008
+ {
10009
+ className: "gap-x-2",
10010
+ onClick: () => deleteRow(index),
10011
+ children: [
10012
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10013
+ "Delete row"
10014
+ ]
10015
+ }
10016
+ )
10017
+ ] })
10018
+ ] })
10019
+ ] })
10020
+ },
10021
+ field.id
10022
+ );
10023
+ })
10024
+ ] }),
10025
+ 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." })
10026
+ ] }),
10027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10028
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10029
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10030
+ ] }) })
10031
+ ]
10032
+ }
10033
+ ) });
10034
+ };
10035
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10036
+ return /* @__PURE__ */ jsxRuntime.jsx(
10037
+ "input",
10038
+ {
10039
+ ref,
10040
+ ...props,
10041
+ autoComplete: "off",
10042
+ className: ui.clx(
10043
+ "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",
10044
+ className
10045
+ )
10046
+ }
10047
+ );
10048
+ });
10049
+ GridInput.displayName = "MetadataForm.GridInput";
10050
+ const PlaceholderInner = () => {
10051
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10052
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10053
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10054
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10055
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10056
+ ] }) })
10057
+ ] });
10058
+ };
10059
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10060
+ function getDefaultValues(metadata) {
10061
+ if (!metadata || !Object.keys(metadata).length) {
10062
+ return [
10063
+ {
10064
+ key: "",
10065
+ value: "",
10066
+ disabled: false
10067
+ }
10068
+ ];
10069
+ }
10070
+ return Object.entries(metadata).map(([key, value]) => {
10071
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10072
+ return {
10073
+ key,
10074
+ value,
10075
+ disabled: true
10076
+ };
10077
+ }
10078
+ let stringValue = value;
10079
+ if (typeof value !== "string") {
10080
+ stringValue = JSON.stringify(value);
10081
+ }
10082
+ return {
10083
+ key,
10084
+ value: stringValue,
10085
+ original_key: key
10086
+ };
10087
+ });
10088
+ }
10089
+ function parseValues(values) {
10090
+ const metadata = values.metadata;
10091
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10092
+ if (isEmpty) {
10093
+ return null;
10094
+ }
10095
+ const update = {};
10096
+ metadata.forEach((field) => {
10097
+ let key = field.key;
10098
+ let value = field.value;
10099
+ const disabled = field.disabled;
10100
+ if (!key || !value) {
10101
+ return;
10102
+ }
10103
+ if (disabled) {
10104
+ update[key] = value;
10105
+ return;
10106
+ }
10107
+ key = key.trim();
10108
+ value = value.trim();
10109
+ if (value === "true") {
10110
+ update[key] = true;
10111
+ } else if (value === "false") {
10112
+ update[key] = false;
10113
+ } else {
10114
+ const parsedNumber = parseFloat(value);
10115
+ if (!isNaN(parsedNumber)) {
10116
+ update[key] = parsedNumber;
10117
+ } else {
10118
+ update[key] = value;
10119
+ }
10120
+ }
10121
+ });
10122
+ return update;
10123
+ }
10124
+ function getHasUneditableRows(metadata) {
10125
+ if (!metadata) {
10126
+ return false;
10127
+ }
10128
+ return Object.values(metadata).some(
10129
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10130
+ );
10131
+ }
10132
+ const Email = () => {
10133
+ const { id } = reactRouterDom.useParams();
10134
+ const { order, isPending, isError, error } = useOrder(id, {
10135
+ fields: "+email"
10136
+ });
10137
+ if (isError) {
10138
+ throw error;
10139
+ }
10140
+ const isReady = !isPending && !!order;
10141
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10142
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10143
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10144
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10145
+ ] }),
10146
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10147
+ ] });
10148
+ };
10149
+ const EmailForm = ({ order }) => {
10150
+ const form = reactHookForm.useForm({
10151
+ defaultValues: {
10152
+ email: order.email ?? ""
10153
+ },
10154
+ resolver: zod.zodResolver(schema$3)
10155
+ });
10156
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10157
+ const { handleSuccess } = useRouteModal();
10158
+ const onSubmit = form.handleSubmit(async (data) => {
10159
+ await mutateAsync(
10160
+ { email: data.email },
10161
+ {
10162
+ onSuccess: () => {
10163
+ handleSuccess();
10164
+ },
10165
+ onError: (error) => {
10166
+ ui.toast.error(error.message);
10167
+ }
10168
+ }
10169
+ );
10170
+ });
10171
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10172
+ KeyboundForm,
10173
+ {
10174
+ className: "flex flex-1 flex-col overflow-hidden",
10175
+ onSubmit,
10176
+ children: [
10177
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10178
+ Form$2.Field,
10179
+ {
10180
+ control: form.control,
10181
+ name: "email",
10182
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10183
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10184
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10185
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10186
+ ] })
10187
+ }
10188
+ ) }),
10189
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10190
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10192
+ ] }) })
10193
+ ]
10194
+ }
10195
+ ) });
10196
+ };
10197
+ const schema$3 = objectType({
10198
+ email: stringType().email()
10199
+ });
10200
+ const NumberInput = React.forwardRef(
10201
+ ({
10202
+ value,
10203
+ onChange,
10204
+ size = "base",
10205
+ min = 0,
10206
+ max = 100,
10207
+ step = 1,
10208
+ className,
10209
+ disabled,
10210
+ ...props
10211
+ }, ref) => {
10212
+ const handleChange = (event) => {
10213
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10214
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10215
+ onChange(newValue);
10216
+ }
10217
+ };
10218
+ const handleIncrement = () => {
10219
+ const newValue = value + step;
10220
+ if (max === void 0 || newValue <= max) {
10221
+ onChange(newValue);
10222
+ }
10223
+ };
10224
+ const handleDecrement = () => {
10225
+ const newValue = value - step;
10226
+ if (min === void 0 || newValue >= min) {
10227
+ onChange(newValue);
10228
+ }
10229
+ };
10230
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10231
+ "div",
10232
+ {
10233
+ className: ui.clx(
10234
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10235
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10236
+ {
10237
+ "h-7": size === "small",
10238
+ "h-8": size === "base"
10239
+ },
10240
+ className
10241
+ ),
10242
+ children: [
10243
+ /* @__PURE__ */ jsxRuntime.jsx(
10244
+ "input",
10245
+ {
10246
+ ref,
10247
+ type: "number",
10248
+ value,
10249
+ onChange: handleChange,
10250
+ min,
10251
+ max,
10252
+ step,
10253
+ className: ui.clx(
10254
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10255
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10256
+ "placeholder:text-ui-fg-muted"
10257
+ ),
10258
+ ...props
10259
+ }
10260
+ ),
10261
+ /* @__PURE__ */ jsxRuntime.jsxs(
10262
+ "button",
10263
+ {
10264
+ className: ui.clx(
10265
+ "flex items-center justify-center outline-none transition-fg",
10266
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10267
+ "focus:bg-ui-bg-field-component-hover",
10268
+ "hover:bg-ui-bg-field-component-hover",
10269
+ {
10270
+ "size-7": size === "small",
10271
+ "size-8": size === "base"
10272
+ }
10273
+ ),
10274
+ type: "button",
10275
+ onClick: handleDecrement,
10276
+ disabled: min !== void 0 && value <= min || disabled,
9927
10277
  children: [
9928
10278
  /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9929
10279
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
@@ -10252,168 +10602,20 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10252
10602
  const [editing, setEditing] = React.useState(false);
10253
10603
  const form = reactHookForm.useForm({
10254
10604
  defaultValues: {
10255
- quantity: item.quantity,
10256
- unit_price: item.unit_price
10257
- },
10258
- resolver: zod.zodResolver(variantItemSchema)
10259
- });
10260
- const actionId = React.useMemo(() => {
10261
- var _a, _b;
10262
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10263
- }, [item]);
10264
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10265
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10266
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10267
- const onSubmit = form.handleSubmit(async (data) => {
10268
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10269
- setEditing(false);
10270
- return;
10271
- }
10272
- if (!actionId) {
10273
- await updateOriginalItem(
10274
- {
10275
- item_id: item.id,
10276
- quantity: data.quantity,
10277
- unit_price: convertNumber(data.unit_price)
10278
- },
10279
- {
10280
- onSuccess: () => {
10281
- setEditing(false);
10282
- },
10283
- onError: (e) => {
10284
- ui.toast.error(e.message);
10285
- }
10286
- }
10287
- );
10288
- return;
10289
- }
10290
- await updateActionItem(
10291
- {
10292
- action_id: actionId,
10293
- quantity: data.quantity,
10294
- unit_price: convertNumber(data.unit_price)
10295
- },
10296
- {
10297
- onSuccess: () => {
10298
- setEditing(false);
10299
- },
10300
- onError: (e) => {
10301
- ui.toast.error(e.message);
10302
- }
10303
- }
10304
- );
10305
- });
10306
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10307
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10308
- /* @__PURE__ */ jsxRuntime.jsx(
10309
- Thumbnail,
10310
- {
10311
- thumbnail: item.thumbnail,
10312
- alt: item.product_title ?? void 0
10313
- }
10314
- ),
10315
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10316
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10317
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10318
- /* @__PURE__ */ jsxRuntime.jsxs(
10319
- ui.Text,
10320
- {
10321
- size: "small",
10322
- leading: "compact",
10323
- className: "text-ui-fg-subtle",
10324
- children: [
10325
- "(",
10326
- item.variant_title,
10327
- ")"
10328
- ]
10329
- }
10330
- )
10331
- ] }),
10332
- /* @__PURE__ */ jsxRuntime.jsx(
10333
- ui.Text,
10334
- {
10335
- size: "small",
10336
- leading: "compact",
10337
- className: "text-ui-fg-subtle",
10338
- children: item.variant_sku
10339
- }
10340
- )
10341
- ] })
10342
- ] }),
10343
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10344
- Form$2.Field,
10345
- {
10346
- control: form.control,
10347
- name: "quantity",
10348
- render: ({ field }) => {
10349
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10350
- }
10351
- }
10352
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10353
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10354
- Form$2.Field,
10355
- {
10356
- control: form.control,
10357
- name: "unit_price",
10358
- render: ({ field: { onChange, ...field } }) => {
10359
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10360
- ui.CurrencyInput,
10361
- {
10362
- ...field,
10363
- symbol: getNativeSymbol(currencyCode),
10364
- code: currencyCode,
10365
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10366
- }
10367
- ) }) });
10368
- }
10369
- }
10370
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10371
- /* @__PURE__ */ jsxRuntime.jsx(
10372
- ui.IconButton,
10373
- {
10374
- type: "button",
10375
- size: "small",
10376
- onClick: editing ? onSubmit : () => {
10377
- setEditing(true);
10378
- },
10379
- disabled: isPending,
10380
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10381
- }
10382
- )
10383
- ] }) }) });
10384
- };
10385
- const variantItemSchema = objectType({
10386
- quantity: numberType(),
10387
- unit_price: unionType([numberType(), stringType()])
10388
- });
10389
- const CustomItem = ({ item, preview, currencyCode }) => {
10390
- const [editing, setEditing] = React.useState(false);
10391
- const { quantity, unit_price, title } = item;
10392
- const form = reactHookForm.useForm({
10393
- defaultValues: {
10394
- title,
10395
- quantity,
10396
- unit_price
10397
- },
10398
- resolver: zod.zodResolver(customItemSchema)
10399
- });
10400
- React.useEffect(() => {
10401
- form.reset({
10402
- title,
10403
- quantity,
10404
- unit_price
10405
- });
10406
- }, [form, title, quantity, unit_price]);
10605
+ quantity: item.quantity,
10606
+ unit_price: item.unit_price
10607
+ },
10608
+ resolver: zod.zodResolver(variantItemSchema)
10609
+ });
10407
10610
  const actionId = React.useMemo(() => {
10408
10611
  var _a, _b;
10409
10612
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10410
10613
  }, [item]);
10411
10614
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10412
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10413
10615
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10414
10616
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10415
10617
  const onSubmit = form.handleSubmit(async (data) => {
10416
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10618
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10417
10619
  setEditing(false);
10418
10620
  return;
10419
10621
  }
@@ -10435,17 +10637,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10435
10637
  );
10436
10638
  return;
10437
10639
  }
10438
- if (data.quantity === 0) {
10439
- await removeActionItem(actionId, {
10440
- onSuccess: () => {
10441
- setEditing(false);
10442
- },
10443
- onError: (e) => {
10444
- ui.toast.error(e.message);
10445
- }
10446
- });
10447
- return;
10448
- }
10449
10640
  await updateActionItem(
10450
10641
  {
10451
10642
  action_id: actionId,
@@ -10463,26 +10654,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10463
10654
  );
10464
10655
  });
10465
10656
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10466
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10657
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10467
10658
  /* @__PURE__ */ jsxRuntime.jsx(
10468
10659
  Thumbnail,
10469
10660
  {
10470
10661
  thumbnail: item.thumbnail,
10471
- alt: item.title ?? void 0
10662
+ alt: item.product_title ?? void 0
10472
10663
  }
10473
10664
  ),
10474
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10475
- Form$2.Field,
10476
- {
10477
- control: form.control,
10478
- name: "title",
10479
- render: ({ field }) => {
10480
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10665
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10666
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10667
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10668
+ /* @__PURE__ */ jsxRuntime.jsxs(
10669
+ ui.Text,
10670
+ {
10671
+ size: "small",
10672
+ leading: "compact",
10673
+ className: "text-ui-fg-subtle",
10674
+ children: [
10675
+ "(",
10676
+ item.variant_title,
10677
+ ")"
10678
+ ]
10679
+ }
10680
+ )
10681
+ ] }),
10682
+ /* @__PURE__ */ jsxRuntime.jsx(
10683
+ ui.Text,
10684
+ {
10685
+ size: "small",
10686
+ leading: "compact",
10687
+ className: "text-ui-fg-subtle",
10688
+ children: item.variant_sku
10481
10689
  }
10482
- }
10483
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10690
+ )
10691
+ ] })
10484
10692
  ] }),
10485
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10693
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10486
10694
  Form$2.Field,
10487
10695
  {
10488
10696
  control: form.control,
@@ -10491,8 +10699,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10491
10699
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10492
10700
  }
10493
10701
  }
10494
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10495
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10702
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10703
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10496
10704
  Form$2.Field,
10497
10705
  {
10498
10706
  control: form.control,
@@ -10509,230 +10717,94 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10509
10717
  ) }) });
10510
10718
  }
10511
10719
  }
10512
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10513
- /* @__PURE__ */ jsxRuntime.jsx(
10514
- ui.IconButton,
10515
- {
10516
- type: "button",
10517
- size: "small",
10518
- onClick: editing ? onSubmit : () => {
10519
- setEditing(true);
10520
- },
10521
- disabled: isPending,
10522
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10523
- }
10524
- )
10525
- ] }) }) });
10526
- };
10527
- const StackedModalTrigger$1 = ({
10528
- type,
10529
- setModalContent
10530
- }) => {
10531
- const { setIsOpen } = useStackedModal();
10532
- const onClick = React.useCallback(() => {
10533
- setModalContent(type);
10534
- setIsOpen(STACKED_MODAL_ID, true);
10535
- }, [setModalContent, setIsOpen, type]);
10536
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10537
- };
10538
- const VARIANT_PREFIX = "items";
10539
- const LIMIT = 50;
10540
- const ExistingItemsForm = ({ orderId, items }) => {
10541
- const { setIsOpen } = useStackedModal();
10542
- const [rowSelection, setRowSelection] = React.useState(
10543
- items.reduce((acc, item) => {
10544
- acc[item.variant_id] = true;
10545
- return acc;
10546
- }, {})
10547
- );
10548
- React.useEffect(() => {
10549
- setRowSelection(
10550
- items.reduce((acc, item) => {
10551
- if (item.variant_id) {
10552
- acc[item.variant_id] = true;
10553
- }
10554
- return acc;
10555
- }, {})
10556
- );
10557
- }, [items]);
10558
- const { q, order, offset } = useQueryParams(
10559
- ["q", "order", "offset"],
10560
- VARIANT_PREFIX
10561
- );
10562
- const { variants, count, isPending, isError, error } = useProductVariants(
10563
- {
10564
- q,
10565
- order,
10566
- offset: offset ? parseInt(offset) : void 0,
10567
- limit: LIMIT
10568
- },
10569
- {
10570
- placeholderData: reactQuery.keepPreviousData
10571
- }
10572
- );
10573
- const columns = useColumns();
10574
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10575
- const onSubmit = async () => {
10576
- const ids = Object.keys(rowSelection).filter(
10577
- (id) => !items.find((i) => i.variant_id === id)
10578
- );
10579
- await mutateAsync(
10580
- {
10581
- items: ids.map((id) => ({
10582
- variant_id: id,
10583
- quantity: 1
10584
- }))
10585
- },
10586
- {
10587
- onSuccess: () => {
10588
- setRowSelection({});
10589
- setIsOpen(STACKED_MODAL_ID, false);
10590
- },
10591
- onError: (e) => {
10592
- ui.toast.error(e.message);
10593
- }
10594
- }
10595
- );
10596
- };
10597
- if (isError) {
10598
- throw error;
10599
- }
10600
- return /* @__PURE__ */ jsxRuntime.jsxs(
10601
- StackedFocusModal.Content,
10602
- {
10603
- onOpenAutoFocus: (e) => {
10604
- e.preventDefault();
10605
- const searchInput = document.querySelector(
10606
- "[data-modal-id='modal-search-input']"
10607
- );
10608
- if (searchInput) {
10609
- searchInput.focus();
10610
- }
10611
- },
10612
- children: [
10613
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10614
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10615
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10616
- ] }),
10617
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10618
- DataTable,
10619
- {
10620
- data: variants,
10621
- columns,
10622
- isLoading: isPending,
10623
- getRowId: (row) => row.id,
10624
- rowCount: count,
10625
- prefix: VARIANT_PREFIX,
10626
- layout: "fill",
10627
- rowSelection: {
10628
- state: rowSelection,
10629
- onRowSelectionChange: setRowSelection,
10630
- enableRowSelection: (row) => {
10631
- return !items.find((i) => i.variant_id === row.original.id);
10632
- }
10633
- },
10634
- autoFocusSearch: true
10635
- }
10636
- ) }),
10637
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10638
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10639
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10640
- ] }) })
10641
- ]
10642
- }
10643
- );
10644
- };
10645
- const columnHelper = ui.createDataTableColumnHelper();
10646
- const useColumns = () => {
10647
- return React.useMemo(() => {
10648
- return [
10649
- columnHelper.select(),
10650
- columnHelper.accessor("product.title", {
10651
- header: "Product",
10652
- cell: ({ row }) => {
10653
- var _a, _b, _c;
10654
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10655
- /* @__PURE__ */ jsxRuntime.jsx(
10656
- Thumbnail,
10657
- {
10658
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10659
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10660
- }
10661
- ),
10662
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10663
- ] });
10664
- },
10665
- enableSorting: true
10666
- }),
10667
- columnHelper.accessor("title", {
10668
- header: "Variant",
10669
- enableSorting: true
10670
- }),
10671
- columnHelper.accessor("sku", {
10672
- header: "SKU",
10673
- cell: ({ getValue }) => {
10674
- return getValue() ?? "-";
10675
- },
10676
- enableSorting: true
10677
- }),
10678
- columnHelper.accessor("updated_at", {
10679
- header: "Updated",
10680
- cell: ({ getValue }) => {
10681
- return /* @__PURE__ */ jsxRuntime.jsx(
10682
- ui.Tooltip,
10683
- {
10684
- content: getFullDate({ date: getValue(), includeTime: true }),
10685
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10686
- }
10687
- );
10688
- },
10689
- enableSorting: true,
10690
- sortAscLabel: "Oldest first",
10691
- sortDescLabel: "Newest first"
10692
- }),
10693
- columnHelper.accessor("created_at", {
10694
- header: "Created",
10695
- cell: ({ getValue }) => {
10696
- return /* @__PURE__ */ jsxRuntime.jsx(
10697
- ui.Tooltip,
10698
- {
10699
- content: getFullDate({ date: getValue(), includeTime: true }),
10700
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10701
- }
10702
- );
10720
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10721
+ /* @__PURE__ */ jsxRuntime.jsx(
10722
+ ui.IconButton,
10723
+ {
10724
+ type: "button",
10725
+ size: "small",
10726
+ onClick: editing ? onSubmit : () => {
10727
+ setEditing(true);
10703
10728
  },
10704
- enableSorting: true,
10705
- sortAscLabel: "Oldest first",
10706
- sortDescLabel: "Newest first"
10707
- })
10708
- ];
10709
- }, []);
10729
+ disabled: isPending,
10730
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10731
+ }
10732
+ )
10733
+ ] }) }) });
10710
10734
  };
10711
- const CustomItemForm = ({ orderId, currencyCode }) => {
10712
- const { setIsOpen } = useStackedModal();
10713
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10735
+ const variantItemSchema = objectType({
10736
+ quantity: numberType(),
10737
+ unit_price: unionType([numberType(), stringType()])
10738
+ });
10739
+ const CustomItem = ({ item, preview, currencyCode }) => {
10740
+ const [editing, setEditing] = React.useState(false);
10741
+ const { quantity, unit_price, title } = item;
10714
10742
  const form = reactHookForm.useForm({
10715
10743
  defaultValues: {
10716
- title: "",
10717
- quantity: 1,
10718
- unit_price: ""
10744
+ title,
10745
+ quantity,
10746
+ unit_price
10719
10747
  },
10720
10748
  resolver: zod.zodResolver(customItemSchema)
10721
10749
  });
10750
+ React.useEffect(() => {
10751
+ form.reset({
10752
+ title,
10753
+ quantity,
10754
+ unit_price
10755
+ });
10756
+ }, [form, title, quantity, unit_price]);
10757
+ const actionId = React.useMemo(() => {
10758
+ var _a, _b;
10759
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10760
+ }, [item]);
10761
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10762
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10763
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10764
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10722
10765
  const onSubmit = form.handleSubmit(async (data) => {
10723
- await addItems(
10724
- {
10725
- items: [
10726
- {
10727
- title: data.title,
10728
- quantity: data.quantity,
10729
- unit_price: convertNumber(data.unit_price)
10766
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10767
+ setEditing(false);
10768
+ return;
10769
+ }
10770
+ if (!actionId) {
10771
+ await updateOriginalItem(
10772
+ {
10773
+ item_id: item.id,
10774
+ quantity: data.quantity,
10775
+ unit_price: convertNumber(data.unit_price)
10776
+ },
10777
+ {
10778
+ onSuccess: () => {
10779
+ setEditing(false);
10780
+ },
10781
+ onError: (e) => {
10782
+ ui.toast.error(e.message);
10730
10783
  }
10731
- ]
10784
+ }
10785
+ );
10786
+ return;
10787
+ }
10788
+ if (data.quantity === 0) {
10789
+ await removeActionItem(actionId, {
10790
+ onSuccess: () => {
10791
+ setEditing(false);
10792
+ },
10793
+ onError: (e) => {
10794
+ ui.toast.error(e.message);
10795
+ }
10796
+ });
10797
+ return;
10798
+ }
10799
+ await updateActionItem(
10800
+ {
10801
+ action_id: actionId,
10802
+ quantity: data.quantity,
10803
+ unit_price: convertNumber(data.unit_price)
10732
10804
  },
10733
10805
  {
10734
10806
  onSuccess: () => {
10735
- setIsOpen(STACKED_MODAL_ID, false);
10807
+ setEditing(false);
10736
10808
  },
10737
10809
  onError: (e) => {
10738
10810
  ui.toast.error(e.message);
@@ -10740,437 +10812,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10740
10812
  }
10741
10813
  );
10742
10814
  });
10743
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10744
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10745
- /* @__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: [
10746
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10747
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10748
- /* @__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." }) })
10749
- ] }),
10750
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10751
- /* @__PURE__ */ jsxRuntime.jsx(
10752
- Form$2.Field,
10753
- {
10754
- control: form.control,
10755
- name: "title",
10756
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10757
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10758
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10759
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10760
- ] }),
10761
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10762
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10764
- ] })
10765
- ] }) })
10766
- }
10767
- ),
10768
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10815
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10816
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10769
10817
  /* @__PURE__ */ jsxRuntime.jsx(
10770
- Form$2.Field,
10818
+ Thumbnail,
10771
10819
  {
10772
- control: form.control,
10773
- name: "unit_price",
10774
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10775
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10776
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10777
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10778
- ] }),
10779
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10780
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10781
- ui.CurrencyInput,
10782
- {
10783
- symbol: getNativeSymbol(currencyCode),
10784
- code: currencyCode,
10785
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10786
- ...field
10787
- }
10788
- ) }),
10789
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10790
- ] })
10791
- ] }) })
10820
+ thumbnail: item.thumbnail,
10821
+ alt: item.title ?? void 0
10792
10822
  }
10793
10823
  ),
10794
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10795
- /* @__PURE__ */ jsxRuntime.jsx(
10824
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10796
10825
  Form$2.Field,
10797
10826
  {
10798
10827
  control: form.control,
10799
- name: "quantity",
10800
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10801
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10802
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10803
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10804
- ] }),
10805
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10806
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10807
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10808
- ] })
10809
- ] }) })
10810
- }
10811
- )
10812
- ] }) }) }),
10813
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10814
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10815
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10816
- ] }) })
10817
- ] }) }) });
10818
- };
10819
- const customItemSchema = objectType({
10820
- title: stringType().min(1),
10821
- quantity: numberType(),
10822
- unit_price: unionType([numberType(), stringType()])
10823
- });
10824
- const InlineTip = React.forwardRef(
10825
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10826
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10827
- return /* @__PURE__ */ jsxRuntime.jsxs(
10828
- "div",
10829
- {
10830
- ref,
10831
- className: ui.clx(
10832
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10833
- className
10834
- ),
10835
- ...props,
10836
- children: [
10837
- /* @__PURE__ */ jsxRuntime.jsx(
10838
- "div",
10839
- {
10840
- role: "presentation",
10841
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10842
- "bg-ui-tag-orange-icon": variant === "warning"
10843
- })
10844
- }
10845
- ),
10846
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10847
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10848
- labelValue,
10849
- ":"
10850
- ] }),
10851
- " ",
10852
- children
10853
- ] })
10854
- ]
10855
- }
10856
- );
10857
- }
10858
- );
10859
- InlineTip.displayName = "InlineTip";
10860
- const MetadataFieldSchema = objectType({
10861
- key: stringType(),
10862
- disabled: booleanType().optional(),
10863
- value: anyType()
10864
- });
10865
- const MetadataSchema = objectType({
10866
- metadata: arrayType(MetadataFieldSchema)
10867
- });
10868
- const Metadata = () => {
10869
- const { id } = reactRouterDom.useParams();
10870
- const { order, isPending, isError, error } = useOrder(id, {
10871
- fields: "metadata"
10872
- });
10873
- if (isError) {
10874
- throw error;
10875
- }
10876
- const isReady = !isPending && !!order;
10877
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10878
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10879
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10880
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10881
- ] }),
10882
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10883
- ] });
10884
- };
10885
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10886
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10887
- const MetadataForm = ({ orderId, metadata }) => {
10888
- const { handleSuccess } = useRouteModal();
10889
- const hasUneditableRows = getHasUneditableRows(metadata);
10890
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10891
- const form = reactHookForm.useForm({
10892
- defaultValues: {
10893
- metadata: getDefaultValues(metadata)
10894
- },
10895
- resolver: zod.zodResolver(MetadataSchema)
10896
- });
10897
- const handleSubmit = form.handleSubmit(async (data) => {
10898
- const parsedData = parseValues(data);
10899
- await mutateAsync(
10828
+ name: "title",
10829
+ render: ({ field }) => {
10830
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10831
+ }
10832
+ }
10833
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10834
+ ] }),
10835
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10836
+ Form$2.Field,
10900
10837
  {
10901
- metadata: parsedData
10902
- },
10838
+ control: form.control,
10839
+ name: "quantity",
10840
+ render: ({ field }) => {
10841
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10842
+ }
10843
+ }
10844
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10845
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10846
+ Form$2.Field,
10903
10847
  {
10904
- onSuccess: () => {
10905
- ui.toast.success("Metadata updated");
10906
- handleSuccess();
10907
- },
10908
- onError: (error) => {
10909
- ui.toast.error(error.message);
10848
+ control: form.control,
10849
+ name: "unit_price",
10850
+ render: ({ field: { onChange, ...field } }) => {
10851
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10852
+ ui.CurrencyInput,
10853
+ {
10854
+ ...field,
10855
+ symbol: getNativeSymbol(currencyCode),
10856
+ code: currencyCode,
10857
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10858
+ }
10859
+ ) }) });
10910
10860
  }
10911
10861
  }
10862
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10863
+ /* @__PURE__ */ jsxRuntime.jsx(
10864
+ ui.IconButton,
10865
+ {
10866
+ type: "button",
10867
+ size: "small",
10868
+ onClick: editing ? onSubmit : () => {
10869
+ setEditing(true);
10870
+ },
10871
+ disabled: isPending,
10872
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10873
+ }
10874
+ )
10875
+ ] }) }) });
10876
+ };
10877
+ const StackedModalTrigger$1 = ({
10878
+ type,
10879
+ setModalContent
10880
+ }) => {
10881
+ const { setIsOpen } = useStackedModal();
10882
+ const onClick = React.useCallback(() => {
10883
+ setModalContent(type);
10884
+ setIsOpen(STACKED_MODAL_ID, true);
10885
+ }, [setModalContent, setIsOpen, type]);
10886
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10887
+ };
10888
+ const VARIANT_PREFIX = "items";
10889
+ const LIMIT = 50;
10890
+ const ExistingItemsForm = ({ orderId, items }) => {
10891
+ const { setIsOpen } = useStackedModal();
10892
+ const [rowSelection, setRowSelection] = React.useState(
10893
+ items.reduce((acc, item) => {
10894
+ acc[item.variant_id] = true;
10895
+ return acc;
10896
+ }, {})
10897
+ );
10898
+ React.useEffect(() => {
10899
+ setRowSelection(
10900
+ items.reduce((acc, item) => {
10901
+ if (item.variant_id) {
10902
+ acc[item.variant_id] = true;
10903
+ }
10904
+ return acc;
10905
+ }, {})
10912
10906
  );
10913
- });
10914
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10915
- control: form.control,
10916
- name: "metadata"
10917
- });
10918
- function deleteRow(index) {
10919
- remove(index);
10920
- if (fields.length === 1) {
10921
- insert(0, {
10922
- key: "",
10923
- value: "",
10924
- disabled: false
10925
- });
10926
- }
10927
- }
10928
- function insertRow(index, position) {
10929
- insert(index + (position === "above" ? 0 : 1), {
10930
- key: "",
10931
- value: "",
10932
- disabled: false
10933
- });
10934
- }
10935
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10936
- KeyboundForm,
10907
+ }, [items]);
10908
+ const { q, order, offset } = useQueryParams(
10909
+ ["q", "order", "offset"],
10910
+ VARIANT_PREFIX
10911
+ );
10912
+ const { variants, count, isPending, isError, error } = useProductVariants(
10937
10913
  {
10938
- onSubmit: handleSubmit,
10939
- className: "flex flex-1 flex-col overflow-hidden",
10940
- children: [
10941
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10942
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10943
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10944
- /* @__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" }) }),
10945
- /* @__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" }) })
10946
- ] }),
10947
- fields.map((field, index) => {
10948
- const isDisabled = field.disabled || false;
10949
- let placeholder = "-";
10950
- if (typeof field.value === "object") {
10951
- placeholder = "{ ... }";
10952
- }
10953
- if (Array.isArray(field.value)) {
10954
- placeholder = "[ ... ]";
10955
- }
10956
- return /* @__PURE__ */ jsxRuntime.jsx(
10957
- ConditionalTooltip,
10958
- {
10959
- showTooltip: isDisabled,
10960
- content: "This row is disabled because it contains non-primitive data.",
10961
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10962
- /* @__PURE__ */ jsxRuntime.jsxs(
10963
- "div",
10964
- {
10965
- className: ui.clx("grid grid-cols-2 divide-x", {
10966
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10967
- }),
10968
- children: [
10969
- /* @__PURE__ */ jsxRuntime.jsx(
10970
- Form$2.Field,
10971
- {
10972
- control: form.control,
10973
- name: `metadata.${index}.key`,
10974
- render: ({ field: field2 }) => {
10975
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10976
- GridInput,
10977
- {
10978
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10979
- ...field2,
10980
- disabled: isDisabled,
10981
- placeholder: "Key"
10982
- }
10983
- ) }) });
10984
- }
10985
- }
10986
- ),
10987
- /* @__PURE__ */ jsxRuntime.jsx(
10988
- Form$2.Field,
10989
- {
10990
- control: form.control,
10991
- name: `metadata.${index}.value`,
10992
- render: ({ field: { value, ...field2 } }) => {
10993
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10994
- GridInput,
10995
- {
10996
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10997
- ...field2,
10998
- value: isDisabled ? placeholder : value,
10999
- disabled: isDisabled,
11000
- placeholder: "Value"
11001
- }
11002
- ) }) });
11003
- }
11004
- }
11005
- )
11006
- ]
11007
- }
11008
- ),
11009
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11010
- /* @__PURE__ */ jsxRuntime.jsx(
11011
- ui.DropdownMenu.Trigger,
11012
- {
11013
- className: ui.clx(
11014
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11015
- {
11016
- hidden: isDisabled
11017
- }
11018
- ),
11019
- disabled: isDisabled,
11020
- asChild: true,
11021
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11022
- }
11023
- ),
11024
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11025
- /* @__PURE__ */ jsxRuntime.jsxs(
11026
- ui.DropdownMenu.Item,
11027
- {
11028
- className: "gap-x-2",
11029
- onClick: () => insertRow(index, "above"),
11030
- children: [
11031
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11032
- "Insert row above"
11033
- ]
11034
- }
11035
- ),
11036
- /* @__PURE__ */ jsxRuntime.jsxs(
11037
- ui.DropdownMenu.Item,
11038
- {
11039
- className: "gap-x-2",
11040
- onClick: () => insertRow(index, "below"),
11041
- children: [
11042
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11043
- "Insert row below"
11044
- ]
11045
- }
11046
- ),
11047
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11048
- /* @__PURE__ */ jsxRuntime.jsxs(
11049
- ui.DropdownMenu.Item,
11050
- {
11051
- className: "gap-x-2",
11052
- onClick: () => deleteRow(index),
11053
- children: [
11054
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11055
- "Delete row"
11056
- ]
11057
- }
11058
- )
11059
- ] })
11060
- ] })
11061
- ] })
11062
- },
11063
- field.id
11064
- );
11065
- })
11066
- ] }),
11067
- 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." })
10914
+ q,
10915
+ order,
10916
+ offset: offset ? parseInt(offset) : void 0,
10917
+ limit: LIMIT
10918
+ },
10919
+ {
10920
+ placeholderData: reactQuery.keepPreviousData
10921
+ }
10922
+ );
10923
+ const columns = useColumns();
10924
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10925
+ const onSubmit = async () => {
10926
+ const ids = Object.keys(rowSelection).filter(
10927
+ (id) => !items.find((i) => i.variant_id === id)
10928
+ );
10929
+ await mutateAsync(
10930
+ {
10931
+ items: ids.map((id) => ({
10932
+ variant_id: id,
10933
+ quantity: 1
10934
+ }))
10935
+ },
10936
+ {
10937
+ onSuccess: () => {
10938
+ setRowSelection({});
10939
+ setIsOpen(STACKED_MODAL_ID, false);
10940
+ },
10941
+ onError: (e) => {
10942
+ ui.toast.error(e.message);
10943
+ }
10944
+ }
10945
+ );
10946
+ };
10947
+ if (isError) {
10948
+ throw error;
10949
+ }
10950
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10951
+ StackedFocusModal.Content,
10952
+ {
10953
+ onOpenAutoFocus: (e) => {
10954
+ e.preventDefault();
10955
+ const searchInput = document.querySelector(
10956
+ "[data-modal-id='modal-search-input']"
10957
+ );
10958
+ if (searchInput) {
10959
+ searchInput.focus();
10960
+ }
10961
+ },
10962
+ children: [
10963
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10964
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10965
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11068
10966
  ] }),
11069
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11070
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11071
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10967
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10968
+ DataTable,
10969
+ {
10970
+ data: variants,
10971
+ columns,
10972
+ isLoading: isPending,
10973
+ getRowId: (row) => row.id,
10974
+ rowCount: count,
10975
+ prefix: VARIANT_PREFIX,
10976
+ layout: "fill",
10977
+ rowSelection: {
10978
+ state: rowSelection,
10979
+ onRowSelectionChange: setRowSelection,
10980
+ enableRowSelection: (row) => {
10981
+ return !items.find((i) => i.variant_id === row.original.id);
10982
+ }
10983
+ },
10984
+ autoFocusSearch: true
10985
+ }
10986
+ ) }),
10987
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10988
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10989
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11072
10990
  ] }) })
11073
10991
  ]
11074
10992
  }
11075
- ) });
11076
- };
11077
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11078
- return /* @__PURE__ */ jsxRuntime.jsx(
11079
- "input",
11080
- {
11081
- ref,
11082
- ...props,
11083
- autoComplete: "off",
11084
- className: ui.clx(
11085
- "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",
11086
- className
11087
- )
11088
- }
11089
10993
  );
11090
- });
11091
- GridInput.displayName = "MetadataForm.GridInput";
11092
- const PlaceholderInner = () => {
11093
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11094
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11095
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11096
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11097
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11098
- ] }) })
11099
- ] });
11100
10994
  };
11101
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11102
- function getDefaultValues(metadata) {
11103
- if (!metadata || !Object.keys(metadata).length) {
10995
+ const columnHelper = ui.createDataTableColumnHelper();
10996
+ const useColumns = () => {
10997
+ return React.useMemo(() => {
11104
10998
  return [
11105
- {
11106
- key: "",
11107
- value: "",
11108
- disabled: false
11109
- }
10999
+ columnHelper.select(),
11000
+ columnHelper.accessor("product.title", {
11001
+ header: "Product",
11002
+ cell: ({ row }) => {
11003
+ var _a, _b, _c;
11004
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
11005
+ /* @__PURE__ */ jsxRuntime.jsx(
11006
+ Thumbnail,
11007
+ {
11008
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11009
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11010
+ }
11011
+ ),
11012
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11013
+ ] });
11014
+ },
11015
+ enableSorting: true
11016
+ }),
11017
+ columnHelper.accessor("title", {
11018
+ header: "Variant",
11019
+ enableSorting: true
11020
+ }),
11021
+ columnHelper.accessor("sku", {
11022
+ header: "SKU",
11023
+ cell: ({ getValue }) => {
11024
+ return getValue() ?? "-";
11025
+ },
11026
+ enableSorting: true
11027
+ }),
11028
+ columnHelper.accessor("updated_at", {
11029
+ header: "Updated",
11030
+ cell: ({ getValue }) => {
11031
+ return /* @__PURE__ */ jsxRuntime.jsx(
11032
+ ui.Tooltip,
11033
+ {
11034
+ content: getFullDate({ date: getValue(), includeTime: true }),
11035
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11036
+ }
11037
+ );
11038
+ },
11039
+ enableSorting: true,
11040
+ sortAscLabel: "Oldest first",
11041
+ sortDescLabel: "Newest first"
11042
+ }),
11043
+ columnHelper.accessor("created_at", {
11044
+ header: "Created",
11045
+ cell: ({ getValue }) => {
11046
+ return /* @__PURE__ */ jsxRuntime.jsx(
11047
+ ui.Tooltip,
11048
+ {
11049
+ content: getFullDate({ date: getValue(), includeTime: true }),
11050
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11051
+ }
11052
+ );
11053
+ },
11054
+ enableSorting: true,
11055
+ sortAscLabel: "Oldest first",
11056
+ sortDescLabel: "Newest first"
11057
+ })
11110
11058
  ];
11111
- }
11112
- return Object.entries(metadata).map(([key, value]) => {
11113
- if (!EDITABLE_TYPES.includes(typeof value)) {
11114
- return {
11115
- key,
11116
- value,
11117
- disabled: true
11118
- };
11119
- }
11120
- let stringValue = value;
11121
- if (typeof value !== "string") {
11122
- stringValue = JSON.stringify(value);
11123
- }
11124
- return {
11125
- key,
11126
- value: stringValue,
11127
- original_key: key
11128
- };
11059
+ }, []);
11060
+ };
11061
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11062
+ const { setIsOpen } = useStackedModal();
11063
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11064
+ const form = reactHookForm.useForm({
11065
+ defaultValues: {
11066
+ title: "",
11067
+ quantity: 1,
11068
+ unit_price: ""
11069
+ },
11070
+ resolver: zod.zodResolver(customItemSchema)
11129
11071
  });
11130
- }
11131
- function parseValues(values) {
11132
- const metadata = values.metadata;
11133
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11134
- if (isEmpty) {
11135
- return null;
11136
- }
11137
- const update = {};
11138
- metadata.forEach((field) => {
11139
- let key = field.key;
11140
- let value = field.value;
11141
- const disabled = field.disabled;
11142
- if (!key || !value) {
11143
- return;
11144
- }
11145
- if (disabled) {
11146
- update[key] = value;
11147
- return;
11148
- }
11149
- key = key.trim();
11150
- value = value.trim();
11151
- if (value === "true") {
11152
- update[key] = true;
11153
- } else if (value === "false") {
11154
- update[key] = false;
11155
- } else {
11156
- const parsedNumber = parseFloat(value);
11157
- if (!isNaN(parsedNumber)) {
11158
- update[key] = parsedNumber;
11159
- } else {
11160
- update[key] = value;
11072
+ const onSubmit = form.handleSubmit(async (data) => {
11073
+ await addItems(
11074
+ {
11075
+ items: [
11076
+ {
11077
+ title: data.title,
11078
+ quantity: data.quantity,
11079
+ unit_price: convertNumber(data.unit_price)
11080
+ }
11081
+ ]
11082
+ },
11083
+ {
11084
+ onSuccess: () => {
11085
+ setIsOpen(STACKED_MODAL_ID, false);
11086
+ },
11087
+ onError: (e) => {
11088
+ ui.toast.error(e.message);
11089
+ }
11161
11090
  }
11162
- }
11091
+ );
11163
11092
  });
11164
- return update;
11165
- }
11166
- function getHasUneditableRows(metadata) {
11167
- if (!metadata) {
11168
- return false;
11169
- }
11170
- return Object.values(metadata).some(
11171
- (value) => !EDITABLE_TYPES.includes(typeof value)
11172
- );
11173
- }
11093
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11094
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11095
+ /* @__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: [
11096
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11098
+ /* @__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." }) })
11099
+ ] }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11101
+ /* @__PURE__ */ jsxRuntime.jsx(
11102
+ Form$2.Field,
11103
+ {
11104
+ control: form.control,
11105
+ name: "title",
11106
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11107
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11108
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11109
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
11110
+ ] }),
11111
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11112
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11113
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11114
+ ] })
11115
+ ] }) })
11116
+ }
11117
+ ),
11118
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11119
+ /* @__PURE__ */ jsxRuntime.jsx(
11120
+ Form$2.Field,
11121
+ {
11122
+ control: form.control,
11123
+ name: "unit_price",
11124
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11125
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11126
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11127
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11128
+ ] }),
11129
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11130
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11131
+ ui.CurrencyInput,
11132
+ {
11133
+ symbol: getNativeSymbol(currencyCode),
11134
+ code: currencyCode,
11135
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11136
+ ...field
11137
+ }
11138
+ ) }),
11139
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11140
+ ] })
11141
+ ] }) })
11142
+ }
11143
+ ),
11144
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11145
+ /* @__PURE__ */ jsxRuntime.jsx(
11146
+ Form$2.Field,
11147
+ {
11148
+ control: form.control,
11149
+ name: "quantity",
11150
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11151
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11152
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11153
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11154
+ ] }),
11155
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
11156
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11157
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11158
+ ] })
11159
+ ] }) })
11160
+ }
11161
+ )
11162
+ ] }) }) }),
11163
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11164
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11165
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11166
+ ] }) })
11167
+ ] }) }) });
11168
+ };
11169
+ const customItemSchema = objectType({
11170
+ title: stringType().min(1),
11171
+ quantity: numberType(),
11172
+ unit_price: unionType([numberType(), stringType()])
11173
+ });
11174
11174
  const PROMOTION_QUERY_KEY = "promotions";
11175
11175
  const promotionsQueryKeys = {
11176
11176
  list: (query2) => [
@@ -12350,17 +12350,220 @@ const CustomAmountField = ({
12350
12350
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12351
12351
  ui.CurrencyInput,
12352
12352
  {
12353
- ...field,
12354
- onValueChange: (value) => onChange(value),
12355
- symbol: getNativeSymbol(currencyCode),
12356
- code: currencyCode
12353
+ ...field,
12354
+ onValueChange: (value) => onChange(value),
12355
+ symbol: getNativeSymbol(currencyCode),
12356
+ code: currencyCode
12357
+ }
12358
+ ) })
12359
+ ] });
12360
+ }
12361
+ }
12362
+ );
12363
+ };
12364
+ const ShippingAddress = () => {
12365
+ const { id } = reactRouterDom.useParams();
12366
+ const { order, isPending, isError, error } = useOrder(id, {
12367
+ fields: "+shipping_address"
12368
+ });
12369
+ if (isError) {
12370
+ throw error;
12371
+ }
12372
+ const isReady = !isPending && !!order;
12373
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12374
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12376
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12377
+ ] }),
12378
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12379
+ ] });
12380
+ };
12381
+ const ShippingAddressForm = ({ order }) => {
12382
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12383
+ const form = reactHookForm.useForm({
12384
+ defaultValues: {
12385
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12386
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12387
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12388
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12389
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12390
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12391
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12392
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12393
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12394
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12395
+ },
12396
+ resolver: zod.zodResolver(schema$1)
12397
+ });
12398
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12399
+ const { handleSuccess } = useRouteModal();
12400
+ const onSubmit = form.handleSubmit(async (data) => {
12401
+ await mutateAsync(
12402
+ {
12403
+ shipping_address: {
12404
+ first_name: data.first_name,
12405
+ last_name: data.last_name,
12406
+ company: data.company,
12407
+ address_1: data.address_1,
12408
+ address_2: data.address_2,
12409
+ city: data.city,
12410
+ province: data.province,
12411
+ country_code: data.country_code,
12412
+ postal_code: data.postal_code,
12413
+ phone: data.phone
12414
+ }
12415
+ },
12416
+ {
12417
+ onSuccess: () => {
12418
+ handleSuccess();
12419
+ },
12420
+ onError: (error) => {
12421
+ ui.toast.error(error.message);
12422
+ }
12423
+ }
12424
+ );
12425
+ });
12426
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12427
+ KeyboundForm,
12428
+ {
12429
+ className: "flex flex-1 flex-col overflow-hidden",
12430
+ onSubmit,
12431
+ children: [
12432
+ /* @__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: [
12433
+ /* @__PURE__ */ jsxRuntime.jsx(
12434
+ Form$2.Field,
12435
+ {
12436
+ control: form.control,
12437
+ name: "country_code",
12438
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12441
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12442
+ ] })
12443
+ }
12444
+ ),
12445
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12446
+ /* @__PURE__ */ jsxRuntime.jsx(
12447
+ Form$2.Field,
12448
+ {
12449
+ control: form.control,
12450
+ name: "first_name",
12451
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12452
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12453
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12454
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12455
+ ] })
12456
+ }
12457
+ ),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(
12459
+ Form$2.Field,
12460
+ {
12461
+ control: form.control,
12462
+ name: "last_name",
12463
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12466
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12467
+ ] })
12468
+ }
12469
+ )
12470
+ ] }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(
12472
+ Form$2.Field,
12473
+ {
12474
+ control: form.control,
12475
+ name: "company",
12476
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12478
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12479
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12480
+ ] })
12481
+ }
12482
+ ),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(
12484
+ Form$2.Field,
12485
+ {
12486
+ control: form.control,
12487
+ name: "address_1",
12488
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12490
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12491
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12492
+ ] })
12493
+ }
12494
+ ),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(
12496
+ Form$2.Field,
12497
+ {
12498
+ control: form.control,
12499
+ name: "address_2",
12500
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12501
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12502
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12503
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12504
+ ] })
12505
+ }
12506
+ ),
12507
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12508
+ /* @__PURE__ */ jsxRuntime.jsx(
12509
+ Form$2.Field,
12510
+ {
12511
+ control: form.control,
12512
+ name: "postal_code",
12513
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12514
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12515
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12516
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12517
+ ] })
12518
+ }
12519
+ ),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(
12521
+ Form$2.Field,
12522
+ {
12523
+ control: form.control,
12524
+ name: "city",
12525
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12526
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12527
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12528
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12529
+ ] })
12530
+ }
12531
+ )
12532
+ ] }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(
12534
+ Form$2.Field,
12535
+ {
12536
+ control: form.control,
12537
+ name: "province",
12538
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12542
+ ] })
12543
+ }
12544
+ ),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(
12546
+ Form$2.Field,
12547
+ {
12548
+ control: form.control,
12549
+ name: "phone",
12550
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12551
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12554
+ ] })
12357
12555
  }
12358
- ) })
12359
- ] });
12360
- }
12556
+ )
12557
+ ] }) }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12559
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12560
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12561
+ ] }) })
12562
+ ]
12361
12563
  }
12362
- );
12564
+ ) });
12363
12565
  };
12566
+ const schema$1 = addressSchema;
12364
12567
  const TransferOwnership = () => {
12365
12568
  const { id } = reactRouterDom.useParams();
12366
12569
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12384,7 +12587,7 @@ const TransferOwnershipForm = ({ order }) => {
12384
12587
  defaultValues: {
12385
12588
  customer_id: order.customer_id || ""
12386
12589
  },
12387
- resolver: zod.zodResolver(schema$1)
12590
+ resolver: zod.zodResolver(schema)
12388
12591
  });
12389
12592
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12390
12593
  const { handleSuccess } = useRouteModal();
@@ -12834,212 +13037,9 @@ const Illustration = () => {
12834
13037
  }
12835
13038
  );
12836
13039
  };
12837
- const schema$1 = objectType({
13040
+ const schema = objectType({
12838
13041
  customer_id: stringType().min(1)
12839
13042
  });
12840
- const ShippingAddress = () => {
12841
- const { id } = reactRouterDom.useParams();
12842
- const { order, isPending, isError, error } = useOrder(id, {
12843
- fields: "+shipping_address"
12844
- });
12845
- if (isError) {
12846
- throw error;
12847
- }
12848
- const isReady = !isPending && !!order;
12849
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12850
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12851
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12852
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12853
- ] }),
12854
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12855
- ] });
12856
- };
12857
- const ShippingAddressForm = ({ order }) => {
12858
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12859
- const form = reactHookForm.useForm({
12860
- defaultValues: {
12861
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12862
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12863
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12864
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12865
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12866
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12867
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12868
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12869
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12870
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12871
- },
12872
- resolver: zod.zodResolver(schema)
12873
- });
12874
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12875
- const { handleSuccess } = useRouteModal();
12876
- const onSubmit = form.handleSubmit(async (data) => {
12877
- await mutateAsync(
12878
- {
12879
- shipping_address: {
12880
- first_name: data.first_name,
12881
- last_name: data.last_name,
12882
- company: data.company,
12883
- address_1: data.address_1,
12884
- address_2: data.address_2,
12885
- city: data.city,
12886
- province: data.province,
12887
- country_code: data.country_code,
12888
- postal_code: data.postal_code,
12889
- phone: data.phone
12890
- }
12891
- },
12892
- {
12893
- onSuccess: () => {
12894
- handleSuccess();
12895
- },
12896
- onError: (error) => {
12897
- ui.toast.error(error.message);
12898
- }
12899
- }
12900
- );
12901
- });
12902
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
- KeyboundForm,
12904
- {
12905
- className: "flex flex-1 flex-col overflow-hidden",
12906
- onSubmit,
12907
- children: [
12908
- /* @__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: [
12909
- /* @__PURE__ */ jsxRuntime.jsx(
12910
- Form$2.Field,
12911
- {
12912
- control: form.control,
12913
- name: "country_code",
12914
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12915
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12916
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12917
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12918
- ] })
12919
- }
12920
- ),
12921
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12922
- /* @__PURE__ */ jsxRuntime.jsx(
12923
- Form$2.Field,
12924
- {
12925
- control: form.control,
12926
- name: "first_name",
12927
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12928
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12929
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12930
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12931
- ] })
12932
- }
12933
- ),
12934
- /* @__PURE__ */ jsxRuntime.jsx(
12935
- Form$2.Field,
12936
- {
12937
- control: form.control,
12938
- name: "last_name",
12939
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12940
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12941
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12942
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12943
- ] })
12944
- }
12945
- )
12946
- ] }),
12947
- /* @__PURE__ */ jsxRuntime.jsx(
12948
- Form$2.Field,
12949
- {
12950
- control: form.control,
12951
- name: "company",
12952
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12953
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12954
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12955
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12956
- ] })
12957
- }
12958
- ),
12959
- /* @__PURE__ */ jsxRuntime.jsx(
12960
- Form$2.Field,
12961
- {
12962
- control: form.control,
12963
- name: "address_1",
12964
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12966
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12967
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12968
- ] })
12969
- }
12970
- ),
12971
- /* @__PURE__ */ jsxRuntime.jsx(
12972
- Form$2.Field,
12973
- {
12974
- control: form.control,
12975
- name: "address_2",
12976
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12977
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12980
- ] })
12981
- }
12982
- ),
12983
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12984
- /* @__PURE__ */ jsxRuntime.jsx(
12985
- Form$2.Field,
12986
- {
12987
- control: form.control,
12988
- name: "postal_code",
12989
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12990
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12992
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12993
- ] })
12994
- }
12995
- ),
12996
- /* @__PURE__ */ jsxRuntime.jsx(
12997
- Form$2.Field,
12998
- {
12999
- control: form.control,
13000
- name: "city",
13001
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13005
- ] })
13006
- }
13007
- )
13008
- ] }),
13009
- /* @__PURE__ */ jsxRuntime.jsx(
13010
- Form$2.Field,
13011
- {
13012
- control: form.control,
13013
- name: "province",
13014
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13015
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13016
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13017
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13018
- ] })
13019
- }
13020
- ),
13021
- /* @__PURE__ */ jsxRuntime.jsx(
13022
- Form$2.Field,
13023
- {
13024
- control: form.control,
13025
- name: "phone",
13026
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13028
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13029
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13030
- ] })
13031
- }
13032
- )
13033
- ] }) }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13035
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13036
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13037
- ] }) })
13038
- ]
13039
- }
13040
- ) });
13041
- };
13042
- const schema = addressSchema;
13043
13043
  const widgetModule = { widgets: [] };
13044
13044
  const routeModule = {
13045
13045
  routes: [
@@ -13060,13 +13060,17 @@ const routeModule = {
13060
13060
  handle,
13061
13061
  loader,
13062
13062
  children: [
13063
+ {
13064
+ Component: BillingAddress,
13065
+ path: "/draft-orders/:id/billing-address"
13066
+ },
13063
13067
  {
13064
13068
  Component: CustomItems,
13065
13069
  path: "/draft-orders/:id/custom-items"
13066
13070
  },
13067
13071
  {
13068
- Component: BillingAddress,
13069
- path: "/draft-orders/:id/billing-address"
13072
+ Component: Metadata,
13073
+ path: "/draft-orders/:id/metadata"
13070
13074
  },
13071
13075
  {
13072
13076
  Component: Email,
@@ -13076,10 +13080,6 @@ const routeModule = {
13076
13080
  Component: Items,
13077
13081
  path: "/draft-orders/:id/items"
13078
13082
  },
13079
- {
13080
- Component: Metadata,
13081
- path: "/draft-orders/:id/metadata"
13082
- },
13083
13083
  {
13084
13084
  Component: Promotions,
13085
13085
  path: "/draft-orders/:id/promotions"
@@ -13092,13 +13092,13 @@ const routeModule = {
13092
13092
  Component: Shipping,
13093
13093
  path: "/draft-orders/:id/shipping"
13094
13094
  },
13095
- {
13096
- Component: TransferOwnership,
13097
- path: "/draft-orders/:id/transfer-ownership"
13098
- },
13099
13095
  {
13100
13096
  Component: ShippingAddress,
13101
13097
  path: "/draft-orders/:id/shipping-address"
13098
+ },
13099
+ {
13100
+ Component: TransferOwnership,
13101
+ path: "/draft-orders/:id/transfer-ownership"
13102
13102
  }
13103
13103
  ]
13104
13104
  }