@medusajs/draft-order 2.12.0 → 3.0.0-preview-20251202120138

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.
@@ -9762,6 +9762,95 @@ const BillingAddressForm = ({ order }) => {
9762
9762
  ) });
9763
9763
  };
9764
9764
  const schema$5 = addressSchema;
9765
+ const CustomItems = () => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
+ ] });
9770
+ };
9771
+ const CustomItemsForm = () => {
9772
+ const form = reactHookForm.useForm({
9773
+ resolver: zod.zodResolver(schema$4)
9774
+ });
9775
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
+ ] }) })
9781
+ ] }) });
9782
+ };
9783
+ const schema$4 = objectType({
9784
+ email: stringType().email()
9785
+ });
9786
+ const Email = () => {
9787
+ const { id } = reactRouterDom.useParams();
9788
+ const { order, isPending, isError, error } = useOrder(id, {
9789
+ fields: "+email"
9790
+ });
9791
+ if (isError) {
9792
+ throw error;
9793
+ }
9794
+ const isReady = !isPending && !!order;
9795
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9796
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9799
+ ] }),
9800
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9801
+ ] });
9802
+ };
9803
+ const EmailForm = ({ order }) => {
9804
+ const form = reactHookForm.useForm({
9805
+ defaultValues: {
9806
+ email: order.email ?? ""
9807
+ },
9808
+ resolver: zod.zodResolver(schema$3)
9809
+ });
9810
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
+ const { handleSuccess } = useRouteModal();
9812
+ const onSubmit = form.handleSubmit(async (data) => {
9813
+ await mutateAsync(
9814
+ { email: data.email },
9815
+ {
9816
+ onSuccess: () => {
9817
+ handleSuccess();
9818
+ },
9819
+ onError: (error) => {
9820
+ ui.toast.error(error.message);
9821
+ }
9822
+ }
9823
+ );
9824
+ });
9825
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9826
+ KeyboundForm,
9827
+ {
9828
+ className: "flex flex-1 flex-col overflow-hidden",
9829
+ onSubmit,
9830
+ children: [
9831
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9832
+ Form$2.Field,
9833
+ {
9834
+ control: form.control,
9835
+ name: "email",
9836
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
+ ] })
9841
+ }
9842
+ ) }),
9843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9845
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9846
+ ] }) })
9847
+ ]
9848
+ }
9849
+ ) });
9850
+ };
9851
+ const schema$3 = objectType({
9852
+ email: stringType().email()
9853
+ });
9765
9854
  const NumberInput = React.forwardRef(
9766
9855
  ({
9767
9856
  value,
@@ -10736,193 +10825,543 @@ const customItemSchema = objectType({
10736
10825
  quantity: numberType(),
10737
10826
  unit_price: unionType([numberType(), stringType()])
10738
10827
  });
10739
- const PROMOTION_QUERY_KEY = "promotions";
10740
- const promotionsQueryKeys = {
10741
- list: (query2) => [
10742
- PROMOTION_QUERY_KEY,
10743
- query2 ? query2 : void 0
10744
- ],
10745
- detail: (id, query2) => [
10746
- PROMOTION_QUERY_KEY,
10747
- id,
10748
- query2 ? query2 : void 0
10749
- ]
10750
- };
10751
- const usePromotions = (query2, options) => {
10752
- const { data, ...rest } = reactQuery.useQuery({
10753
- queryKey: promotionsQueryKeys.list(query2),
10754
- queryFn: async () => sdk.admin.promotion.list(query2),
10755
- ...options
10756
- });
10757
- return { ...data, ...rest };
10758
- };
10759
- const Promotions = () => {
10828
+ const InlineTip = React.forwardRef(
10829
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10830
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10831
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10832
+ "div",
10833
+ {
10834
+ ref,
10835
+ className: ui.clx(
10836
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10837
+ className
10838
+ ),
10839
+ ...props,
10840
+ children: [
10841
+ /* @__PURE__ */ jsxRuntime.jsx(
10842
+ "div",
10843
+ {
10844
+ role: "presentation",
10845
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10846
+ "bg-ui-tag-orange-icon": variant === "warning"
10847
+ })
10848
+ }
10849
+ ),
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10851
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10852
+ labelValue,
10853
+ ":"
10854
+ ] }),
10855
+ " ",
10856
+ children
10857
+ ] })
10858
+ ]
10859
+ }
10860
+ );
10861
+ }
10862
+ );
10863
+ InlineTip.displayName = "InlineTip";
10864
+ const MetadataFieldSchema = objectType({
10865
+ key: stringType(),
10866
+ disabled: booleanType().optional(),
10867
+ value: anyType()
10868
+ });
10869
+ const MetadataSchema = objectType({
10870
+ metadata: arrayType(MetadataFieldSchema)
10871
+ });
10872
+ const Metadata = () => {
10760
10873
  const { id } = reactRouterDom.useParams();
10761
- const {
10762
- order: preview,
10763
- isError: isPreviewError,
10764
- error: previewError
10765
- } = useOrderPreview(id, void 0);
10766
- useInitiateOrderEdit({ preview });
10767
- const { onCancel } = useCancelOrderEdit({ preview });
10768
- if (isPreviewError) {
10769
- throw previewError;
10874
+ const { order, isPending, isError, error } = useOrder(id, {
10875
+ fields: "metadata"
10876
+ });
10877
+ if (isError) {
10878
+ throw error;
10770
10879
  }
10771
- const isReady = !!preview;
10772
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10773
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10774
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10880
+ const isReady = !isPending && !!order;
10881
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10884
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10885
+ ] }),
10886
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10775
10887
  ] });
10776
10888
  };
10777
- const PromotionForm = ({ preview }) => {
10778
- const { items, shipping_methods } = preview;
10779
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10780
- const [comboboxValue, setComboboxValue] = React.useState("");
10889
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10890
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10891
+ const MetadataForm = ({ orderId, metadata }) => {
10781
10892
  const { handleSuccess } = useRouteModal();
10782
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10783
- const promoIds = getPromotionIds(items, shipping_methods);
10784
- const { promotions, isPending, isError, error } = usePromotions(
10785
- {
10786
- id: promoIds
10787
- },
10788
- {
10789
- enabled: !!promoIds.length
10790
- }
10791
- );
10792
- const comboboxData = useComboboxData({
10793
- queryKey: ["promotions", "combobox", promoIds],
10794
- queryFn: async (params) => {
10795
- return await sdk.admin.promotion.list({
10796
- ...params,
10797
- id: {
10798
- $nin: promoIds
10799
- }
10800
- });
10893
+ const hasUneditableRows = getHasUneditableRows(metadata);
10894
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10895
+ const form = reactHookForm.useForm({
10896
+ defaultValues: {
10897
+ metadata: getDefaultValues(metadata)
10801
10898
  },
10802
- getOptions: (data) => {
10803
- return data.promotions.map((promotion) => ({
10804
- label: promotion.code,
10805
- value: promotion.code
10806
- }));
10807
- }
10899
+ resolver: zod.zodResolver(MetadataSchema)
10808
10900
  });
10809
- const add = async (value) => {
10810
- if (!value) {
10811
- return;
10812
- }
10813
- addPromotions(
10901
+ const handleSubmit = form.handleSubmit(async (data) => {
10902
+ const parsedData = parseValues(data);
10903
+ await mutateAsync(
10814
10904
  {
10815
- promo_codes: [value]
10905
+ metadata: parsedData
10816
10906
  },
10817
10907
  {
10818
- onError: (e) => {
10819
- ui.toast.error(e.message);
10820
- comboboxData.onSearchValueChange("");
10821
- setComboboxValue("");
10822
- },
10823
10908
  onSuccess: () => {
10824
- comboboxData.onSearchValueChange("");
10825
- setComboboxValue("");
10909
+ ui.toast.success("Metadata updated");
10910
+ handleSuccess();
10911
+ },
10912
+ onError: (error) => {
10913
+ ui.toast.error(error.message);
10826
10914
  }
10827
10915
  }
10828
10916
  );
10829
- };
10830
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10831
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10832
- const onSubmit = async () => {
10833
- setIsSubmitting(true);
10834
- let requestSucceeded = false;
10835
- await requestOrderEdit(void 0, {
10836
- onError: (e) => {
10837
- ui.toast.error(e.message);
10838
- },
10839
- onSuccess: () => {
10840
- requestSucceeded = true;
10841
- }
10842
- });
10843
- if (!requestSucceeded) {
10844
- setIsSubmitting(false);
10845
- return;
10917
+ });
10918
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10919
+ control: form.control,
10920
+ name: "metadata"
10921
+ });
10922
+ function deleteRow(index) {
10923
+ remove(index);
10924
+ if (fields.length === 1) {
10925
+ insert(0, {
10926
+ key: "",
10927
+ value: "",
10928
+ disabled: false
10929
+ });
10846
10930
  }
10847
- await confirmOrderEdit(void 0, {
10848
- onError: (e) => {
10849
- ui.toast.error(e.message);
10850
- },
10851
- onSuccess: () => {
10852
- handleSuccess();
10853
- },
10854
- onSettled: () => {
10855
- setIsSubmitting(false);
10856
- }
10931
+ }
10932
+ function insertRow(index, position) {
10933
+ insert(index + (position === "above" ? 0 : 1), {
10934
+ key: "",
10935
+ value: "",
10936
+ disabled: false
10857
10937
  });
10858
- };
10859
- if (isError) {
10860
- throw error;
10861
10938
  }
10862
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10863
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10864
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10865
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10866
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10867
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10939
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10940
+ KeyboundForm,
10941
+ {
10942
+ onSubmit: handleSubmit,
10943
+ className: "flex flex-1 flex-col overflow-hidden",
10944
+ children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10947
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
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_KEY_LABEL_ID, children: "Key" }) }),
10949
+ /* @__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" }) })
10950
+ ] }),
10951
+ fields.map((field, index) => {
10952
+ const isDisabled = field.disabled || false;
10953
+ let placeholder = "-";
10954
+ if (typeof field.value === "object") {
10955
+ placeholder = "{ ... }";
10956
+ }
10957
+ if (Array.isArray(field.value)) {
10958
+ placeholder = "[ ... ]";
10959
+ }
10960
+ return /* @__PURE__ */ jsxRuntime.jsx(
10961
+ ConditionalTooltip,
10962
+ {
10963
+ showTooltip: isDisabled,
10964
+ content: "This row is disabled because it contains non-primitive data.",
10965
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10966
+ /* @__PURE__ */ jsxRuntime.jsxs(
10967
+ "div",
10968
+ {
10969
+ className: ui.clx("grid grid-cols-2 divide-x", {
10970
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10971
+ }),
10972
+ children: [
10973
+ /* @__PURE__ */ jsxRuntime.jsx(
10974
+ Form$2.Field,
10975
+ {
10976
+ control: form.control,
10977
+ name: `metadata.${index}.key`,
10978
+ render: ({ field: field2 }) => {
10979
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10980
+ GridInput,
10981
+ {
10982
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10983
+ ...field2,
10984
+ disabled: isDisabled,
10985
+ placeholder: "Key"
10986
+ }
10987
+ ) }) });
10988
+ }
10989
+ }
10990
+ ),
10991
+ /* @__PURE__ */ jsxRuntime.jsx(
10992
+ Form$2.Field,
10993
+ {
10994
+ control: form.control,
10995
+ name: `metadata.${index}.value`,
10996
+ render: ({ field: { value, ...field2 } }) => {
10997
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10998
+ GridInput,
10999
+ {
11000
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11001
+ ...field2,
11002
+ value: isDisabled ? placeholder : value,
11003
+ disabled: isDisabled,
11004
+ placeholder: "Value"
11005
+ }
11006
+ ) }) });
11007
+ }
11008
+ }
11009
+ )
11010
+ ]
11011
+ }
11012
+ ),
11013
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11014
+ /* @__PURE__ */ jsxRuntime.jsx(
11015
+ ui.DropdownMenu.Trigger,
11016
+ {
11017
+ className: ui.clx(
11018
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11019
+ {
11020
+ hidden: isDisabled
11021
+ }
11022
+ ),
11023
+ disabled: isDisabled,
11024
+ asChild: true,
11025
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11026
+ }
11027
+ ),
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11029
+ /* @__PURE__ */ jsxRuntime.jsxs(
11030
+ ui.DropdownMenu.Item,
11031
+ {
11032
+ className: "gap-x-2",
11033
+ onClick: () => insertRow(index, "above"),
11034
+ children: [
11035
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11036
+ "Insert row above"
11037
+ ]
11038
+ }
11039
+ ),
11040
+ /* @__PURE__ */ jsxRuntime.jsxs(
11041
+ ui.DropdownMenu.Item,
11042
+ {
11043
+ className: "gap-x-2",
11044
+ onClick: () => insertRow(index, "below"),
11045
+ children: [
11046
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11047
+ "Insert row below"
11048
+ ]
11049
+ }
11050
+ ),
11051
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11052
+ /* @__PURE__ */ jsxRuntime.jsxs(
11053
+ ui.DropdownMenu.Item,
11054
+ {
11055
+ className: "gap-x-2",
11056
+ onClick: () => deleteRow(index),
11057
+ children: [
11058
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11059
+ "Delete row"
11060
+ ]
11061
+ }
11062
+ )
11063
+ ] })
11064
+ ] })
11065
+ ] })
11066
+ },
11067
+ field.id
11068
+ );
11069
+ })
11070
+ ] }),
11071
+ 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." })
10868
11072
  ] }),
10869
- /* @__PURE__ */ jsxRuntime.jsx(
10870
- Combobox,
10871
- {
10872
- id: "promotion-combobox",
10873
- "aria-describedby": "promotion-combobox-hint",
10874
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10875
- fetchNextPage: comboboxData.fetchNextPage,
10876
- options: comboboxData.options,
10877
- onSearchValueChange: comboboxData.onSearchValueChange,
10878
- searchValue: comboboxData.searchValue,
10879
- disabled: comboboxData.disabled || isAddingPromotions,
10880
- onChange: add,
10881
- value: comboboxValue
10882
- }
10883
- )
10884
- ] }),
10885
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10886
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10887
- PromotionItem,
10888
- {
10889
- promotion,
10890
- orderId: preview.id,
10891
- isLoading: isPending
10892
- },
10893
- promotion.id
10894
- )) })
10895
- ] }) }),
10896
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10897
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10898
- /* @__PURE__ */ jsxRuntime.jsx(
10899
- ui.Button,
10900
- {
10901
- size: "small",
10902
- type: "submit",
10903
- isLoading: isSubmitting || isAddingPromotions,
10904
- children: "Save"
10905
- }
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11075
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
+ ] }) })
11077
+ ]
11078
+ }
11079
+ ) });
11080
+ };
11081
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11082
+ return /* @__PURE__ */ jsxRuntime.jsx(
11083
+ "input",
11084
+ {
11085
+ ref,
11086
+ ...props,
11087
+ autoComplete: "off",
11088
+ className: ui.clx(
11089
+ "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",
11090
+ className
10906
11091
  )
11092
+ }
11093
+ );
11094
+ });
11095
+ GridInput.displayName = "MetadataForm.GridInput";
11096
+ const PlaceholderInner = () => {
11097
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11099
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11101
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10907
11102
  ] }) })
10908
11103
  ] });
10909
11104
  };
10910
- const PromotionItem = ({
10911
- promotion,
10912
- orderId,
10913
- isLoading
10914
- }) => {
10915
- var _a;
10916
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10917
- const onRemove = async () => {
10918
- removePromotions(
10919
- {
10920
- promo_codes: [promotion.code]
10921
- },
11105
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11106
+ function getDefaultValues(metadata) {
11107
+ if (!metadata || !Object.keys(metadata).length) {
11108
+ return [
10922
11109
  {
10923
- onError: (e) => {
10924
- ui.toast.error(e.message);
10925
- }
11110
+ key: "",
11111
+ value: "",
11112
+ disabled: false
11113
+ }
11114
+ ];
11115
+ }
11116
+ return Object.entries(metadata).map(([key, value]) => {
11117
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11118
+ return {
11119
+ key,
11120
+ value,
11121
+ disabled: true
11122
+ };
11123
+ }
11124
+ let stringValue = value;
11125
+ if (typeof value !== "string") {
11126
+ stringValue = JSON.stringify(value);
11127
+ }
11128
+ return {
11129
+ key,
11130
+ value: stringValue,
11131
+ original_key: key
11132
+ };
11133
+ });
11134
+ }
11135
+ function parseValues(values) {
11136
+ const metadata = values.metadata;
11137
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11138
+ if (isEmpty) {
11139
+ return null;
11140
+ }
11141
+ const update = {};
11142
+ metadata.forEach((field) => {
11143
+ let key = field.key;
11144
+ let value = field.value;
11145
+ const disabled = field.disabled;
11146
+ if (!key || !value) {
11147
+ return;
11148
+ }
11149
+ if (disabled) {
11150
+ update[key] = value;
11151
+ return;
11152
+ }
11153
+ key = key.trim();
11154
+ value = value.trim();
11155
+ if (value === "true") {
11156
+ update[key] = true;
11157
+ } else if (value === "false") {
11158
+ update[key] = false;
11159
+ } else {
11160
+ const parsedNumber = parseFloat(value);
11161
+ if (!isNaN(parsedNumber)) {
11162
+ update[key] = parsedNumber;
11163
+ } else {
11164
+ update[key] = value;
11165
+ }
11166
+ }
11167
+ });
11168
+ return update;
11169
+ }
11170
+ function getHasUneditableRows(metadata) {
11171
+ if (!metadata) {
11172
+ return false;
11173
+ }
11174
+ return Object.values(metadata).some(
11175
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11176
+ );
11177
+ }
11178
+ const PROMOTION_QUERY_KEY = "promotions";
11179
+ const promotionsQueryKeys = {
11180
+ list: (query2) => [
11181
+ PROMOTION_QUERY_KEY,
11182
+ query2 ? query2 : void 0
11183
+ ],
11184
+ detail: (id, query2) => [
11185
+ PROMOTION_QUERY_KEY,
11186
+ id,
11187
+ query2 ? query2 : void 0
11188
+ ]
11189
+ };
11190
+ const usePromotions = (query2, options) => {
11191
+ const { data, ...rest } = reactQuery.useQuery({
11192
+ queryKey: promotionsQueryKeys.list(query2),
11193
+ queryFn: async () => sdk.admin.promotion.list(query2),
11194
+ ...options
11195
+ });
11196
+ return { ...data, ...rest };
11197
+ };
11198
+ const Promotions = () => {
11199
+ const { id } = reactRouterDom.useParams();
11200
+ const {
11201
+ order: preview,
11202
+ isError: isPreviewError,
11203
+ error: previewError
11204
+ } = useOrderPreview(id, void 0);
11205
+ useInitiateOrderEdit({ preview });
11206
+ const { onCancel } = useCancelOrderEdit({ preview });
11207
+ if (isPreviewError) {
11208
+ throw previewError;
11209
+ }
11210
+ const isReady = !!preview;
11211
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11212
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11213
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11214
+ ] });
11215
+ };
11216
+ const PromotionForm = ({ preview }) => {
11217
+ const { items, shipping_methods } = preview;
11218
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11219
+ const [comboboxValue, setComboboxValue] = React.useState("");
11220
+ const { handleSuccess } = useRouteModal();
11221
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11222
+ const promoIds = getPromotionIds(items, shipping_methods);
11223
+ const { promotions, isPending, isError, error } = usePromotions(
11224
+ {
11225
+ id: promoIds
11226
+ },
11227
+ {
11228
+ enabled: !!promoIds.length
11229
+ }
11230
+ );
11231
+ const comboboxData = useComboboxData({
11232
+ queryKey: ["promotions", "combobox", promoIds],
11233
+ queryFn: async (params) => {
11234
+ return await sdk.admin.promotion.list({
11235
+ ...params,
11236
+ id: {
11237
+ $nin: promoIds
11238
+ }
11239
+ });
11240
+ },
11241
+ getOptions: (data) => {
11242
+ return data.promotions.map((promotion) => ({
11243
+ label: promotion.code,
11244
+ value: promotion.code
11245
+ }));
11246
+ }
11247
+ });
11248
+ const add = async (value) => {
11249
+ if (!value) {
11250
+ return;
11251
+ }
11252
+ addPromotions(
11253
+ {
11254
+ promo_codes: [value]
11255
+ },
11256
+ {
11257
+ onError: (e) => {
11258
+ ui.toast.error(e.message);
11259
+ comboboxData.onSearchValueChange("");
11260
+ setComboboxValue("");
11261
+ },
11262
+ onSuccess: () => {
11263
+ comboboxData.onSearchValueChange("");
11264
+ setComboboxValue("");
11265
+ }
11266
+ }
11267
+ );
11268
+ };
11269
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11270
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11271
+ const onSubmit = async () => {
11272
+ setIsSubmitting(true);
11273
+ let requestSucceeded = false;
11274
+ await requestOrderEdit(void 0, {
11275
+ onError: (e) => {
11276
+ ui.toast.error(e.message);
11277
+ },
11278
+ onSuccess: () => {
11279
+ requestSucceeded = true;
11280
+ }
11281
+ });
11282
+ if (!requestSucceeded) {
11283
+ setIsSubmitting(false);
11284
+ return;
11285
+ }
11286
+ await confirmOrderEdit(void 0, {
11287
+ onError: (e) => {
11288
+ ui.toast.error(e.message);
11289
+ },
11290
+ onSuccess: () => {
11291
+ handleSuccess();
11292
+ },
11293
+ onSettled: () => {
11294
+ setIsSubmitting(false);
11295
+ }
11296
+ });
11297
+ };
11298
+ if (isError) {
11299
+ throw error;
11300
+ }
11301
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11307
+ ] }),
11308
+ /* @__PURE__ */ jsxRuntime.jsx(
11309
+ Combobox,
11310
+ {
11311
+ id: "promotion-combobox",
11312
+ "aria-describedby": "promotion-combobox-hint",
11313
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11314
+ fetchNextPage: comboboxData.fetchNextPage,
11315
+ options: comboboxData.options,
11316
+ onSearchValueChange: comboboxData.onSearchValueChange,
11317
+ searchValue: comboboxData.searchValue,
11318
+ disabled: comboboxData.disabled || isAddingPromotions,
11319
+ onChange: add,
11320
+ value: comboboxValue
11321
+ }
11322
+ )
11323
+ ] }),
11324
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11326
+ PromotionItem,
11327
+ {
11328
+ promotion,
11329
+ orderId: preview.id,
11330
+ isLoading: isPending
11331
+ },
11332
+ promotion.id
11333
+ )) })
11334
+ ] }) }),
11335
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11337
+ /* @__PURE__ */ jsxRuntime.jsx(
11338
+ ui.Button,
11339
+ {
11340
+ size: "small",
11341
+ type: "submit",
11342
+ isLoading: isSubmitting || isAddingPromotions,
11343
+ children: "Save"
11344
+ }
11345
+ )
11346
+ ] }) })
11347
+ ] });
11348
+ };
11349
+ const PromotionItem = ({
11350
+ promotion,
11351
+ orderId,
11352
+ isLoading
11353
+ }) => {
11354
+ var _a;
11355
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11356
+ const onRemove = async () => {
11357
+ removePromotions(
11358
+ {
11359
+ promo_codes: [promotion.code]
11360
+ },
11361
+ {
11362
+ onError: (e) => {
11363
+ ui.toast.error(e.message);
11364
+ }
10926
11365
  }
10927
11366
  );
10928
11367
  };
@@ -11013,74 +11452,6 @@ function getPromotionIds(items, shippingMethods) {
11013
11452
  }
11014
11453
  return Array.from(promotionIds);
11015
11454
  }
11016
- const Email = () => {
11017
- const { id } = reactRouterDom.useParams();
11018
- const { order, isPending, isError, error } = useOrder(id, {
11019
- fields: "+email"
11020
- });
11021
- if (isError) {
11022
- throw error;
11023
- }
11024
- const isReady = !isPending && !!order;
11025
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11026
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11027
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
11028
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11029
- ] }),
11030
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
11031
- ] });
11032
- };
11033
- const EmailForm = ({ order }) => {
11034
- const form = reactHookForm.useForm({
11035
- defaultValues: {
11036
- email: order.email ?? ""
11037
- },
11038
- resolver: zod.zodResolver(schema$4)
11039
- });
11040
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11041
- const { handleSuccess } = useRouteModal();
11042
- const onSubmit = form.handleSubmit(async (data) => {
11043
- await mutateAsync(
11044
- { email: data.email },
11045
- {
11046
- onSuccess: () => {
11047
- handleSuccess();
11048
- },
11049
- onError: (error) => {
11050
- ui.toast.error(error.message);
11051
- }
11052
- }
11053
- );
11054
- });
11055
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11056
- KeyboundForm,
11057
- {
11058
- className: "flex flex-1 flex-col overflow-hidden",
11059
- onSubmit,
11060
- children: [
11061
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
11062
- Form$2.Field,
11063
- {
11064
- control: form.control,
11065
- name: "email",
11066
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11067
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
11068
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11069
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11070
- ] })
11071
- }
11072
- ) }),
11073
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11074
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11075
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
- ] }) })
11077
- ]
11078
- }
11079
- ) });
11080
- };
11081
- const schema$4 = objectType({
11082
- email: stringType().email()
11083
- });
11084
11455
  const SalesChannel = () => {
11085
11456
  const { id } = reactRouterDom.useParams();
11086
11457
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -11109,7 +11480,7 @@ const SalesChannelForm = ({ order }) => {
11109
11480
  defaultValues: {
11110
11481
  sales_channel_id: order.sales_channel_id || ""
11111
11482
  },
11112
- resolver: zod.zodResolver(schema$3)
11483
+ resolver: zod.zodResolver(schema$2)
11113
11484
  });
11114
11485
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11115
11486
  const { handleSuccess } = useRouteModal();
@@ -11184,334 +11555,131 @@ const SalesChannelField = ({ control, order }) => {
11184
11555
  }
11185
11556
  );
11186
11557
  };
11187
- const schema$3 = objectType({
11558
+ const schema$2 = objectType({
11188
11559
  sales_channel_id: stringType().min(1)
11189
11560
  });
11190
- const ShippingAddress = () => {
11561
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11562
+ const Shipping = () => {
11563
+ var _a;
11191
11564
  const { id } = reactRouterDom.useParams();
11192
11565
  const { order, isPending, isError, error } = useOrder(id, {
11193
- fields: "+shipping_address"
11566
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11194
11567
  });
11568
+ const {
11569
+ order: preview,
11570
+ isPending: isPreviewPending,
11571
+ isError: isPreviewError,
11572
+ error: previewError
11573
+ } = useOrderPreview(id);
11574
+ useInitiateOrderEdit({ preview });
11575
+ const { onCancel } = useCancelOrderEdit({ preview });
11195
11576
  if (isError) {
11196
11577
  throw error;
11197
11578
  }
11198
- const isReady = !isPending && !!order;
11199
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11200
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11201
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11202
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11203
- ] }),
11204
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11205
- ] });
11579
+ if (isPreviewError) {
11580
+ throw previewError;
11581
+ }
11582
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11583
+ const isReady = preview && !isPreviewPending && order && !isPending;
11584
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11589
+ ] }) }) }),
11590
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11591
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11592
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11594
+ ] }) });
11206
11595
  };
11207
- const ShippingAddressForm = ({ order }) => {
11208
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11209
- const form = reactHookForm.useForm({
11210
- defaultValues: {
11211
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11212
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11213
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11214
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11215
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11216
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11217
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11218
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11219
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11220
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11596
+ const ShippingForm = ({ preview, order }) => {
11597
+ var _a;
11598
+ const { setIsOpen } = useStackedModal();
11599
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11600
+ const [data, setData] = React.useState(null);
11601
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11602
+ const { shipping_options } = useShippingOptions(
11603
+ {
11604
+ id: appliedShippingOptionIds,
11605
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11221
11606
  },
11222
- resolver: zod.zodResolver(schema$2)
11223
- });
11224
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11607
+ {
11608
+ enabled: appliedShippingOptionIds.length > 0
11609
+ }
11610
+ );
11611
+ const uniqueShippingProfiles = React.useMemo(() => {
11612
+ const profiles = /* @__PURE__ */ new Map();
11613
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11614
+ profiles.set(profile.id, profile);
11615
+ });
11616
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11617
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11618
+ });
11619
+ return Array.from(profiles.values());
11620
+ }, [order.items, shipping_options]);
11225
11621
  const { handleSuccess } = useRouteModal();
11226
- const onSubmit = form.handleSubmit(async (data) => {
11227
- await mutateAsync(
11228
- {
11229
- shipping_address: {
11230
- first_name: data.first_name,
11231
- last_name: data.last_name,
11232
- company: data.company,
11233
- address_1: data.address_1,
11234
- address_2: data.address_2,
11235
- city: data.city,
11236
- province: data.province,
11237
- country_code: data.country_code,
11238
- postal_code: data.postal_code,
11239
- phone: data.phone
11240
- }
11622
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11623
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11624
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11625
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11626
+ const onSubmit = async () => {
11627
+ setIsSubmitting(true);
11628
+ let requestSucceeded = false;
11629
+ await requestOrderEdit(void 0, {
11630
+ onError: (e) => {
11631
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11241
11632
  },
11242
- {
11243
- onSuccess: () => {
11244
- handleSuccess();
11245
- },
11246
- onError: (error) => {
11247
- ui.toast.error(error.message);
11633
+ onSuccess: () => {
11634
+ requestSucceeded = true;
11635
+ }
11636
+ });
11637
+ if (!requestSucceeded) {
11638
+ setIsSubmitting(false);
11639
+ return;
11640
+ }
11641
+ await confirmOrderEdit(void 0, {
11642
+ onError: (e) => {
11643
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11644
+ },
11645
+ onSuccess: () => {
11646
+ handleSuccess();
11647
+ },
11648
+ onSettled: () => {
11649
+ setIsSubmitting(false);
11650
+ }
11651
+ });
11652
+ };
11653
+ const onKeydown = React.useCallback(
11654
+ (e) => {
11655
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11656
+ if (data || isSubmitting) {
11657
+ return;
11248
11658
  }
11659
+ onSubmit();
11249
11660
  }
11250
- );
11251
- });
11252
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11253
- KeyboundForm,
11254
- {
11255
- className: "flex flex-1 flex-col overflow-hidden",
11256
- onSubmit,
11257
- children: [
11258
- /* @__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: [
11259
- /* @__PURE__ */ jsxRuntime.jsx(
11260
- Form$2.Field,
11261
- {
11262
- control: form.control,
11263
- name: "country_code",
11264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11268
- ] })
11269
- }
11270
- ),
11271
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11661
+ },
11662
+ [data, isSubmitting, onSubmit]
11663
+ );
11664
+ React.useEffect(() => {
11665
+ document.addEventListener("keydown", onKeydown);
11666
+ return () => {
11667
+ document.removeEventListener("keydown", onKeydown);
11668
+ };
11669
+ }, [onKeydown]);
11670
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11671
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11672
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11673
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11674
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11675
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11676
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11677
+ ] }),
11678
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11679
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11680
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11272
11681
  /* @__PURE__ */ jsxRuntime.jsx(
11273
- Form$2.Field,
11274
- {
11275
- control: form.control,
11276
- name: "first_name",
11277
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11281
- ] })
11282
- }
11283
- ),
11284
- /* @__PURE__ */ jsxRuntime.jsx(
11285
- Form$2.Field,
11286
- {
11287
- control: form.control,
11288
- name: "last_name",
11289
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11290
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11293
- ] })
11294
- }
11295
- )
11296
- ] }),
11297
- /* @__PURE__ */ jsxRuntime.jsx(
11298
- Form$2.Field,
11299
- {
11300
- control: form.control,
11301
- name: "company",
11302
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11305
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11306
- ] })
11307
- }
11308
- ),
11309
- /* @__PURE__ */ jsxRuntime.jsx(
11310
- Form$2.Field,
11311
- {
11312
- control: form.control,
11313
- name: "address_1",
11314
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11318
- ] })
11319
- }
11320
- ),
11321
- /* @__PURE__ */ jsxRuntime.jsx(
11322
- Form$2.Field,
11323
- {
11324
- control: form.control,
11325
- name: "address_2",
11326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
- ] })
11331
- }
11332
- ),
11333
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11334
- /* @__PURE__ */ jsxRuntime.jsx(
11335
- Form$2.Field,
11336
- {
11337
- control: form.control,
11338
- name: "postal_code",
11339
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
- ] })
11344
- }
11345
- ),
11346
- /* @__PURE__ */ jsxRuntime.jsx(
11347
- Form$2.Field,
11348
- {
11349
- control: form.control,
11350
- name: "city",
11351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
- ] })
11356
- }
11357
- )
11358
- ] }),
11359
- /* @__PURE__ */ jsxRuntime.jsx(
11360
- Form$2.Field,
11361
- {
11362
- control: form.control,
11363
- name: "province",
11364
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
- ] })
11369
- }
11370
- ),
11371
- /* @__PURE__ */ jsxRuntime.jsx(
11372
- Form$2.Field,
11373
- {
11374
- control: form.control,
11375
- name: "phone",
11376
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
- ] })
11381
- }
11382
- )
11383
- ] }) }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11385
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11386
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11387
- ] }) })
11388
- ]
11389
- }
11390
- ) });
11391
- };
11392
- const schema$2 = addressSchema;
11393
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11394
- const Shipping = () => {
11395
- var _a;
11396
- const { id } = reactRouterDom.useParams();
11397
- const { order, isPending, isError, error } = useOrder(id, {
11398
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11399
- });
11400
- const {
11401
- order: preview,
11402
- isPending: isPreviewPending,
11403
- isError: isPreviewError,
11404
- error: previewError
11405
- } = useOrderPreview(id);
11406
- useInitiateOrderEdit({ preview });
11407
- const { onCancel } = useCancelOrderEdit({ preview });
11408
- if (isError) {
11409
- throw error;
11410
- }
11411
- if (isPreviewError) {
11412
- throw previewError;
11413
- }
11414
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11415
- const isReady = preview && !isPreviewPending && order && !isPending;
11416
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11417
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11418
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11419
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11420
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11421
- ] }) }) }),
11422
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11423
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11424
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11425
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11426
- ] }) });
11427
- };
11428
- const ShippingForm = ({ preview, order }) => {
11429
- var _a;
11430
- const { setIsOpen } = useStackedModal();
11431
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11432
- const [data, setData] = React.useState(null);
11433
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11434
- const { shipping_options } = useShippingOptions(
11435
- {
11436
- id: appliedShippingOptionIds,
11437
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11438
- },
11439
- {
11440
- enabled: appliedShippingOptionIds.length > 0
11441
- }
11442
- );
11443
- const uniqueShippingProfiles = React.useMemo(() => {
11444
- const profiles = /* @__PURE__ */ new Map();
11445
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11446
- profiles.set(profile.id, profile);
11447
- });
11448
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11449
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11450
- });
11451
- return Array.from(profiles.values());
11452
- }, [order.items, shipping_options]);
11453
- const { handleSuccess } = useRouteModal();
11454
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11455
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11456
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11457
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11458
- const onSubmit = async () => {
11459
- setIsSubmitting(true);
11460
- let requestSucceeded = false;
11461
- await requestOrderEdit(void 0, {
11462
- onError: (e) => {
11463
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11464
- },
11465
- onSuccess: () => {
11466
- requestSucceeded = true;
11467
- }
11468
- });
11469
- if (!requestSucceeded) {
11470
- setIsSubmitting(false);
11471
- return;
11472
- }
11473
- await confirmOrderEdit(void 0, {
11474
- onError: (e) => {
11475
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11476
- },
11477
- onSuccess: () => {
11478
- handleSuccess();
11479
- },
11480
- onSettled: () => {
11481
- setIsSubmitting(false);
11482
- }
11483
- });
11484
- };
11485
- const onKeydown = React.useCallback(
11486
- (e) => {
11487
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11488
- if (data || isSubmitting) {
11489
- return;
11490
- }
11491
- onSubmit();
11492
- }
11493
- },
11494
- [data, isSubmitting, onSubmit]
11495
- );
11496
- React.useEffect(() => {
11497
- document.addEventListener("keydown", onKeydown);
11498
- return () => {
11499
- document.removeEventListener("keydown", onKeydown);
11500
- };
11501
- }, [onKeydown]);
11502
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11503
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11504
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11505
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11506
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11507
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11508
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11509
- ] }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11512
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11513
- /* @__PURE__ */ jsxRuntime.jsx(
11514
- ui.Text,
11682
+ ui.Text,
11515
11683
  {
11516
11684
  size: "xsmall",
11517
11685
  weight: "plus",
@@ -12182,392 +12350,224 @@ const CustomAmountField = ({
12182
12350
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12183
12351
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12184
12352
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12185
- ] }),
12186
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12187
- ui.CurrencyInput,
12188
- {
12189
- ...field,
12190
- onValueChange: (value) => onChange(value),
12191
- symbol: getNativeSymbol(currencyCode),
12192
- code: currencyCode
12193
- }
12194
- ) })
12195
- ] });
12196
- }
12197
- }
12198
- );
12199
- };
12200
- const InlineTip = React.forwardRef(
12201
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12202
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12203
- return /* @__PURE__ */ jsxRuntime.jsxs(
12204
- "div",
12205
- {
12206
- ref,
12207
- className: ui.clx(
12208
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12209
- className
12210
- ),
12211
- ...props,
12212
- children: [
12213
- /* @__PURE__ */ jsxRuntime.jsx(
12214
- "div",
12215
- {
12216
- role: "presentation",
12217
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12218
- "bg-ui-tag-orange-icon": variant === "warning"
12219
- })
12220
- }
12221
- ),
12222
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12223
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12224
- labelValue,
12225
- ":"
12226
- ] }),
12227
- " ",
12228
- children
12229
- ] })
12230
- ]
12231
- }
12232
- );
12233
- }
12234
- );
12235
- InlineTip.displayName = "InlineTip";
12236
- const MetadataFieldSchema = objectType({
12237
- key: stringType(),
12238
- disabled: booleanType().optional(),
12239
- value: anyType()
12240
- });
12241
- const MetadataSchema = objectType({
12242
- metadata: arrayType(MetadataFieldSchema)
12243
- });
12244
- const Metadata = () => {
12245
- const { id } = reactRouterDom.useParams();
12246
- const { order, isPending, isError, error } = useOrder(id, {
12247
- fields: "metadata"
12248
- });
12249
- if (isError) {
12250
- throw error;
12251
- }
12252
- const isReady = !isPending && !!order;
12253
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12254
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12255
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12256
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12257
- ] }),
12258
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12259
- ] });
12260
- };
12261
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12262
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12263
- const MetadataForm = ({ orderId, metadata }) => {
12264
- const { handleSuccess } = useRouteModal();
12265
- const hasUneditableRows = getHasUneditableRows(metadata);
12266
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12267
- const form = reactHookForm.useForm({
12268
- defaultValues: {
12269
- metadata: getDefaultValues(metadata)
12270
- },
12271
- resolver: zod.zodResolver(MetadataSchema)
12272
- });
12273
- const handleSubmit = form.handleSubmit(async (data) => {
12274
- const parsedData = parseValues(data);
12275
- await mutateAsync(
12276
- {
12277
- metadata: parsedData
12278
- },
12279
- {
12280
- onSuccess: () => {
12281
- ui.toast.success("Metadata updated");
12282
- handleSuccess();
12283
- },
12284
- onError: (error) => {
12285
- ui.toast.error(error.message);
12286
- }
12287
- }
12288
- );
12289
- });
12290
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12291
- control: form.control,
12292
- name: "metadata"
12293
- });
12294
- function deleteRow(index) {
12295
- remove(index);
12296
- if (fields.length === 1) {
12297
- insert(0, {
12298
- key: "",
12299
- value: "",
12300
- disabled: false
12301
- });
12302
- }
12303
- }
12304
- function insertRow(index, position) {
12305
- insert(index + (position === "above" ? 0 : 1), {
12306
- key: "",
12307
- value: "",
12308
- disabled: false
12309
- });
12310
- }
12311
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12312
- KeyboundForm,
12313
- {
12314
- onSubmit: handleSubmit,
12315
- className: "flex flex-1 flex-col overflow-hidden",
12316
- children: [
12317
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12318
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12319
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12320
- /* @__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" }) }),
12321
- /* @__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" }) })
12322
- ] }),
12323
- fields.map((field, index) => {
12324
- const isDisabled = field.disabled || false;
12325
- let placeholder = "-";
12326
- if (typeof field.value === "object") {
12327
- placeholder = "{ ... }";
12328
- }
12329
- if (Array.isArray(field.value)) {
12330
- placeholder = "[ ... ]";
12331
- }
12332
- return /* @__PURE__ */ jsxRuntime.jsx(
12333
- ConditionalTooltip,
12334
- {
12335
- showTooltip: isDisabled,
12336
- content: "This row is disabled because it contains non-primitive data.",
12337
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12338
- /* @__PURE__ */ jsxRuntime.jsxs(
12339
- "div",
12340
- {
12341
- className: ui.clx("grid grid-cols-2 divide-x", {
12342
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12343
- }),
12344
- children: [
12345
- /* @__PURE__ */ jsxRuntime.jsx(
12346
- Form$2.Field,
12347
- {
12348
- control: form.control,
12349
- name: `metadata.${index}.key`,
12350
- render: ({ field: field2 }) => {
12351
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12352
- GridInput,
12353
- {
12354
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12355
- ...field2,
12356
- disabled: isDisabled,
12357
- placeholder: "Key"
12358
- }
12359
- ) }) });
12360
- }
12361
- }
12362
- ),
12363
- /* @__PURE__ */ jsxRuntime.jsx(
12364
- Form$2.Field,
12365
- {
12366
- control: form.control,
12367
- name: `metadata.${index}.value`,
12368
- render: ({ field: { value, ...field2 } }) => {
12369
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12370
- GridInput,
12371
- {
12372
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12373
- ...field2,
12374
- value: isDisabled ? placeholder : value,
12375
- disabled: isDisabled,
12376
- placeholder: "Value"
12377
- }
12378
- ) }) });
12379
- }
12380
- }
12381
- )
12382
- ]
12383
- }
12384
- ),
12385
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12386
- /* @__PURE__ */ jsxRuntime.jsx(
12387
- ui.DropdownMenu.Trigger,
12388
- {
12389
- className: ui.clx(
12390
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12391
- {
12392
- hidden: isDisabled
12393
- }
12394
- ),
12395
- disabled: isDisabled,
12396
- asChild: true,
12397
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12398
- }
12399
- ),
12400
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12401
- /* @__PURE__ */ jsxRuntime.jsxs(
12402
- ui.DropdownMenu.Item,
12403
- {
12404
- className: "gap-x-2",
12405
- onClick: () => insertRow(index, "above"),
12406
- children: [
12407
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12408
- "Insert row above"
12409
- ]
12410
- }
12411
- ),
12412
- /* @__PURE__ */ jsxRuntime.jsxs(
12413
- ui.DropdownMenu.Item,
12414
- {
12415
- className: "gap-x-2",
12416
- onClick: () => insertRow(index, "below"),
12417
- children: [
12418
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12419
- "Insert row below"
12420
- ]
12421
- }
12422
- ),
12423
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12424
- /* @__PURE__ */ jsxRuntime.jsxs(
12425
- ui.DropdownMenu.Item,
12426
- {
12427
- className: "gap-x-2",
12428
- onClick: () => deleteRow(index),
12429
- children: [
12430
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12431
- "Delete row"
12432
- ]
12433
- }
12434
- )
12435
- ] })
12436
- ] })
12437
- ] })
12438
- },
12439
- field.id
12440
- );
12441
- })
12442
- ] }),
12443
- 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." })
12444
- ] }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12446
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12447
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12448
- ] }) })
12449
- ]
12450
- }
12451
- ) });
12452
- };
12453
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12454
- return /* @__PURE__ */ jsxRuntime.jsx(
12455
- "input",
12456
- {
12457
- ref,
12458
- ...props,
12459
- autoComplete: "off",
12460
- className: ui.clx(
12461
- "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",
12462
- className
12463
- )
12464
- }
12465
- );
12466
- });
12467
- GridInput.displayName = "MetadataForm.GridInput";
12468
- const PlaceholderInner = () => {
12469
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12470
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12472
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12473
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12474
- ] }) })
12475
- ] });
12476
- };
12477
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12478
- function getDefaultValues(metadata) {
12479
- if (!metadata || !Object.keys(metadata).length) {
12480
- return [
12481
- {
12482
- key: "",
12483
- value: "",
12484
- disabled: false
12485
- }
12486
- ];
12487
- }
12488
- return Object.entries(metadata).map(([key, value]) => {
12489
- if (!EDITABLE_TYPES.includes(typeof value)) {
12490
- return {
12491
- key,
12492
- value,
12493
- disabled: true
12494
- };
12495
- }
12496
- let stringValue = value;
12497
- if (typeof value !== "string") {
12498
- stringValue = JSON.stringify(value);
12499
- }
12500
- return {
12501
- key,
12502
- value: stringValue,
12503
- original_key: key
12504
- };
12505
- });
12506
- }
12507
- function parseValues(values) {
12508
- const metadata = values.metadata;
12509
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
12510
- if (isEmpty) {
12511
- return null;
12512
- }
12513
- const update = {};
12514
- metadata.forEach((field) => {
12515
- let key = field.key;
12516
- let value = field.value;
12517
- const disabled = field.disabled;
12518
- if (!key || !value) {
12519
- return;
12520
- }
12521
- if (disabled) {
12522
- update[key] = value;
12523
- return;
12524
- }
12525
- key = key.trim();
12526
- value = value.trim();
12527
- if (value === "true") {
12528
- update[key] = true;
12529
- } else if (value === "false") {
12530
- update[key] = false;
12531
- } else {
12532
- const parsedNumber = parseFloat(value);
12533
- if (!isNaN(parsedNumber)) {
12534
- update[key] = parsedNumber;
12535
- } else {
12536
- update[key] = value;
12353
+ ] }),
12354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12355
+ ui.CurrencyInput,
12356
+ {
12357
+ ...field,
12358
+ onValueChange: (value) => onChange(value),
12359
+ symbol: getNativeSymbol(currencyCode),
12360
+ code: currencyCode
12361
+ }
12362
+ ) })
12363
+ ] });
12537
12364
  }
12538
12365
  }
12366
+ );
12367
+ };
12368
+ const ShippingAddress = () => {
12369
+ const { id } = reactRouterDom.useParams();
12370
+ const { order, isPending, isError, error } = useOrder(id, {
12371
+ fields: "+shipping_address"
12539
12372
  });
12540
- return update;
12541
- }
12542
- function getHasUneditableRows(metadata) {
12543
- if (!metadata) {
12544
- return false;
12373
+ if (isError) {
12374
+ throw error;
12545
12375
  }
12546
- return Object.values(metadata).some(
12547
- (value) => !EDITABLE_TYPES.includes(typeof value)
12548
- );
12549
- }
12550
- const CustomItems = () => {
12376
+ const isReady = !isPending && !!order;
12551
12377
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12552
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
12553
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12378
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12381
+ ] }),
12382
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12554
12383
  ] });
12555
12384
  };
12556
- const CustomItemsForm = () => {
12385
+ const ShippingAddressForm = ({ order }) => {
12386
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12557
12387
  const form = reactHookForm.useForm({
12388
+ defaultValues: {
12389
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12390
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12391
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12392
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12393
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12394
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12395
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12396
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12397
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12398
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12399
+ },
12558
12400
  resolver: zod.zodResolver(schema$1)
12559
12401
  });
12560
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
12565
- ] }) })
12566
- ] }) });
12402
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12403
+ const { handleSuccess } = useRouteModal();
12404
+ const onSubmit = form.handleSubmit(async (data) => {
12405
+ await mutateAsync(
12406
+ {
12407
+ shipping_address: {
12408
+ first_name: data.first_name,
12409
+ last_name: data.last_name,
12410
+ company: data.company,
12411
+ address_1: data.address_1,
12412
+ address_2: data.address_2,
12413
+ city: data.city,
12414
+ province: data.province,
12415
+ country_code: data.country_code,
12416
+ postal_code: data.postal_code,
12417
+ phone: data.phone
12418
+ }
12419
+ },
12420
+ {
12421
+ onSuccess: () => {
12422
+ handleSuccess();
12423
+ },
12424
+ onError: (error) => {
12425
+ ui.toast.error(error.message);
12426
+ }
12427
+ }
12428
+ );
12429
+ });
12430
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12431
+ KeyboundForm,
12432
+ {
12433
+ className: "flex flex-1 flex-col overflow-hidden",
12434
+ onSubmit,
12435
+ children: [
12436
+ /* @__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: [
12437
+ /* @__PURE__ */ jsxRuntime.jsx(
12438
+ Form$2.Field,
12439
+ {
12440
+ control: form.control,
12441
+ name: "country_code",
12442
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12443
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12446
+ ] })
12447
+ }
12448
+ ),
12449
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12450
+ /* @__PURE__ */ jsxRuntime.jsx(
12451
+ Form$2.Field,
12452
+ {
12453
+ control: form.control,
12454
+ name: "first_name",
12455
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
+ ] })
12460
+ }
12461
+ ),
12462
+ /* @__PURE__ */ jsxRuntime.jsx(
12463
+ Form$2.Field,
12464
+ {
12465
+ control: form.control,
12466
+ name: "last_name",
12467
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12468
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12471
+ ] })
12472
+ }
12473
+ )
12474
+ ] }),
12475
+ /* @__PURE__ */ jsxRuntime.jsx(
12476
+ Form$2.Field,
12477
+ {
12478
+ control: form.control,
12479
+ name: "company",
12480
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
+ ] })
12485
+ }
12486
+ ),
12487
+ /* @__PURE__ */ jsxRuntime.jsx(
12488
+ Form$2.Field,
12489
+ {
12490
+ control: form.control,
12491
+ name: "address_1",
12492
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
+ ] })
12497
+ }
12498
+ ),
12499
+ /* @__PURE__ */ jsxRuntime.jsx(
12500
+ Form$2.Field,
12501
+ {
12502
+ control: form.control,
12503
+ name: "address_2",
12504
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12505
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12508
+ ] })
12509
+ }
12510
+ ),
12511
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12512
+ /* @__PURE__ */ jsxRuntime.jsx(
12513
+ Form$2.Field,
12514
+ {
12515
+ control: form.control,
12516
+ name: "postal_code",
12517
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
+ ] })
12522
+ }
12523
+ ),
12524
+ /* @__PURE__ */ jsxRuntime.jsx(
12525
+ Form$2.Field,
12526
+ {
12527
+ control: form.control,
12528
+ name: "city",
12529
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12533
+ ] })
12534
+ }
12535
+ )
12536
+ ] }),
12537
+ /* @__PURE__ */ jsxRuntime.jsx(
12538
+ Form$2.Field,
12539
+ {
12540
+ control: form.control,
12541
+ name: "province",
12542
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
+ ] })
12547
+ }
12548
+ ),
12549
+ /* @__PURE__ */ jsxRuntime.jsx(
12550
+ Form$2.Field,
12551
+ {
12552
+ control: form.control,
12553
+ name: "phone",
12554
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12558
+ ] })
12559
+ }
12560
+ )
12561
+ ] }) }),
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12565
+ ] }) })
12566
+ ]
12567
+ }
12568
+ ) });
12567
12569
  };
12568
- const schema$1 = objectType({
12569
- email: stringType().email()
12570
- });
12570
+ const schema$1 = addressSchema;
12571
12571
  const TransferOwnership = () => {
12572
12572
  const { id } = reactRouterDom.useParams();
12573
12573
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13068,37 +13068,37 @@ const routeModule = {
13068
13068
  Component: BillingAddress,
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
+ {
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
+ },
13075
+ {
13076
+ Component: Email,
13077
+ path: "/draft-orders/:id/email"
13078
+ },
13071
13079
  {
13072
13080
  Component: Items,
13073
13081
  path: "/draft-orders/:id/items"
13074
13082
  },
13075
13083
  {
13076
- Component: Promotions,
13077
- path: "/draft-orders/:id/promotions"
13084
+ Component: Metadata,
13085
+ path: "/draft-orders/:id/metadata"
13078
13086
  },
13079
13087
  {
13080
- Component: Email,
13081
- path: "/draft-orders/:id/email"
13088
+ Component: Promotions,
13089
+ path: "/draft-orders/:id/promotions"
13082
13090
  },
13083
13091
  {
13084
13092
  Component: SalesChannel,
13085
13093
  path: "/draft-orders/:id/sales-channel"
13086
13094
  },
13087
- {
13088
- Component: ShippingAddress,
13089
- path: "/draft-orders/:id/shipping-address"
13090
- },
13091
13095
  {
13092
13096
  Component: Shipping,
13093
13097
  path: "/draft-orders/:id/shipping"
13094
13098
  },
13095
13099
  {
13096
- Component: Metadata,
13097
- path: "/draft-orders/:id/metadata"
13098
- },
13099
- {
13100
- Component: CustomItems,
13101
- path: "/draft-orders/:id/custom-items"
13100
+ Component: ShippingAddress,
13101
+ path: "/draft-orders/:id/shipping-address"
13102
13102
  },
13103
13103
  {
13104
13104
  Component: TransferOwnership,