@medusajs/draft-order 2.11.0-snapshot-20251016121452 → 2.11.0-snapshot-20251016172801

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.
@@ -9757,23 +9757,70 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9760
+ const Email = () => {
9761
+ const { id } = useParams();
9762
+ const { order, isPending, isError, error } = useOrder(id, {
9763
+ fields: "+email"
9764
+ });
9765
+ if (isError) {
9766
+ throw error;
9767
+ }
9768
+ const isReady = !isPending && !!order;
9761
9769
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9770
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9773
+ ] }),
9774
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9764
9775
  ] });
9765
9776
  };
9766
- const CustomItemsForm = () => {
9777
+ const EmailForm = ({ order }) => {
9767
9778
  const form = useForm({
9779
+ defaultValues: {
9780
+ email: order.email ?? ""
9781
+ },
9768
9782
  resolver: zodResolver(schema$4)
9769
9783
  });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9784
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
+ const { handleSuccess } = useRouteModal();
9786
+ const onSubmit = form.handleSubmit(async (data) => {
9787
+ await mutateAsync(
9788
+ { email: data.email },
9789
+ {
9790
+ onSuccess: () => {
9791
+ handleSuccess();
9792
+ },
9793
+ onError: (error) => {
9794
+ toast.error(error.message);
9795
+ }
9796
+ }
9797
+ );
9798
+ });
9799
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9800
+ KeyboundForm,
9801
+ {
9802
+ className: "flex flex-1 flex-col overflow-hidden",
9803
+ onSubmit,
9804
+ children: [
9805
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9806
+ Form$2.Field,
9807
+ {
9808
+ control: form.control,
9809
+ name: "email",
9810
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9811
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9812
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9813
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9814
+ ] })
9815
+ }
9816
+ ) }),
9817
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9818
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9819
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9820
+ ] }) })
9821
+ ]
9822
+ }
9823
+ ) });
9777
9824
  };
9778
9825
  const schema$4 = objectType({
9779
9826
  email: stringType().email()
@@ -10752,380 +10799,662 @@ const customItemSchema = objectType({
10752
10799
  quantity: numberType(),
10753
10800
  unit_price: unionType([numberType(), stringType()])
10754
10801
  });
10755
- const PROMOTION_QUERY_KEY = "promotions";
10756
- const promotionsQueryKeys = {
10757
- list: (query2) => [
10758
- PROMOTION_QUERY_KEY,
10759
- query2 ? query2 : void 0
10760
- ],
10761
- detail: (id, query2) => [
10762
- PROMOTION_QUERY_KEY,
10763
- id,
10764
- query2 ? query2 : void 0
10765
- ]
10766
- };
10767
- const usePromotions = (query2, options) => {
10768
- const { data, ...rest } = useQuery({
10769
- queryKey: promotionsQueryKeys.list(query2),
10770
- queryFn: async () => sdk.admin.promotion.list(query2),
10771
- ...options
10772
- });
10773
- return { ...data, ...rest };
10774
- };
10775
- const Promotions = () => {
10802
+ const InlineTip = forwardRef(
10803
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10804
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10805
+ return /* @__PURE__ */ jsxs(
10806
+ "div",
10807
+ {
10808
+ ref,
10809
+ className: clx(
10810
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10811
+ className
10812
+ ),
10813
+ ...props,
10814
+ children: [
10815
+ /* @__PURE__ */ jsx(
10816
+ "div",
10817
+ {
10818
+ role: "presentation",
10819
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10820
+ "bg-ui-tag-orange-icon": variant === "warning"
10821
+ })
10822
+ }
10823
+ ),
10824
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10825
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10826
+ labelValue,
10827
+ ":"
10828
+ ] }),
10829
+ " ",
10830
+ children
10831
+ ] })
10832
+ ]
10833
+ }
10834
+ );
10835
+ }
10836
+ );
10837
+ InlineTip.displayName = "InlineTip";
10838
+ const MetadataFieldSchema = objectType({
10839
+ key: stringType(),
10840
+ disabled: booleanType().optional(),
10841
+ value: anyType()
10842
+ });
10843
+ const MetadataSchema = objectType({
10844
+ metadata: arrayType(MetadataFieldSchema)
10845
+ });
10846
+ const Metadata = () => {
10776
10847
  const { id } = useParams();
10777
- const {
10778
- order: preview,
10779
- isError: isPreviewError,
10780
- error: previewError
10781
- } = useOrderPreview(id, void 0);
10782
- useInitiateOrderEdit({ preview });
10783
- const { onCancel } = useCancelOrderEdit({ preview });
10784
- if (isPreviewError) {
10785
- throw previewError;
10848
+ const { order, isPending, isError, error } = useOrder(id, {
10849
+ fields: "metadata"
10850
+ });
10851
+ if (isError) {
10852
+ throw error;
10786
10853
  }
10787
- const isReady = !!preview;
10788
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10789
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10790
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10854
+ const isReady = !isPending && !!order;
10855
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10856
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10857
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10858
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10859
+ ] }),
10860
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10791
10861
  ] });
10792
10862
  };
10793
- const PromotionForm = ({ preview }) => {
10794
- const { items, shipping_methods } = preview;
10795
- const [isSubmitting, setIsSubmitting] = useState(false);
10796
- const [comboboxValue, setComboboxValue] = useState("");
10863
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10864
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10865
+ const MetadataForm = ({ orderId, metadata }) => {
10797
10866
  const { handleSuccess } = useRouteModal();
10798
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10799
- const promoIds = getPromotionIds(items, shipping_methods);
10800
- const { promotions, isPending, isError, error } = usePromotions(
10801
- {
10802
- id: promoIds
10803
- },
10804
- {
10805
- enabled: !!promoIds.length
10806
- }
10807
- );
10808
- const comboboxData = useComboboxData({
10809
- queryKey: ["promotions", "combobox", promoIds],
10810
- queryFn: async (params) => {
10811
- return await sdk.admin.promotion.list({
10812
- ...params,
10813
- id: {
10814
- $nin: promoIds
10815
- }
10816
- });
10867
+ const hasUneditableRows = getHasUneditableRows(metadata);
10868
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10869
+ const form = useForm({
10870
+ defaultValues: {
10871
+ metadata: getDefaultValues(metadata)
10817
10872
  },
10818
- getOptions: (data) => {
10819
- return data.promotions.map((promotion) => ({
10820
- label: promotion.code,
10821
- value: promotion.code
10822
- }));
10823
- }
10873
+ resolver: zodResolver(MetadataSchema)
10824
10874
  });
10825
- const add = async (value) => {
10826
- if (!value) {
10827
- return;
10828
- }
10829
- addPromotions(
10875
+ const handleSubmit = form.handleSubmit(async (data) => {
10876
+ const parsedData = parseValues(data);
10877
+ await mutateAsync(
10830
10878
  {
10831
- promo_codes: [value]
10879
+ metadata: parsedData
10832
10880
  },
10833
10881
  {
10834
- onError: (e) => {
10835
- toast.error(e.message);
10836
- comboboxData.onSearchValueChange("");
10837
- setComboboxValue("");
10838
- },
10839
10882
  onSuccess: () => {
10840
- comboboxData.onSearchValueChange("");
10841
- setComboboxValue("");
10883
+ toast.success("Metadata updated");
10884
+ handleSuccess();
10885
+ },
10886
+ onError: (error) => {
10887
+ toast.error(error.message);
10842
10888
  }
10843
10889
  }
10844
10890
  );
10845
- };
10846
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10847
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10848
- const onSubmit = async () => {
10849
- setIsSubmitting(true);
10850
- let requestSucceeded = false;
10851
- await requestOrderEdit(void 0, {
10852
- onError: (e) => {
10853
- toast.error(e.message);
10854
- },
10855
- onSuccess: () => {
10856
- requestSucceeded = true;
10857
- }
10858
- });
10859
- if (!requestSucceeded) {
10860
- setIsSubmitting(false);
10861
- return;
10891
+ });
10892
+ const { fields, insert, remove } = useFieldArray({
10893
+ control: form.control,
10894
+ name: "metadata"
10895
+ });
10896
+ function deleteRow(index) {
10897
+ remove(index);
10898
+ if (fields.length === 1) {
10899
+ insert(0, {
10900
+ key: "",
10901
+ value: "",
10902
+ disabled: false
10903
+ });
10862
10904
  }
10863
- await confirmOrderEdit(void 0, {
10864
- onError: (e) => {
10865
- toast.error(e.message);
10866
- },
10867
- onSuccess: () => {
10868
- handleSuccess();
10869
- },
10870
- onSettled: () => {
10871
- setIsSubmitting(false);
10872
- }
10905
+ }
10906
+ function insertRow(index, position) {
10907
+ insert(index + (position === "above" ? 0 : 1), {
10908
+ key: "",
10909
+ value: "",
10910
+ disabled: false
10873
10911
  });
10874
- };
10875
- if (isError) {
10876
- throw error;
10877
10912
  }
10878
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10879
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10880
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10881
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10882
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10883
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10913
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10914
+ KeyboundForm,
10915
+ {
10916
+ onSubmit: handleSubmit,
10917
+ className: "flex flex-1 flex-col overflow-hidden",
10918
+ children: [
10919
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10920
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10921
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10922
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10923
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10924
+ ] }),
10925
+ fields.map((field, index) => {
10926
+ const isDisabled = field.disabled || false;
10927
+ let placeholder = "-";
10928
+ if (typeof field.value === "object") {
10929
+ placeholder = "{ ... }";
10930
+ }
10931
+ if (Array.isArray(field.value)) {
10932
+ placeholder = "[ ... ]";
10933
+ }
10934
+ return /* @__PURE__ */ jsx(
10935
+ ConditionalTooltip,
10936
+ {
10937
+ showTooltip: isDisabled,
10938
+ content: "This row is disabled because it contains non-primitive data.",
10939
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10940
+ /* @__PURE__ */ jsxs(
10941
+ "div",
10942
+ {
10943
+ className: clx("grid grid-cols-2 divide-x", {
10944
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10945
+ }),
10946
+ children: [
10947
+ /* @__PURE__ */ jsx(
10948
+ Form$2.Field,
10949
+ {
10950
+ control: form.control,
10951
+ name: `metadata.${index}.key`,
10952
+ render: ({ field: field2 }) => {
10953
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10954
+ GridInput,
10955
+ {
10956
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10957
+ ...field2,
10958
+ disabled: isDisabled,
10959
+ placeholder: "Key"
10960
+ }
10961
+ ) }) });
10962
+ }
10963
+ }
10964
+ ),
10965
+ /* @__PURE__ */ jsx(
10966
+ Form$2.Field,
10967
+ {
10968
+ control: form.control,
10969
+ name: `metadata.${index}.value`,
10970
+ render: ({ field: { value, ...field2 } }) => {
10971
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10972
+ GridInput,
10973
+ {
10974
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10975
+ ...field2,
10976
+ value: isDisabled ? placeholder : value,
10977
+ disabled: isDisabled,
10978
+ placeholder: "Value"
10979
+ }
10980
+ ) }) });
10981
+ }
10982
+ }
10983
+ )
10984
+ ]
10985
+ }
10986
+ ),
10987
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10988
+ /* @__PURE__ */ jsx(
10989
+ DropdownMenu.Trigger,
10990
+ {
10991
+ className: clx(
10992
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10993
+ {
10994
+ hidden: isDisabled
10995
+ }
10996
+ ),
10997
+ disabled: isDisabled,
10998
+ asChild: true,
10999
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11000
+ }
11001
+ ),
11002
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11003
+ /* @__PURE__ */ jsxs(
11004
+ DropdownMenu.Item,
11005
+ {
11006
+ className: "gap-x-2",
11007
+ onClick: () => insertRow(index, "above"),
11008
+ children: [
11009
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11010
+ "Insert row above"
11011
+ ]
11012
+ }
11013
+ ),
11014
+ /* @__PURE__ */ jsxs(
11015
+ DropdownMenu.Item,
11016
+ {
11017
+ className: "gap-x-2",
11018
+ onClick: () => insertRow(index, "below"),
11019
+ children: [
11020
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11021
+ "Insert row below"
11022
+ ]
11023
+ }
11024
+ ),
11025
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11026
+ /* @__PURE__ */ jsxs(
11027
+ DropdownMenu.Item,
11028
+ {
11029
+ className: "gap-x-2",
11030
+ onClick: () => deleteRow(index),
11031
+ children: [
11032
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11033
+ "Delete row"
11034
+ ]
11035
+ }
11036
+ )
11037
+ ] })
11038
+ ] })
11039
+ ] })
11040
+ },
11041
+ field.id
11042
+ );
11043
+ })
11044
+ ] }),
11045
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10884
11046
  ] }),
10885
- /* @__PURE__ */ jsx(
10886
- Combobox,
10887
- {
10888
- id: "promotion-combobox",
10889
- "aria-describedby": "promotion-combobox-hint",
10890
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10891
- fetchNextPage: comboboxData.fetchNextPage,
10892
- options: comboboxData.options,
10893
- onSearchValueChange: comboboxData.onSearchValueChange,
10894
- searchValue: comboboxData.searchValue,
10895
- disabled: comboboxData.disabled || isAddingPromotions,
10896
- onChange: add,
10897
- value: comboboxValue
10898
- }
10899
- )
10900
- ] }),
10901
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10902
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10903
- PromotionItem,
10904
- {
10905
- promotion,
10906
- orderId: preview.id,
10907
- isLoading: isPending
10908
- },
10909
- promotion.id
10910
- )) })
10911
- ] }) }),
10912
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10913
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10914
- /* @__PURE__ */ jsx(
10915
- Button,
10916
- {
10917
- size: "small",
10918
- type: "submit",
10919
- isLoading: isSubmitting || isAddingPromotions,
10920
- children: "Save"
10921
- }
11047
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11048
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11049
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11050
+ ] }) })
11051
+ ]
11052
+ }
11053
+ ) });
11054
+ };
11055
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11056
+ return /* @__PURE__ */ jsx(
11057
+ "input",
11058
+ {
11059
+ ref,
11060
+ ...props,
11061
+ autoComplete: "off",
11062
+ className: clx(
11063
+ "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",
11064
+ className
10922
11065
  )
11066
+ }
11067
+ );
11068
+ });
11069
+ GridInput.displayName = "MetadataForm.GridInput";
11070
+ const PlaceholderInner = () => {
11071
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11072
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11073
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11075
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10923
11076
  ] }) })
10924
11077
  ] });
10925
11078
  };
10926
- const PromotionItem = ({
10927
- promotion,
10928
- orderId,
10929
- isLoading
10930
- }) => {
10931
- var _a;
10932
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10933
- const onRemove = async () => {
10934
- removePromotions(
10935
- {
10936
- promo_codes: [promotion.code]
10937
- },
11079
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11080
+ function getDefaultValues(metadata) {
11081
+ if (!metadata || !Object.keys(metadata).length) {
11082
+ return [
10938
11083
  {
10939
- onError: (e) => {
10940
- toast.error(e.message);
10941
- }
11084
+ key: "",
11085
+ value: "",
11086
+ disabled: false
10942
11087
  }
10943
- );
10944
- };
10945
- const displayValue = getDisplayValue(promotion);
10946
- return /* @__PURE__ */ jsxs(
10947
- "div",
10948
- {
10949
- className: clx(
10950
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10951
- {
10952
- "animate-pulse": isLoading
10953
- }
10954
- ),
10955
- children: [
10956
- /* @__PURE__ */ jsxs("div", { children: [
10957
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10958
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10959
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10960
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
10961
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10962
- ] }),
10963
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10964
- ] })
10965
- ] }),
10966
- /* @__PURE__ */ jsx(
10967
- IconButton,
10968
- {
10969
- size: "small",
10970
- type: "button",
10971
- variant: "transparent",
10972
- onClick: onRemove,
10973
- isLoading: isPending || isLoading,
10974
- children: /* @__PURE__ */ jsx(XMark, {})
10975
- }
10976
- )
10977
- ]
10978
- },
10979
- promotion.id
10980
- );
10981
- };
10982
- function getDisplayValue(promotion) {
10983
- var _a, _b, _c, _d;
10984
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10985
- if (!value) {
10986
- return null;
11088
+ ];
10987
11089
  }
10988
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10989
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10990
- if (!currency) {
10991
- return null;
11090
+ return Object.entries(metadata).map(([key, value]) => {
11091
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11092
+ return {
11093
+ key,
11094
+ value,
11095
+ disabled: true
11096
+ };
10992
11097
  }
10993
- return getLocaleAmount(value, currency);
10994
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10995
- return formatPercentage(value);
10996
- }
10997
- return null;
11098
+ let stringValue = value;
11099
+ if (typeof value !== "string") {
11100
+ stringValue = JSON.stringify(value);
11101
+ }
11102
+ return {
11103
+ key,
11104
+ value: stringValue,
11105
+ original_key: key
11106
+ };
11107
+ });
10998
11108
  }
10999
- const formatter = new Intl.NumberFormat([], {
11000
- style: "percent",
11001
- minimumFractionDigits: 2
11002
- });
11003
- const formatPercentage = (value, isPercentageValue = false) => {
11004
- let val = value || 0;
11005
- if (!isPercentageValue) {
11006
- val = val / 100;
11109
+ function parseValues(values) {
11110
+ const metadata = values.metadata;
11111
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11112
+ if (isEmpty) {
11113
+ return null;
11007
11114
  }
11008
- return formatter.format(val);
11009
- };
11010
- function getPromotionIds(items, shippingMethods) {
11011
- const promotionIds = /* @__PURE__ */ new Set();
11012
- for (const item of items) {
11013
- if (item.adjustments) {
11014
- for (const adjustment of item.adjustments) {
11015
- if (adjustment.promotion_id) {
11016
- promotionIds.add(adjustment.promotion_id);
11017
- }
11018
- }
11115
+ const update = {};
11116
+ metadata.forEach((field) => {
11117
+ let key = field.key;
11118
+ let value = field.value;
11119
+ const disabled = field.disabled;
11120
+ if (!key || !value) {
11121
+ return;
11019
11122
  }
11020
- }
11021
- for (const shippingMethod of shippingMethods) {
11022
- if (shippingMethod.adjustments) {
11023
- for (const adjustment of shippingMethod.adjustments) {
11024
- if (adjustment.promotion_id) {
11025
- promotionIds.add(adjustment.promotion_id);
11026
- }
11123
+ if (disabled) {
11124
+ update[key] = value;
11125
+ return;
11126
+ }
11127
+ key = key.trim();
11128
+ value = value.trim();
11129
+ if (value === "true") {
11130
+ update[key] = true;
11131
+ } else if (value === "false") {
11132
+ update[key] = false;
11133
+ } else {
11134
+ const parsedNumber = parseFloat(value);
11135
+ if (!isNaN(parsedNumber)) {
11136
+ update[key] = parsedNumber;
11137
+ } else {
11138
+ update[key] = value;
11027
11139
  }
11028
11140
  }
11141
+ });
11142
+ return update;
11143
+ }
11144
+ function getHasUneditableRows(metadata) {
11145
+ if (!metadata) {
11146
+ return false;
11029
11147
  }
11030
- return Array.from(promotionIds);
11148
+ return Object.values(metadata).some(
11149
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11150
+ );
11031
11151
  }
11032
- const Email = () => {
11033
- const { id } = useParams();
11034
- const { order, isPending, isError, error } = useOrder(id, {
11035
- fields: "+email"
11152
+ const PROMOTION_QUERY_KEY = "promotions";
11153
+ const promotionsQueryKeys = {
11154
+ list: (query2) => [
11155
+ PROMOTION_QUERY_KEY,
11156
+ query2 ? query2 : void 0
11157
+ ],
11158
+ detail: (id, query2) => [
11159
+ PROMOTION_QUERY_KEY,
11160
+ id,
11161
+ query2 ? query2 : void 0
11162
+ ]
11163
+ };
11164
+ const usePromotions = (query2, options) => {
11165
+ const { data, ...rest } = useQuery({
11166
+ queryKey: promotionsQueryKeys.list(query2),
11167
+ queryFn: async () => sdk.admin.promotion.list(query2),
11168
+ ...options
11036
11169
  });
11037
- if (isError) {
11038
- throw error;
11170
+ return { ...data, ...rest };
11171
+ };
11172
+ const Promotions = () => {
11173
+ const { id } = useParams();
11174
+ const {
11175
+ order: preview,
11176
+ isError: isPreviewError,
11177
+ error: previewError
11178
+ } = useOrderPreview(id, void 0);
11179
+ useInitiateOrderEdit({ preview });
11180
+ const { onCancel } = useCancelOrderEdit({ preview });
11181
+ if (isPreviewError) {
11182
+ throw previewError;
11039
11183
  }
11040
- const isReady = !isPending && !!order;
11041
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11042
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11043
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
11044
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11045
- ] }),
11046
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
11184
+ const isReady = !!preview;
11185
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11186
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11187
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11047
11188
  ] });
11048
11189
  };
11049
- const EmailForm = ({ order }) => {
11050
- const form = useForm({
11051
- defaultValues: {
11052
- email: order.email ?? ""
11053
- },
11054
- resolver: zodResolver(schema$3)
11055
- });
11056
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11190
+ const PromotionForm = ({ preview }) => {
11191
+ const { items, shipping_methods } = preview;
11192
+ const [isSubmitting, setIsSubmitting] = useState(false);
11193
+ const [comboboxValue, setComboboxValue] = useState("");
11057
11194
  const { handleSuccess } = useRouteModal();
11058
- const onSubmit = form.handleSubmit(async (data) => {
11059
- await mutateAsync(
11060
- { email: data.email },
11061
- {
11062
- onSuccess: () => {
11063
- handleSuccess();
11064
- },
11065
- onError: (error) => {
11066
- toast.error(error.message);
11067
- }
11068
- }
11069
- );
11070
- });
11071
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11072
- KeyboundForm,
11073
- {
11074
- className: "flex flex-1 flex-col overflow-hidden",
11075
- onSubmit,
11076
- children: [
11077
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
11078
- Form$2.Field,
11079
- {
11080
- control: form.control,
11081
- name: "email",
11082
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11083
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
11084
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11085
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11086
- ] })
11087
- }
11088
- ) }),
11089
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11090
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11091
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11092
- ] }) })
11093
- ]
11094
- }
11095
- ) });
11096
- };
11097
- const schema$3 = objectType({
11098
- email: stringType().email()
11099
- });
11100
- const SalesChannel = () => {
11101
- const { id } = useParams();
11102
- const { draft_order, isPending, isError, error } = useDraftOrder(
11103
- id,
11195
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11196
+ const promoIds = getPromotionIds(items, shipping_methods);
11197
+ const { promotions, isPending, isError, error } = usePromotions(
11104
11198
  {
11105
- fields: "+sales_channel_id"
11199
+ id: promoIds
11106
11200
  },
11107
11201
  {
11108
- enabled: !!id
11202
+ enabled: !!promoIds.length
11109
11203
  }
11110
11204
  );
11111
- if (isError) {
11112
- throw error;
11113
- }
11114
- const ISrEADY = !!draft_order && !isPending;
11115
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11116
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11117
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11118
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11119
- ] }),
11120
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11121
- ] });
11122
- };
11123
- const SalesChannelForm = ({ order }) => {
11124
- const form = useForm({
11125
- defaultValues: {
11126
- sales_channel_id: order.sales_channel_id || ""
11205
+ const comboboxData = useComboboxData({
11206
+ queryKey: ["promotions", "combobox", promoIds],
11207
+ queryFn: async (params) => {
11208
+ return await sdk.admin.promotion.list({
11209
+ ...params,
11210
+ id: {
11211
+ $nin: promoIds
11212
+ }
11213
+ });
11127
11214
  },
11128
- resolver: zodResolver(schema$2)
11215
+ getOptions: (data) => {
11216
+ return data.promotions.map((promotion) => ({
11217
+ label: promotion.code,
11218
+ value: promotion.code
11219
+ }));
11220
+ }
11221
+ });
11222
+ const add = async (value) => {
11223
+ if (!value) {
11224
+ return;
11225
+ }
11226
+ addPromotions(
11227
+ {
11228
+ promo_codes: [value]
11229
+ },
11230
+ {
11231
+ onError: (e) => {
11232
+ toast.error(e.message);
11233
+ comboboxData.onSearchValueChange("");
11234
+ setComboboxValue("");
11235
+ },
11236
+ onSuccess: () => {
11237
+ comboboxData.onSearchValueChange("");
11238
+ setComboboxValue("");
11239
+ }
11240
+ }
11241
+ );
11242
+ };
11243
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11244
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11245
+ const onSubmit = async () => {
11246
+ setIsSubmitting(true);
11247
+ let requestSucceeded = false;
11248
+ await requestOrderEdit(void 0, {
11249
+ onError: (e) => {
11250
+ toast.error(e.message);
11251
+ },
11252
+ onSuccess: () => {
11253
+ requestSucceeded = true;
11254
+ }
11255
+ });
11256
+ if (!requestSucceeded) {
11257
+ setIsSubmitting(false);
11258
+ return;
11259
+ }
11260
+ await confirmOrderEdit(void 0, {
11261
+ onError: (e) => {
11262
+ toast.error(e.message);
11263
+ },
11264
+ onSuccess: () => {
11265
+ handleSuccess();
11266
+ },
11267
+ onSettled: () => {
11268
+ setIsSubmitting(false);
11269
+ }
11270
+ });
11271
+ };
11272
+ if (isError) {
11273
+ throw error;
11274
+ }
11275
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11276
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11277
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11278
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11279
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11280
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11281
+ ] }),
11282
+ /* @__PURE__ */ jsx(
11283
+ Combobox,
11284
+ {
11285
+ id: "promotion-combobox",
11286
+ "aria-describedby": "promotion-combobox-hint",
11287
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11288
+ fetchNextPage: comboboxData.fetchNextPage,
11289
+ options: comboboxData.options,
11290
+ onSearchValueChange: comboboxData.onSearchValueChange,
11291
+ searchValue: comboboxData.searchValue,
11292
+ disabled: comboboxData.disabled || isAddingPromotions,
11293
+ onChange: add,
11294
+ value: comboboxValue
11295
+ }
11296
+ )
11297
+ ] }),
11298
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11299
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11300
+ PromotionItem,
11301
+ {
11302
+ promotion,
11303
+ orderId: preview.id,
11304
+ isLoading: isPending
11305
+ },
11306
+ promotion.id
11307
+ )) })
11308
+ ] }) }),
11309
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11310
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11311
+ /* @__PURE__ */ jsx(
11312
+ Button,
11313
+ {
11314
+ size: "small",
11315
+ type: "submit",
11316
+ isLoading: isSubmitting || isAddingPromotions,
11317
+ children: "Save"
11318
+ }
11319
+ )
11320
+ ] }) })
11321
+ ] });
11322
+ };
11323
+ const PromotionItem = ({
11324
+ promotion,
11325
+ orderId,
11326
+ isLoading
11327
+ }) => {
11328
+ var _a;
11329
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11330
+ const onRemove = async () => {
11331
+ removePromotions(
11332
+ {
11333
+ promo_codes: [promotion.code]
11334
+ },
11335
+ {
11336
+ onError: (e) => {
11337
+ toast.error(e.message);
11338
+ }
11339
+ }
11340
+ );
11341
+ };
11342
+ const displayValue = getDisplayValue(promotion);
11343
+ return /* @__PURE__ */ jsxs(
11344
+ "div",
11345
+ {
11346
+ className: clx(
11347
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11348
+ {
11349
+ "animate-pulse": isLoading
11350
+ }
11351
+ ),
11352
+ children: [
11353
+ /* @__PURE__ */ jsxs("div", { children: [
11354
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11355
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11356
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11357
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11358
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11359
+ ] }),
11360
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11361
+ ] })
11362
+ ] }),
11363
+ /* @__PURE__ */ jsx(
11364
+ IconButton,
11365
+ {
11366
+ size: "small",
11367
+ type: "button",
11368
+ variant: "transparent",
11369
+ onClick: onRemove,
11370
+ isLoading: isPending || isLoading,
11371
+ children: /* @__PURE__ */ jsx(XMark, {})
11372
+ }
11373
+ )
11374
+ ]
11375
+ },
11376
+ promotion.id
11377
+ );
11378
+ };
11379
+ function getDisplayValue(promotion) {
11380
+ var _a, _b, _c, _d;
11381
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11382
+ if (!value) {
11383
+ return null;
11384
+ }
11385
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11386
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11387
+ if (!currency) {
11388
+ return null;
11389
+ }
11390
+ return getLocaleAmount(value, currency);
11391
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11392
+ return formatPercentage(value);
11393
+ }
11394
+ return null;
11395
+ }
11396
+ const formatter = new Intl.NumberFormat([], {
11397
+ style: "percent",
11398
+ minimumFractionDigits: 2
11399
+ });
11400
+ const formatPercentage = (value, isPercentageValue = false) => {
11401
+ let val = value || 0;
11402
+ if (!isPercentageValue) {
11403
+ val = val / 100;
11404
+ }
11405
+ return formatter.format(val);
11406
+ };
11407
+ function getPromotionIds(items, shippingMethods) {
11408
+ const promotionIds = /* @__PURE__ */ new Set();
11409
+ for (const item of items) {
11410
+ if (item.adjustments) {
11411
+ for (const adjustment of item.adjustments) {
11412
+ if (adjustment.promotion_id) {
11413
+ promotionIds.add(adjustment.promotion_id);
11414
+ }
11415
+ }
11416
+ }
11417
+ }
11418
+ for (const shippingMethod of shippingMethods) {
11419
+ if (shippingMethod.adjustments) {
11420
+ for (const adjustment of shippingMethod.adjustments) {
11421
+ if (adjustment.promotion_id) {
11422
+ promotionIds.add(adjustment.promotion_id);
11423
+ }
11424
+ }
11425
+ }
11426
+ }
11427
+ return Array.from(promotionIds);
11428
+ }
11429
+ const SalesChannel = () => {
11430
+ const { id } = useParams();
11431
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11432
+ id,
11433
+ {
11434
+ fields: "+sales_channel_id"
11435
+ },
11436
+ {
11437
+ enabled: !!id
11438
+ }
11439
+ );
11440
+ if (isError) {
11441
+ throw error;
11442
+ }
11443
+ const ISrEADY = !!draft_order && !isPending;
11444
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11445
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11446
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11447
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11448
+ ] }),
11449
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11450
+ ] });
11451
+ };
11452
+ const SalesChannelForm = ({ order }) => {
11453
+ const form = useForm({
11454
+ defaultValues: {
11455
+ sales_channel_id: order.sales_channel_id || ""
11456
+ },
11457
+ resolver: zodResolver(schema$3)
11129
11458
  });
11130
11459
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11131
11460
  const { handleSuccess } = useRouteModal();
@@ -11200,7 +11529,7 @@ const SalesChannelField = ({ control, order }) => {
11200
11529
  }
11201
11530
  );
11202
11531
  };
11203
- const schema$2 = objectType({
11532
+ const schema$3 = objectType({
11204
11533
  sales_channel_id: stringType().min(1)
11205
11534
  });
11206
11535
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12042,7 +12371,7 @@ const ShippingAddressForm = ({ order }) => {
12042
12371
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12043
12372
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12044
12373
  },
12045
- resolver: zodResolver(schema$1)
12374
+ resolver: zodResolver(schema$2)
12046
12375
  });
12047
12376
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12048
12377
  const { handleSuccess } = useRouteModal();
@@ -12212,7 +12541,7 @@ const ShippingAddressForm = ({ order }) => {
12212
12541
  }
12213
12542
  ) });
12214
12543
  };
12215
- const schema$1 = addressSchema;
12544
+ const schema$2 = addressSchema;
12216
12545
  const TransferOwnership = () => {
12217
12546
  const { id } = useParams();
12218
12547
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12236,7 +12565,7 @@ const TransferOwnershipForm = ({ order }) => {
12236
12565
  defaultValues: {
12237
12566
  customer_id: order.customer_id || ""
12238
12567
  },
12239
- resolver: zodResolver(schema)
12568
+ resolver: zodResolver(schema$1)
12240
12569
  });
12241
12570
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12242
12571
  const { handleSuccess } = useRouteModal();
@@ -12556,489 +12885,160 @@ const Illustration = () => {
12556
12885
  height: "3",
12557
12886
  rx: "1.5",
12558
12887
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12559
- fill: "#A1A1AA"
12560
- }
12561
- ),
12562
- /* @__PURE__ */ jsx(
12563
- "path",
12564
- {
12565
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12566
- fill: "#52525B"
12567
- }
12568
- ),
12569
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12570
- "path",
12571
- {
12572
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12573
- stroke: "#A1A1AA",
12574
- strokeWidth: "1.5",
12575
- strokeLinecap: "round",
12576
- strokeLinejoin: "round"
12577
- }
12578
- ) }),
12579
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12580
- "path",
12581
- {
12582
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12583
- stroke: "#A1A1AA",
12584
- strokeWidth: "1.5",
12585
- strokeLinecap: "round",
12586
- strokeLinejoin: "round"
12587
- }
12588
- ) }),
12589
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12590
- "path",
12591
- {
12592
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12593
- stroke: "#A1A1AA",
12594
- strokeWidth: "1.5",
12595
- strokeLinecap: "round",
12596
- strokeLinejoin: "round"
12597
- }
12598
- ) }),
12599
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12600
- "path",
12601
- {
12602
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12603
- stroke: "#A1A1AA",
12604
- strokeWidth: "1.5",
12605
- strokeLinecap: "round",
12606
- strokeLinejoin: "round"
12607
- }
12608
- ) }),
12609
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12610
- "path",
12611
- {
12612
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12613
- stroke: "#A1A1AA",
12614
- strokeWidth: "1.5",
12615
- strokeLinecap: "round",
12616
- strokeLinejoin: "round"
12617
- }
12618
- ) }),
12619
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12620
- "path",
12621
- {
12622
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12623
- stroke: "#A1A1AA",
12624
- strokeWidth: "1.5",
12625
- strokeLinecap: "round",
12626
- strokeLinejoin: "round"
12627
- }
12628
- ) }),
12629
- /* @__PURE__ */ jsxs("defs", { children: [
12630
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12631
- "rect",
12632
- {
12633
- width: "12",
12634
- height: "12",
12635
- fill: "white",
12636
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12637
- }
12638
- ) }),
12639
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12640
- "rect",
12641
- {
12642
- width: "12",
12643
- height: "12",
12644
- fill: "white",
12645
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12646
- }
12647
- ) }),
12648
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12649
- "rect",
12650
- {
12651
- width: "12",
12652
- height: "12",
12653
- fill: "white",
12654
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12655
- }
12656
- ) }),
12657
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12658
- "rect",
12659
- {
12660
- width: "12",
12661
- height: "12",
12662
- fill: "white",
12663
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12664
- }
12665
- ) }),
12666
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12667
- "rect",
12668
- {
12669
- width: "12",
12670
- height: "12",
12671
- fill: "white",
12672
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12673
- }
12674
- ) }),
12675
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12676
- "rect",
12677
- {
12678
- width: "12",
12679
- height: "12",
12680
- fill: "white",
12681
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12682
- }
12683
- ) })
12684
- ] })
12685
- ]
12686
- }
12687
- );
12688
- };
12689
- const schema = objectType({
12690
- customer_id: stringType().min(1)
12691
- });
12692
- const InlineTip = forwardRef(
12693
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12694
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12695
- return /* @__PURE__ */ jsxs(
12696
- "div",
12697
- {
12698
- ref,
12699
- className: clx(
12700
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12701
- className
12702
- ),
12703
- ...props,
12704
- children: [
12705
- /* @__PURE__ */ jsx(
12706
- "div",
12707
- {
12708
- role: "presentation",
12709
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12710
- "bg-ui-tag-orange-icon": variant === "warning"
12711
- })
12712
- }
12713
- ),
12714
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
12715
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12716
- labelValue,
12717
- ":"
12718
- ] }),
12719
- " ",
12720
- children
12721
- ] })
12722
- ]
12723
- }
12724
- );
12725
- }
12726
- );
12727
- InlineTip.displayName = "InlineTip";
12728
- const MetadataFieldSchema = objectType({
12729
- key: stringType(),
12730
- disabled: booleanType().optional(),
12731
- value: anyType()
12732
- });
12733
- const MetadataSchema = objectType({
12734
- metadata: arrayType(MetadataFieldSchema)
12735
- });
12736
- const Metadata = () => {
12737
- const { id } = useParams();
12738
- const { order, isPending, isError, error } = useOrder(id, {
12739
- fields: "metadata"
12740
- });
12741
- if (isError) {
12742
- throw error;
12743
- }
12744
- const isReady = !isPending && !!order;
12745
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12746
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12747
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
12748
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12749
- ] }),
12750
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12751
- ] });
12752
- };
12753
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12754
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12755
- const MetadataForm = ({ orderId, metadata }) => {
12756
- const { handleSuccess } = useRouteModal();
12757
- const hasUneditableRows = getHasUneditableRows(metadata);
12758
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12759
- const form = useForm({
12760
- defaultValues: {
12761
- metadata: getDefaultValues(metadata)
12762
- },
12763
- resolver: zodResolver(MetadataSchema)
12764
- });
12765
- const handleSubmit = form.handleSubmit(async (data) => {
12766
- const parsedData = parseValues(data);
12767
- await mutateAsync(
12768
- {
12769
- metadata: parsedData
12770
- },
12771
- {
12772
- onSuccess: () => {
12773
- toast.success("Metadata updated");
12774
- handleSuccess();
12775
- },
12776
- onError: (error) => {
12777
- toast.error(error.message);
12778
- }
12779
- }
12780
- );
12781
- });
12782
- const { fields, insert, remove } = useFieldArray({
12783
- control: form.control,
12784
- name: "metadata"
12785
- });
12786
- function deleteRow(index) {
12787
- remove(index);
12788
- if (fields.length === 1) {
12789
- insert(0, {
12790
- key: "",
12791
- value: "",
12792
- disabled: false
12793
- });
12794
- }
12795
- }
12796
- function insertRow(index, position) {
12797
- insert(index + (position === "above" ? 0 : 1), {
12798
- key: "",
12799
- value: "",
12800
- disabled: false
12801
- });
12802
- }
12803
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12804
- KeyboundForm,
12805
- {
12806
- onSubmit: handleSubmit,
12807
- className: "flex flex-1 flex-col overflow-hidden",
12808
- children: [
12809
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12810
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12811
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12812
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
12813
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12814
- ] }),
12815
- fields.map((field, index) => {
12816
- const isDisabled = field.disabled || false;
12817
- let placeholder = "-";
12818
- if (typeof field.value === "object") {
12819
- placeholder = "{ ... }";
12820
- }
12821
- if (Array.isArray(field.value)) {
12822
- placeholder = "[ ... ]";
12823
- }
12824
- return /* @__PURE__ */ jsx(
12825
- ConditionalTooltip,
12826
- {
12827
- showTooltip: isDisabled,
12828
- content: "This row is disabled because it contains non-primitive data.",
12829
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
12830
- /* @__PURE__ */ jsxs(
12831
- "div",
12832
- {
12833
- className: clx("grid grid-cols-2 divide-x", {
12834
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12835
- }),
12836
- children: [
12837
- /* @__PURE__ */ jsx(
12838
- Form$2.Field,
12839
- {
12840
- control: form.control,
12841
- name: `metadata.${index}.key`,
12842
- render: ({ field: field2 }) => {
12843
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12844
- GridInput,
12845
- {
12846
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12847
- ...field2,
12848
- disabled: isDisabled,
12849
- placeholder: "Key"
12850
- }
12851
- ) }) });
12852
- }
12853
- }
12854
- ),
12855
- /* @__PURE__ */ jsx(
12856
- Form$2.Field,
12857
- {
12858
- control: form.control,
12859
- name: `metadata.${index}.value`,
12860
- render: ({ field: { value, ...field2 } }) => {
12861
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12862
- GridInput,
12863
- {
12864
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12865
- ...field2,
12866
- value: isDisabled ? placeholder : value,
12867
- disabled: isDisabled,
12868
- placeholder: "Value"
12869
- }
12870
- ) }) });
12871
- }
12872
- }
12873
- )
12874
- ]
12875
- }
12876
- ),
12877
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12878
- /* @__PURE__ */ jsx(
12879
- DropdownMenu.Trigger,
12880
- {
12881
- className: clx(
12882
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12883
- {
12884
- hidden: isDisabled
12885
- }
12886
- ),
12887
- disabled: isDisabled,
12888
- asChild: true,
12889
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
12890
- }
12891
- ),
12892
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12893
- /* @__PURE__ */ jsxs(
12894
- DropdownMenu.Item,
12895
- {
12896
- className: "gap-x-2",
12897
- onClick: () => insertRow(index, "above"),
12898
- children: [
12899
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
12900
- "Insert row above"
12901
- ]
12902
- }
12903
- ),
12904
- /* @__PURE__ */ jsxs(
12905
- DropdownMenu.Item,
12906
- {
12907
- className: "gap-x-2",
12908
- onClick: () => insertRow(index, "below"),
12909
- children: [
12910
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
12911
- "Insert row below"
12912
- ]
12913
- }
12914
- ),
12915
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
12916
- /* @__PURE__ */ jsxs(
12917
- DropdownMenu.Item,
12918
- {
12919
- className: "gap-x-2",
12920
- onClick: () => deleteRow(index),
12921
- children: [
12922
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
12923
- "Delete row"
12924
- ]
12925
- }
12926
- )
12927
- ] })
12928
- ] })
12929
- ] })
12930
- },
12931
- field.id
12932
- );
12933
- })
12934
- ] }),
12935
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
12936
- ] }),
12937
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12938
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12939
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12940
- ] }) })
12888
+ fill: "#A1A1AA"
12889
+ }
12890
+ ),
12891
+ /* @__PURE__ */ jsx(
12892
+ "path",
12893
+ {
12894
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12895
+ fill: "#52525B"
12896
+ }
12897
+ ),
12898
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12899
+ "path",
12900
+ {
12901
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12902
+ stroke: "#A1A1AA",
12903
+ strokeWidth: "1.5",
12904
+ strokeLinecap: "round",
12905
+ strokeLinejoin: "round"
12906
+ }
12907
+ ) }),
12908
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12909
+ "path",
12910
+ {
12911
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12912
+ stroke: "#A1A1AA",
12913
+ strokeWidth: "1.5",
12914
+ strokeLinecap: "round",
12915
+ strokeLinejoin: "round"
12916
+ }
12917
+ ) }),
12918
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12919
+ "path",
12920
+ {
12921
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12922
+ stroke: "#A1A1AA",
12923
+ strokeWidth: "1.5",
12924
+ strokeLinecap: "round",
12925
+ strokeLinejoin: "round"
12926
+ }
12927
+ ) }),
12928
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12929
+ "path",
12930
+ {
12931
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12932
+ stroke: "#A1A1AA",
12933
+ strokeWidth: "1.5",
12934
+ strokeLinecap: "round",
12935
+ strokeLinejoin: "round"
12936
+ }
12937
+ ) }),
12938
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12939
+ "path",
12940
+ {
12941
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12942
+ stroke: "#A1A1AA",
12943
+ strokeWidth: "1.5",
12944
+ strokeLinecap: "round",
12945
+ strokeLinejoin: "round"
12946
+ }
12947
+ ) }),
12948
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12949
+ "path",
12950
+ {
12951
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12952
+ stroke: "#A1A1AA",
12953
+ strokeWidth: "1.5",
12954
+ strokeLinecap: "round",
12955
+ strokeLinejoin: "round"
12956
+ }
12957
+ ) }),
12958
+ /* @__PURE__ */ jsxs("defs", { children: [
12959
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12960
+ "rect",
12961
+ {
12962
+ width: "12",
12963
+ height: "12",
12964
+ fill: "white",
12965
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12966
+ }
12967
+ ) }),
12968
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12969
+ "rect",
12970
+ {
12971
+ width: "12",
12972
+ height: "12",
12973
+ fill: "white",
12974
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12975
+ }
12976
+ ) }),
12977
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12978
+ "rect",
12979
+ {
12980
+ width: "12",
12981
+ height: "12",
12982
+ fill: "white",
12983
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12984
+ }
12985
+ ) }),
12986
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12987
+ "rect",
12988
+ {
12989
+ width: "12",
12990
+ height: "12",
12991
+ fill: "white",
12992
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12993
+ }
12994
+ ) }),
12995
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12996
+ "rect",
12997
+ {
12998
+ width: "12",
12999
+ height: "12",
13000
+ fill: "white",
13001
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13002
+ }
13003
+ ) }),
13004
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13005
+ "rect",
13006
+ {
13007
+ width: "12",
13008
+ height: "12",
13009
+ fill: "white",
13010
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13011
+ }
13012
+ ) })
13013
+ ] })
12941
13014
  ]
12942
13015
  }
12943
- ) });
12944
- };
12945
- const GridInput = forwardRef(({ className, ...props }, ref) => {
12946
- return /* @__PURE__ */ jsx(
12947
- "input",
12948
- {
12949
- ref,
12950
- ...props,
12951
- autoComplete: "off",
12952
- className: clx(
12953
- "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",
12954
- className
12955
- )
12956
- }
12957
13016
  );
13017
+ };
13018
+ const schema$1 = objectType({
13019
+ customer_id: stringType().min(1)
12958
13020
  });
12959
- GridInput.displayName = "MetadataForm.GridInput";
12960
- const PlaceholderInner = () => {
12961
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12962
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12963
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12964
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
12965
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
12966
- ] }) })
13021
+ const CustomItems = () => {
13022
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
12967
13025
  ] });
12968
13026
  };
12969
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12970
- function getDefaultValues(metadata) {
12971
- if (!metadata || !Object.keys(metadata).length) {
12972
- return [
12973
- {
12974
- key: "",
12975
- value: "",
12976
- disabled: false
12977
- }
12978
- ];
12979
- }
12980
- return Object.entries(metadata).map(([key, value]) => {
12981
- if (!EDITABLE_TYPES.includes(typeof value)) {
12982
- return {
12983
- key,
12984
- value,
12985
- disabled: true
12986
- };
12987
- }
12988
- let stringValue = value;
12989
- if (typeof value !== "string") {
12990
- stringValue = JSON.stringify(value);
12991
- }
12992
- return {
12993
- key,
12994
- value: stringValue,
12995
- original_key: key
12996
- };
12997
- });
12998
- }
12999
- function parseValues(values) {
13000
- const metadata = values.metadata;
13001
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13002
- if (isEmpty) {
13003
- return null;
13004
- }
13005
- const update = {};
13006
- metadata.forEach((field) => {
13007
- let key = field.key;
13008
- let value = field.value;
13009
- const disabled = field.disabled;
13010
- if (!key || !value) {
13011
- return;
13012
- }
13013
- if (disabled) {
13014
- update[key] = value;
13015
- return;
13016
- }
13017
- key = key.trim();
13018
- value = value.trim();
13019
- if (value === "true") {
13020
- update[key] = true;
13021
- } else if (value === "false") {
13022
- update[key] = false;
13023
- } else {
13024
- const parsedNumber = parseFloat(value);
13025
- if (!isNaN(parsedNumber)) {
13026
- update[key] = parsedNumber;
13027
- } else {
13028
- update[key] = value;
13029
- }
13030
- }
13027
+ const CustomItemsForm = () => {
13028
+ const form = useForm({
13029
+ resolver: zodResolver(schema)
13031
13030
  });
13032
- return update;
13033
- }
13034
- function getHasUneditableRows(metadata) {
13035
- if (!metadata) {
13036
- return false;
13037
- }
13038
- return Object.values(metadata).some(
13039
- (value) => !EDITABLE_TYPES.includes(typeof value)
13040
- );
13041
- }
13031
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
+ ] }) })
13037
+ ] }) });
13038
+ };
13039
+ const schema = objectType({
13040
+ email: stringType().email()
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13064,20 +13064,20 @@ const routeModule = {
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
13066
  {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13067
+ Component: Email,
13068
+ path: "/draft-orders/:id/email"
13069
13069
  },
13070
13070
  {
13071
13071
  Component: Items,
13072
13072
  path: "/draft-orders/:id/items"
13073
13073
  },
13074
13074
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13075
+ Component: Metadata,
13076
+ path: "/draft-orders/:id/metadata"
13077
13077
  },
13078
13078
  {
13079
- Component: Email,
13080
- path: "/draft-orders/:id/email"
13079
+ Component: Promotions,
13080
+ path: "/draft-orders/:id/promotions"
13081
13081
  },
13082
13082
  {
13083
13083
  Component: SalesChannel,
@@ -13096,8 +13096,8 @@ const routeModule = {
13096
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
13097
  },
13098
13098
  {
13099
- Component: Metadata,
13100
- path: "/draft-orders/:id/metadata"
13099
+ Component: CustomItems,
13100
+ path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }