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

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.
@@ -9567,6 +9567,27 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
+ const CustomItems = () => {
9571
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9574
+ ] });
9575
+ };
9576
+ const CustomItemsForm = () => {
9577
+ const form = useForm({
9578
+ resolver: zodResolver(schema$5)
9579
+ });
9580
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
+ ] }) })
9586
+ ] }) });
9587
+ };
9588
+ const schema$5 = objectType({
9589
+ email: stringType().email()
9590
+ });
9570
9591
  const BillingAddress = () => {
9571
9592
  const { id } = useParams();
9572
9593
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9599,7 +9620,7 @@ const BillingAddressForm = ({ order }) => {
9599
9620
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
9621
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
9622
  },
9602
- resolver: zodResolver(schema$5)
9623
+ resolver: zodResolver(schema$4)
9603
9624
  });
9604
9625
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
9626
  const { handleSuccess } = useRouteModal();
@@ -9756,26 +9777,73 @@ const BillingAddressForm = ({ order }) => {
9756
9777
  }
9757
9778
  ) });
9758
9779
  };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9780
+ const schema$4 = addressSchema;
9781
+ const Email = () => {
9782
+ const { id } = useParams();
9783
+ const { order, isPending, isError, error } = useOrder(id, {
9784
+ fields: "+email"
9785
+ });
9786
+ if (isError) {
9787
+ throw error;
9788
+ }
9789
+ const isReady = !isPending && !!order;
9761
9790
  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, {})
9791
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
+ ] }),
9795
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9764
9796
  ] });
9765
9797
  };
9766
- const CustomItemsForm = () => {
9798
+ const EmailForm = ({ order }) => {
9767
9799
  const form = useForm({
9768
- resolver: zodResolver(schema$4)
9800
+ defaultValues: {
9801
+ email: order.email ?? ""
9802
+ },
9803
+ resolver: zodResolver(schema$3)
9769
9804
  });
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
- ] }) });
9805
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
+ const { handleSuccess } = useRouteModal();
9807
+ const onSubmit = form.handleSubmit(async (data) => {
9808
+ await mutateAsync(
9809
+ { email: data.email },
9810
+ {
9811
+ onSuccess: () => {
9812
+ handleSuccess();
9813
+ },
9814
+ onError: (error) => {
9815
+ toast.error(error.message);
9816
+ }
9817
+ }
9818
+ );
9819
+ });
9820
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
+ KeyboundForm,
9822
+ {
9823
+ className: "flex flex-1 flex-col overflow-hidden",
9824
+ onSubmit,
9825
+ children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
+ Form$2.Field,
9828
+ {
9829
+ control: form.control,
9830
+ name: "email",
9831
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
+ ] })
9836
+ }
9837
+ ) }),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9777
9845
  };
9778
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9779
9847
  email: stringType().email()
9780
9848
  });
9781
9849
  const NumberInput = forwardRef(
@@ -10752,188 +10820,538 @@ const customItemSchema = objectType({
10752
10820
  quantity: numberType(),
10753
10821
  unit_price: unionType([numberType(), stringType()])
10754
10822
  });
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 = () => {
10823
+ const InlineTip = forwardRef(
10824
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
+ return /* @__PURE__ */ jsxs(
10827
+ "div",
10828
+ {
10829
+ ref,
10830
+ className: clx(
10831
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
+ className
10833
+ ),
10834
+ ...props,
10835
+ children: [
10836
+ /* @__PURE__ */ jsx(
10837
+ "div",
10838
+ {
10839
+ role: "presentation",
10840
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
+ "bg-ui-tag-orange-icon": variant === "warning"
10842
+ })
10843
+ }
10844
+ ),
10845
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
+ labelValue,
10848
+ ":"
10849
+ ] }),
10850
+ " ",
10851
+ children
10852
+ ] })
10853
+ ]
10854
+ }
10855
+ );
10856
+ }
10857
+ );
10858
+ InlineTip.displayName = "InlineTip";
10859
+ const MetadataFieldSchema = objectType({
10860
+ key: stringType(),
10861
+ disabled: booleanType().optional(),
10862
+ value: anyType()
10863
+ });
10864
+ const MetadataSchema = objectType({
10865
+ metadata: arrayType(MetadataFieldSchema)
10866
+ });
10867
+ const Metadata = () => {
10776
10868
  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;
10869
+ const { order, isPending, isError, error } = useOrder(id, {
10870
+ fields: "metadata"
10871
+ });
10872
+ if (isError) {
10873
+ throw error;
10786
10874
  }
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 })
10875
+ const isReady = !isPending && !!order;
10876
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
+ ] }),
10881
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10791
10882
  ] });
10792
10883
  };
10793
- const PromotionForm = ({ preview }) => {
10794
- const { items, shipping_methods } = preview;
10795
- const [isSubmitting, setIsSubmitting] = useState(false);
10796
- const [comboboxValue, setComboboxValue] = useState("");
10884
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
+ const MetadataForm = ({ orderId, metadata }) => {
10797
10887
  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
- });
10888
+ const hasUneditableRows = getHasUneditableRows(metadata);
10889
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
+ const form = useForm({
10891
+ defaultValues: {
10892
+ metadata: getDefaultValues(metadata)
10817
10893
  },
10818
- getOptions: (data) => {
10819
- return data.promotions.map((promotion) => ({
10820
- label: promotion.code,
10821
- value: promotion.code
10822
- }));
10823
- }
10894
+ resolver: zodResolver(MetadataSchema)
10824
10895
  });
10825
- const add = async (value) => {
10826
- if (!value) {
10827
- return;
10828
- }
10829
- addPromotions(
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
10898
+ await mutateAsync(
10830
10899
  {
10831
- promo_codes: [value]
10900
+ metadata: parsedData
10832
10901
  },
10833
10902
  {
10834
- onError: (e) => {
10835
- toast.error(e.message);
10836
- comboboxData.onSearchValueChange("");
10837
- setComboboxValue("");
10838
- },
10839
10903
  onSuccess: () => {
10840
- comboboxData.onSearchValueChange("");
10841
- setComboboxValue("");
10904
+ toast.success("Metadata updated");
10905
+ handleSuccess();
10906
+ },
10907
+ onError: (error) => {
10908
+ toast.error(error.message);
10842
10909
  }
10843
10910
  }
10844
10911
  );
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;
10912
+ });
10913
+ const { fields, insert, remove } = useFieldArray({
10914
+ control: form.control,
10915
+ name: "metadata"
10916
+ });
10917
+ function deleteRow(index) {
10918
+ remove(index);
10919
+ if (fields.length === 1) {
10920
+ insert(0, {
10921
+ key: "",
10922
+ value: "",
10923
+ disabled: false
10924
+ });
10862
10925
  }
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
- }
10926
+ }
10927
+ function insertRow(index, position) {
10928
+ insert(index + (position === "above" ? 0 : 1), {
10929
+ key: "",
10930
+ value: "",
10931
+ disabled: false
10873
10932
  });
10874
- };
10875
- if (isError) {
10876
- throw error;
10877
10933
  }
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." })
10934
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10935
+ KeyboundForm,
10936
+ {
10937
+ onSubmit: handleSubmit,
10938
+ className: "flex flex-1 flex-col overflow-hidden",
10939
+ children: [
10940
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10941
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10942
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10943
+ /* @__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" }) }),
10944
+ /* @__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" }) })
10945
+ ] }),
10946
+ fields.map((field, index) => {
10947
+ const isDisabled = field.disabled || false;
10948
+ let placeholder = "-";
10949
+ if (typeof field.value === "object") {
10950
+ placeholder = "{ ... }";
10951
+ }
10952
+ if (Array.isArray(field.value)) {
10953
+ placeholder = "[ ... ]";
10954
+ }
10955
+ return /* @__PURE__ */ jsx(
10956
+ ConditionalTooltip,
10957
+ {
10958
+ showTooltip: isDisabled,
10959
+ content: "This row is disabled because it contains non-primitive data.",
10960
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10961
+ /* @__PURE__ */ jsxs(
10962
+ "div",
10963
+ {
10964
+ className: clx("grid grid-cols-2 divide-x", {
10965
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10966
+ }),
10967
+ children: [
10968
+ /* @__PURE__ */ jsx(
10969
+ Form$2.Field,
10970
+ {
10971
+ control: form.control,
10972
+ name: `metadata.${index}.key`,
10973
+ render: ({ field: field2 }) => {
10974
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10975
+ GridInput,
10976
+ {
10977
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10978
+ ...field2,
10979
+ disabled: isDisabled,
10980
+ placeholder: "Key"
10981
+ }
10982
+ ) }) });
10983
+ }
10984
+ }
10985
+ ),
10986
+ /* @__PURE__ */ jsx(
10987
+ Form$2.Field,
10988
+ {
10989
+ control: form.control,
10990
+ name: `metadata.${index}.value`,
10991
+ render: ({ field: { value, ...field2 } }) => {
10992
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10993
+ GridInput,
10994
+ {
10995
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10996
+ ...field2,
10997
+ value: isDisabled ? placeholder : value,
10998
+ disabled: isDisabled,
10999
+ placeholder: "Value"
11000
+ }
11001
+ ) }) });
11002
+ }
11003
+ }
11004
+ )
11005
+ ]
11006
+ }
11007
+ ),
11008
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11009
+ /* @__PURE__ */ jsx(
11010
+ DropdownMenu.Trigger,
11011
+ {
11012
+ className: clx(
11013
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11014
+ {
11015
+ hidden: isDisabled
11016
+ }
11017
+ ),
11018
+ disabled: isDisabled,
11019
+ asChild: true,
11020
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11021
+ }
11022
+ ),
11023
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11024
+ /* @__PURE__ */ jsxs(
11025
+ DropdownMenu.Item,
11026
+ {
11027
+ className: "gap-x-2",
11028
+ onClick: () => insertRow(index, "above"),
11029
+ children: [
11030
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11031
+ "Insert row above"
11032
+ ]
11033
+ }
11034
+ ),
11035
+ /* @__PURE__ */ jsxs(
11036
+ DropdownMenu.Item,
11037
+ {
11038
+ className: "gap-x-2",
11039
+ onClick: () => insertRow(index, "below"),
11040
+ children: [
11041
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
+ "Insert row below"
11043
+ ]
11044
+ }
11045
+ ),
11046
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11047
+ /* @__PURE__ */ jsxs(
11048
+ DropdownMenu.Item,
11049
+ {
11050
+ className: "gap-x-2",
11051
+ onClick: () => deleteRow(index),
11052
+ children: [
11053
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
+ "Delete row"
11055
+ ]
11056
+ }
11057
+ )
11058
+ ] })
11059
+ ] })
11060
+ ] })
11061
+ },
11062
+ field.id
11063
+ );
11064
+ })
11065
+ ] }),
11066
+ 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
11067
  ] }),
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
- }
11068
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11069
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11070
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11071
+ ] }) })
11072
+ ]
11073
+ }
11074
+ ) });
11075
+ };
11076
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11077
+ return /* @__PURE__ */ jsx(
11078
+ "input",
11079
+ {
11080
+ ref,
11081
+ ...props,
11082
+ autoComplete: "off",
11083
+ className: clx(
11084
+ "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",
11085
+ className
10922
11086
  )
11087
+ }
11088
+ );
11089
+ });
11090
+ GridInput.displayName = "MetadataForm.GridInput";
11091
+ const PlaceholderInner = () => {
11092
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11093
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11094
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11095
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11096
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10923
11097
  ] }) })
10924
11098
  ] });
10925
11099
  };
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(
11100
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11101
+ function getDefaultValues(metadata) {
11102
+ if (!metadata || !Object.keys(metadata).length) {
11103
+ return [
10935
11104
  {
10936
- promo_codes: [promotion.code]
11105
+ key: "",
11106
+ value: "",
11107
+ disabled: false
11108
+ }
11109
+ ];
11110
+ }
11111
+ return Object.entries(metadata).map(([key, value]) => {
11112
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11113
+ return {
11114
+ key,
11115
+ value,
11116
+ disabled: true
11117
+ };
11118
+ }
11119
+ let stringValue = value;
11120
+ if (typeof value !== "string") {
11121
+ stringValue = JSON.stringify(value);
11122
+ }
11123
+ return {
11124
+ key,
11125
+ value: stringValue,
11126
+ original_key: key
11127
+ };
11128
+ });
11129
+ }
11130
+ function parseValues(values) {
11131
+ const metadata = values.metadata;
11132
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11133
+ if (isEmpty) {
11134
+ return null;
11135
+ }
11136
+ const update = {};
11137
+ metadata.forEach((field) => {
11138
+ let key = field.key;
11139
+ let value = field.value;
11140
+ const disabled = field.disabled;
11141
+ if (!key || !value) {
11142
+ return;
11143
+ }
11144
+ if (disabled) {
11145
+ update[key] = value;
11146
+ return;
11147
+ }
11148
+ key = key.trim();
11149
+ value = value.trim();
11150
+ if (value === "true") {
11151
+ update[key] = true;
11152
+ } else if (value === "false") {
11153
+ update[key] = false;
11154
+ } else {
11155
+ const parsedNumber = parseFloat(value);
11156
+ if (!isNaN(parsedNumber)) {
11157
+ update[key] = parsedNumber;
11158
+ } else {
11159
+ update[key] = value;
11160
+ }
11161
+ }
11162
+ });
11163
+ return update;
11164
+ }
11165
+ function getHasUneditableRows(metadata) {
11166
+ if (!metadata) {
11167
+ return false;
11168
+ }
11169
+ return Object.values(metadata).some(
11170
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11171
+ );
11172
+ }
11173
+ const PROMOTION_QUERY_KEY = "promotions";
11174
+ const promotionsQueryKeys = {
11175
+ list: (query2) => [
11176
+ PROMOTION_QUERY_KEY,
11177
+ query2 ? query2 : void 0
11178
+ ],
11179
+ detail: (id, query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ id,
11182
+ query2 ? query2 : void 0
11183
+ ]
11184
+ };
11185
+ const usePromotions = (query2, options) => {
11186
+ const { data, ...rest } = useQuery({
11187
+ queryKey: promotionsQueryKeys.list(query2),
11188
+ queryFn: async () => sdk.admin.promotion.list(query2),
11189
+ ...options
11190
+ });
11191
+ return { ...data, ...rest };
11192
+ };
11193
+ const Promotions = () => {
11194
+ const { id } = useParams();
11195
+ const {
11196
+ order: preview,
11197
+ isError: isPreviewError,
11198
+ error: previewError
11199
+ } = useOrderPreview(id, void 0);
11200
+ useInitiateOrderEdit({ preview });
11201
+ const { onCancel } = useCancelOrderEdit({ preview });
11202
+ if (isPreviewError) {
11203
+ throw previewError;
11204
+ }
11205
+ const isReady = !!preview;
11206
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
+ ] });
11210
+ };
11211
+ const PromotionForm = ({ preview }) => {
11212
+ const { items, shipping_methods } = preview;
11213
+ const [isSubmitting, setIsSubmitting] = useState(false);
11214
+ const [comboboxValue, setComboboxValue] = useState("");
11215
+ const { handleSuccess } = useRouteModal();
11216
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
+ const promoIds = getPromotionIds(items, shipping_methods);
11218
+ const { promotions, isPending, isError, error } = usePromotions(
11219
+ {
11220
+ id: promoIds
11221
+ },
11222
+ {
11223
+ enabled: !!promoIds.length
11224
+ }
11225
+ );
11226
+ const comboboxData = useComboboxData({
11227
+ queryKey: ["promotions", "combobox", promoIds],
11228
+ queryFn: async (params) => {
11229
+ return await sdk.admin.promotion.list({
11230
+ ...params,
11231
+ id: {
11232
+ $nin: promoIds
11233
+ }
11234
+ });
11235
+ },
11236
+ getOptions: (data) => {
11237
+ return data.promotions.map((promotion) => ({
11238
+ label: promotion.code,
11239
+ value: promotion.code
11240
+ }));
11241
+ }
11242
+ });
11243
+ const add = async (value) => {
11244
+ if (!value) {
11245
+ return;
11246
+ }
11247
+ addPromotions(
11248
+ {
11249
+ promo_codes: [value]
11250
+ },
11251
+ {
11252
+ onError: (e) => {
11253
+ toast.error(e.message);
11254
+ comboboxData.onSearchValueChange("");
11255
+ setComboboxValue("");
11256
+ },
11257
+ onSuccess: () => {
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11260
+ }
11261
+ }
11262
+ );
11263
+ };
11264
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
+ const onSubmit = async () => {
11267
+ setIsSubmitting(true);
11268
+ let requestSucceeded = false;
11269
+ await requestOrderEdit(void 0, {
11270
+ onError: (e) => {
11271
+ toast.error(e.message);
11272
+ },
11273
+ onSuccess: () => {
11274
+ requestSucceeded = true;
11275
+ }
11276
+ });
11277
+ if (!requestSucceeded) {
11278
+ setIsSubmitting(false);
11279
+ return;
11280
+ }
11281
+ await confirmOrderEdit(void 0, {
11282
+ onError: (e) => {
11283
+ toast.error(e.message);
11284
+ },
11285
+ onSuccess: () => {
11286
+ handleSuccess();
11287
+ },
11288
+ onSettled: () => {
11289
+ setIsSubmitting(false);
11290
+ }
11291
+ });
11292
+ };
11293
+ if (isError) {
11294
+ throw error;
11295
+ }
11296
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
+ ] }),
11303
+ /* @__PURE__ */ jsx(
11304
+ Combobox,
11305
+ {
11306
+ id: "promotion-combobox",
11307
+ "aria-describedby": "promotion-combobox-hint",
11308
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
+ fetchNextPage: comboboxData.fetchNextPage,
11310
+ options: comboboxData.options,
11311
+ onSearchValueChange: comboboxData.onSearchValueChange,
11312
+ searchValue: comboboxData.searchValue,
11313
+ disabled: comboboxData.disabled || isAddingPromotions,
11314
+ onChange: add,
11315
+ value: comboboxValue
11316
+ }
11317
+ )
11318
+ ] }),
11319
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
+ PromotionItem,
11322
+ {
11323
+ promotion,
11324
+ orderId: preview.id,
11325
+ isLoading: isPending
11326
+ },
11327
+ promotion.id
11328
+ )) })
11329
+ ] }) }),
11330
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
+ /* @__PURE__ */ jsx(
11333
+ Button,
11334
+ {
11335
+ size: "small",
11336
+ type: "submit",
11337
+ isLoading: isSubmitting || isAddingPromotions,
11338
+ children: "Save"
11339
+ }
11340
+ )
11341
+ ] }) })
11342
+ ] });
11343
+ };
11344
+ const PromotionItem = ({
11345
+ promotion,
11346
+ orderId,
11347
+ isLoading
11348
+ }) => {
11349
+ var _a;
11350
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
+ const onRemove = async () => {
11352
+ removePromotions(
11353
+ {
11354
+ promo_codes: [promotion.code]
10937
11355
  },
10938
11356
  {
10939
11357
  onError: (e) => {
@@ -11029,75 +11447,7 @@ function getPromotionIds(items, shippingMethods) {
11029
11447
  }
11030
11448
  return Array.from(promotionIds);
11031
11449
  }
11032
- const Email = () => {
11033
- const { id } = useParams();
11034
- const { order, isPending, isError, error } = useOrder(id, {
11035
- fields: "+email"
11036
- });
11037
- if (isError) {
11038
- throw error;
11039
- }
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 })
11047
- ] });
11048
- };
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);
11057
- 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 = () => {
11450
+ const SalesChannel = () => {
11101
11451
  const { id } = useParams();
11102
11452
  const { draft_order, isPending, isError, error } = useDraftOrder(
11103
11453
  id,
@@ -12546,499 +12896,149 @@ const Illustration = () => {
12546
12896
  height: "3",
12547
12897
  rx: "1.5",
12548
12898
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12549
- fill: "#A1A1AA"
12550
- }
12551
- ),
12552
- /* @__PURE__ */ jsx(
12553
- "rect",
12554
- {
12555
- width: "12",
12556
- height: "3",
12557
- rx: "1.5",
12558
- 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
- ] }) })
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ 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",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12941
+ {
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12947
+ }
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12982
+ {
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12987
+ }
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12991
+ {
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12996
+ }
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
13000
+ {
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
+ }
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
+ }
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13018
+ {
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
+ }
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13027
+ {
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13032
+ }
13033
+ ) })
13034
+ ] })
12941
13035
  ]
12942
13036
  }
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
13037
  );
12958
- });
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
- ] }) })
12967
- ] });
12968
13038
  };
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
- }
13031
- });
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
- }
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,25 +13059,29 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
+ {
13063
+ Component: CustomItems,
13064
+ path: "/draft-orders/:id/custom-items"
13065
+ },
13062
13066
  {
13063
13067
  Component: BillingAddress,
13064
13068
  path: "/draft-orders/:id/billing-address"
13065
13069
  },
13066
13070
  {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13069
13073
  },
13070
13074
  {
13071
13075
  Component: Items,
13072
13076
  path: "/draft-orders/:id/items"
13073
13077
  },
13074
13078
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13079
+ Component: Metadata,
13080
+ path: "/draft-orders/:id/metadata"
13077
13081
  },
13078
13082
  {
13079
- Component: Email,
13080
- path: "/draft-orders/:id/email"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13081
13085
  },
13082
13086
  {
13083
13087
  Component: SalesChannel,
@@ -13094,10 +13098,6 @@ const routeModule = {
13094
13098
  {
13095
13099
  Component: TransferOwnership,
13096
13100
  path: "/draft-orders/:id/transfer-ownership"
13097
- },
13098
- {
13099
- Component: Metadata,
13100
- path: "/draft-orders/:id/metadata"
13101
13101
  }
13102
13102
  ]
13103
13103
  }