@medusajs/draft-order 2.12.2 → 2.13.0-snapshot-20251214175925

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.
@@ -9572,27 +9572,6 @@ const ID = () => {
9572
9572
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9573
9573
  ] });
9574
9574
  };
9575
- const CustomItems = () => {
9576
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9577
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9578
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9579
- ] });
9580
- };
9581
- const CustomItemsForm = () => {
9582
- const form = reactHookForm.useForm({
9583
- resolver: zod.zodResolver(schema$5)
9584
- });
9585
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9589
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9590
- ] }) })
9591
- ] }) });
9592
- };
9593
- const schema$5 = objectType({
9594
- email: stringType().email()
9595
- });
9596
9575
  const BillingAddress = () => {
9597
9576
  const { id } = reactRouterDom.useParams();
9598
9577
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9625,7 +9604,7 @@ const BillingAddressForm = ({ order }) => {
9625
9604
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9626
9605
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9627
9606
  },
9628
- resolver: zod.zodResolver(schema$4)
9607
+ resolver: zod.zodResolver(schema$5)
9629
9608
  });
9630
9609
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9631
9610
  const { handleSuccess } = useRouteModal();
@@ -9782,7 +9761,28 @@ const BillingAddressForm = ({ order }) => {
9782
9761
  }
9783
9762
  ) });
9784
9763
  };
9785
- const schema$4 = addressSchema;
9764
+ const schema$5 = addressSchema;
9765
+ const CustomItems = () => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
+ ] });
9770
+ };
9771
+ const CustomItemsForm = () => {
9772
+ const form = reactHookForm.useForm({
9773
+ resolver: zod.zodResolver(schema$4)
9774
+ });
9775
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
+ ] }) })
9781
+ ] }) });
9782
+ };
9783
+ const schema$4 = objectType({
9784
+ email: stringType().email()
9785
+ });
9786
9786
  const NumberInput = React.forwardRef(
9787
9787
  ({
9788
9788
  value,
@@ -10757,54 +10757,10 @@ const customItemSchema = objectType({
10757
10757
  quantity: numberType(),
10758
10758
  unit_price: unionType([numberType(), stringType()])
10759
10759
  });
10760
- const InlineTip = React.forwardRef(
10761
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10762
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10763
- return /* @__PURE__ */ jsxRuntime.jsxs(
10764
- "div",
10765
- {
10766
- ref,
10767
- className: ui.clx(
10768
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10769
- className
10770
- ),
10771
- ...props,
10772
- children: [
10773
- /* @__PURE__ */ jsxRuntime.jsx(
10774
- "div",
10775
- {
10776
- role: "presentation",
10777
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10778
- "bg-ui-tag-orange-icon": variant === "warning"
10779
- })
10780
- }
10781
- ),
10782
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10783
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10784
- labelValue,
10785
- ":"
10786
- ] }),
10787
- " ",
10788
- children
10789
- ] })
10790
- ]
10791
- }
10792
- );
10793
- }
10794
- );
10795
- InlineTip.displayName = "InlineTip";
10796
- const MetadataFieldSchema = objectType({
10797
- key: stringType(),
10798
- disabled: booleanType().optional(),
10799
- value: anyType()
10800
- });
10801
- const MetadataSchema = objectType({
10802
- metadata: arrayType(MetadataFieldSchema)
10803
- });
10804
- const Metadata = () => {
10760
+ const Email = () => {
10805
10761
  const { id } = reactRouterDom.useParams();
10806
10762
  const { order, isPending, isError, error } = useOrder(id, {
10807
- fields: "metadata"
10763
+ fields: "+email"
10808
10764
  });
10809
10765
  if (isError) {
10810
10766
  throw error;
@@ -10812,33 +10768,26 @@ const Metadata = () => {
10812
10768
  const isReady = !isPending && !!order;
10813
10769
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10814
10770
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10815
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10816
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10771
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10772
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10817
10773
  ] }),
10818
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10774
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10819
10775
  ] });
10820
10776
  };
10821
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10822
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10823
- const MetadataForm = ({ orderId, metadata }) => {
10824
- const { handleSuccess } = useRouteModal();
10825
- const hasUneditableRows = getHasUneditableRows(metadata);
10826
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10777
+ const EmailForm = ({ order }) => {
10827
10778
  const form = reactHookForm.useForm({
10828
10779
  defaultValues: {
10829
- metadata: getDefaultValues(metadata)
10780
+ email: order.email ?? ""
10830
10781
  },
10831
- resolver: zod.zodResolver(MetadataSchema)
10782
+ resolver: zod.zodResolver(schema$3)
10832
10783
  });
10833
- const handleSubmit = form.handleSubmit(async (data) => {
10834
- const parsedData = parseValues(data);
10784
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10785
+ const { handleSuccess } = useRouteModal();
10786
+ const onSubmit = form.handleSubmit(async (data) => {
10835
10787
  await mutateAsync(
10836
- {
10837
- metadata: parsedData
10838
- },
10788
+ { email: data.email },
10839
10789
  {
10840
10790
  onSuccess: () => {
10841
- ui.toast.success("Metadata updated");
10842
10791
  handleSuccess();
10843
10792
  },
10844
10793
  onError: (error) => {
@@ -10847,266 +10796,35 @@ const MetadataForm = ({ orderId, metadata }) => {
10847
10796
  }
10848
10797
  );
10849
10798
  });
10850
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10851
- control: form.control,
10852
- name: "metadata"
10853
- });
10854
- function deleteRow(index) {
10855
- remove(index);
10856
- if (fields.length === 1) {
10857
- insert(0, {
10858
- key: "",
10859
- value: "",
10860
- disabled: false
10861
- });
10862
- }
10863
- }
10864
- function insertRow(index, position) {
10865
- insert(index + (position === "above" ? 0 : 1), {
10866
- key: "",
10867
- value: "",
10868
- disabled: false
10869
- });
10870
- }
10871
10799
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10872
10800
  KeyboundForm,
10873
10801
  {
10874
- onSubmit: handleSubmit,
10875
10802
  className: "flex flex-1 flex-col overflow-hidden",
10803
+ onSubmit,
10876
10804
  children: [
10877
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10878
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10879
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10880
- /* @__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" }) }),
10881
- /* @__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" }) })
10882
- ] }),
10883
- fields.map((field, index) => {
10884
- const isDisabled = field.disabled || false;
10885
- let placeholder = "-";
10886
- if (typeof field.value === "object") {
10887
- placeholder = "{ ... }";
10888
- }
10889
- if (Array.isArray(field.value)) {
10890
- placeholder = "[ ... ]";
10891
- }
10892
- return /* @__PURE__ */ jsxRuntime.jsx(
10893
- ConditionalTooltip,
10894
- {
10895
- showTooltip: isDisabled,
10896
- content: "This row is disabled because it contains non-primitive data.",
10897
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10898
- /* @__PURE__ */ jsxRuntime.jsxs(
10899
- "div",
10900
- {
10901
- className: ui.clx("grid grid-cols-2 divide-x", {
10902
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10903
- }),
10904
- children: [
10905
- /* @__PURE__ */ jsxRuntime.jsx(
10906
- Form$2.Field,
10907
- {
10908
- control: form.control,
10909
- name: `metadata.${index}.key`,
10910
- render: ({ field: field2 }) => {
10911
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10912
- GridInput,
10913
- {
10914
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10915
- ...field2,
10916
- disabled: isDisabled,
10917
- placeholder: "Key"
10918
- }
10919
- ) }) });
10920
- }
10921
- }
10922
- ),
10923
- /* @__PURE__ */ jsxRuntime.jsx(
10924
- Form$2.Field,
10925
- {
10926
- control: form.control,
10927
- name: `metadata.${index}.value`,
10928
- render: ({ field: { value, ...field2 } }) => {
10929
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10930
- GridInput,
10931
- {
10932
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10933
- ...field2,
10934
- value: isDisabled ? placeholder : value,
10935
- disabled: isDisabled,
10936
- placeholder: "Value"
10937
- }
10938
- ) }) });
10939
- }
10940
- }
10941
- )
10942
- ]
10943
- }
10944
- ),
10945
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10946
- /* @__PURE__ */ jsxRuntime.jsx(
10947
- ui.DropdownMenu.Trigger,
10948
- {
10949
- className: ui.clx(
10950
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10951
- {
10952
- hidden: isDisabled
10953
- }
10954
- ),
10955
- disabled: isDisabled,
10956
- asChild: true,
10957
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10958
- }
10959
- ),
10960
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10961
- /* @__PURE__ */ jsxRuntime.jsxs(
10962
- ui.DropdownMenu.Item,
10963
- {
10964
- className: "gap-x-2",
10965
- onClick: () => insertRow(index, "above"),
10966
- children: [
10967
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10968
- "Insert row above"
10969
- ]
10970
- }
10971
- ),
10972
- /* @__PURE__ */ jsxRuntime.jsxs(
10973
- ui.DropdownMenu.Item,
10974
- {
10975
- className: "gap-x-2",
10976
- onClick: () => insertRow(index, "below"),
10977
- children: [
10978
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10979
- "Insert row below"
10980
- ]
10981
- }
10982
- ),
10983
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10984
- /* @__PURE__ */ jsxRuntime.jsxs(
10985
- ui.DropdownMenu.Item,
10986
- {
10987
- className: "gap-x-2",
10988
- onClick: () => deleteRow(index),
10989
- children: [
10990
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10991
- "Delete row"
10992
- ]
10993
- }
10994
- )
10995
- ] })
10996
- ] })
10997
- ] })
10998
- },
10999
- field.id
11000
- );
11001
- })
11002
- ] }),
11003
- 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." })
11004
- ] }),
11005
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11006
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10805
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10806
+ Form$2.Field,
10807
+ {
10808
+ control: form.control,
10809
+ name: "email",
10810
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10811
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10813
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10814
+ ] })
10815
+ }
10816
+ ) }),
10817
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10818
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11007
10819
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11008
10820
  ] }) })
11009
10821
  ]
11010
10822
  }
11011
10823
  ) });
11012
10824
  };
11013
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11014
- return /* @__PURE__ */ jsxRuntime.jsx(
11015
- "input",
11016
- {
11017
- ref,
11018
- ...props,
11019
- autoComplete: "off",
11020
- className: ui.clx(
11021
- "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",
11022
- className
11023
- )
11024
- }
11025
- );
10825
+ const schema$3 = objectType({
10826
+ email: stringType().email()
11026
10827
  });
11027
- GridInput.displayName = "MetadataForm.GridInput";
11028
- const PlaceholderInner = () => {
11029
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11030
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11031
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11032
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11033
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11034
- ] }) })
11035
- ] });
11036
- };
11037
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11038
- function getDefaultValues(metadata) {
11039
- if (!metadata || !Object.keys(metadata).length) {
11040
- return [
11041
- {
11042
- key: "",
11043
- value: "",
11044
- disabled: false
11045
- }
11046
- ];
11047
- }
11048
- return Object.entries(metadata).map(([key, value]) => {
11049
- if (!EDITABLE_TYPES.includes(typeof value)) {
11050
- return {
11051
- key,
11052
- value,
11053
- disabled: true
11054
- };
11055
- }
11056
- let stringValue = value;
11057
- if (typeof value !== "string") {
11058
- stringValue = JSON.stringify(value);
11059
- }
11060
- return {
11061
- key,
11062
- value: stringValue,
11063
- original_key: key
11064
- };
11065
- });
11066
- }
11067
- function parseValues(values) {
11068
- const metadata = values.metadata;
11069
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11070
- if (isEmpty) {
11071
- return null;
11072
- }
11073
- const update = {};
11074
- metadata.forEach((field) => {
11075
- let key = field.key;
11076
- let value = field.value;
11077
- const disabled = field.disabled;
11078
- if (!key || !value) {
11079
- return;
11080
- }
11081
- if (disabled) {
11082
- update[key] = value;
11083
- return;
11084
- }
11085
- key = key.trim();
11086
- value = value.trim();
11087
- if (value === "true") {
11088
- update[key] = true;
11089
- } else if (value === "false") {
11090
- update[key] = false;
11091
- } else {
11092
- const parsedNumber = parseFloat(value);
11093
- if (!isNaN(parsedNumber)) {
11094
- update[key] = parsedNumber;
11095
- } else {
11096
- update[key] = value;
11097
- }
11098
- }
11099
- });
11100
- return update;
11101
- }
11102
- function getHasUneditableRows(metadata) {
11103
- if (!metadata) {
11104
- return false;
11105
- }
11106
- return Object.values(metadata).some(
11107
- (value) => !EDITABLE_TYPES.includes(typeof value)
11108
- );
11109
- }
11110
10828
  const PROMOTION_QUERY_KEY = "promotions";
11111
10829
  const promotionsQueryKeys = {
11112
10830
  list: (query2) => [
@@ -11278,111 +10996,461 @@ const PromotionForm = ({ preview }) => {
11278
10996
  ] }) })
11279
10997
  ] });
11280
10998
  };
11281
- const PromotionItem = ({
11282
- promotion,
11283
- orderId,
11284
- isLoading
11285
- }) => {
11286
- var _a;
11287
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11288
- const onRemove = async () => {
11289
- removePromotions(
11290
- {
11291
- promo_codes: [promotion.code]
11292
- },
10999
+ const PromotionItem = ({
11000
+ promotion,
11001
+ orderId,
11002
+ isLoading
11003
+ }) => {
11004
+ var _a;
11005
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11006
+ const onRemove = async () => {
11007
+ removePromotions(
11008
+ {
11009
+ promo_codes: [promotion.code]
11010
+ },
11011
+ {
11012
+ onError: (e) => {
11013
+ ui.toast.error(e.message);
11014
+ }
11015
+ }
11016
+ );
11017
+ };
11018
+ const displayValue = getDisplayValue(promotion);
11019
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11020
+ "div",
11021
+ {
11022
+ className: ui.clx(
11023
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11024
+ {
11025
+ "animate-pulse": isLoading
11026
+ }
11027
+ ),
11028
+ children: [
11029
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11030
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11031
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11032
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11033
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11034
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11035
+ ] }),
11036
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11037
+ ] })
11038
+ ] }),
11039
+ /* @__PURE__ */ jsxRuntime.jsx(
11040
+ ui.IconButton,
11041
+ {
11042
+ size: "small",
11043
+ type: "button",
11044
+ variant: "transparent",
11045
+ onClick: onRemove,
11046
+ isLoading: isPending || isLoading,
11047
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11048
+ }
11049
+ )
11050
+ ]
11051
+ },
11052
+ promotion.id
11053
+ );
11054
+ };
11055
+ function getDisplayValue(promotion) {
11056
+ var _a, _b, _c, _d;
11057
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11058
+ if (!value) {
11059
+ return null;
11060
+ }
11061
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11062
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11063
+ if (!currency) {
11064
+ return null;
11065
+ }
11066
+ return getLocaleAmount(value, currency);
11067
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11068
+ return formatPercentage(value);
11069
+ }
11070
+ return null;
11071
+ }
11072
+ const formatter = new Intl.NumberFormat([], {
11073
+ style: "percent",
11074
+ minimumFractionDigits: 2
11075
+ });
11076
+ const formatPercentage = (value, isPercentageValue = false) => {
11077
+ let val = value || 0;
11078
+ if (!isPercentageValue) {
11079
+ val = val / 100;
11080
+ }
11081
+ return formatter.format(val);
11082
+ };
11083
+ function getPromotionIds(items, shippingMethods) {
11084
+ const promotionIds = /* @__PURE__ */ new Set();
11085
+ for (const item of items) {
11086
+ if (item.adjustments) {
11087
+ for (const adjustment of item.adjustments) {
11088
+ if (adjustment.promotion_id) {
11089
+ promotionIds.add(adjustment.promotion_id);
11090
+ }
11091
+ }
11092
+ }
11093
+ }
11094
+ for (const shippingMethod of shippingMethods) {
11095
+ if (shippingMethod.adjustments) {
11096
+ for (const adjustment of shippingMethod.adjustments) {
11097
+ if (adjustment.promotion_id) {
11098
+ promotionIds.add(adjustment.promotion_id);
11099
+ }
11100
+ }
11101
+ }
11102
+ }
11103
+ return Array.from(promotionIds);
11104
+ }
11105
+ const InlineTip = React.forwardRef(
11106
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11107
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11108
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11109
+ "div",
11110
+ {
11111
+ ref,
11112
+ className: ui.clx(
11113
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11114
+ className
11115
+ ),
11116
+ ...props,
11117
+ children: [
11118
+ /* @__PURE__ */ jsxRuntime.jsx(
11119
+ "div",
11120
+ {
11121
+ role: "presentation",
11122
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11123
+ "bg-ui-tag-orange-icon": variant === "warning"
11124
+ })
11125
+ }
11126
+ ),
11127
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11128
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11129
+ labelValue,
11130
+ ":"
11131
+ ] }),
11132
+ " ",
11133
+ children
11134
+ ] })
11135
+ ]
11136
+ }
11137
+ );
11138
+ }
11139
+ );
11140
+ InlineTip.displayName = "InlineTip";
11141
+ const MetadataFieldSchema = objectType({
11142
+ key: stringType(),
11143
+ disabled: booleanType().optional(),
11144
+ value: anyType()
11145
+ });
11146
+ const MetadataSchema = objectType({
11147
+ metadata: arrayType(MetadataFieldSchema)
11148
+ });
11149
+ const Metadata = () => {
11150
+ const { id } = reactRouterDom.useParams();
11151
+ const { order, isPending, isError, error } = useOrder(id, {
11152
+ fields: "metadata"
11153
+ });
11154
+ if (isError) {
11155
+ throw error;
11156
+ }
11157
+ const isReady = !isPending && !!order;
11158
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11159
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11161
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11162
+ ] }),
11163
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11164
+ ] });
11165
+ };
11166
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11167
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11168
+ const MetadataForm = ({ orderId, metadata }) => {
11169
+ const { handleSuccess } = useRouteModal();
11170
+ const hasUneditableRows = getHasUneditableRows(metadata);
11171
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11172
+ const form = reactHookForm.useForm({
11173
+ defaultValues: {
11174
+ metadata: getDefaultValues(metadata)
11175
+ },
11176
+ resolver: zod.zodResolver(MetadataSchema)
11177
+ });
11178
+ const handleSubmit = form.handleSubmit(async (data) => {
11179
+ const parsedData = parseValues(data);
11180
+ await mutateAsync(
11181
+ {
11182
+ metadata: parsedData
11183
+ },
11184
+ {
11185
+ onSuccess: () => {
11186
+ ui.toast.success("Metadata updated");
11187
+ handleSuccess();
11188
+ },
11189
+ onError: (error) => {
11190
+ ui.toast.error(error.message);
11191
+ }
11192
+ }
11193
+ );
11194
+ });
11195
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11196
+ control: form.control,
11197
+ name: "metadata"
11198
+ });
11199
+ function deleteRow(index) {
11200
+ remove(index);
11201
+ if (fields.length === 1) {
11202
+ insert(0, {
11203
+ key: "",
11204
+ value: "",
11205
+ disabled: false
11206
+ });
11207
+ }
11208
+ }
11209
+ function insertRow(index, position) {
11210
+ insert(index + (position === "above" ? 0 : 1), {
11211
+ key: "",
11212
+ value: "",
11213
+ disabled: false
11214
+ });
11215
+ }
11216
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11217
+ KeyboundForm,
11218
+ {
11219
+ onSubmit: handleSubmit,
11220
+ className: "flex flex-1 flex-col overflow-hidden",
11221
+ children: [
11222
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11224
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11225
+ /* @__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" }) }),
11226
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11227
+ ] }),
11228
+ fields.map((field, index) => {
11229
+ const isDisabled = field.disabled || false;
11230
+ let placeholder = "-";
11231
+ if (typeof field.value === "object") {
11232
+ placeholder = "{ ... }";
11233
+ }
11234
+ if (Array.isArray(field.value)) {
11235
+ placeholder = "[ ... ]";
11236
+ }
11237
+ return /* @__PURE__ */ jsxRuntime.jsx(
11238
+ ConditionalTooltip,
11239
+ {
11240
+ showTooltip: isDisabled,
11241
+ content: "This row is disabled because it contains non-primitive data.",
11242
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11243
+ /* @__PURE__ */ jsxRuntime.jsxs(
11244
+ "div",
11245
+ {
11246
+ className: ui.clx("grid grid-cols-2 divide-x", {
11247
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11248
+ }),
11249
+ children: [
11250
+ /* @__PURE__ */ jsxRuntime.jsx(
11251
+ Form$2.Field,
11252
+ {
11253
+ control: form.control,
11254
+ name: `metadata.${index}.key`,
11255
+ render: ({ field: field2 }) => {
11256
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11257
+ GridInput,
11258
+ {
11259
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11260
+ ...field2,
11261
+ disabled: isDisabled,
11262
+ placeholder: "Key"
11263
+ }
11264
+ ) }) });
11265
+ }
11266
+ }
11267
+ ),
11268
+ /* @__PURE__ */ jsxRuntime.jsx(
11269
+ Form$2.Field,
11270
+ {
11271
+ control: form.control,
11272
+ name: `metadata.${index}.value`,
11273
+ render: ({ field: { value, ...field2 } }) => {
11274
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11275
+ GridInput,
11276
+ {
11277
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11278
+ ...field2,
11279
+ value: isDisabled ? placeholder : value,
11280
+ disabled: isDisabled,
11281
+ placeholder: "Value"
11282
+ }
11283
+ ) }) });
11284
+ }
11285
+ }
11286
+ )
11287
+ ]
11288
+ }
11289
+ ),
11290
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11291
+ /* @__PURE__ */ jsxRuntime.jsx(
11292
+ ui.DropdownMenu.Trigger,
11293
+ {
11294
+ className: ui.clx(
11295
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11296
+ {
11297
+ hidden: isDisabled
11298
+ }
11299
+ ),
11300
+ disabled: isDisabled,
11301
+ asChild: true,
11302
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11303
+ }
11304
+ ),
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsxs(
11307
+ ui.DropdownMenu.Item,
11308
+ {
11309
+ className: "gap-x-2",
11310
+ onClick: () => insertRow(index, "above"),
11311
+ children: [
11312
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11313
+ "Insert row above"
11314
+ ]
11315
+ }
11316
+ ),
11317
+ /* @__PURE__ */ jsxRuntime.jsxs(
11318
+ ui.DropdownMenu.Item,
11319
+ {
11320
+ className: "gap-x-2",
11321
+ onClick: () => insertRow(index, "below"),
11322
+ children: [
11323
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11324
+ "Insert row below"
11325
+ ]
11326
+ }
11327
+ ),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11329
+ /* @__PURE__ */ jsxRuntime.jsxs(
11330
+ ui.DropdownMenu.Item,
11331
+ {
11332
+ className: "gap-x-2",
11333
+ onClick: () => deleteRow(index),
11334
+ children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11336
+ "Delete row"
11337
+ ]
11338
+ }
11339
+ )
11340
+ ] })
11341
+ ] })
11342
+ ] })
11343
+ },
11344
+ field.id
11345
+ );
11346
+ })
11347
+ ] }),
11348
+ 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." })
11349
+ ] }),
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11351
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11352
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11353
+ ] }) })
11354
+ ]
11355
+ }
11356
+ ) });
11357
+ };
11358
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11359
+ return /* @__PURE__ */ jsxRuntime.jsx(
11360
+ "input",
11361
+ {
11362
+ ref,
11363
+ ...props,
11364
+ autoComplete: "off",
11365
+ className: ui.clx(
11366
+ "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",
11367
+ className
11368
+ )
11369
+ }
11370
+ );
11371
+ });
11372
+ GridInput.displayName = "MetadataForm.GridInput";
11373
+ const PlaceholderInner = () => {
11374
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11376
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11378
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11379
+ ] }) })
11380
+ ] });
11381
+ };
11382
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11383
+ function getDefaultValues(metadata) {
11384
+ if (!metadata || !Object.keys(metadata).length) {
11385
+ return [
11293
11386
  {
11294
- onError: (e) => {
11295
- ui.toast.error(e.message);
11296
- }
11387
+ key: "",
11388
+ value: "",
11389
+ disabled: false
11297
11390
  }
11298
- );
11299
- };
11300
- const displayValue = getDisplayValue(promotion);
11301
- return /* @__PURE__ */ jsxRuntime.jsxs(
11302
- "div",
11303
- {
11304
- className: ui.clx(
11305
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11306
- {
11307
- "animate-pulse": isLoading
11308
- }
11309
- ),
11310
- children: [
11311
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11312
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11313
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11314
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11315
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11316
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11317
- ] }),
11318
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11319
- ] })
11320
- ] }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(
11322
- ui.IconButton,
11323
- {
11324
- size: "small",
11325
- type: "button",
11326
- variant: "transparent",
11327
- onClick: onRemove,
11328
- isLoading: isPending || isLoading,
11329
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11330
- }
11331
- )
11332
- ]
11333
- },
11334
- promotion.id
11335
- );
11336
- };
11337
- function getDisplayValue(promotion) {
11338
- var _a, _b, _c, _d;
11339
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11340
- if (!value) {
11341
- return null;
11391
+ ];
11342
11392
  }
11343
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11344
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11345
- if (!currency) {
11346
- return null;
11393
+ return Object.entries(metadata).map(([key, value]) => {
11394
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11395
+ return {
11396
+ key,
11397
+ value,
11398
+ disabled: true
11399
+ };
11347
11400
  }
11348
- return getLocaleAmount(value, currency);
11349
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11350
- return formatPercentage(value);
11351
- }
11352
- return null;
11401
+ let stringValue = value;
11402
+ if (typeof value !== "string") {
11403
+ stringValue = JSON.stringify(value);
11404
+ }
11405
+ return {
11406
+ key,
11407
+ value: stringValue,
11408
+ original_key: key
11409
+ };
11410
+ });
11353
11411
  }
11354
- const formatter = new Intl.NumberFormat([], {
11355
- style: "percent",
11356
- minimumFractionDigits: 2
11357
- });
11358
- const formatPercentage = (value, isPercentageValue = false) => {
11359
- let val = value || 0;
11360
- if (!isPercentageValue) {
11361
- val = val / 100;
11412
+ function parseValues(values) {
11413
+ const metadata = values.metadata;
11414
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11415
+ if (isEmpty) {
11416
+ return null;
11362
11417
  }
11363
- return formatter.format(val);
11364
- };
11365
- function getPromotionIds(items, shippingMethods) {
11366
- const promotionIds = /* @__PURE__ */ new Set();
11367
- for (const item of items) {
11368
- if (item.adjustments) {
11369
- for (const adjustment of item.adjustments) {
11370
- if (adjustment.promotion_id) {
11371
- promotionIds.add(adjustment.promotion_id);
11372
- }
11373
- }
11418
+ const update = {};
11419
+ metadata.forEach((field) => {
11420
+ let key = field.key;
11421
+ let value = field.value;
11422
+ const disabled = field.disabled;
11423
+ if (!key || !value) {
11424
+ return;
11374
11425
  }
11375
- }
11376
- for (const shippingMethod of shippingMethods) {
11377
- if (shippingMethod.adjustments) {
11378
- for (const adjustment of shippingMethod.adjustments) {
11379
- if (adjustment.promotion_id) {
11380
- promotionIds.add(adjustment.promotion_id);
11381
- }
11426
+ if (disabled) {
11427
+ update[key] = value;
11428
+ return;
11429
+ }
11430
+ key = key.trim();
11431
+ value = value.trim();
11432
+ if (value === "true") {
11433
+ update[key] = true;
11434
+ } else if (value === "false") {
11435
+ update[key] = false;
11436
+ } else {
11437
+ const parsedNumber = parseFloat(value);
11438
+ if (!isNaN(parsedNumber)) {
11439
+ update[key] = parsedNumber;
11440
+ } else {
11441
+ update[key] = value;
11382
11442
  }
11383
11443
  }
11444
+ });
11445
+ return update;
11446
+ }
11447
+ function getHasUneditableRows(metadata) {
11448
+ if (!metadata) {
11449
+ return false;
11384
11450
  }
11385
- return Array.from(promotionIds);
11451
+ return Object.values(metadata).some(
11452
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11453
+ );
11386
11454
  }
11387
11455
  const SalesChannel = () => {
11388
11456
  const { id } = reactRouterDom.useParams();
@@ -11412,7 +11480,7 @@ const SalesChannelForm = ({ order }) => {
11412
11480
  defaultValues: {
11413
11481
  sales_channel_id: order.sales_channel_id || ""
11414
11482
  },
11415
- resolver: zod.zodResolver(schema$3)
11483
+ resolver: zod.zodResolver(schema$2)
11416
11484
  });
11417
11485
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11418
11486
  const { handleSuccess } = useRouteModal();
@@ -11487,7 +11555,7 @@ const SalesChannelField = ({ control, order }) => {
11487
11555
  }
11488
11556
  );
11489
11557
  };
11490
- const schema$3 = objectType({
11558
+ const schema$2 = objectType({
11491
11559
  sales_channel_id: stringType().min(1)
11492
11560
  });
11493
11561
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12329,7 +12397,7 @@ const ShippingAddressForm = ({ order }) => {
12329
12397
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12330
12398
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12331
12399
  },
12332
- resolver: zod.zodResolver(schema$2)
12400
+ resolver: zod.zodResolver(schema$1)
12333
12401
  });
12334
12402
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12335
12403
  const { handleSuccess } = useRouteModal();
@@ -12499,7 +12567,7 @@ const ShippingAddressForm = ({ order }) => {
12499
12567
  }
12500
12568
  ) });
12501
12569
  };
12502
- const schema$2 = addressSchema;
12570
+ const schema$1 = addressSchema;
12503
12571
  const TransferOwnership = () => {
12504
12572
  const { id } = reactRouterDom.useParams();
12505
12573
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12523,7 +12591,7 @@ const TransferOwnershipForm = ({ order }) => {
12523
12591
  defaultValues: {
12524
12592
  customer_id: order.customer_id || ""
12525
12593
  },
12526
- resolver: zod.zodResolver(schema$1)
12594
+ resolver: zod.zodResolver(schema)
12527
12595
  });
12528
12596
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12529
12597
  const { handleSuccess } = useRouteModal();
@@ -12973,76 +13041,8 @@ const Illustration = () => {
12973
13041
  }
12974
13042
  );
12975
13043
  };
12976
- const schema$1 = objectType({
12977
- customer_id: stringType().min(1)
12978
- });
12979
- const Email = () => {
12980
- const { id } = reactRouterDom.useParams();
12981
- const { order, isPending, isError, error } = useOrder(id, {
12982
- fields: "+email"
12983
- });
12984
- if (isError) {
12985
- throw error;
12986
- }
12987
- const isReady = !isPending && !!order;
12988
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12989
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12990
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12991
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12992
- ] }),
12993
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12994
- ] });
12995
- };
12996
- const EmailForm = ({ order }) => {
12997
- const form = reactHookForm.useForm({
12998
- defaultValues: {
12999
- email: order.email ?? ""
13000
- },
13001
- resolver: zod.zodResolver(schema)
13002
- });
13003
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13004
- const { handleSuccess } = useRouteModal();
13005
- const onSubmit = form.handleSubmit(async (data) => {
13006
- await mutateAsync(
13007
- { email: data.email },
13008
- {
13009
- onSuccess: () => {
13010
- handleSuccess();
13011
- },
13012
- onError: (error) => {
13013
- ui.toast.error(error.message);
13014
- }
13015
- }
13016
- );
13017
- });
13018
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13019
- KeyboundForm,
13020
- {
13021
- className: "flex flex-1 flex-col overflow-hidden",
13022
- onSubmit,
13023
- children: [
13024
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13025
- Form$2.Field,
13026
- {
13027
- control: form.control,
13028
- name: "email",
13029
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
- ] })
13034
- }
13035
- ) }),
13036
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13037
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13038
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13039
- ] }) })
13040
- ]
13041
- }
13042
- ) });
13043
- };
13044
13044
  const schema = objectType({
13045
- email: stringType().email()
13045
+ customer_id: stringType().min(1)
13046
13046
  });
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
@@ -13064,26 +13064,30 @@ const routeModule = {
13064
13064
  handle,
13065
13065
  loader,
13066
13066
  children: [
13067
- {
13068
- Component: CustomItems,
13069
- path: "/draft-orders/:id/custom-items"
13070
- },
13071
13067
  {
13072
13068
  Component: BillingAddress,
13073
13069
  path: "/draft-orders/:id/billing-address"
13074
13070
  },
13071
+ {
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
+ },
13075
13075
  {
13076
13076
  Component: Items,
13077
13077
  path: "/draft-orders/:id/items"
13078
13078
  },
13079
13079
  {
13080
- Component: Metadata,
13081
- path: "/draft-orders/:id/metadata"
13080
+ Component: Email,
13081
+ path: "/draft-orders/:id/email"
13082
13082
  },
13083
13083
  {
13084
13084
  Component: Promotions,
13085
13085
  path: "/draft-orders/:id/promotions"
13086
13086
  },
13087
+ {
13088
+ Component: Metadata,
13089
+ path: "/draft-orders/:id/metadata"
13090
+ },
13087
13091
  {
13088
13092
  Component: SalesChannel,
13089
13093
  path: "/draft-orders/:id/sales-channel"
@@ -13099,10 +13103,6 @@ const routeModule = {
13099
13103
  {
13100
13104
  Component: TransferOwnership,
13101
13105
  path: "/draft-orders/:id/transfer-ownership"
13102
- },
13103
- {
13104
- Component: Email,
13105
- path: "/draft-orders/:id/email"
13106
13106
  }
13107
13107
  ]
13108
13108
  }