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