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