@medusajs/draft-order 2.11.2-preview-20251028031854 → 2.11.2-preview-20251028090156

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.
@@ -10824,6 +10824,356 @@ const customItemSchema = objectType({
10824
10824
  quantity: numberType(),
10825
10825
  unit_price: unionType([numberType(), stringType()])
10826
10826
  });
10827
+ const InlineTip = React.forwardRef(
10828
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10829
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10830
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10831
+ "div",
10832
+ {
10833
+ ref,
10834
+ className: ui.clx(
10835
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10836
+ className
10837
+ ),
10838
+ ...props,
10839
+ children: [
10840
+ /* @__PURE__ */ jsxRuntime.jsx(
10841
+ "div",
10842
+ {
10843
+ role: "presentation",
10844
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10845
+ "bg-ui-tag-orange-icon": variant === "warning"
10846
+ })
10847
+ }
10848
+ ),
10849
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10851
+ labelValue,
10852
+ ":"
10853
+ ] }),
10854
+ " ",
10855
+ children
10856
+ ] })
10857
+ ]
10858
+ }
10859
+ );
10860
+ }
10861
+ );
10862
+ InlineTip.displayName = "InlineTip";
10863
+ const MetadataFieldSchema = objectType({
10864
+ key: stringType(),
10865
+ disabled: booleanType().optional(),
10866
+ value: anyType()
10867
+ });
10868
+ const MetadataSchema = objectType({
10869
+ metadata: arrayType(MetadataFieldSchema)
10870
+ });
10871
+ const Metadata = () => {
10872
+ const { id } = reactRouterDom.useParams();
10873
+ const { order, isPending, isError, error } = useOrder(id, {
10874
+ fields: "metadata"
10875
+ });
10876
+ if (isError) {
10877
+ throw error;
10878
+ }
10879
+ const isReady = !isPending && !!order;
10880
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10881
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10884
+ ] }),
10885
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10886
+ ] });
10887
+ };
10888
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10889
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10890
+ const MetadataForm = ({ orderId, metadata }) => {
10891
+ const { handleSuccess } = useRouteModal();
10892
+ const hasUneditableRows = getHasUneditableRows(metadata);
10893
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10894
+ const form = reactHookForm.useForm({
10895
+ defaultValues: {
10896
+ metadata: getDefaultValues(metadata)
10897
+ },
10898
+ resolver: zod.zodResolver(MetadataSchema)
10899
+ });
10900
+ const handleSubmit = form.handleSubmit(async (data) => {
10901
+ const parsedData = parseValues(data);
10902
+ await mutateAsync(
10903
+ {
10904
+ metadata: parsedData
10905
+ },
10906
+ {
10907
+ onSuccess: () => {
10908
+ ui.toast.success("Metadata updated");
10909
+ handleSuccess();
10910
+ },
10911
+ onError: (error) => {
10912
+ ui.toast.error(error.message);
10913
+ }
10914
+ }
10915
+ );
10916
+ });
10917
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10918
+ control: form.control,
10919
+ name: "metadata"
10920
+ });
10921
+ function deleteRow(index) {
10922
+ remove(index);
10923
+ if (fields.length === 1) {
10924
+ insert(0, {
10925
+ key: "",
10926
+ value: "",
10927
+ disabled: false
10928
+ });
10929
+ }
10930
+ }
10931
+ function insertRow(index, position) {
10932
+ insert(index + (position === "above" ? 0 : 1), {
10933
+ key: "",
10934
+ value: "",
10935
+ disabled: false
10936
+ });
10937
+ }
10938
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10939
+ KeyboundForm,
10940
+ {
10941
+ onSubmit: handleSubmit,
10942
+ className: "flex flex-1 flex-col overflow-hidden",
10943
+ children: [
10944
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10947
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10948
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10949
+ ] }),
10950
+ fields.map((field, index) => {
10951
+ const isDisabled = field.disabled || false;
10952
+ let placeholder = "-";
10953
+ if (typeof field.value === "object") {
10954
+ placeholder = "{ ... }";
10955
+ }
10956
+ if (Array.isArray(field.value)) {
10957
+ placeholder = "[ ... ]";
10958
+ }
10959
+ return /* @__PURE__ */ jsxRuntime.jsx(
10960
+ ConditionalTooltip,
10961
+ {
10962
+ showTooltip: isDisabled,
10963
+ content: "This row is disabled because it contains non-primitive data.",
10964
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10965
+ /* @__PURE__ */ jsxRuntime.jsxs(
10966
+ "div",
10967
+ {
10968
+ className: ui.clx("grid grid-cols-2 divide-x", {
10969
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10970
+ }),
10971
+ children: [
10972
+ /* @__PURE__ */ jsxRuntime.jsx(
10973
+ Form$2.Field,
10974
+ {
10975
+ control: form.control,
10976
+ name: `metadata.${index}.key`,
10977
+ render: ({ field: field2 }) => {
10978
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10979
+ GridInput,
10980
+ {
10981
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10982
+ ...field2,
10983
+ disabled: isDisabled,
10984
+ placeholder: "Key"
10985
+ }
10986
+ ) }) });
10987
+ }
10988
+ }
10989
+ ),
10990
+ /* @__PURE__ */ jsxRuntime.jsx(
10991
+ Form$2.Field,
10992
+ {
10993
+ control: form.control,
10994
+ name: `metadata.${index}.value`,
10995
+ render: ({ field: { value, ...field2 } }) => {
10996
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10997
+ GridInput,
10998
+ {
10999
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11000
+ ...field2,
11001
+ value: isDisabled ? placeholder : value,
11002
+ disabled: isDisabled,
11003
+ placeholder: "Value"
11004
+ }
11005
+ ) }) });
11006
+ }
11007
+ }
11008
+ )
11009
+ ]
11010
+ }
11011
+ ),
11012
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11013
+ /* @__PURE__ */ jsxRuntime.jsx(
11014
+ ui.DropdownMenu.Trigger,
11015
+ {
11016
+ className: ui.clx(
11017
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11018
+ {
11019
+ hidden: isDisabled
11020
+ }
11021
+ ),
11022
+ disabled: isDisabled,
11023
+ asChild: true,
11024
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11025
+ }
11026
+ ),
11027
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(
11029
+ ui.DropdownMenu.Item,
11030
+ {
11031
+ className: "gap-x-2",
11032
+ onClick: () => insertRow(index, "above"),
11033
+ children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11035
+ "Insert row above"
11036
+ ]
11037
+ }
11038
+ ),
11039
+ /* @__PURE__ */ jsxRuntime.jsxs(
11040
+ ui.DropdownMenu.Item,
11041
+ {
11042
+ className: "gap-x-2",
11043
+ onClick: () => insertRow(index, "below"),
11044
+ children: [
11045
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11046
+ "Insert row below"
11047
+ ]
11048
+ }
11049
+ ),
11050
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11051
+ /* @__PURE__ */ jsxRuntime.jsxs(
11052
+ ui.DropdownMenu.Item,
11053
+ {
11054
+ className: "gap-x-2",
11055
+ onClick: () => deleteRow(index),
11056
+ children: [
11057
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11058
+ "Delete row"
11059
+ ]
11060
+ }
11061
+ )
11062
+ ] })
11063
+ ] })
11064
+ ] })
11065
+ },
11066
+ field.id
11067
+ );
11068
+ })
11069
+ ] }),
11070
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11071
+ ] }),
11072
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
+ ] }) })
11076
+ ]
11077
+ }
11078
+ ) });
11079
+ };
11080
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11081
+ return /* @__PURE__ */ jsxRuntime.jsx(
11082
+ "input",
11083
+ {
11084
+ ref,
11085
+ ...props,
11086
+ autoComplete: "off",
11087
+ className: ui.clx(
11088
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11089
+ className
11090
+ )
11091
+ }
11092
+ );
11093
+ });
11094
+ GridInput.displayName = "MetadataForm.GridInput";
11095
+ const PlaceholderInner = () => {
11096
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11099
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11101
+ ] }) })
11102
+ ] });
11103
+ };
11104
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11105
+ function getDefaultValues(metadata) {
11106
+ if (!metadata || !Object.keys(metadata).length) {
11107
+ return [
11108
+ {
11109
+ key: "",
11110
+ value: "",
11111
+ disabled: false
11112
+ }
11113
+ ];
11114
+ }
11115
+ return Object.entries(metadata).map(([key, value]) => {
11116
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11117
+ return {
11118
+ key,
11119
+ value,
11120
+ disabled: true
11121
+ };
11122
+ }
11123
+ let stringValue = value;
11124
+ if (typeof value !== "string") {
11125
+ stringValue = JSON.stringify(value);
11126
+ }
11127
+ return {
11128
+ key,
11129
+ value: stringValue,
11130
+ original_key: key
11131
+ };
11132
+ });
11133
+ }
11134
+ function parseValues(values) {
11135
+ const metadata = values.metadata;
11136
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11137
+ if (isEmpty) {
11138
+ return null;
11139
+ }
11140
+ const update = {};
11141
+ metadata.forEach((field) => {
11142
+ let key = field.key;
11143
+ let value = field.value;
11144
+ const disabled = field.disabled;
11145
+ if (!key || !value) {
11146
+ return;
11147
+ }
11148
+ if (disabled) {
11149
+ update[key] = value;
11150
+ return;
11151
+ }
11152
+ key = key.trim();
11153
+ value = value.trim();
11154
+ if (value === "true") {
11155
+ update[key] = true;
11156
+ } else if (value === "false") {
11157
+ update[key] = false;
11158
+ } else {
11159
+ const parsedNumber = parseFloat(value);
11160
+ if (!isNaN(parsedNumber)) {
11161
+ update[key] = parsedNumber;
11162
+ } else {
11163
+ update[key] = value;
11164
+ }
11165
+ }
11166
+ });
11167
+ return update;
11168
+ }
11169
+ function getHasUneditableRows(metadata) {
11170
+ if (!metadata) {
11171
+ return false;
11172
+ }
11173
+ return Object.values(metadata).some(
11174
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11175
+ );
11176
+ }
10827
11177
  const PROMOTION_QUERY_KEY = "promotions";
10828
11178
  const promotionsQueryKeys = {
10829
11179
  list: (query2) => [
@@ -11101,88 +11451,46 @@ function getPromotionIds(items, shippingMethods) {
11101
11451
  }
11102
11452
  return Array.from(promotionIds);
11103
11453
  }
11104
- const InlineTip = React.forwardRef(
11105
- ({ variant = "tip", label, className, children, ...props }, ref) => {
11106
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11107
- return /* @__PURE__ */ jsxRuntime.jsxs(
11108
- "div",
11109
- {
11110
- ref,
11111
- className: ui.clx(
11112
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11113
- className
11114
- ),
11115
- ...props,
11116
- children: [
11117
- /* @__PURE__ */ jsxRuntime.jsx(
11118
- "div",
11119
- {
11120
- role: "presentation",
11121
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11122
- "bg-ui-tag-orange-icon": variant === "warning"
11123
- })
11124
- }
11125
- ),
11126
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11127
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11128
- labelValue,
11129
- ":"
11130
- ] }),
11131
- " ",
11132
- children
11133
- ] })
11134
- ]
11135
- }
11136
- );
11137
- }
11138
- );
11139
- InlineTip.displayName = "InlineTip";
11140
- const MetadataFieldSchema = objectType({
11141
- key: stringType(),
11142
- disabled: booleanType().optional(),
11143
- value: anyType()
11144
- });
11145
- const MetadataSchema = objectType({
11146
- metadata: arrayType(MetadataFieldSchema)
11147
- });
11148
- const Metadata = () => {
11454
+ const SalesChannel = () => {
11149
11455
  const { id } = reactRouterDom.useParams();
11150
- const { order, isPending, isError, error } = useOrder(id, {
11151
- fields: "metadata"
11152
- });
11456
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11457
+ id,
11458
+ {
11459
+ fields: "+sales_channel_id"
11460
+ },
11461
+ {
11462
+ enabled: !!id
11463
+ }
11464
+ );
11153
11465
  if (isError) {
11154
11466
  throw error;
11155
11467
  }
11156
- const isReady = !isPending && !!order;
11468
+ const ISrEADY = !!draft_order && !isPending;
11157
11469
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11158
11470
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11159
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11160
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11471
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11472
+ /* @__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" }) })
11161
11473
  ] }),
11162
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11474
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11163
11475
  ] });
11164
11476
  };
11165
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11166
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11167
- const MetadataForm = ({ orderId, metadata }) => {
11168
- const { handleSuccess } = useRouteModal();
11169
- const hasUneditableRows = getHasUneditableRows(metadata);
11170
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11477
+ const SalesChannelForm = ({ order }) => {
11171
11478
  const form = reactHookForm.useForm({
11172
11479
  defaultValues: {
11173
- metadata: getDefaultValues(metadata)
11480
+ sales_channel_id: order.sales_channel_id || ""
11174
11481
  },
11175
- resolver: zod.zodResolver(MetadataSchema)
11482
+ resolver: zod.zodResolver(schema$2)
11176
11483
  });
11177
- const handleSubmit = form.handleSubmit(async (data) => {
11178
- const parsedData = parseValues(data);
11484
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
+ const { handleSuccess } = useRouteModal();
11486
+ const onSubmit = form.handleSubmit(async (data) => {
11179
11487
  await mutateAsync(
11180
11488
  {
11181
- metadata: parsedData
11489
+ sales_channel_id: data.sales_channel_id
11182
11490
  },
11183
11491
  {
11184
11492
  onSuccess: () => {
11185
- ui.toast.success("Metadata updated");
11493
+ ui.toast.success("Sales channel updated");
11186
11494
  handleSuccess();
11187
11495
  },
11188
11496
  onError: (error) => {
@@ -11191,266 +11499,64 @@ const MetadataForm = ({ orderId, metadata }) => {
11191
11499
  }
11192
11500
  );
11193
11501
  });
11194
- const { fields, insert, remove } = reactHookForm.useFieldArray({
11195
- control: form.control,
11196
- name: "metadata"
11197
- });
11198
- function deleteRow(index) {
11199
- remove(index);
11200
- if (fields.length === 1) {
11201
- insert(0, {
11202
- key: "",
11203
- value: "",
11204
- disabled: false
11205
- });
11206
- }
11207
- }
11208
- function insertRow(index, position) {
11209
- insert(index + (position === "above" ? 0 : 1), {
11210
- key: "",
11211
- value: "",
11212
- disabled: false
11213
- });
11214
- }
11215
11502
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11216
11503
  KeyboundForm,
11217
11504
  {
11218
- onSubmit: handleSubmit,
11219
11505
  className: "flex flex-1 flex-col overflow-hidden",
11220
- children: [
11221
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11222
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11223
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11224
- /* @__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" }) }),
11225
- /* @__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" }) })
11226
- ] }),
11227
- fields.map((field, index) => {
11228
- const isDisabled = field.disabled || false;
11229
- let placeholder = "-";
11230
- if (typeof field.value === "object") {
11231
- placeholder = "{ ... }";
11232
- }
11233
- if (Array.isArray(field.value)) {
11234
- placeholder = "[ ... ]";
11235
- }
11236
- return /* @__PURE__ */ jsxRuntime.jsx(
11237
- ConditionalTooltip,
11238
- {
11239
- showTooltip: isDisabled,
11240
- content: "This row is disabled because it contains non-primitive data.",
11241
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11242
- /* @__PURE__ */ jsxRuntime.jsxs(
11243
- "div",
11244
- {
11245
- className: ui.clx("grid grid-cols-2 divide-x", {
11246
- "overflow-hidden rounded-b-lg": index === fields.length - 1
11247
- }),
11248
- children: [
11249
- /* @__PURE__ */ jsxRuntime.jsx(
11250
- Form$2.Field,
11251
- {
11252
- control: form.control,
11253
- name: `metadata.${index}.key`,
11254
- render: ({ field: field2 }) => {
11255
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11256
- GridInput,
11257
- {
11258
- "aria-labelledby": METADATA_KEY_LABEL_ID,
11259
- ...field2,
11260
- disabled: isDisabled,
11261
- placeholder: "Key"
11262
- }
11263
- ) }) });
11264
- }
11265
- }
11266
- ),
11267
- /* @__PURE__ */ jsxRuntime.jsx(
11268
- Form$2.Field,
11269
- {
11270
- control: form.control,
11271
- name: `metadata.${index}.value`,
11272
- render: ({ field: { value, ...field2 } }) => {
11273
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11274
- GridInput,
11275
- {
11276
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11277
- ...field2,
11278
- value: isDisabled ? placeholder : value,
11279
- disabled: isDisabled,
11280
- placeholder: "Value"
11281
- }
11282
- ) }) });
11283
- }
11284
- }
11285
- )
11286
- ]
11287
- }
11288
- ),
11289
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11290
- /* @__PURE__ */ jsxRuntime.jsx(
11291
- ui.DropdownMenu.Trigger,
11292
- {
11293
- className: ui.clx(
11294
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11295
- {
11296
- hidden: isDisabled
11297
- }
11298
- ),
11299
- disabled: isDisabled,
11300
- asChild: true,
11301
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11302
- }
11303
- ),
11304
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11305
- /* @__PURE__ */ jsxRuntime.jsxs(
11306
- ui.DropdownMenu.Item,
11307
- {
11308
- className: "gap-x-2",
11309
- onClick: () => insertRow(index, "above"),
11310
- children: [
11311
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11312
- "Insert row above"
11313
- ]
11314
- }
11315
- ),
11316
- /* @__PURE__ */ jsxRuntime.jsxs(
11317
- ui.DropdownMenu.Item,
11318
- {
11319
- className: "gap-x-2",
11320
- onClick: () => insertRow(index, "below"),
11321
- children: [
11322
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11323
- "Insert row below"
11324
- ]
11325
- }
11326
- ),
11327
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11328
- /* @__PURE__ */ jsxRuntime.jsxs(
11329
- ui.DropdownMenu.Item,
11330
- {
11331
- className: "gap-x-2",
11332
- onClick: () => deleteRow(index),
11333
- children: [
11334
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11335
- "Delete row"
11336
- ]
11337
- }
11338
- )
11339
- ] })
11340
- ] })
11341
- ] })
11342
- },
11343
- field.id
11344
- );
11345
- })
11346
- ] }),
11347
- 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." })
11348
- ] }),
11349
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11350
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11506
+ onSubmit,
11507
+ children: [
11508
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11351
11511
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11352
11512
  ] }) })
11353
11513
  ]
11354
11514
  }
11355
11515
  ) });
11356
11516
  };
11357
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11517
+ const SalesChannelField = ({ control, order }) => {
11518
+ const salesChannels = useComboboxData({
11519
+ queryFn: async (params) => {
11520
+ return await sdk.admin.salesChannel.list(params);
11521
+ },
11522
+ queryKey: ["sales-channels"],
11523
+ getOptions: (data) => {
11524
+ return data.sales_channels.map((salesChannel) => ({
11525
+ label: salesChannel.name,
11526
+ value: salesChannel.id
11527
+ }));
11528
+ },
11529
+ defaultValue: order.sales_channel_id || void 0
11530
+ });
11358
11531
  return /* @__PURE__ */ jsxRuntime.jsx(
11359
- "input",
11532
+ Form$2.Field,
11360
11533
  {
11361
- ref,
11362
- ...props,
11363
- autoComplete: "off",
11364
- className: ui.clx(
11365
- "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",
11366
- className
11367
- )
11368
- }
11369
- );
11370
- });
11371
- GridInput.displayName = "MetadataForm.GridInput";
11372
- const PlaceholderInner = () => {
11373
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11374
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11375
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11376
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11377
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11378
- ] }) })
11379
- ] });
11380
- };
11381
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11382
- function getDefaultValues(metadata) {
11383
- if (!metadata || !Object.keys(metadata).length) {
11384
- return [
11385
- {
11386
- key: "",
11387
- value: "",
11388
- disabled: false
11389
- }
11390
- ];
11391
- }
11392
- return Object.entries(metadata).map(([key, value]) => {
11393
- if (!EDITABLE_TYPES.includes(typeof value)) {
11394
- return {
11395
- key,
11396
- value,
11397
- disabled: true
11398
- };
11399
- }
11400
- let stringValue = value;
11401
- if (typeof value !== "string") {
11402
- stringValue = JSON.stringify(value);
11403
- }
11404
- return {
11405
- key,
11406
- value: stringValue,
11407
- original_key: key
11408
- };
11409
- });
11410
- }
11411
- function parseValues(values) {
11412
- const metadata = values.metadata;
11413
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11414
- if (isEmpty) {
11415
- return null;
11416
- }
11417
- const update = {};
11418
- metadata.forEach((field) => {
11419
- let key = field.key;
11420
- let value = field.value;
11421
- const disabled = field.disabled;
11422
- if (!key || !value) {
11423
- return;
11424
- }
11425
- if (disabled) {
11426
- update[key] = value;
11427
- return;
11428
- }
11429
- key = key.trim();
11430
- value = value.trim();
11431
- if (value === "true") {
11432
- update[key] = true;
11433
- } else if (value === "false") {
11434
- update[key] = false;
11435
- } else {
11436
- const parsedNumber = parseFloat(value);
11437
- if (!isNaN(parsedNumber)) {
11438
- update[key] = parsedNumber;
11439
- } else {
11440
- update[key] = value;
11534
+ control,
11535
+ name: "sales_channel_id",
11536
+ render: ({ field }) => {
11537
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Combobox,
11541
+ {
11542
+ options: salesChannels.options,
11543
+ fetchNextPage: salesChannels.fetchNextPage,
11544
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11545
+ searchValue: salesChannels.searchValue,
11546
+ onSearchValueChange: salesChannels.onSearchValueChange,
11547
+ placeholder: "Select sales channel",
11548
+ ...field
11549
+ }
11550
+ ) }),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11552
+ ] });
11441
11553
  }
11442
11554
  }
11443
- });
11444
- return update;
11445
- }
11446
- function getHasUneditableRows(metadata) {
11447
- if (!metadata) {
11448
- return false;
11449
- }
11450
- return Object.values(metadata).some(
11451
- (value) => !EDITABLE_TYPES.includes(typeof value)
11452
11555
  );
11453
- }
11556
+ };
11557
+ const schema$2 = objectType({
11558
+ sales_channel_id: stringType().min(1)
11559
+ });
11454
11560
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11455
11561
  const Shipping = () => {
11456
11562
  var _a;
@@ -12290,7 +12396,7 @@ const ShippingAddressForm = ({ order }) => {
12290
12396
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12291
12397
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12292
12398
  },
12293
- resolver: zod.zodResolver(schema$2)
12399
+ resolver: zod.zodResolver(schema$1)
12294
12400
  });
12295
12401
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12296
12402
  const { handleSuccess } = useRouteModal();
@@ -12460,7 +12566,7 @@ const ShippingAddressForm = ({ order }) => {
12460
12566
  }
12461
12567
  ) });
12462
12568
  };
12463
- const schema$2 = addressSchema;
12569
+ const schema$1 = addressSchema;
12464
12570
  const TransferOwnership = () => {
12465
12571
  const { id } = reactRouterDom.useParams();
12466
12572
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12484,7 +12590,7 @@ const TransferOwnershipForm = ({ order }) => {
12484
12590
  defaultValues: {
12485
12591
  customer_id: order.customer_id || ""
12486
12592
  },
12487
- resolver: zod.zodResolver(schema$1)
12593
+ resolver: zod.zodResolver(schema)
12488
12594
  });
12489
12595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12490
12596
  const { handleSuccess } = useRouteModal();
@@ -12934,114 +13040,8 @@ const Illustration = () => {
12934
13040
  }
12935
13041
  );
12936
13042
  };
12937
- const schema$1 = objectType({
12938
- customer_id: stringType().min(1)
12939
- });
12940
- const SalesChannel = () => {
12941
- const { id } = reactRouterDom.useParams();
12942
- const { draft_order, isPending, isError, error } = useDraftOrder(
12943
- id,
12944
- {
12945
- fields: "+sales_channel_id"
12946
- },
12947
- {
12948
- enabled: !!id
12949
- }
12950
- );
12951
- if (isError) {
12952
- throw error;
12953
- }
12954
- const ISrEADY = !!draft_order && !isPending;
12955
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12958
- /* @__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" }) })
12959
- ] }),
12960
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12961
- ] });
12962
- };
12963
- const SalesChannelForm = ({ order }) => {
12964
- const form = reactHookForm.useForm({
12965
- defaultValues: {
12966
- sales_channel_id: order.sales_channel_id || ""
12967
- },
12968
- resolver: zod.zodResolver(schema)
12969
- });
12970
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12971
- const { handleSuccess } = useRouteModal();
12972
- const onSubmit = form.handleSubmit(async (data) => {
12973
- await mutateAsync(
12974
- {
12975
- sales_channel_id: data.sales_channel_id
12976
- },
12977
- {
12978
- onSuccess: () => {
12979
- ui.toast.success("Sales channel updated");
12980
- handleSuccess();
12981
- },
12982
- onError: (error) => {
12983
- ui.toast.error(error.message);
12984
- }
12985
- }
12986
- );
12987
- });
12988
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12989
- KeyboundForm,
12990
- {
12991
- className: "flex flex-1 flex-col overflow-hidden",
12992
- onSubmit,
12993
- children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12997
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12998
- ] }) })
12999
- ]
13000
- }
13001
- ) });
13002
- };
13003
- const SalesChannelField = ({ control, order }) => {
13004
- const salesChannels = useComboboxData({
13005
- queryFn: async (params) => {
13006
- return await sdk.admin.salesChannel.list(params);
13007
- },
13008
- queryKey: ["sales-channels"],
13009
- getOptions: (data) => {
13010
- return data.sales_channels.map((salesChannel) => ({
13011
- label: salesChannel.name,
13012
- value: salesChannel.id
13013
- }));
13014
- },
13015
- defaultValue: order.sales_channel_id || void 0
13016
- });
13017
- return /* @__PURE__ */ jsxRuntime.jsx(
13018
- Form$2.Field,
13019
- {
13020
- control,
13021
- name: "sales_channel_id",
13022
- render: ({ field }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13026
- Combobox,
13027
- {
13028
- options: salesChannels.options,
13029
- fetchNextPage: salesChannels.fetchNextPage,
13030
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13031
- searchValue: salesChannels.searchValue,
13032
- onSearchValueChange: salesChannels.onSearchValueChange,
13033
- placeholder: "Select sales channel",
13034
- ...field
13035
- }
13036
- ) }),
13037
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13038
- ] });
13039
- }
13040
- }
13041
- );
13042
- };
13043
13043
  const schema = objectType({
13044
- sales_channel_id: stringType().min(1)
13044
+ customer_id: stringType().min(1)
13045
13045
  });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
@@ -13079,13 +13079,17 @@ const routeModule = {
13079
13079
  Component: Items,
13080
13080
  path: "/draft-orders/:id/items"
13081
13081
  },
13082
+ {
13083
+ Component: Metadata,
13084
+ path: "/draft-orders/:id/metadata"
13085
+ },
13082
13086
  {
13083
13087
  Component: Promotions,
13084
13088
  path: "/draft-orders/:id/promotions"
13085
13089
  },
13086
13090
  {
13087
- Component: Metadata,
13088
- path: "/draft-orders/:id/metadata"
13091
+ Component: SalesChannel,
13092
+ path: "/draft-orders/:id/sales-channel"
13089
13093
  },
13090
13094
  {
13091
13095
  Component: Shipping,
@@ -13098,10 +13102,6 @@ const routeModule = {
13098
13102
  {
13099
13103
  Component: TransferOwnership,
13100
13104
  path: "/draft-orders/:id/transfer-ownership"
13101
- },
13102
- {
13103
- Component: SalesChannel,
13104
- path: "/draft-orders/:id/sales-channel"
13105
13105
  }
13106
13106
  ]
13107
13107
  }