@medusajs/draft-order 2.11.2-preview-20251029090152 → 2.11.2-preview-20251029180202

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.
@@ -10750,10 +10750,54 @@ const customItemSchema = objectType({
10750
10750
  quantity: numberType(),
10751
10751
  unit_price: unionType([numberType(), stringType()])
10752
10752
  });
10753
- const Email = () => {
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 = () => {
10754
10798
  const { id } = useParams();
10755
10799
  const { order, isPending, isError, error } = useOrder(id, {
10756
- fields: "+email"
10800
+ fields: "metadata"
10757
10801
  });
10758
10802
  if (isError) {
10759
10803
  throw error;
@@ -10761,26 +10805,33 @@ const Email = () => {
10761
10805
  const isReady = !isPending && !!order;
10762
10806
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10763
10807
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
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" }) })
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." }) })
10766
10810
  ] }),
10767
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10811
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10768
10812
  ] });
10769
10813
  };
10770
- const EmailForm = ({ order }) => {
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);
10771
10820
  const form = useForm({
10772
10821
  defaultValues: {
10773
- email: order.email ?? ""
10822
+ metadata: getDefaultValues(metadata)
10774
10823
  },
10775
- resolver: zodResolver(schema$3)
10824
+ resolver: zodResolver(MetadataSchema)
10776
10825
  });
10777
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10778
- const { handleSuccess } = useRouteModal();
10779
- const onSubmit = form.handleSubmit(async (data) => {
10826
+ const handleSubmit = form.handleSubmit(async (data) => {
10827
+ const parsedData = parseValues(data);
10780
10828
  await mutateAsync(
10781
- { email: data.email },
10829
+ {
10830
+ metadata: parsedData
10831
+ },
10782
10832
  {
10783
10833
  onSuccess: () => {
10834
+ toast.success("Metadata updated");
10784
10835
  handleSuccess();
10785
10836
  },
10786
10837
  onError: (error) => {
@@ -10789,46 +10840,277 @@ const EmailForm = ({ order }) => {
10789
10840
  }
10790
10841
  );
10791
10842
  });
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
+ }
10792
10864
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10793
10865
  KeyboundForm,
10794
10866
  {
10867
+ onSubmit: handleSubmit,
10795
10868
  className: "flex flex-1 flex-col overflow-hidden",
10796
- onSubmit,
10797
10869
  children: [
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" }) }),
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" }) }),
10812
11000
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10813
11001
  ] }) })
10814
11002
  ]
10815
11003
  }
10816
11004
  ) });
10817
11005
  };
10818
- const schema$3 = objectType({
10819
- email: stringType().email()
10820
- });
10821
- const PROMOTION_QUERY_KEY = "promotions";
10822
- const promotionsQueryKeys = {
10823
- list: (query2) => [
10824
- PROMOTION_QUERY_KEY,
10825
- query2 ? query2 : void 0
10826
- ],
10827
- detail: (id, query2) => [
10828
- PROMOTION_QUERY_KEY,
10829
- id,
10830
- query2 ? query2 : void 0
10831
- ]
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
+ );
11019
+ });
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
+ const PROMOTION_QUERY_KEY = "promotions";
11104
+ const promotionsQueryKeys = {
11105
+ list: (query2) => [
11106
+ PROMOTION_QUERY_KEY,
11107
+ query2 ? query2 : void 0
11108
+ ],
11109
+ detail: (id, query2) => [
11110
+ PROMOTION_QUERY_KEY,
11111
+ id,
11112
+ query2 ? query2 : void 0
11113
+ ]
10832
11114
  };
10833
11115
  const usePromotions = (query2, options) => {
10834
11116
  const { data, ...rest } = useQuery({
@@ -11095,88 +11377,46 @@ function getPromotionIds(items, shippingMethods) {
11095
11377
  }
11096
11378
  return Array.from(promotionIds);
11097
11379
  }
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 = () => {
11380
+ const SalesChannel = () => {
11143
11381
  const { id } = useParams();
11144
- const { order, isPending, isError, error } = useOrder(id, {
11145
- fields: "metadata"
11146
- });
11382
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11383
+ id,
11384
+ {
11385
+ fields: "+sales_channel_id"
11386
+ },
11387
+ {
11388
+ enabled: !!id
11389
+ }
11390
+ );
11147
11391
  if (isError) {
11148
11392
  throw error;
11149
11393
  }
11150
- const isReady = !isPending && !!order;
11394
+ const ISrEADY = !!draft_order && !isPending;
11151
11395
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11152
11396
  /* @__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." }) })
11397
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11398
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11155
11399
  ] }),
11156
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11400
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11157
11401
  ] });
11158
11402
  };
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);
11403
+ const SalesChannelForm = ({ order }) => {
11165
11404
  const form = useForm({
11166
11405
  defaultValues: {
11167
- metadata: getDefaultValues(metadata)
11406
+ sales_channel_id: order.sales_channel_id || ""
11168
11407
  },
11169
- resolver: zodResolver(MetadataSchema)
11408
+ resolver: zodResolver(schema$3)
11170
11409
  });
11171
- const handleSubmit = form.handleSubmit(async (data) => {
11172
- const parsedData = parseValues(data);
11410
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11411
+ const { handleSuccess } = useRouteModal();
11412
+ const onSubmit = form.handleSubmit(async (data) => {
11173
11413
  await mutateAsync(
11174
11414
  {
11175
- metadata: parsedData
11415
+ sales_channel_id: data.sales_channel_id
11176
11416
  },
11177
11417
  {
11178
11418
  onSuccess: () => {
11179
- toast.success("Metadata updated");
11419
+ toast.success("Sales channel updated");
11180
11420
  handleSuccess();
11181
11421
  },
11182
11422
  onError: (error) => {
@@ -11185,319 +11425,11 @@ const MetadataForm = ({ orderId, metadata }) => {
11185
11425
  }
11186
11426
  );
11187
11427
  });
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
11428
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11210
11429
  KeyboundForm,
11211
11430
  {
11212
- onSubmit: handleSubmit,
11213
11431
  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 [
11379
- {
11380
- key: "",
11381
- value: "",
11382
- disabled: false
11383
- }
11384
- ];
11385
- }
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
- };
11393
- }
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
- });
11404
- }
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;
11410
- }
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;
11418
- }
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;
11435
- }
11436
- }
11437
- });
11438
- return update;
11439
- }
11440
- function getHasUneditableRows(metadata) {
11441
- if (!metadata) {
11442
- return false;
11443
- }
11444
- return Object.values(metadata).some(
11445
- (value) => !EDITABLE_TYPES.includes(typeof value)
11446
- );
11447
- }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- KeyboundForm,
11498
- {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11432
+ onSubmit,
11501
11433
  children: [
11502
11434
  /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
11435
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
@@ -11548,17 +11480,220 @@ const SalesChannelField = ({ control, order }) => {
11548
11480
  }
11549
11481
  );
11550
11482
  };
11551
- const schema$2 = objectType({
11483
+ const schema$3 = objectType({
11552
11484
  sales_channel_id: stringType().min(1)
11553
11485
  });
11554
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
- const Shipping = () => {
11556
- var _a;
11486
+ const ShippingAddress = () => {
11557
11487
  const { id } = useParams();
11558
11488
  const { order, isPending, isError, error } = useOrder(id, {
11559
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11489
+ fields: "+shipping_address"
11560
11490
  });
11561
- const {
11491
+ if (isError) {
11492
+ throw error;
11493
+ }
11494
+ const isReady = !isPending && !!order;
11495
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11496
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11497
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11498
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11499
+ ] }),
11500
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11501
+ ] });
11502
+ };
11503
+ const ShippingAddressForm = ({ order }) => {
11504
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11505
+ const form = useForm({
11506
+ defaultValues: {
11507
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11508
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11509
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11510
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11511
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11512
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11513
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11514
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11515
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11516
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11517
+ },
11518
+ resolver: zodResolver(schema$2)
11519
+ });
11520
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11521
+ const { handleSuccess } = useRouteModal();
11522
+ const onSubmit = form.handleSubmit(async (data) => {
11523
+ await mutateAsync(
11524
+ {
11525
+ shipping_address: {
11526
+ first_name: data.first_name,
11527
+ last_name: data.last_name,
11528
+ company: data.company,
11529
+ address_1: data.address_1,
11530
+ address_2: data.address_2,
11531
+ city: data.city,
11532
+ province: data.province,
11533
+ country_code: data.country_code,
11534
+ postal_code: data.postal_code,
11535
+ phone: data.phone
11536
+ }
11537
+ },
11538
+ {
11539
+ onSuccess: () => {
11540
+ handleSuccess();
11541
+ },
11542
+ onError: (error) => {
11543
+ toast.error(error.message);
11544
+ }
11545
+ }
11546
+ );
11547
+ });
11548
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11549
+ KeyboundForm,
11550
+ {
11551
+ className: "flex flex-1 flex-col overflow-hidden",
11552
+ onSubmit,
11553
+ children: [
11554
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11555
+ /* @__PURE__ */ jsx(
11556
+ Form$2.Field,
11557
+ {
11558
+ control: form.control,
11559
+ name: "country_code",
11560
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11561
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11562
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11563
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11564
+ ] })
11565
+ }
11566
+ ),
11567
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11568
+ /* @__PURE__ */ jsx(
11569
+ Form$2.Field,
11570
+ {
11571
+ control: form.control,
11572
+ name: "first_name",
11573
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11574
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11575
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11576
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11577
+ ] })
11578
+ }
11579
+ ),
11580
+ /* @__PURE__ */ jsx(
11581
+ Form$2.Field,
11582
+ {
11583
+ control: form.control,
11584
+ name: "last_name",
11585
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11586
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11587
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11588
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11589
+ ] })
11590
+ }
11591
+ )
11592
+ ] }),
11593
+ /* @__PURE__ */ jsx(
11594
+ Form$2.Field,
11595
+ {
11596
+ control: form.control,
11597
+ name: "company",
11598
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11599
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11600
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11601
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11602
+ ] })
11603
+ }
11604
+ ),
11605
+ /* @__PURE__ */ jsx(
11606
+ Form$2.Field,
11607
+ {
11608
+ control: form.control,
11609
+ name: "address_1",
11610
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11611
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11612
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11613
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11614
+ ] })
11615
+ }
11616
+ ),
11617
+ /* @__PURE__ */ jsx(
11618
+ Form$2.Field,
11619
+ {
11620
+ control: form.control,
11621
+ name: "address_2",
11622
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11623
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11624
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11625
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11626
+ ] })
11627
+ }
11628
+ ),
11629
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11630
+ /* @__PURE__ */ jsx(
11631
+ Form$2.Field,
11632
+ {
11633
+ control: form.control,
11634
+ name: "postal_code",
11635
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11636
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11637
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11638
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11639
+ ] })
11640
+ }
11641
+ ),
11642
+ /* @__PURE__ */ jsx(
11643
+ Form$2.Field,
11644
+ {
11645
+ control: form.control,
11646
+ name: "city",
11647
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11648
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11649
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11650
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11651
+ ] })
11652
+ }
11653
+ )
11654
+ ] }),
11655
+ /* @__PURE__ */ jsx(
11656
+ Form$2.Field,
11657
+ {
11658
+ control: form.control,
11659
+ name: "province",
11660
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11661
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11662
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11663
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11664
+ ] })
11665
+ }
11666
+ ),
11667
+ /* @__PURE__ */ jsx(
11668
+ Form$2.Field,
11669
+ {
11670
+ control: form.control,
11671
+ name: "phone",
11672
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11673
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11674
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11675
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11676
+ ] })
11677
+ }
11678
+ )
11679
+ ] }) }),
11680
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11681
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11682
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11683
+ ] }) })
11684
+ ]
11685
+ }
11686
+ ) });
11687
+ };
11688
+ const schema$2 = addressSchema;
11689
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11690
+ const Shipping = () => {
11691
+ var _a;
11692
+ const { id } = useParams();
11693
+ const { order, isPending, isError, error } = useOrder(id, {
11694
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11695
+ });
11696
+ const {
11562
11697
  order: preview,
11563
11698
  isPending: isPreviewPending,
11564
11699
  isError: isPreviewError,
@@ -12209,358 +12344,155 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12209
12344
  ] })
12210
12345
  ] }) })
12211
12346
  ] })
12212
- ] });
12213
- };
12214
- const LocationField = ({ control, setValue }) => {
12215
- const locations = useComboboxData({
12216
- queryKey: ["locations"],
12217
- queryFn: async (params) => {
12218
- return await sdk.admin.stockLocation.list(params);
12219
- },
12220
- getOptions: (data) => {
12221
- return data.stock_locations.map((location) => ({
12222
- label: location.name,
12223
- value: location.id
12224
- }));
12225
- }
12226
- });
12227
- return /* @__PURE__ */ jsx(
12228
- Form$2.Field,
12229
- {
12230
- control,
12231
- name: "location_id",
12232
- render: ({ field: { onChange, ...field } }) => {
12233
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12234
- /* @__PURE__ */ jsxs("div", { children: [
12235
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12236
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12237
- ] }),
12238
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12239
- Combobox,
12240
- {
12241
- options: locations.options,
12242
- fetchNextPage: locations.fetchNextPage,
12243
- isFetchingNextPage: locations.isFetchingNextPage,
12244
- searchValue: locations.searchValue,
12245
- onSearchValueChange: locations.onSearchValueChange,
12246
- placeholder: "Select location",
12247
- onChange: (value) => {
12248
- setValue("shipping_option_id", "", {
12249
- shouldDirty: true,
12250
- shouldTouch: true
12251
- });
12252
- onChange(value);
12253
- },
12254
- ...field
12255
- }
12256
- ) })
12257
- ] }) });
12258
- }
12259
- }
12260
- );
12261
- };
12262
- const ShippingOptionField = ({
12263
- shippingProfileId,
12264
- preview,
12265
- control
12266
- }) => {
12267
- var _a;
12268
- const locationId = useWatch({ control, name: "location_id" });
12269
- const shippingOptions = useComboboxData({
12270
- queryKey: ["shipping_options", locationId, shippingProfileId],
12271
- queryFn: async (params) => {
12272
- return await sdk.admin.shippingOption.list({
12273
- ...params,
12274
- stock_location_id: locationId,
12275
- shipping_profile_id: shippingProfileId
12276
- });
12277
- },
12278
- getOptions: (data) => {
12279
- return data.shipping_options.map((option) => {
12280
- var _a2;
12281
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12282
- (r) => r.attribute === "is_return" && r.value === "true"
12283
- )) {
12284
- return void 0;
12285
- }
12286
- return {
12287
- label: option.name,
12288
- value: option.id
12289
- };
12290
- }).filter(Boolean);
12291
- },
12292
- enabled: !!locationId && !!shippingProfileId,
12293
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12294
- });
12295
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12296
- return /* @__PURE__ */ jsx(
12297
- Form$2.Field,
12298
- {
12299
- control,
12300
- name: "shipping_option_id",
12301
- render: ({ field }) => {
12302
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12303
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12304
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12305
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12306
- ] }),
12307
- /* @__PURE__ */ jsx(
12308
- ConditionalTooltip,
12309
- {
12310
- content: tooltipContent,
12311
- showTooltip: !locationId || !shippingProfileId,
12312
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12313
- Combobox,
12314
- {
12315
- options: shippingOptions.options,
12316
- fetchNextPage: shippingOptions.fetchNextPage,
12317
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12318
- searchValue: shippingOptions.searchValue,
12319
- onSearchValueChange: shippingOptions.onSearchValueChange,
12320
- placeholder: "Select shipping option",
12321
- ...field,
12322
- disabled: !locationId || !shippingProfileId
12323
- }
12324
- ) }) })
12325
- }
12326
- )
12327
- ] }) });
12328
- }
12329
- }
12330
- );
12331
- };
12332
- const CustomAmountField = ({
12333
- control,
12334
- currencyCode
12335
- }) => {
12336
- return /* @__PURE__ */ jsx(
12337
- Form$2.Field,
12338
- {
12339
- control,
12340
- name: "custom_amount",
12341
- render: ({ field: { onChange, ...field } }) => {
12342
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
- ] }),
12347
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
- CurrencyInput,
12349
- {
12350
- ...field,
12351
- onValueChange: (value) => onChange(value),
12352
- symbol: getNativeSymbol(currencyCode),
12353
- code: currencyCode
12354
- }
12355
- ) })
12356
- ] });
12357
- }
12358
- }
12359
- );
12360
- };
12361
- const ShippingAddress = () => {
12362
- const { id } = useParams();
12363
- const { order, isPending, isError, error } = useOrder(id, {
12364
- fields: "+shipping_address"
12365
- });
12366
- if (isError) {
12367
- throw error;
12368
- }
12369
- const isReady = !isPending && !!order;
12370
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
- ] }),
12375
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
- ] });
12377
- };
12378
- const ShippingAddressForm = ({ order }) => {
12379
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
- const form = useForm({
12381
- defaultValues: {
12382
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
- },
12393
- resolver: zodResolver(schema$1)
12394
- });
12395
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
- const { handleSuccess } = useRouteModal();
12397
- const onSubmit = form.handleSubmit(async (data) => {
12398
- await mutateAsync(
12399
- {
12400
- shipping_address: {
12401
- first_name: data.first_name,
12402
- last_name: data.last_name,
12403
- company: data.company,
12404
- address_1: data.address_1,
12405
- address_2: data.address_2,
12406
- city: data.city,
12407
- province: data.province,
12408
- country_code: data.country_code,
12409
- postal_code: data.postal_code,
12410
- phone: data.phone
12411
- }
12412
- },
12413
- {
12414
- onSuccess: () => {
12415
- handleSuccess();
12416
- },
12417
- onError: (error) => {
12418
- toast.error(error.message);
12419
- }
12420
- }
12421
- );
12422
- });
12423
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12424
- KeyboundForm,
12425
- {
12426
- className: "flex flex-1 flex-col overflow-hidden",
12427
- onSubmit,
12428
- children: [
12429
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12430
- /* @__PURE__ */ jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "country_code",
12435
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
- /* @__PURE__ */ jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "first_name",
12448
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- ),
12455
- /* @__PURE__ */ jsx(
12456
- Form$2.Field,
12457
- {
12458
- control: form.control,
12459
- name: "last_name",
12460
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- }
12466
- )
12467
- ] }),
12468
- /* @__PURE__ */ jsx(
12469
- Form$2.Field,
12470
- {
12471
- control: form.control,
12472
- name: "company",
12473
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
- ] })
12478
- }
12479
- ),
12480
- /* @__PURE__ */ jsx(
12481
- Form$2.Field,
12482
- {
12483
- control: form.control,
12484
- name: "address_1",
12485
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
- ] })
12490
- }
12491
- ),
12492
- /* @__PURE__ */ jsx(
12493
- Form$2.Field,
12494
- {
12495
- control: form.control,
12496
- name: "address_2",
12497
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
- ] })
12502
- }
12503
- ),
12504
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
- /* @__PURE__ */ jsx(
12506
- Form$2.Field,
12507
- {
12508
- control: form.control,
12509
- name: "postal_code",
12510
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
- ] })
12515
- }
12516
- ),
12517
- /* @__PURE__ */ jsx(
12518
- Form$2.Field,
12519
- {
12520
- control: form.control,
12521
- name: "city",
12522
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
- ] })
12527
- }
12528
- )
12347
+ ] });
12348
+ };
12349
+ const LocationField = ({ control, setValue }) => {
12350
+ const locations = useComboboxData({
12351
+ queryKey: ["locations"],
12352
+ queryFn: async (params) => {
12353
+ return await sdk.admin.stockLocation.list(params);
12354
+ },
12355
+ getOptions: (data) => {
12356
+ return data.stock_locations.map((location) => ({
12357
+ label: location.name,
12358
+ value: location.id
12359
+ }));
12360
+ }
12361
+ });
12362
+ return /* @__PURE__ */ jsx(
12363
+ Form$2.Field,
12364
+ {
12365
+ control,
12366
+ name: "location_id",
12367
+ render: ({ field: { onChange, ...field } }) => {
12368
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12369
+ /* @__PURE__ */ jsxs("div", { children: [
12370
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12371
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12529
12372
  ] }),
12530
- /* @__PURE__ */ jsx(
12531
- Form$2.Field,
12373
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12374
+ Combobox,
12532
12375
  {
12533
- control: form.control,
12534
- name: "province",
12535
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
- ] })
12376
+ options: locations.options,
12377
+ fetchNextPage: locations.fetchNextPage,
12378
+ isFetchingNextPage: locations.isFetchingNextPage,
12379
+ searchValue: locations.searchValue,
12380
+ onSearchValueChange: locations.onSearchValueChange,
12381
+ placeholder: "Select location",
12382
+ onChange: (value) => {
12383
+ setValue("shipping_option_id", "", {
12384
+ shouldDirty: true,
12385
+ shouldTouch: true
12386
+ });
12387
+ onChange(value);
12388
+ },
12389
+ ...field
12540
12390
  }
12541
- ),
12391
+ ) })
12392
+ ] }) });
12393
+ }
12394
+ }
12395
+ );
12396
+ };
12397
+ const ShippingOptionField = ({
12398
+ shippingProfileId,
12399
+ preview,
12400
+ control
12401
+ }) => {
12402
+ var _a;
12403
+ const locationId = useWatch({ control, name: "location_id" });
12404
+ const shippingOptions = useComboboxData({
12405
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12406
+ queryFn: async (params) => {
12407
+ return await sdk.admin.shippingOption.list({
12408
+ ...params,
12409
+ stock_location_id: locationId,
12410
+ shipping_profile_id: shippingProfileId
12411
+ });
12412
+ },
12413
+ getOptions: (data) => {
12414
+ return data.shipping_options.map((option) => {
12415
+ var _a2;
12416
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12417
+ (r) => r.attribute === "is_return" && r.value === "true"
12418
+ )) {
12419
+ return void 0;
12420
+ }
12421
+ return {
12422
+ label: option.name,
12423
+ value: option.id
12424
+ };
12425
+ }).filter(Boolean);
12426
+ },
12427
+ enabled: !!locationId && !!shippingProfileId,
12428
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12429
+ });
12430
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12431
+ return /* @__PURE__ */ jsx(
12432
+ Form$2.Field,
12433
+ {
12434
+ control,
12435
+ name: "shipping_option_id",
12436
+ render: ({ field }) => {
12437
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12438
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12439
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12440
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12441
+ ] }),
12542
12442
  /* @__PURE__ */ jsx(
12543
- Form$2.Field,
12443
+ ConditionalTooltip,
12544
12444
  {
12545
- control: form.control,
12546
- name: "phone",
12547
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
- ] })
12445
+ content: tooltipContent,
12446
+ showTooltip: !locationId || !shippingProfileId,
12447
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12448
+ Combobox,
12449
+ {
12450
+ options: shippingOptions.options,
12451
+ fetchNextPage: shippingOptions.fetchNextPage,
12452
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12453
+ searchValue: shippingOptions.searchValue,
12454
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12455
+ placeholder: "Select shipping option",
12456
+ ...field,
12457
+ disabled: !locationId || !shippingProfileId
12458
+ }
12459
+ ) }) })
12552
12460
  }
12553
12461
  )
12554
- ] }) }),
12555
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
- ] }) })
12559
- ]
12462
+ ] }) });
12463
+ }
12560
12464
  }
12561
- ) });
12465
+ );
12466
+ };
12467
+ const CustomAmountField = ({
12468
+ control,
12469
+ currencyCode
12470
+ }) => {
12471
+ return /* @__PURE__ */ jsx(
12472
+ Form$2.Field,
12473
+ {
12474
+ control,
12475
+ name: "custom_amount",
12476
+ render: ({ field: { onChange, ...field } }) => {
12477
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12478
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12479
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12480
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12481
+ ] }),
12482
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12483
+ CurrencyInput,
12484
+ {
12485
+ ...field,
12486
+ onValueChange: (value) => onChange(value),
12487
+ symbol: getNativeSymbol(currencyCode),
12488
+ code: currencyCode
12489
+ }
12490
+ ) })
12491
+ ] });
12492
+ }
12493
+ }
12494
+ );
12562
12495
  };
12563
- const schema$1 = addressSchema;
12564
12496
  const TransferOwnership = () => {
12565
12497
  const { id } = useParams();
12566
12498
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12584,7 +12516,7 @@ const TransferOwnershipForm = ({ order }) => {
12584
12516
  defaultValues: {
12585
12517
  customer_id: order.customer_id || ""
12586
12518
  },
12587
- resolver: zodResolver(schema)
12519
+ resolver: zodResolver(schema$1)
12588
12520
  });
12589
12521
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12522
  const { handleSuccess } = useRouteModal();
@@ -13034,9 +12966,77 @@ const Illustration = () => {
13034
12966
  }
13035
12967
  );
13036
12968
  };
13037
- const schema = objectType({
12969
+ const schema$1 = objectType({
13038
12970
  customer_id: stringType().min(1)
13039
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
+ const schema = objectType({
13038
+ email: stringType().email()
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13070,32 +13070,32 @@ const routeModule = {
13070
13070
  path: "/draft-orders/:id/items"
13071
13071
  },
13072
13072
  {
13073
- Component: Email,
13074
- path: "/draft-orders/:id/email"
13073
+ Component: Metadata,
13074
+ path: "/draft-orders/:id/metadata"
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
- },
13084
13080
  {
13085
13081
  Component: SalesChannel,
13086
13082
  path: "/draft-orders/:id/sales-channel"
13087
13083
  },
13088
- {
13089
- Component: Shipping,
13090
- path: "/draft-orders/:id/shipping"
13091
- },
13092
13084
  {
13093
13085
  Component: ShippingAddress,
13094
13086
  path: "/draft-orders/:id/shipping-address"
13095
13087
  },
13088
+ {
13089
+ Component: Shipping,
13090
+ path: "/draft-orders/:id/shipping"
13091
+ },
13096
13092
  {
13097
13093
  Component: TransferOwnership,
13098
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: Email,
13098
+ path: "/draft-orders/:id/email"
13099
13099
  }
13100
13100
  ]
13101
13101
  }