@medusajs/draft-order 2.11.4-preview-20251108180137 → 2.11.4-preview-20251109000311

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.
@@ -9772,6 +9772,74 @@ const CustomItemsForm = () => {
9772
9772
  const schema$4 = objectType({
9773
9773
  email: stringType().email()
9774
9774
  });
9775
+ const Email = () => {
9776
+ const { id } = useParams();
9777
+ const { order, isPending, isError, error } = useOrder(id, {
9778
+ fields: "+email"
9779
+ });
9780
+ if (isError) {
9781
+ throw error;
9782
+ }
9783
+ const isReady = !isPending && !!order;
9784
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9785
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9786
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9787
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9788
+ ] }),
9789
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9790
+ ] });
9791
+ };
9792
+ const EmailForm = ({ order }) => {
9793
+ const form = useForm({
9794
+ defaultValues: {
9795
+ email: order.email ?? ""
9796
+ },
9797
+ resolver: zodResolver(schema$3)
9798
+ });
9799
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9800
+ const { handleSuccess } = useRouteModal();
9801
+ const onSubmit = form.handleSubmit(async (data) => {
9802
+ await mutateAsync(
9803
+ { email: data.email },
9804
+ {
9805
+ onSuccess: () => {
9806
+ handleSuccess();
9807
+ },
9808
+ onError: (error) => {
9809
+ toast.error(error.message);
9810
+ }
9811
+ }
9812
+ );
9813
+ });
9814
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9815
+ KeyboundForm,
9816
+ {
9817
+ className: "flex flex-1 flex-col overflow-hidden",
9818
+ onSubmit,
9819
+ children: [
9820
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9821
+ Form$2.Field,
9822
+ {
9823
+ control: form.control,
9824
+ name: "email",
9825
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9826
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9827
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9828
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9829
+ ] })
9830
+ }
9831
+ ) }),
9832
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9833
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9834
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9835
+ ] }) })
9836
+ ]
9837
+ }
9838
+ ) });
9839
+ };
9840
+ const schema$3 = objectType({
9841
+ email: stringType().email()
9842
+ });
9775
9843
  const NumberInput = forwardRef(
9776
9844
  ({
9777
9845
  value,
@@ -10746,527 +10814,109 @@ const customItemSchema = objectType({
10746
10814
  quantity: numberType(),
10747
10815
  unit_price: unionType([numberType(), stringType()])
10748
10816
  });
10749
- const InlineTip = forwardRef(
10750
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10751
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10752
- return /* @__PURE__ */ jsxs(
10753
- "div",
10754
- {
10755
- ref,
10756
- className: clx(
10757
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10758
- className
10759
- ),
10760
- ...props,
10761
- children: [
10762
- /* @__PURE__ */ jsx(
10763
- "div",
10764
- {
10765
- role: "presentation",
10766
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10767
- "bg-ui-tag-orange-icon": variant === "warning"
10768
- })
10769
- }
10770
- ),
10771
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10772
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10773
- labelValue,
10774
- ":"
10775
- ] }),
10776
- " ",
10777
- children
10778
- ] })
10779
- ]
10780
- }
10781
- );
10782
- }
10783
- );
10784
- InlineTip.displayName = "InlineTip";
10785
- const MetadataFieldSchema = objectType({
10786
- key: stringType(),
10787
- disabled: booleanType().optional(),
10788
- value: anyType()
10789
- });
10790
- const MetadataSchema = objectType({
10791
- metadata: arrayType(MetadataFieldSchema)
10792
- });
10793
- const Metadata = () => {
10794
- const { id } = useParams();
10795
- const { order, isPending, isError, error } = useOrder(id, {
10796
- fields: "metadata"
10817
+ const PROMOTION_QUERY_KEY = "promotions";
10818
+ const promotionsQueryKeys = {
10819
+ list: (query2) => [
10820
+ PROMOTION_QUERY_KEY,
10821
+ query2 ? query2 : void 0
10822
+ ],
10823
+ detail: (id, query2) => [
10824
+ PROMOTION_QUERY_KEY,
10825
+ id,
10826
+ query2 ? query2 : void 0
10827
+ ]
10828
+ };
10829
+ const usePromotions = (query2, options) => {
10830
+ const { data, ...rest } = useQuery({
10831
+ queryKey: promotionsQueryKeys.list(query2),
10832
+ queryFn: async () => sdk.admin.promotion.list(query2),
10833
+ ...options
10797
10834
  });
10798
- if (isError) {
10799
- throw error;
10835
+ return { ...data, ...rest };
10836
+ };
10837
+ const Promotions = () => {
10838
+ const { id } = useParams();
10839
+ const {
10840
+ order: preview,
10841
+ isError: isPreviewError,
10842
+ error: previewError
10843
+ } = useOrderPreview(id, void 0);
10844
+ useInitiateOrderEdit({ preview });
10845
+ const { onCancel } = useCancelOrderEdit({ preview });
10846
+ if (isPreviewError) {
10847
+ throw previewError;
10800
10848
  }
10801
- const isReady = !isPending && !!order;
10802
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10803
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10804
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10805
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10806
- ] }),
10807
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10849
+ const isReady = !!preview;
10850
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10851
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10852
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10808
10853
  ] });
10809
10854
  };
10810
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10811
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10812
- const MetadataForm = ({ orderId, metadata }) => {
10855
+ const PromotionForm = ({ preview }) => {
10856
+ const { items, shipping_methods } = preview;
10857
+ const [isSubmitting, setIsSubmitting] = useState(false);
10858
+ const [comboboxValue, setComboboxValue] = useState("");
10813
10859
  const { handleSuccess } = useRouteModal();
10814
- const hasUneditableRows = getHasUneditableRows(metadata);
10815
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10816
- const form = useForm({
10817
- defaultValues: {
10818
- metadata: getDefaultValues(metadata)
10860
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10861
+ const promoIds = getPromotionIds(items, shipping_methods);
10862
+ const { promotions, isPending, isError, error } = usePromotions(
10863
+ {
10864
+ id: promoIds
10819
10865
  },
10820
- resolver: zodResolver(MetadataSchema)
10866
+ {
10867
+ enabled: !!promoIds.length
10868
+ }
10869
+ );
10870
+ const comboboxData = useComboboxData({
10871
+ queryKey: ["promotions", "combobox", promoIds],
10872
+ queryFn: async (params) => {
10873
+ return await sdk.admin.promotion.list({
10874
+ ...params,
10875
+ id: {
10876
+ $nin: promoIds
10877
+ }
10878
+ });
10879
+ },
10880
+ getOptions: (data) => {
10881
+ return data.promotions.map((promotion) => ({
10882
+ label: promotion.code,
10883
+ value: promotion.code
10884
+ }));
10885
+ }
10821
10886
  });
10822
- const handleSubmit = form.handleSubmit(async (data) => {
10823
- const parsedData = parseValues(data);
10824
- await mutateAsync(
10887
+ const add = async (value) => {
10888
+ if (!value) {
10889
+ return;
10890
+ }
10891
+ addPromotions(
10825
10892
  {
10826
- metadata: parsedData
10893
+ promo_codes: [value]
10827
10894
  },
10828
10895
  {
10829
- onSuccess: () => {
10830
- toast.success("Metadata updated");
10831
- handleSuccess();
10896
+ onError: (e) => {
10897
+ toast.error(e.message);
10898
+ comboboxData.onSearchValueChange("");
10899
+ setComboboxValue("");
10832
10900
  },
10833
- onError: (error) => {
10834
- toast.error(error.message);
10901
+ onSuccess: () => {
10902
+ comboboxData.onSearchValueChange("");
10903
+ setComboboxValue("");
10835
10904
  }
10836
10905
  }
10837
10906
  );
10838
- });
10839
- const { fields, insert, remove } = useFieldArray({
10840
- control: form.control,
10841
- name: "metadata"
10842
- });
10843
- function deleteRow(index) {
10844
- remove(index);
10845
- if (fields.length === 1) {
10846
- insert(0, {
10847
- key: "",
10848
- value: "",
10849
- disabled: false
10850
- });
10851
- }
10852
- }
10853
- function insertRow(index, position) {
10854
- insert(index + (position === "above" ? 0 : 1), {
10855
- key: "",
10856
- value: "",
10857
- disabled: false
10858
- });
10859
- }
10860
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10861
- KeyboundForm,
10862
- {
10863
- onSubmit: handleSubmit,
10864
- className: "flex flex-1 flex-col overflow-hidden",
10865
- children: [
10866
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10867
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10868
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10869
- /* @__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" }) }),
10870
- /* @__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" }) })
10871
- ] }),
10872
- fields.map((field, index) => {
10873
- const isDisabled = field.disabled || false;
10874
- let placeholder = "-";
10875
- if (typeof field.value === "object") {
10876
- placeholder = "{ ... }";
10877
- }
10878
- if (Array.isArray(field.value)) {
10879
- placeholder = "[ ... ]";
10880
- }
10881
- return /* @__PURE__ */ jsx(
10882
- ConditionalTooltip,
10883
- {
10884
- showTooltip: isDisabled,
10885
- content: "This row is disabled because it contains non-primitive data.",
10886
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10887
- /* @__PURE__ */ jsxs(
10888
- "div",
10889
- {
10890
- className: clx("grid grid-cols-2 divide-x", {
10891
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10892
- }),
10893
- children: [
10894
- /* @__PURE__ */ jsx(
10895
- Form$2.Field,
10896
- {
10897
- control: form.control,
10898
- name: `metadata.${index}.key`,
10899
- render: ({ field: field2 }) => {
10900
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10901
- GridInput,
10902
- {
10903
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10904
- ...field2,
10905
- disabled: isDisabled,
10906
- placeholder: "Key"
10907
- }
10908
- ) }) });
10909
- }
10910
- }
10911
- ),
10912
- /* @__PURE__ */ jsx(
10913
- Form$2.Field,
10914
- {
10915
- control: form.control,
10916
- name: `metadata.${index}.value`,
10917
- render: ({ field: { value, ...field2 } }) => {
10918
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10919
- GridInput,
10920
- {
10921
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10922
- ...field2,
10923
- value: isDisabled ? placeholder : value,
10924
- disabled: isDisabled,
10925
- placeholder: "Value"
10926
- }
10927
- ) }) });
10928
- }
10929
- }
10930
- )
10931
- ]
10932
- }
10933
- ),
10934
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10935
- /* @__PURE__ */ jsx(
10936
- DropdownMenu.Trigger,
10937
- {
10938
- className: clx(
10939
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10940
- {
10941
- hidden: isDisabled
10942
- }
10943
- ),
10944
- disabled: isDisabled,
10945
- asChild: true,
10946
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10947
- }
10948
- ),
10949
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10950
- /* @__PURE__ */ jsxs(
10951
- DropdownMenu.Item,
10952
- {
10953
- className: "gap-x-2",
10954
- onClick: () => insertRow(index, "above"),
10955
- children: [
10956
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10957
- "Insert row above"
10958
- ]
10959
- }
10960
- ),
10961
- /* @__PURE__ */ jsxs(
10962
- DropdownMenu.Item,
10963
- {
10964
- className: "gap-x-2",
10965
- onClick: () => insertRow(index, "below"),
10966
- children: [
10967
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10968
- "Insert row below"
10969
- ]
10970
- }
10971
- ),
10972
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10973
- /* @__PURE__ */ jsxs(
10974
- DropdownMenu.Item,
10975
- {
10976
- className: "gap-x-2",
10977
- onClick: () => deleteRow(index),
10978
- children: [
10979
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10980
- "Delete row"
10981
- ]
10982
- }
10983
- )
10984
- ] })
10985
- ] })
10986
- ] })
10987
- },
10988
- field.id
10989
- );
10990
- })
10991
- ] }),
10992
- 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." })
10993
- ] }),
10994
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10995
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10996
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10997
- ] }) })
10998
- ]
10999
- }
11000
- ) });
11001
- };
11002
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11003
- return /* @__PURE__ */ jsx(
11004
- "input",
11005
- {
11006
- ref,
11007
- ...props,
11008
- autoComplete: "off",
11009
- className: clx(
11010
- "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",
11011
- className
11012
- )
11013
- }
11014
- );
11015
- });
11016
- GridInput.displayName = "MetadataForm.GridInput";
11017
- const PlaceholderInner = () => {
11018
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11019
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11020
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11021
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11022
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11023
- ] }) })
11024
- ] });
11025
- };
11026
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11027
- function getDefaultValues(metadata) {
11028
- if (!metadata || !Object.keys(metadata).length) {
11029
- return [
11030
- {
11031
- key: "",
11032
- value: "",
11033
- disabled: false
11034
- }
11035
- ];
11036
- }
11037
- return Object.entries(metadata).map(([key, value]) => {
11038
- if (!EDITABLE_TYPES.includes(typeof value)) {
11039
- return {
11040
- key,
11041
- value,
11042
- disabled: true
11043
- };
11044
- }
11045
- let stringValue = value;
11046
- if (typeof value !== "string") {
11047
- stringValue = JSON.stringify(value);
11048
- }
11049
- return {
11050
- key,
11051
- value: stringValue,
11052
- original_key: key
11053
- };
11054
- });
11055
- }
11056
- function parseValues(values) {
11057
- const metadata = values.metadata;
11058
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11059
- if (isEmpty) {
11060
- return null;
11061
- }
11062
- const update = {};
11063
- metadata.forEach((field) => {
11064
- let key = field.key;
11065
- let value = field.value;
11066
- const disabled = field.disabled;
11067
- if (!key || !value) {
11068
- return;
11069
- }
11070
- if (disabled) {
11071
- update[key] = value;
11072
- return;
11073
- }
11074
- key = key.trim();
11075
- value = value.trim();
11076
- if (value === "true") {
11077
- update[key] = true;
11078
- } else if (value === "false") {
11079
- update[key] = false;
11080
- } else {
11081
- const parsedNumber = parseFloat(value);
11082
- if (!isNaN(parsedNumber)) {
11083
- update[key] = parsedNumber;
11084
- } else {
11085
- update[key] = value;
11086
- }
11087
- }
11088
- });
11089
- return update;
11090
- }
11091
- function getHasUneditableRows(metadata) {
11092
- if (!metadata) {
11093
- return false;
11094
- }
11095
- return Object.values(metadata).some(
11096
- (value) => !EDITABLE_TYPES.includes(typeof value)
11097
- );
11098
- }
11099
- const Email = () => {
11100
- const { id } = useParams();
11101
- const { order, isPending, isError, error } = useOrder(id, {
11102
- fields: "+email"
11103
- });
11104
- if (isError) {
11105
- throw error;
11106
- }
11107
- const isReady = !isPending && !!order;
11108
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11109
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11110
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
11111
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11112
- ] }),
11113
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
11114
- ] });
11115
- };
11116
- const EmailForm = ({ order }) => {
11117
- const form = useForm({
11118
- defaultValues: {
11119
- email: order.email ?? ""
11120
- },
11121
- resolver: zodResolver(schema$3)
11122
- });
11123
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11124
- const { handleSuccess } = useRouteModal();
11125
- const onSubmit = form.handleSubmit(async (data) => {
11126
- await mutateAsync(
11127
- { email: data.email },
11128
- {
11129
- onSuccess: () => {
11130
- handleSuccess();
11131
- },
11132
- onError: (error) => {
11133
- toast.error(error.message);
11134
- }
11135
- }
11136
- );
11137
- });
11138
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11139
- KeyboundForm,
11140
- {
11141
- className: "flex flex-1 flex-col overflow-hidden",
11142
- onSubmit,
11143
- children: [
11144
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
11145
- Form$2.Field,
11146
- {
11147
- control: form.control,
11148
- name: "email",
11149
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11150
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
11151
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11152
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11153
- ] })
11154
- }
11155
- ) }),
11156
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11157
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11158
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11159
- ] }) })
11160
- ]
11161
- }
11162
- ) });
11163
- };
11164
- const schema$3 = objectType({
11165
- email: stringType().email()
11166
- });
11167
- const PROMOTION_QUERY_KEY = "promotions";
11168
- const promotionsQueryKeys = {
11169
- list: (query2) => [
11170
- PROMOTION_QUERY_KEY,
11171
- query2 ? query2 : void 0
11172
- ],
11173
- detail: (id, query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- id,
11176
- query2 ? query2 : void 0
11177
- ]
11178
- };
11179
- const usePromotions = (query2, options) => {
11180
- const { data, ...rest } = useQuery({
11181
- queryKey: promotionsQueryKeys.list(query2),
11182
- queryFn: async () => sdk.admin.promotion.list(query2),
11183
- ...options
11184
- });
11185
- return { ...data, ...rest };
11186
- };
11187
- const Promotions = () => {
11188
- const { id } = useParams();
11189
- const {
11190
- order: preview,
11191
- isError: isPreviewError,
11192
- error: previewError
11193
- } = useOrderPreview(id, void 0);
11194
- useInitiateOrderEdit({ preview });
11195
- const { onCancel } = useCancelOrderEdit({ preview });
11196
- if (isPreviewError) {
11197
- throw previewError;
11198
- }
11199
- const isReady = !!preview;
11200
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11201
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11202
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11203
- ] });
11204
- };
11205
- const PromotionForm = ({ preview }) => {
11206
- const { items, shipping_methods } = preview;
11207
- const [isSubmitting, setIsSubmitting] = useState(false);
11208
- const [comboboxValue, setComboboxValue] = useState("");
11209
- const { handleSuccess } = useRouteModal();
11210
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11211
- const promoIds = getPromotionIds(items, shipping_methods);
11212
- const { promotions, isPending, isError, error } = usePromotions(
11213
- {
11214
- id: promoIds
11215
- },
11216
- {
11217
- enabled: !!promoIds.length
11218
- }
11219
- );
11220
- const comboboxData = useComboboxData({
11221
- queryKey: ["promotions", "combobox", promoIds],
11222
- queryFn: async (params) => {
11223
- return await sdk.admin.promotion.list({
11224
- ...params,
11225
- id: {
11226
- $nin: promoIds
11227
- }
11228
- });
11229
- },
11230
- getOptions: (data) => {
11231
- return data.promotions.map((promotion) => ({
11232
- label: promotion.code,
11233
- value: promotion.code
11234
- }));
11235
- }
11236
- });
11237
- const add = async (value) => {
11238
- if (!value) {
11239
- return;
11240
- }
11241
- addPromotions(
11242
- {
11243
- promo_codes: [value]
11244
- },
11245
- {
11246
- onError: (e) => {
11247
- toast.error(e.message);
11248
- comboboxData.onSearchValueChange("");
11249
- setComboboxValue("");
11250
- },
11251
- onSuccess: () => {
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- }
11255
- }
11256
- );
11257
- };
11258
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11259
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11260
- const onSubmit = async () => {
11261
- setIsSubmitting(true);
11262
- let requestSucceeded = false;
11263
- await requestOrderEdit(void 0, {
11264
- onError: (e) => {
11265
- toast.error(e.message);
11266
- },
11267
- onSuccess: () => {
11268
- requestSucceeded = true;
11269
- }
10907
+ };
10908
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10909
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10910
+ const onSubmit = async () => {
10911
+ setIsSubmitting(true);
10912
+ let requestSucceeded = false;
10913
+ await requestOrderEdit(void 0, {
10914
+ onError: (e) => {
10915
+ toast.error(e.message);
10916
+ },
10917
+ onSuccess: () => {
10918
+ requestSucceeded = true;
10919
+ }
11270
10920
  });
11271
10921
  if (!requestSucceeded) {
11272
10922
  setIsSubmitting(false);
@@ -11353,93 +11003,443 @@ const PromotionItem = ({
11353
11003
  }
11354
11004
  }
11355
11005
  );
11356
- };
11357
- const displayValue = getDisplayValue(promotion);
11358
- return /* @__PURE__ */ jsxs(
11359
- "div",
11006
+ };
11007
+ const displayValue = getDisplayValue(promotion);
11008
+ return /* @__PURE__ */ jsxs(
11009
+ "div",
11010
+ {
11011
+ className: clx(
11012
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11013
+ {
11014
+ "animate-pulse": isLoading
11015
+ }
11016
+ ),
11017
+ children: [
11018
+ /* @__PURE__ */ jsxs("div", { children: [
11019
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11020
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11021
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11022
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11023
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11024
+ ] }),
11025
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11026
+ ] })
11027
+ ] }),
11028
+ /* @__PURE__ */ jsx(
11029
+ IconButton,
11030
+ {
11031
+ size: "small",
11032
+ type: "button",
11033
+ variant: "transparent",
11034
+ onClick: onRemove,
11035
+ isLoading: isPending || isLoading,
11036
+ children: /* @__PURE__ */ jsx(XMark, {})
11037
+ }
11038
+ )
11039
+ ]
11040
+ },
11041
+ promotion.id
11042
+ );
11043
+ };
11044
+ function getDisplayValue(promotion) {
11045
+ var _a, _b, _c, _d;
11046
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11047
+ if (!value) {
11048
+ return null;
11049
+ }
11050
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11051
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11052
+ if (!currency) {
11053
+ return null;
11054
+ }
11055
+ return getLocaleAmount(value, currency);
11056
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11057
+ return formatPercentage(value);
11058
+ }
11059
+ return null;
11060
+ }
11061
+ const formatter = new Intl.NumberFormat([], {
11062
+ style: "percent",
11063
+ minimumFractionDigits: 2
11064
+ });
11065
+ const formatPercentage = (value, isPercentageValue = false) => {
11066
+ let val = value || 0;
11067
+ if (!isPercentageValue) {
11068
+ val = val / 100;
11069
+ }
11070
+ return formatter.format(val);
11071
+ };
11072
+ function getPromotionIds(items, shippingMethods) {
11073
+ const promotionIds = /* @__PURE__ */ new Set();
11074
+ for (const item of items) {
11075
+ if (item.adjustments) {
11076
+ for (const adjustment of item.adjustments) {
11077
+ if (adjustment.promotion_id) {
11078
+ promotionIds.add(adjustment.promotion_id);
11079
+ }
11080
+ }
11081
+ }
11082
+ }
11083
+ for (const shippingMethod of shippingMethods) {
11084
+ if (shippingMethod.adjustments) {
11085
+ for (const adjustment of shippingMethod.adjustments) {
11086
+ if (adjustment.promotion_id) {
11087
+ promotionIds.add(adjustment.promotion_id);
11088
+ }
11089
+ }
11090
+ }
11091
+ }
11092
+ return Array.from(promotionIds);
11093
+ }
11094
+ const InlineTip = forwardRef(
11095
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11096
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11097
+ return /* @__PURE__ */ jsxs(
11098
+ "div",
11099
+ {
11100
+ ref,
11101
+ className: clx(
11102
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11103
+ className
11104
+ ),
11105
+ ...props,
11106
+ children: [
11107
+ /* @__PURE__ */ jsx(
11108
+ "div",
11109
+ {
11110
+ role: "presentation",
11111
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11112
+ "bg-ui-tag-orange-icon": variant === "warning"
11113
+ })
11114
+ }
11115
+ ),
11116
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11117
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11118
+ labelValue,
11119
+ ":"
11120
+ ] }),
11121
+ " ",
11122
+ children
11123
+ ] })
11124
+ ]
11125
+ }
11126
+ );
11127
+ }
11128
+ );
11129
+ InlineTip.displayName = "InlineTip";
11130
+ const MetadataFieldSchema = objectType({
11131
+ key: stringType(),
11132
+ disabled: booleanType().optional(),
11133
+ value: anyType()
11134
+ });
11135
+ const MetadataSchema = objectType({
11136
+ metadata: arrayType(MetadataFieldSchema)
11137
+ });
11138
+ const Metadata = () => {
11139
+ const { id } = useParams();
11140
+ const { order, isPending, isError, error } = useOrder(id, {
11141
+ fields: "metadata"
11142
+ });
11143
+ if (isError) {
11144
+ throw error;
11145
+ }
11146
+ const isReady = !isPending && !!order;
11147
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11148
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11149
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11150
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11151
+ ] }),
11152
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11153
+ ] });
11154
+ };
11155
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11156
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11157
+ const MetadataForm = ({ orderId, metadata }) => {
11158
+ const { handleSuccess } = useRouteModal();
11159
+ const hasUneditableRows = getHasUneditableRows(metadata);
11160
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11161
+ const form = useForm({
11162
+ defaultValues: {
11163
+ metadata: getDefaultValues(metadata)
11164
+ },
11165
+ resolver: zodResolver(MetadataSchema)
11166
+ });
11167
+ const handleSubmit = form.handleSubmit(async (data) => {
11168
+ const parsedData = parseValues(data);
11169
+ await mutateAsync(
11170
+ {
11171
+ metadata: parsedData
11172
+ },
11173
+ {
11174
+ onSuccess: () => {
11175
+ toast.success("Metadata updated");
11176
+ handleSuccess();
11177
+ },
11178
+ onError: (error) => {
11179
+ toast.error(error.message);
11180
+ }
11181
+ }
11182
+ );
11183
+ });
11184
+ const { fields, insert, remove } = useFieldArray({
11185
+ control: form.control,
11186
+ name: "metadata"
11187
+ });
11188
+ function deleteRow(index) {
11189
+ remove(index);
11190
+ if (fields.length === 1) {
11191
+ insert(0, {
11192
+ key: "",
11193
+ value: "",
11194
+ disabled: false
11195
+ });
11196
+ }
11197
+ }
11198
+ function insertRow(index, position) {
11199
+ insert(index + (position === "above" ? 0 : 1), {
11200
+ key: "",
11201
+ value: "",
11202
+ disabled: false
11203
+ });
11204
+ }
11205
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11206
+ KeyboundForm,
11360
11207
  {
11361
- className: clx(
11362
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11363
- {
11364
- "animate-pulse": isLoading
11365
- }
11366
- ),
11208
+ onSubmit: handleSubmit,
11209
+ className: "flex flex-1 flex-col overflow-hidden",
11367
11210
  children: [
11368
- /* @__PURE__ */ jsxs("div", { children: [
11369
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11370
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11371
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11372
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11373
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11211
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11212
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11213
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11214
+ /* @__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" }) }),
11215
+ /* @__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" }) })
11374
11216
  ] }),
11375
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11376
- ] })
11217
+ fields.map((field, index) => {
11218
+ const isDisabled = field.disabled || false;
11219
+ let placeholder = "-";
11220
+ if (typeof field.value === "object") {
11221
+ placeholder = "{ ... }";
11222
+ }
11223
+ if (Array.isArray(field.value)) {
11224
+ placeholder = "[ ... ]";
11225
+ }
11226
+ return /* @__PURE__ */ jsx(
11227
+ ConditionalTooltip,
11228
+ {
11229
+ showTooltip: isDisabled,
11230
+ content: "This row is disabled because it contains non-primitive data.",
11231
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11232
+ /* @__PURE__ */ jsxs(
11233
+ "div",
11234
+ {
11235
+ className: clx("grid grid-cols-2 divide-x", {
11236
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11237
+ }),
11238
+ children: [
11239
+ /* @__PURE__ */ jsx(
11240
+ Form$2.Field,
11241
+ {
11242
+ control: form.control,
11243
+ name: `metadata.${index}.key`,
11244
+ render: ({ field: field2 }) => {
11245
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11246
+ GridInput,
11247
+ {
11248
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11249
+ ...field2,
11250
+ disabled: isDisabled,
11251
+ placeholder: "Key"
11252
+ }
11253
+ ) }) });
11254
+ }
11255
+ }
11256
+ ),
11257
+ /* @__PURE__ */ jsx(
11258
+ Form$2.Field,
11259
+ {
11260
+ control: form.control,
11261
+ name: `metadata.${index}.value`,
11262
+ render: ({ field: { value, ...field2 } }) => {
11263
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11264
+ GridInput,
11265
+ {
11266
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11267
+ ...field2,
11268
+ value: isDisabled ? placeholder : value,
11269
+ disabled: isDisabled,
11270
+ placeholder: "Value"
11271
+ }
11272
+ ) }) });
11273
+ }
11274
+ }
11275
+ )
11276
+ ]
11277
+ }
11278
+ ),
11279
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11280
+ /* @__PURE__ */ jsx(
11281
+ DropdownMenu.Trigger,
11282
+ {
11283
+ className: clx(
11284
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11285
+ {
11286
+ hidden: isDisabled
11287
+ }
11288
+ ),
11289
+ disabled: isDisabled,
11290
+ asChild: true,
11291
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11292
+ }
11293
+ ),
11294
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11295
+ /* @__PURE__ */ jsxs(
11296
+ DropdownMenu.Item,
11297
+ {
11298
+ className: "gap-x-2",
11299
+ onClick: () => insertRow(index, "above"),
11300
+ children: [
11301
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11302
+ "Insert row above"
11303
+ ]
11304
+ }
11305
+ ),
11306
+ /* @__PURE__ */ jsxs(
11307
+ DropdownMenu.Item,
11308
+ {
11309
+ className: "gap-x-2",
11310
+ onClick: () => insertRow(index, "below"),
11311
+ children: [
11312
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11313
+ "Insert row below"
11314
+ ]
11315
+ }
11316
+ ),
11317
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11318
+ /* @__PURE__ */ jsxs(
11319
+ DropdownMenu.Item,
11320
+ {
11321
+ className: "gap-x-2",
11322
+ onClick: () => deleteRow(index),
11323
+ children: [
11324
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11325
+ "Delete row"
11326
+ ]
11327
+ }
11328
+ )
11329
+ ] })
11330
+ ] })
11331
+ ] })
11332
+ },
11333
+ field.id
11334
+ );
11335
+ })
11336
+ ] }),
11337
+ 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." })
11377
11338
  ] }),
11378
- /* @__PURE__ */ jsx(
11379
- IconButton,
11380
- {
11381
- size: "small",
11382
- type: "button",
11383
- variant: "transparent",
11384
- onClick: onRemove,
11385
- isLoading: isPending || isLoading,
11386
- children: /* @__PURE__ */ jsx(XMark, {})
11387
- }
11388
- )
11339
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11340
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11341
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11342
+ ] }) })
11389
11343
  ]
11390
- },
11391
- promotion.id
11392
- );
11344
+ }
11345
+ ) });
11393
11346
  };
11394
- function getDisplayValue(promotion) {
11395
- var _a, _b, _c, _d;
11396
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11397
- if (!value) {
11398
- return null;
11399
- }
11400
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11401
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11402
- if (!currency) {
11403
- return null;
11347
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11348
+ return /* @__PURE__ */ jsx(
11349
+ "input",
11350
+ {
11351
+ ref,
11352
+ ...props,
11353
+ autoComplete: "off",
11354
+ className: clx(
11355
+ "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",
11356
+ className
11357
+ )
11404
11358
  }
11405
- return getLocaleAmount(value, currency);
11406
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11407
- return formatPercentage(value);
11408
- }
11409
- return null;
11410
- }
11411
- const formatter = new Intl.NumberFormat([], {
11412
- style: "percent",
11413
- minimumFractionDigits: 2
11359
+ );
11414
11360
  });
11415
- const formatPercentage = (value, isPercentageValue = false) => {
11416
- let val = value || 0;
11417
- if (!isPercentageValue) {
11418
- val = val / 100;
11419
- }
11420
- return formatter.format(val);
11361
+ GridInput.displayName = "MetadataForm.GridInput";
11362
+ const PlaceholderInner = () => {
11363
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11364
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11365
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11366
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11367
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11368
+ ] }) })
11369
+ ] });
11421
11370
  };
11422
- function getPromotionIds(items, shippingMethods) {
11423
- const promotionIds = /* @__PURE__ */ new Set();
11424
- for (const item of items) {
11425
- if (item.adjustments) {
11426
- for (const adjustment of item.adjustments) {
11427
- if (adjustment.promotion_id) {
11428
- promotionIds.add(adjustment.promotion_id);
11429
- }
11371
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11372
+ function getDefaultValues(metadata) {
11373
+ if (!metadata || !Object.keys(metadata).length) {
11374
+ return [
11375
+ {
11376
+ key: "",
11377
+ value: "",
11378
+ disabled: false
11430
11379
  }
11380
+ ];
11381
+ }
11382
+ return Object.entries(metadata).map(([key, value]) => {
11383
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11384
+ return {
11385
+ key,
11386
+ value,
11387
+ disabled: true
11388
+ };
11389
+ }
11390
+ let stringValue = value;
11391
+ if (typeof value !== "string") {
11392
+ stringValue = JSON.stringify(value);
11431
11393
  }
11394
+ return {
11395
+ key,
11396
+ value: stringValue,
11397
+ original_key: key
11398
+ };
11399
+ });
11400
+ }
11401
+ function parseValues(values) {
11402
+ const metadata = values.metadata;
11403
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11404
+ if (isEmpty) {
11405
+ return null;
11432
11406
  }
11433
- for (const shippingMethod of shippingMethods) {
11434
- if (shippingMethod.adjustments) {
11435
- for (const adjustment of shippingMethod.adjustments) {
11436
- if (adjustment.promotion_id) {
11437
- promotionIds.add(adjustment.promotion_id);
11438
- }
11407
+ const update = {};
11408
+ metadata.forEach((field) => {
11409
+ let key = field.key;
11410
+ let value = field.value;
11411
+ const disabled = field.disabled;
11412
+ if (!key || !value) {
11413
+ return;
11414
+ }
11415
+ if (disabled) {
11416
+ update[key] = value;
11417
+ return;
11418
+ }
11419
+ key = key.trim();
11420
+ value = value.trim();
11421
+ if (value === "true") {
11422
+ update[key] = true;
11423
+ } else if (value === "false") {
11424
+ update[key] = false;
11425
+ } else {
11426
+ const parsedNumber = parseFloat(value);
11427
+ if (!isNaN(parsedNumber)) {
11428
+ update[key] = parsedNumber;
11429
+ } else {
11430
+ update[key] = value;
11439
11431
  }
11440
11432
  }
11433
+ });
11434
+ return update;
11435
+ }
11436
+ function getHasUneditableRows(metadata) {
11437
+ if (!metadata) {
11438
+ return false;
11441
11439
  }
11442
- return Array.from(promotionIds);
11440
+ return Object.values(metadata).some(
11441
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11442
+ );
11443
11443
  }
11444
11444
  const SalesChannel = () => {
11445
11445
  const { id } = useParams();
@@ -12343,17 +12343,220 @@ const CustomAmountField = ({
12343
12343
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12344
12344
  CurrencyInput,
12345
12345
  {
12346
- ...field,
12347
- onValueChange: (value) => onChange(value),
12348
- symbol: getNativeSymbol(currencyCode),
12349
- code: currencyCode
12346
+ ...field,
12347
+ onValueChange: (value) => onChange(value),
12348
+ symbol: getNativeSymbol(currencyCode),
12349
+ code: currencyCode
12350
+ }
12351
+ ) })
12352
+ ] });
12353
+ }
12354
+ }
12355
+ );
12356
+ };
12357
+ const ShippingAddress = () => {
12358
+ const { id } = useParams();
12359
+ const { order, isPending, isError, error } = useOrder(id, {
12360
+ fields: "+shipping_address"
12361
+ });
12362
+ if (isError) {
12363
+ throw error;
12364
+ }
12365
+ const isReady = !isPending && !!order;
12366
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12367
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12368
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12369
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12370
+ ] }),
12371
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12372
+ ] });
12373
+ };
12374
+ const ShippingAddressForm = ({ order }) => {
12375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12376
+ const form = useForm({
12377
+ defaultValues: {
12378
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12379
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12380
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12381
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12382
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12383
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12384
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12385
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12386
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12387
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12388
+ },
12389
+ resolver: zodResolver(schema$1)
12390
+ });
12391
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12392
+ const { handleSuccess } = useRouteModal();
12393
+ const onSubmit = form.handleSubmit(async (data) => {
12394
+ await mutateAsync(
12395
+ {
12396
+ shipping_address: {
12397
+ first_name: data.first_name,
12398
+ last_name: data.last_name,
12399
+ company: data.company,
12400
+ address_1: data.address_1,
12401
+ address_2: data.address_2,
12402
+ city: data.city,
12403
+ province: data.province,
12404
+ country_code: data.country_code,
12405
+ postal_code: data.postal_code,
12406
+ phone: data.phone
12407
+ }
12408
+ },
12409
+ {
12410
+ onSuccess: () => {
12411
+ handleSuccess();
12412
+ },
12413
+ onError: (error) => {
12414
+ toast.error(error.message);
12415
+ }
12416
+ }
12417
+ );
12418
+ });
12419
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12420
+ KeyboundForm,
12421
+ {
12422
+ className: "flex flex-1 flex-col overflow-hidden",
12423
+ onSubmit,
12424
+ children: [
12425
+ /* @__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: [
12426
+ /* @__PURE__ */ jsx(
12427
+ Form$2.Field,
12428
+ {
12429
+ control: form.control,
12430
+ name: "country_code",
12431
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12432
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12433
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12434
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12435
+ ] })
12436
+ }
12437
+ ),
12438
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12439
+ /* @__PURE__ */ jsx(
12440
+ Form$2.Field,
12441
+ {
12442
+ control: form.control,
12443
+ name: "first_name",
12444
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12445
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12446
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12447
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12448
+ ] })
12449
+ }
12450
+ ),
12451
+ /* @__PURE__ */ jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "last_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12458
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ )
12463
+ ] }),
12464
+ /* @__PURE__ */ jsx(
12465
+ Form$2.Field,
12466
+ {
12467
+ control: form.control,
12468
+ name: "company",
12469
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12470
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12471
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12472
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12473
+ ] })
12474
+ }
12475
+ ),
12476
+ /* @__PURE__ */ jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "address_1",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12483
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_2",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12495
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12501
+ /* @__PURE__ */ jsx(
12502
+ Form$2.Field,
12503
+ {
12504
+ control: form.control,
12505
+ name: "postal_code",
12506
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12507
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12508
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12509
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12510
+ ] })
12511
+ }
12512
+ ),
12513
+ /* @__PURE__ */ jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "city",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12520
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ )
12525
+ ] }),
12526
+ /* @__PURE__ */ jsx(
12527
+ Form$2.Field,
12528
+ {
12529
+ control: form.control,
12530
+ name: "province",
12531
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12532
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12535
+ ] })
12536
+ }
12537
+ ),
12538
+ /* @__PURE__ */ jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "phone",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12545
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12350
12548
  }
12351
- ) })
12352
- ] });
12353
- }
12549
+ )
12550
+ ] }) }),
12551
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12552
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12553
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12554
+ ] }) })
12555
+ ]
12354
12556
  }
12355
- );
12557
+ ) });
12356
12558
  };
12559
+ const schema$1 = addressSchema;
12357
12560
  const TransferOwnership = () => {
12358
12561
  const { id } = useParams();
12359
12562
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12377,7 +12580,7 @@ const TransferOwnershipForm = ({ order }) => {
12377
12580
  defaultValues: {
12378
12581
  customer_id: order.customer_id || ""
12379
12582
  },
12380
- resolver: zodResolver(schema$1)
12583
+ resolver: zodResolver(schema)
12381
12584
  });
12382
12585
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12383
12586
  const { handleSuccess } = useRouteModal();
@@ -12827,212 +13030,9 @@ const Illustration = () => {
12827
13030
  }
12828
13031
  );
12829
13032
  };
12830
- const schema$1 = objectType({
13033
+ const schema = objectType({
12831
13034
  customer_id: stringType().min(1)
12832
13035
  });
12833
- const ShippingAddress = () => {
12834
- const { id } = useParams();
12835
- const { order, isPending, isError, error } = useOrder(id, {
12836
- fields: "+shipping_address"
12837
- });
12838
- if (isError) {
12839
- throw error;
12840
- }
12841
- const isReady = !isPending && !!order;
12842
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12843
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12844
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12845
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12846
- ] }),
12847
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12848
- ] });
12849
- };
12850
- const ShippingAddressForm = ({ order }) => {
12851
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12852
- const form = useForm({
12853
- defaultValues: {
12854
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12855
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12856
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12857
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12858
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12859
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12860
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12861
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12862
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12863
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12864
- },
12865
- resolver: zodResolver(schema)
12866
- });
12867
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12868
- const { handleSuccess } = useRouteModal();
12869
- const onSubmit = form.handleSubmit(async (data) => {
12870
- await mutateAsync(
12871
- {
12872
- shipping_address: {
12873
- first_name: data.first_name,
12874
- last_name: data.last_name,
12875
- company: data.company,
12876
- address_1: data.address_1,
12877
- address_2: data.address_2,
12878
- city: data.city,
12879
- province: data.province,
12880
- country_code: data.country_code,
12881
- postal_code: data.postal_code,
12882
- phone: data.phone
12883
- }
12884
- },
12885
- {
12886
- onSuccess: () => {
12887
- handleSuccess();
12888
- },
12889
- onError: (error) => {
12890
- toast.error(error.message);
12891
- }
12892
- }
12893
- );
12894
- });
12895
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12896
- KeyboundForm,
12897
- {
12898
- className: "flex flex-1 flex-col overflow-hidden",
12899
- onSubmit,
12900
- children: [
12901
- /* @__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: [
12902
- /* @__PURE__ */ jsx(
12903
- Form$2.Field,
12904
- {
12905
- control: form.control,
12906
- name: "country_code",
12907
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12909
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12910
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12911
- ] })
12912
- }
12913
- ),
12914
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12915
- /* @__PURE__ */ jsx(
12916
- Form$2.Field,
12917
- {
12918
- control: form.control,
12919
- name: "first_name",
12920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12922
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12923
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12924
- ] })
12925
- }
12926
- ),
12927
- /* @__PURE__ */ jsx(
12928
- Form$2.Field,
12929
- {
12930
- control: form.control,
12931
- name: "last_name",
12932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12935
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12936
- ] })
12937
- }
12938
- )
12939
- ] }),
12940
- /* @__PURE__ */ jsx(
12941
- Form$2.Field,
12942
- {
12943
- control: form.control,
12944
- name: "company",
12945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12946
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12947
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12948
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12949
- ] })
12950
- }
12951
- ),
12952
- /* @__PURE__ */ jsx(
12953
- Form$2.Field,
12954
- {
12955
- control: form.control,
12956
- name: "address_1",
12957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12961
- ] })
12962
- }
12963
- ),
12964
- /* @__PURE__ */ jsx(
12965
- Form$2.Field,
12966
- {
12967
- control: form.control,
12968
- name: "address_2",
12969
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12970
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12971
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12972
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12973
- ] })
12974
- }
12975
- ),
12976
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12977
- /* @__PURE__ */ jsx(
12978
- Form$2.Field,
12979
- {
12980
- control: form.control,
12981
- name: "postal_code",
12982
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12983
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12984
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12985
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12986
- ] })
12987
- }
12988
- ),
12989
- /* @__PURE__ */ jsx(
12990
- Form$2.Field,
12991
- {
12992
- control: form.control,
12993
- name: "city",
12994
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12995
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12996
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12997
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12998
- ] })
12999
- }
13000
- )
13001
- ] }),
13002
- /* @__PURE__ */ jsx(
13003
- Form$2.Field,
13004
- {
13005
- control: form.control,
13006
- name: "province",
13007
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13008
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13009
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13010
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13011
- ] })
13012
- }
13013
- ),
13014
- /* @__PURE__ */ jsx(
13015
- Form$2.Field,
13016
- {
13017
- control: form.control,
13018
- name: "phone",
13019
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13021
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13022
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13023
- ] })
13024
- }
13025
- )
13026
- ] }) }),
13027
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13028
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13029
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13030
- ] }) })
13031
- ]
13032
- }
13033
- ) });
13034
- };
13035
- const schema = addressSchema;
13036
13036
  const widgetModule = { widgets: [] };
13037
13037
  const routeModule = {
13038
13038
  routes: [
@@ -13061,22 +13061,22 @@ const routeModule = {
13061
13061
  Component: CustomItems,
13062
13062
  path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
- {
13065
- Component: Items,
13066
- path: "/draft-orders/:id/items"
13067
- },
13068
- {
13069
- Component: Metadata,
13070
- path: "/draft-orders/:id/metadata"
13071
- },
13072
13064
  {
13073
13065
  Component: Email,
13074
13066
  path: "/draft-orders/:id/email"
13075
13067
  },
13068
+ {
13069
+ Component: Items,
13070
+ path: "/draft-orders/:id/items"
13071
+ },
13076
13072
  {
13077
13073
  Component: Promotions,
13078
13074
  path: "/draft-orders/:id/promotions"
13079
13075
  },
13076
+ {
13077
+ Component: Metadata,
13078
+ path: "/draft-orders/:id/metadata"
13079
+ },
13080
13080
  {
13081
13081
  Component: SalesChannel,
13082
13082
  path: "/draft-orders/:id/sales-channel"
@@ -13085,13 +13085,13 @@ const routeModule = {
13085
13085
  Component: Shipping,
13086
13086
  path: "/draft-orders/:id/shipping"
13087
13087
  },
13088
- {
13089
- Component: TransferOwnership,
13090
- path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
13088
  {
13093
13089
  Component: ShippingAddress,
13094
13090
  path: "/draft-orders/:id/shipping-address"
13091
+ },
13092
+ {
13093
+ Component: TransferOwnership,
13094
+ path: "/draft-orders/:id/transfer-ownership"
13095
13095
  }
13096
13096
  ]
13097
13097
  }