@medusajs/draft-order 2.11.1-preview-20251025060207 → 2.11.1-preview-20251025120209

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.
@@ -9571,6 +9571,27 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
+ const CustomItems = () => {
9575
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9576
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9577
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9578
+ ] });
9579
+ };
9580
+ const CustomItemsForm = () => {
9581
+ const form = reactHookForm.useForm({
9582
+ resolver: zod.zodResolver(schema$5)
9583
+ });
9584
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9589
+ ] }) })
9590
+ ] }) });
9591
+ };
9592
+ const schema$5 = objectType({
9593
+ email: stringType().email()
9594
+ });
9574
9595
  const BillingAddress = () => {
9575
9596
  const { id } = reactRouterDom.useParams();
9576
9597
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9603,7 +9624,7 @@ const BillingAddressForm = ({ order }) => {
9603
9624
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
9625
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
9626
  },
9606
- resolver: zod.zodResolver(schema$5)
9627
+ resolver: zod.zodResolver(schema$4)
9607
9628
  });
9608
9629
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
9630
  const { handleSuccess } = useRouteModal();
@@ -9760,28 +9781,7 @@ const BillingAddressForm = ({ order }) => {
9760
9781
  }
9761
9782
  ) });
9762
9783
  };
9763
- const schema$5 = addressSchema;
9764
- const CustomItems = () => {
9765
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9767
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9768
- ] });
9769
- };
9770
- const CustomItemsForm = () => {
9771
- const form = reactHookForm.useForm({
9772
- resolver: zod.zodResolver(schema$4)
9773
- });
9774
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9778
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9779
- ] }) })
9780
- ] }) });
9781
- };
9782
- const schema$4 = objectType({
9783
- email: stringType().email()
9784
- });
9784
+ const schema$4 = addressSchema;
9785
9785
  const Email = () => {
9786
9786
  const { id } = reactRouterDom.useParams();
9787
9787
  const { order, isPending, isError, error } = useOrder(id, {
@@ -10824,143 +10824,493 @@ const customItemSchema = objectType({
10824
10824
  quantity: numberType(),
10825
10825
  unit_price: unionType([numberType(), stringType()])
10826
10826
  });
10827
- const PROMOTION_QUERY_KEY = "promotions";
10828
- const promotionsQueryKeys = {
10829
- list: (query2) => [
10830
- PROMOTION_QUERY_KEY,
10831
- query2 ? query2 : void 0
10832
- ],
10833
- detail: (id, query2) => [
10834
- PROMOTION_QUERY_KEY,
10835
- id,
10836
- query2 ? query2 : void 0
10837
- ]
10838
- };
10839
- const usePromotions = (query2, options) => {
10840
- const { data, ...rest } = reactQuery.useQuery({
10841
- queryKey: promotionsQueryKeys.list(query2),
10842
- queryFn: async () => sdk.admin.promotion.list(query2),
10843
- ...options
10844
- });
10845
- return { ...data, ...rest };
10846
- };
10847
- const Promotions = () => {
10827
+ const InlineTip = React.forwardRef(
10828
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10829
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10830
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10831
+ "div",
10832
+ {
10833
+ ref,
10834
+ className: ui.clx(
10835
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10836
+ className
10837
+ ),
10838
+ ...props,
10839
+ children: [
10840
+ /* @__PURE__ */ jsxRuntime.jsx(
10841
+ "div",
10842
+ {
10843
+ role: "presentation",
10844
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10845
+ "bg-ui-tag-orange-icon": variant === "warning"
10846
+ })
10847
+ }
10848
+ ),
10849
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10851
+ labelValue,
10852
+ ":"
10853
+ ] }),
10854
+ " ",
10855
+ children
10856
+ ] })
10857
+ ]
10858
+ }
10859
+ );
10860
+ }
10861
+ );
10862
+ InlineTip.displayName = "InlineTip";
10863
+ const MetadataFieldSchema = objectType({
10864
+ key: stringType(),
10865
+ disabled: booleanType().optional(),
10866
+ value: anyType()
10867
+ });
10868
+ const MetadataSchema = objectType({
10869
+ metadata: arrayType(MetadataFieldSchema)
10870
+ });
10871
+ const Metadata = () => {
10848
10872
  const { id } = reactRouterDom.useParams();
10849
- const {
10850
- order: preview,
10851
- isError: isPreviewError,
10852
- error: previewError
10853
- } = useOrderPreview(id, void 0);
10854
- useInitiateOrderEdit({ preview });
10855
- const { onCancel } = useCancelOrderEdit({ preview });
10856
- if (isPreviewError) {
10857
- throw previewError;
10873
+ const { order, isPending, isError, error } = useOrder(id, {
10874
+ fields: "metadata"
10875
+ });
10876
+ if (isError) {
10877
+ throw error;
10858
10878
  }
10859
- const isReady = !!preview;
10860
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10861
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10862
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10879
+ const isReady = !isPending && !!order;
10880
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10881
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10884
+ ] }),
10885
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10863
10886
  ] });
10864
10887
  };
10865
- const PromotionForm = ({ preview }) => {
10866
- const { items, shipping_methods } = preview;
10867
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10868
- const [comboboxValue, setComboboxValue] = React.useState("");
10888
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10889
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10890
+ const MetadataForm = ({ orderId, metadata }) => {
10869
10891
  const { handleSuccess } = useRouteModal();
10870
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10871
- const promoIds = getPromotionIds(items, shipping_methods);
10872
- const { promotions, isPending, isError, error } = usePromotions(
10873
- {
10874
- id: promoIds
10875
- },
10876
- {
10877
- enabled: !!promoIds.length
10878
- }
10879
- );
10880
- const comboboxData = useComboboxData({
10881
- queryKey: ["promotions", "combobox", promoIds],
10882
- queryFn: async (params) => {
10883
- return await sdk.admin.promotion.list({
10884
- ...params,
10885
- id: {
10886
- $nin: promoIds
10887
- }
10888
- });
10892
+ const hasUneditableRows = getHasUneditableRows(metadata);
10893
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10894
+ const form = reactHookForm.useForm({
10895
+ defaultValues: {
10896
+ metadata: getDefaultValues(metadata)
10889
10897
  },
10890
- getOptions: (data) => {
10891
- return data.promotions.map((promotion) => ({
10892
- label: promotion.code,
10893
- value: promotion.code
10894
- }));
10895
- }
10898
+ resolver: zod.zodResolver(MetadataSchema)
10896
10899
  });
10897
- const add = async (value) => {
10898
- if (!value) {
10899
- return;
10900
- }
10901
- addPromotions(
10900
+ const handleSubmit = form.handleSubmit(async (data) => {
10901
+ const parsedData = parseValues(data);
10902
+ await mutateAsync(
10902
10903
  {
10903
- promo_codes: [value]
10904
+ metadata: parsedData
10904
10905
  },
10905
10906
  {
10906
- onError: (e) => {
10907
- ui.toast.error(e.message);
10908
- comboboxData.onSearchValueChange("");
10909
- setComboboxValue("");
10910
- },
10911
10907
  onSuccess: () => {
10912
- comboboxData.onSearchValueChange("");
10913
- setComboboxValue("");
10908
+ ui.toast.success("Metadata updated");
10909
+ handleSuccess();
10910
+ },
10911
+ onError: (error) => {
10912
+ ui.toast.error(error.message);
10914
10913
  }
10915
10914
  }
10916
10915
  );
10917
- };
10918
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10919
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10920
- const onSubmit = async () => {
10921
- setIsSubmitting(true);
10922
- let requestSucceeded = false;
10923
- await requestOrderEdit(void 0, {
10924
- onError: (e) => {
10925
- ui.toast.error(e.message);
10926
- },
10927
- onSuccess: () => {
10928
- requestSucceeded = true;
10929
- }
10930
- });
10931
- if (!requestSucceeded) {
10932
- setIsSubmitting(false);
10933
- return;
10916
+ });
10917
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10918
+ control: form.control,
10919
+ name: "metadata"
10920
+ });
10921
+ function deleteRow(index) {
10922
+ remove(index);
10923
+ if (fields.length === 1) {
10924
+ insert(0, {
10925
+ key: "",
10926
+ value: "",
10927
+ disabled: false
10928
+ });
10934
10929
  }
10935
- await confirmOrderEdit(void 0, {
10936
- onError: (e) => {
10937
- ui.toast.error(e.message);
10938
- },
10939
- onSuccess: () => {
10940
- handleSuccess();
10941
- },
10942
- onSettled: () => {
10943
- setIsSubmitting(false);
10944
- }
10930
+ }
10931
+ function insertRow(index, position) {
10932
+ insert(index + (position === "above" ? 0 : 1), {
10933
+ key: "",
10934
+ value: "",
10935
+ disabled: false
10945
10936
  });
10946
- };
10947
- if (isError) {
10948
- throw error;
10949
10937
  }
10950
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10951
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10952
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10953
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10956
- ] }),
10957
- /* @__PURE__ */ jsxRuntime.jsx(
10958
- Combobox,
10959
- {
10960
- id: "promotion-combobox",
10961
- "aria-describedby": "promotion-combobox-hint",
10962
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10963
- fetchNextPage: comboboxData.fetchNextPage,
10938
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10939
+ KeyboundForm,
10940
+ {
10941
+ onSubmit: handleSubmit,
10942
+ className: "flex flex-1 flex-col overflow-hidden",
10943
+ children: [
10944
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10947
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10948
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10949
+ ] }),
10950
+ fields.map((field, index) => {
10951
+ const isDisabled = field.disabled || false;
10952
+ let placeholder = "-";
10953
+ if (typeof field.value === "object") {
10954
+ placeholder = "{ ... }";
10955
+ }
10956
+ if (Array.isArray(field.value)) {
10957
+ placeholder = "[ ... ]";
10958
+ }
10959
+ return /* @__PURE__ */ jsxRuntime.jsx(
10960
+ ConditionalTooltip,
10961
+ {
10962
+ showTooltip: isDisabled,
10963
+ content: "This row is disabled because it contains non-primitive data.",
10964
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10965
+ /* @__PURE__ */ jsxRuntime.jsxs(
10966
+ "div",
10967
+ {
10968
+ className: ui.clx("grid grid-cols-2 divide-x", {
10969
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10970
+ }),
10971
+ children: [
10972
+ /* @__PURE__ */ jsxRuntime.jsx(
10973
+ Form$2.Field,
10974
+ {
10975
+ control: form.control,
10976
+ name: `metadata.${index}.key`,
10977
+ render: ({ field: field2 }) => {
10978
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10979
+ GridInput,
10980
+ {
10981
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10982
+ ...field2,
10983
+ disabled: isDisabled,
10984
+ placeholder: "Key"
10985
+ }
10986
+ ) }) });
10987
+ }
10988
+ }
10989
+ ),
10990
+ /* @__PURE__ */ jsxRuntime.jsx(
10991
+ Form$2.Field,
10992
+ {
10993
+ control: form.control,
10994
+ name: `metadata.${index}.value`,
10995
+ render: ({ field: { value, ...field2 } }) => {
10996
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10997
+ GridInput,
10998
+ {
10999
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11000
+ ...field2,
11001
+ value: isDisabled ? placeholder : value,
11002
+ disabled: isDisabled,
11003
+ placeholder: "Value"
11004
+ }
11005
+ ) }) });
11006
+ }
11007
+ }
11008
+ )
11009
+ ]
11010
+ }
11011
+ ),
11012
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11013
+ /* @__PURE__ */ jsxRuntime.jsx(
11014
+ ui.DropdownMenu.Trigger,
11015
+ {
11016
+ className: ui.clx(
11017
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11018
+ {
11019
+ hidden: isDisabled
11020
+ }
11021
+ ),
11022
+ disabled: isDisabled,
11023
+ asChild: true,
11024
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11025
+ }
11026
+ ),
11027
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(
11029
+ ui.DropdownMenu.Item,
11030
+ {
11031
+ className: "gap-x-2",
11032
+ onClick: () => insertRow(index, "above"),
11033
+ children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11035
+ "Insert row above"
11036
+ ]
11037
+ }
11038
+ ),
11039
+ /* @__PURE__ */ jsxRuntime.jsxs(
11040
+ ui.DropdownMenu.Item,
11041
+ {
11042
+ className: "gap-x-2",
11043
+ onClick: () => insertRow(index, "below"),
11044
+ children: [
11045
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11046
+ "Insert row below"
11047
+ ]
11048
+ }
11049
+ ),
11050
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11051
+ /* @__PURE__ */ jsxRuntime.jsxs(
11052
+ ui.DropdownMenu.Item,
11053
+ {
11054
+ className: "gap-x-2",
11055
+ onClick: () => deleteRow(index),
11056
+ children: [
11057
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11058
+ "Delete row"
11059
+ ]
11060
+ }
11061
+ )
11062
+ ] })
11063
+ ] })
11064
+ ] })
11065
+ },
11066
+ field.id
11067
+ );
11068
+ })
11069
+ ] }),
11070
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11071
+ ] }),
11072
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
+ ] }) })
11076
+ ]
11077
+ }
11078
+ ) });
11079
+ };
11080
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11081
+ return /* @__PURE__ */ jsxRuntime.jsx(
11082
+ "input",
11083
+ {
11084
+ ref,
11085
+ ...props,
11086
+ autoComplete: "off",
11087
+ className: ui.clx(
11088
+ "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",
11089
+ className
11090
+ )
11091
+ }
11092
+ );
11093
+ });
11094
+ GridInput.displayName = "MetadataForm.GridInput";
11095
+ const PlaceholderInner = () => {
11096
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11099
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11101
+ ] }) })
11102
+ ] });
11103
+ };
11104
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11105
+ function getDefaultValues(metadata) {
11106
+ if (!metadata || !Object.keys(metadata).length) {
11107
+ return [
11108
+ {
11109
+ key: "",
11110
+ value: "",
11111
+ disabled: false
11112
+ }
11113
+ ];
11114
+ }
11115
+ return Object.entries(metadata).map(([key, value]) => {
11116
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11117
+ return {
11118
+ key,
11119
+ value,
11120
+ disabled: true
11121
+ };
11122
+ }
11123
+ let stringValue = value;
11124
+ if (typeof value !== "string") {
11125
+ stringValue = JSON.stringify(value);
11126
+ }
11127
+ return {
11128
+ key,
11129
+ value: stringValue,
11130
+ original_key: key
11131
+ };
11132
+ });
11133
+ }
11134
+ function parseValues(values) {
11135
+ const metadata = values.metadata;
11136
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11137
+ if (isEmpty) {
11138
+ return null;
11139
+ }
11140
+ const update = {};
11141
+ metadata.forEach((field) => {
11142
+ let key = field.key;
11143
+ let value = field.value;
11144
+ const disabled = field.disabled;
11145
+ if (!key || !value) {
11146
+ return;
11147
+ }
11148
+ if (disabled) {
11149
+ update[key] = value;
11150
+ return;
11151
+ }
11152
+ key = key.trim();
11153
+ value = value.trim();
11154
+ if (value === "true") {
11155
+ update[key] = true;
11156
+ } else if (value === "false") {
11157
+ update[key] = false;
11158
+ } else {
11159
+ const parsedNumber = parseFloat(value);
11160
+ if (!isNaN(parsedNumber)) {
11161
+ update[key] = parsedNumber;
11162
+ } else {
11163
+ update[key] = value;
11164
+ }
11165
+ }
11166
+ });
11167
+ return update;
11168
+ }
11169
+ function getHasUneditableRows(metadata) {
11170
+ if (!metadata) {
11171
+ return false;
11172
+ }
11173
+ return Object.values(metadata).some(
11174
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11175
+ );
11176
+ }
11177
+ const PROMOTION_QUERY_KEY = "promotions";
11178
+ const promotionsQueryKeys = {
11179
+ list: (query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ query2 ? query2 : void 0
11182
+ ],
11183
+ detail: (id, query2) => [
11184
+ PROMOTION_QUERY_KEY,
11185
+ id,
11186
+ query2 ? query2 : void 0
11187
+ ]
11188
+ };
11189
+ const usePromotions = (query2, options) => {
11190
+ const { data, ...rest } = reactQuery.useQuery({
11191
+ queryKey: promotionsQueryKeys.list(query2),
11192
+ queryFn: async () => sdk.admin.promotion.list(query2),
11193
+ ...options
11194
+ });
11195
+ return { ...data, ...rest };
11196
+ };
11197
+ const Promotions = () => {
11198
+ const { id } = reactRouterDom.useParams();
11199
+ const {
11200
+ order: preview,
11201
+ isError: isPreviewError,
11202
+ error: previewError
11203
+ } = useOrderPreview(id, void 0);
11204
+ useInitiateOrderEdit({ preview });
11205
+ const { onCancel } = useCancelOrderEdit({ preview });
11206
+ if (isPreviewError) {
11207
+ throw previewError;
11208
+ }
11209
+ const isReady = !!preview;
11210
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
+ ] });
11214
+ };
11215
+ const PromotionForm = ({ preview }) => {
11216
+ const { items, shipping_methods } = preview;
11217
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
+ const [comboboxValue, setComboboxValue] = React.useState("");
11219
+ const { handleSuccess } = useRouteModal();
11220
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
+ const promoIds = getPromotionIds(items, shipping_methods);
11222
+ const { promotions, isPending, isError, error } = usePromotions(
11223
+ {
11224
+ id: promoIds
11225
+ },
11226
+ {
11227
+ enabled: !!promoIds.length
11228
+ }
11229
+ );
11230
+ const comboboxData = useComboboxData({
11231
+ queryKey: ["promotions", "combobox", promoIds],
11232
+ queryFn: async (params) => {
11233
+ return await sdk.admin.promotion.list({
11234
+ ...params,
11235
+ id: {
11236
+ $nin: promoIds
11237
+ }
11238
+ });
11239
+ },
11240
+ getOptions: (data) => {
11241
+ return data.promotions.map((promotion) => ({
11242
+ label: promotion.code,
11243
+ value: promotion.code
11244
+ }));
11245
+ }
11246
+ });
11247
+ const add = async (value) => {
11248
+ if (!value) {
11249
+ return;
11250
+ }
11251
+ addPromotions(
11252
+ {
11253
+ promo_codes: [value]
11254
+ },
11255
+ {
11256
+ onError: (e) => {
11257
+ ui.toast.error(e.message);
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11260
+ },
11261
+ onSuccess: () => {
11262
+ comboboxData.onSearchValueChange("");
11263
+ setComboboxValue("");
11264
+ }
11265
+ }
11266
+ );
11267
+ };
11268
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11270
+ const onSubmit = async () => {
11271
+ setIsSubmitting(true);
11272
+ let requestSucceeded = false;
11273
+ await requestOrderEdit(void 0, {
11274
+ onError: (e) => {
11275
+ ui.toast.error(e.message);
11276
+ },
11277
+ onSuccess: () => {
11278
+ requestSucceeded = true;
11279
+ }
11280
+ });
11281
+ if (!requestSucceeded) {
11282
+ setIsSubmitting(false);
11283
+ return;
11284
+ }
11285
+ await confirmOrderEdit(void 0, {
11286
+ onError: (e) => {
11287
+ ui.toast.error(e.message);
11288
+ },
11289
+ onSuccess: () => {
11290
+ handleSuccess();
11291
+ },
11292
+ onSettled: () => {
11293
+ setIsSubmitting(false);
11294
+ }
11295
+ });
11296
+ };
11297
+ if (isError) {
11298
+ throw error;
11299
+ }
11300
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
+ ] }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(
11308
+ Combobox,
11309
+ {
11310
+ id: "promotion-combobox",
11311
+ "aria-describedby": "promotion-combobox-hint",
11312
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
+ fetchNextPage: comboboxData.fetchNextPage,
10964
11314
  options: comboboxData.options,
10965
11315
  onSearchValueChange: comboboxData.onSearchValueChange,
10966
11316
  searchValue: comboboxData.searchValue,
@@ -12007,216 +12357,13 @@ const CustomAmountField = ({
12007
12357
  onValueChange: (value) => onChange(value),
12008
12358
  symbol: getNativeSymbol(currencyCode),
12009
12359
  code: currencyCode
12010
- }
12011
- ) })
12012
- ] });
12013
- }
12014
- }
12015
- );
12016
- };
12017
- const ShippingAddress = () => {
12018
- const { id } = reactRouterDom.useParams();
12019
- const { order, isPending, isError, error } = useOrder(id, {
12020
- fields: "+shipping_address"
12021
- });
12022
- if (isError) {
12023
- throw error;
12024
- }
12025
- const isReady = !isPending && !!order;
12026
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12027
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12028
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12029
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12030
- ] }),
12031
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12032
- ] });
12033
- };
12034
- const ShippingAddressForm = ({ order }) => {
12035
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12036
- const form = reactHookForm.useForm({
12037
- defaultValues: {
12038
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12039
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12040
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12041
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12042
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12043
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12044
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12045
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12046
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12047
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12048
- },
12049
- resolver: zod.zodResolver(schema$1)
12050
- });
12051
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12052
- const { handleSuccess } = useRouteModal();
12053
- const onSubmit = form.handleSubmit(async (data) => {
12054
- await mutateAsync(
12055
- {
12056
- shipping_address: {
12057
- first_name: data.first_name,
12058
- last_name: data.last_name,
12059
- company: data.company,
12060
- address_1: data.address_1,
12061
- address_2: data.address_2,
12062
- city: data.city,
12063
- province: data.province,
12064
- country_code: data.country_code,
12065
- postal_code: data.postal_code,
12066
- phone: data.phone
12067
- }
12068
- },
12069
- {
12070
- onSuccess: () => {
12071
- handleSuccess();
12072
- },
12073
- onError: (error) => {
12074
- ui.toast.error(error.message);
12075
- }
12076
- }
12077
- );
12078
- });
12079
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12080
- KeyboundForm,
12081
- {
12082
- className: "flex flex-1 flex-col overflow-hidden",
12083
- onSubmit,
12084
- children: [
12085
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12086
- /* @__PURE__ */ jsxRuntime.jsx(
12087
- Form$2.Field,
12088
- {
12089
- control: form.control,
12090
- name: "country_code",
12091
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12092
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12093
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12094
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12095
- ] })
12096
- }
12097
- ),
12098
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12099
- /* @__PURE__ */ jsxRuntime.jsx(
12100
- Form$2.Field,
12101
- {
12102
- control: form.control,
12103
- name: "first_name",
12104
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12105
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12106
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12107
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12108
- ] })
12109
- }
12110
- ),
12111
- /* @__PURE__ */ jsxRuntime.jsx(
12112
- Form$2.Field,
12113
- {
12114
- control: form.control,
12115
- name: "last_name",
12116
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12117
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12118
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12119
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12120
- ] })
12121
- }
12122
- )
12123
- ] }),
12124
- /* @__PURE__ */ jsxRuntime.jsx(
12125
- Form$2.Field,
12126
- {
12127
- control: form.control,
12128
- name: "company",
12129
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12130
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12131
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12132
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12133
- ] })
12134
- }
12135
- ),
12136
- /* @__PURE__ */ jsxRuntime.jsx(
12137
- Form$2.Field,
12138
- {
12139
- control: form.control,
12140
- name: "address_1",
12141
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12142
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12143
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12144
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12145
- ] })
12146
- }
12147
- ),
12148
- /* @__PURE__ */ jsxRuntime.jsx(
12149
- Form$2.Field,
12150
- {
12151
- control: form.control,
12152
- name: "address_2",
12153
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12154
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12155
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12156
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12157
- ] })
12158
- }
12159
- ),
12160
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12161
- /* @__PURE__ */ jsxRuntime.jsx(
12162
- Form$2.Field,
12163
- {
12164
- control: form.control,
12165
- name: "postal_code",
12166
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12167
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12168
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12169
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12170
- ] })
12171
- }
12172
- ),
12173
- /* @__PURE__ */ jsxRuntime.jsx(
12174
- Form$2.Field,
12175
- {
12176
- control: form.control,
12177
- name: "city",
12178
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12179
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12180
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12181
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12182
- ] })
12183
- }
12184
- )
12185
- ] }),
12186
- /* @__PURE__ */ jsxRuntime.jsx(
12187
- Form$2.Field,
12188
- {
12189
- control: form.control,
12190
- name: "province",
12191
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12192
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12193
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12194
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12195
- ] })
12196
- }
12197
- ),
12198
- /* @__PURE__ */ jsxRuntime.jsx(
12199
- Form$2.Field,
12200
- {
12201
- control: form.control,
12202
- name: "phone",
12203
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12204
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12205
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12207
- ] })
12208
- }
12209
- )
12210
- ] }) }),
12211
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12212
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12213
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12214
- ] }) })
12215
- ]
12360
+ }
12361
+ ) })
12362
+ ] });
12363
+ }
12216
12364
  }
12217
- ) });
12365
+ );
12218
12366
  };
12219
- const schema$1 = addressSchema;
12220
12367
  const TransferOwnership = () => {
12221
12368
  const { id } = reactRouterDom.useParams();
12222
12369
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12240,7 +12387,7 @@ const TransferOwnershipForm = ({ order }) => {
12240
12387
  defaultValues: {
12241
12388
  customer_id: order.customer_id || ""
12242
12389
  },
12243
- resolver: zod.zodResolver(schema)
12390
+ resolver: zod.zodResolver(schema$1)
12244
12391
  });
12245
12392
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12246
12393
  const { handleSuccess } = useRouteModal();
@@ -12690,57 +12837,13 @@ const Illustration = () => {
12690
12837
  }
12691
12838
  );
12692
12839
  };
12693
- const schema = objectType({
12840
+ const schema$1 = objectType({
12694
12841
  customer_id: stringType().min(1)
12695
12842
  });
12696
- const InlineTip = React.forwardRef(
12697
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12698
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12699
- return /* @__PURE__ */ jsxRuntime.jsxs(
12700
- "div",
12701
- {
12702
- ref,
12703
- className: ui.clx(
12704
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12705
- className
12706
- ),
12707
- ...props,
12708
- children: [
12709
- /* @__PURE__ */ jsxRuntime.jsx(
12710
- "div",
12711
- {
12712
- role: "presentation",
12713
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12714
- "bg-ui-tag-orange-icon": variant === "warning"
12715
- })
12716
- }
12717
- ),
12718
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12719
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12720
- labelValue,
12721
- ":"
12722
- ] }),
12723
- " ",
12724
- children
12725
- ] })
12726
- ]
12727
- }
12728
- );
12729
- }
12730
- );
12731
- InlineTip.displayName = "InlineTip";
12732
- const MetadataFieldSchema = objectType({
12733
- key: stringType(),
12734
- disabled: booleanType().optional(),
12735
- value: anyType()
12736
- });
12737
- const MetadataSchema = objectType({
12738
- metadata: arrayType(MetadataFieldSchema)
12739
- });
12740
- const Metadata = () => {
12843
+ const ShippingAddress = () => {
12741
12844
  const { id } = reactRouterDom.useParams();
12742
12845
  const { order, isPending, isError, error } = useOrder(id, {
12743
- fields: "metadata"
12846
+ fields: "+shipping_address"
12744
12847
  });
12745
12848
  if (isError) {
12746
12849
  throw error;
@@ -12748,301 +12851,198 @@ const Metadata = () => {
12748
12851
  const isReady = !isPending && !!order;
12749
12852
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12750
12853
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12751
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12752
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12854
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12855
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12753
12856
  ] }),
12754
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12857
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12755
12858
  ] });
12756
12859
  };
12757
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12758
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12759
- const MetadataForm = ({ orderId, metadata }) => {
12760
- const { handleSuccess } = useRouteModal();
12761
- const hasUneditableRows = getHasUneditableRows(metadata);
12762
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12860
+ const ShippingAddressForm = ({ order }) => {
12861
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12763
12862
  const form = reactHookForm.useForm({
12764
12863
  defaultValues: {
12765
- metadata: getDefaultValues(metadata)
12864
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12865
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12866
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12867
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12868
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12869
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12870
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12871
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12872
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12873
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12766
12874
  },
12767
- resolver: zod.zodResolver(MetadataSchema)
12875
+ resolver: zod.zodResolver(schema)
12768
12876
  });
12769
- const handleSubmit = form.handleSubmit(async (data) => {
12770
- const parsedData = parseValues(data);
12877
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12878
+ const { handleSuccess } = useRouteModal();
12879
+ const onSubmit = form.handleSubmit(async (data) => {
12771
12880
  await mutateAsync(
12772
12881
  {
12773
- metadata: parsedData
12882
+ shipping_address: {
12883
+ first_name: data.first_name,
12884
+ last_name: data.last_name,
12885
+ company: data.company,
12886
+ address_1: data.address_1,
12887
+ address_2: data.address_2,
12888
+ city: data.city,
12889
+ province: data.province,
12890
+ country_code: data.country_code,
12891
+ postal_code: data.postal_code,
12892
+ phone: data.phone
12893
+ }
12774
12894
  },
12775
12895
  {
12776
12896
  onSuccess: () => {
12777
- ui.toast.success("Metadata updated");
12778
12897
  handleSuccess();
12779
12898
  },
12780
12899
  onError: (error) => {
12781
12900
  ui.toast.error(error.message);
12782
12901
  }
12783
12902
  }
12784
- );
12785
- });
12786
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12787
- control: form.control,
12788
- name: "metadata"
12789
- });
12790
- function deleteRow(index) {
12791
- remove(index);
12792
- if (fields.length === 1) {
12793
- insert(0, {
12794
- key: "",
12795
- value: "",
12796
- disabled: false
12797
- });
12798
- }
12799
- }
12800
- function insertRow(index, position) {
12801
- insert(index + (position === "above" ? 0 : 1), {
12802
- key: "",
12803
- value: "",
12804
- disabled: false
12805
- });
12806
- }
12807
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12808
- KeyboundForm,
12809
- {
12810
- onSubmit: handleSubmit,
12811
- className: "flex flex-1 flex-col overflow-hidden",
12812
- children: [
12813
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12814
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12815
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12816
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
12817
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12818
- ] }),
12819
- fields.map((field, index) => {
12820
- const isDisabled = field.disabled || false;
12821
- let placeholder = "-";
12822
- if (typeof field.value === "object") {
12823
- placeholder = "{ ... }";
12824
- }
12825
- if (Array.isArray(field.value)) {
12826
- placeholder = "[ ... ]";
12827
- }
12828
- return /* @__PURE__ */ jsxRuntime.jsx(
12829
- ConditionalTooltip,
12830
- {
12831
- showTooltip: isDisabled,
12832
- content: "This row is disabled because it contains non-primitive data.",
12833
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12834
- /* @__PURE__ */ jsxRuntime.jsxs(
12835
- "div",
12836
- {
12837
- className: ui.clx("grid grid-cols-2 divide-x", {
12838
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12839
- }),
12840
- children: [
12841
- /* @__PURE__ */ jsxRuntime.jsx(
12842
- Form$2.Field,
12843
- {
12844
- control: form.control,
12845
- name: `metadata.${index}.key`,
12846
- render: ({ field: field2 }) => {
12847
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12848
- GridInput,
12849
- {
12850
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12851
- ...field2,
12852
- disabled: isDisabled,
12853
- placeholder: "Key"
12854
- }
12855
- ) }) });
12856
- }
12857
- }
12858
- ),
12859
- /* @__PURE__ */ jsxRuntime.jsx(
12860
- Form$2.Field,
12861
- {
12862
- control: form.control,
12863
- name: `metadata.${index}.value`,
12864
- render: ({ field: { value, ...field2 } }) => {
12865
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12866
- GridInput,
12867
- {
12868
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12869
- ...field2,
12870
- value: isDisabled ? placeholder : value,
12871
- disabled: isDisabled,
12872
- placeholder: "Value"
12873
- }
12874
- ) }) });
12875
- }
12876
- }
12877
- )
12878
- ]
12879
- }
12880
- ),
12881
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12882
- /* @__PURE__ */ jsxRuntime.jsx(
12883
- ui.DropdownMenu.Trigger,
12884
- {
12885
- className: ui.clx(
12886
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12887
- {
12888
- hidden: isDisabled
12889
- }
12890
- ),
12891
- disabled: isDisabled,
12892
- asChild: true,
12893
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12894
- }
12895
- ),
12896
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12897
- /* @__PURE__ */ jsxRuntime.jsxs(
12898
- ui.DropdownMenu.Item,
12899
- {
12900
- className: "gap-x-2",
12901
- onClick: () => insertRow(index, "above"),
12902
- children: [
12903
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12904
- "Insert row above"
12905
- ]
12906
- }
12907
- ),
12908
- /* @__PURE__ */ jsxRuntime.jsxs(
12909
- ui.DropdownMenu.Item,
12910
- {
12911
- className: "gap-x-2",
12912
- onClick: () => insertRow(index, "below"),
12913
- children: [
12914
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12915
- "Insert row below"
12916
- ]
12917
- }
12918
- ),
12919
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12920
- /* @__PURE__ */ jsxRuntime.jsxs(
12921
- ui.DropdownMenu.Item,
12922
- {
12923
- className: "gap-x-2",
12924
- onClick: () => deleteRow(index),
12925
- children: [
12926
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12927
- "Delete row"
12928
- ]
12929
- }
12930
- )
12931
- ] })
12932
- ] })
12933
- ] })
12934
- },
12935
- field.id
12936
- );
12937
- })
12903
+ );
12904
+ });
12905
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
+ KeyboundForm,
12907
+ {
12908
+ className: "flex flex-1 flex-col overflow-hidden",
12909
+ onSubmit,
12910
+ children: [
12911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "country_code",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ ),
12924
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
+ /* @__PURE__ */ jsxRuntime.jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "first_name",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsxRuntime.jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "last_name",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ )
12938
12949
  ] }),
12939
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
12940
- ] }),
12941
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12942
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(
12951
+ Form$2.Field,
12952
+ {
12953
+ control: form.control,
12954
+ name: "company",
12955
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
+ ] })
12960
+ }
12961
+ ),
12962
+ /* @__PURE__ */ jsxRuntime.jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "address_1",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsxRuntime.jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "address_2",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ ),
12986
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
+ /* @__PURE__ */ jsxRuntime.jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "postal_code",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "city",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx(
13013
+ Form$2.Field,
13014
+ {
13015
+ control: form.control,
13016
+ name: "province",
13017
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
+ ] })
13022
+ }
13023
+ ),
13024
+ /* @__PURE__ */ jsxRuntime.jsx(
13025
+ Form$2.Field,
13026
+ {
13027
+ control: form.control,
13028
+ name: "phone",
13029
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
+ ] })
13034
+ }
13035
+ )
13036
+ ] }) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12943
13039
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12944
13040
  ] }) })
12945
13041
  ]
12946
13042
  }
12947
13043
  ) });
12948
13044
  };
12949
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12950
- return /* @__PURE__ */ jsxRuntime.jsx(
12951
- "input",
12952
- {
12953
- ref,
12954
- ...props,
12955
- autoComplete: "off",
12956
- className: ui.clx(
12957
- "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",
12958
- className
12959
- )
12960
- }
12961
- );
12962
- });
12963
- GridInput.displayName = "MetadataForm.GridInput";
12964
- const PlaceholderInner = () => {
12965
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12966
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12967
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12970
- ] }) })
12971
- ] });
12972
- };
12973
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12974
- function getDefaultValues(metadata) {
12975
- if (!metadata || !Object.keys(metadata).length) {
12976
- return [
12977
- {
12978
- key: "",
12979
- value: "",
12980
- disabled: false
12981
- }
12982
- ];
12983
- }
12984
- return Object.entries(metadata).map(([key, value]) => {
12985
- if (!EDITABLE_TYPES.includes(typeof value)) {
12986
- return {
12987
- key,
12988
- value,
12989
- disabled: true
12990
- };
12991
- }
12992
- let stringValue = value;
12993
- if (typeof value !== "string") {
12994
- stringValue = JSON.stringify(value);
12995
- }
12996
- return {
12997
- key,
12998
- value: stringValue,
12999
- original_key: key
13000
- };
13001
- });
13002
- }
13003
- function parseValues(values) {
13004
- const metadata = values.metadata;
13005
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13006
- if (isEmpty) {
13007
- return null;
13008
- }
13009
- const update = {};
13010
- metadata.forEach((field) => {
13011
- let key = field.key;
13012
- let value = field.value;
13013
- const disabled = field.disabled;
13014
- if (!key || !value) {
13015
- return;
13016
- }
13017
- if (disabled) {
13018
- update[key] = value;
13019
- return;
13020
- }
13021
- key = key.trim();
13022
- value = value.trim();
13023
- if (value === "true") {
13024
- update[key] = true;
13025
- } else if (value === "false") {
13026
- update[key] = false;
13027
- } else {
13028
- const parsedNumber = parseFloat(value);
13029
- if (!isNaN(parsedNumber)) {
13030
- update[key] = parsedNumber;
13031
- } else {
13032
- update[key] = value;
13033
- }
13034
- }
13035
- });
13036
- return update;
13037
- }
13038
- function getHasUneditableRows(metadata) {
13039
- if (!metadata) {
13040
- return false;
13041
- }
13042
- return Object.values(metadata).some(
13043
- (value) => !EDITABLE_TYPES.includes(typeof value)
13044
- );
13045
- }
13045
+ const schema = addressSchema;
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13063,14 +13063,14 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
- {
13067
- Component: BillingAddress,
13068
- path: "/draft-orders/:id/billing-address"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
13073
13069
  },
13070
+ {
13071
+ Component: BillingAddress,
13072
+ path: "/draft-orders/:id/billing-address"
13073
+ },
13074
13074
  {
13075
13075
  Component: Email,
13076
13076
  path: "/draft-orders/:id/email"
@@ -13079,6 +13079,10 @@ const routeModule = {
13079
13079
  Component: Items,
13080
13080
  path: "/draft-orders/:id/items"
13081
13081
  },
13082
+ {
13083
+ Component: Metadata,
13084
+ path: "/draft-orders/:id/metadata"
13085
+ },
13082
13086
  {
13083
13087
  Component: Promotions,
13084
13088
  path: "/draft-orders/:id/promotions"
@@ -13091,17 +13095,13 @@ const routeModule = {
13091
13095
  Component: Shipping,
13092
13096
  path: "/draft-orders/:id/shipping"
13093
13097
  },
13094
- {
13095
- Component: ShippingAddress,
13096
- path: "/draft-orders/:id/shipping-address"
13097
- },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
- Component: Metadata,
13104
- path: "/draft-orders/:id/metadata"
13103
+ Component: ShippingAddress,
13104
+ path: "/draft-orders/:id/shipping-address"
13105
13105
  }
13106
13106
  ]
13107
13107
  }