@medusajs/draft-order 2.22.2 → 2.22.3-snapshot-20261103230838

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.
@@ -2,6 +2,7 @@
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const adminSdk = require("@medusajs/admin-sdk");
4
4
  const components = require("@medusajs/dashboard/components");
5
+ const hooks = require("@medusajs/dashboard/hooks");
5
6
  const ui = require("@medusajs/ui");
6
7
  const reactQuery = require("@tanstack/react-query");
7
8
  const React = require("react");
@@ -942,8 +943,42 @@ const useDataTableDateFilters = (disableRangeOption) => {
942
943
  ];
943
944
  }, [dateFilterOptions, getFullDate, rangeOptions]);
944
945
  };
946
+ const VIEW_DRAFT_ORDER_PERMISSIONS = ["order:read"];
947
+ const CREATE_DRAFT_ORDER_PERMISSIONS = [
948
+ "order:read",
949
+ "order:create",
950
+ "region:read",
951
+ "sales_channel:read"
952
+ ];
953
+ const EDIT_DRAFT_ORDER_PERMISSIONS = [
954
+ "order:read",
955
+ "order:update"
956
+ ];
957
+ const EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS = [
958
+ "order:read",
959
+ "order:update",
960
+ "sales_channel:read"
961
+ ];
962
+ const TRANSFER_DRAFT_ORDER_PERMISSIONS = [
963
+ "order:read",
964
+ "order:update",
965
+ "customer:read"
966
+ ];
967
+ const EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS = [
968
+ "order:read",
969
+ "order:update",
970
+ "promotion:read",
971
+ "order_change:read",
972
+ "order_change:update"
973
+ ];
974
+ const EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS = [
975
+ "order:read",
976
+ "order:update",
977
+ "shipping_option:read",
978
+ "stock_location:read"
979
+ ];
945
980
  const PAGE_SIZE = 20;
946
- const handle$1 = {
981
+ const handle$c = {
947
982
  breadcrumb: () => "Draft Orders"
948
983
  };
949
984
  const List = () => {
@@ -963,6 +998,8 @@ const List = () => {
963
998
  );
964
999
  const columns = useColumns$1();
965
1000
  const filters = useFilters();
1001
+ const { hasAllPermissions } = hooks.usePermissions();
1002
+ const canCreate = hasAllPermissions(CREATE_DRAFT_ORDER_PERMISSIONS);
966
1003
  if (isError) {
967
1004
  throw error;
968
1005
  }
@@ -983,10 +1020,10 @@ const List = () => {
983
1020
  pageSize: PAGE_SIZE,
984
1021
  rowCount: count,
985
1022
  heading: t("draftOrders.domain"),
986
- action: {
1023
+ action: canCreate ? {
987
1024
  label: t("actions.create"),
988
1025
  to: "create"
989
- },
1026
+ } : void 0,
990
1027
  rowHref: (row) => `${row.id}`,
991
1028
  emptyState: {
992
1029
  empty: {
@@ -1006,7 +1043,8 @@ const List = () => {
1006
1043
  };
1007
1044
  const config = adminSdk.defineRouteConfig({
1008
1045
  label: "Drafts",
1009
- nested: "/orders"
1046
+ nested: "/orders",
1047
+ permissions: VIEW_DRAFT_ORDER_PERMISSIONS
1010
1048
  });
1011
1049
  const columnHelper$1 = ui.createDataTableColumnHelper();
1012
1050
  const useColumns$1 = () => {
@@ -1059,13 +1097,18 @@ const useColumns$1 = () => {
1059
1097
  };
1060
1098
  const useFilters = () => {
1061
1099
  const dateFilterOptions = useDataTableDateFilters();
1100
+ const { hasPermission } = hooks.usePermissions();
1101
+ const canReadCustomers = hasPermission("customer:read");
1102
+ const canReadSalesChannels = hasPermission("sales_channel:read");
1103
+ const canReadRegions = hasPermission("region:read");
1062
1104
  const { customers } = useCustomers(
1063
1105
  {
1064
1106
  limit: 1e3,
1065
1107
  fields: "id,email"
1066
1108
  },
1067
1109
  {
1068
- throwOnError: true
1110
+ throwOnError: true,
1111
+ enabled: canReadCustomers
1069
1112
  }
1070
1113
  );
1071
1114
  const { sales_channels } = useSalesChannels(
@@ -1074,7 +1117,8 @@ const useFilters = () => {
1074
1117
  fields: "id,name"
1075
1118
  },
1076
1119
  {
1077
- throwOnError: true
1120
+ throwOnError: true,
1121
+ enabled: canReadSalesChannels
1078
1122
  }
1079
1123
  );
1080
1124
  const { regions } = useRegions(
@@ -1082,11 +1126,12 @@ const useFilters = () => {
1082
1126
  limit: 1e3,
1083
1127
  fields: "id,name"
1084
1128
  },
1085
- { throwOnError: true }
1129
+ { throwOnError: true, enabled: canReadRegions }
1086
1130
  );
1087
1131
  return React.useMemo(() => {
1088
- return [
1089
- {
1132
+ const filters = [];
1133
+ if (canReadCustomers) {
1134
+ filters.push({
1090
1135
  id: "customer_id",
1091
1136
  label: "Customer",
1092
1137
  options: customers?.filter(
@@ -1096,8 +1141,10 @@ const useFilters = () => {
1096
1141
  value: customer.id
1097
1142
  })) ?? [],
1098
1143
  type: "select"
1099
- },
1100
- {
1144
+ });
1145
+ }
1146
+ if (canReadSalesChannels) {
1147
+ filters.push({
1101
1148
  id: "sales_channel_id",
1102
1149
  label: "Sales Channel",
1103
1150
  options: sales_channels?.map((sales_channel) => ({
@@ -1105,8 +1152,10 @@ const useFilters = () => {
1105
1152
  value: sales_channel.id
1106
1153
  })) ?? [],
1107
1154
  type: "select"
1108
- },
1109
- {
1155
+ });
1156
+ }
1157
+ if (canReadRegions) {
1158
+ filters.push({
1110
1159
  id: "region_id",
1111
1160
  label: "Region",
1112
1161
  options: regions?.map((region) => ({
@@ -1114,10 +1163,18 @@ const useFilters = () => {
1114
1163
  value: region.id
1115
1164
  })) ?? [],
1116
1165
  type: "select"
1117
- },
1118
- ...dateFilterOptions
1119
- ];
1120
- }, [customers, sales_channels, regions, dateFilterOptions]);
1166
+ });
1167
+ }
1168
+ return [...filters, ...dateFilterOptions];
1169
+ }, [
1170
+ canReadCustomers,
1171
+ canReadSalesChannels,
1172
+ canReadRegions,
1173
+ customers,
1174
+ sales_channels,
1175
+ regions,
1176
+ dateFilterOptions
1177
+ ]);
1121
1178
  };
1122
1179
  const useDraftOrderTableQuery = ({
1123
1180
  prefix,
@@ -3962,7 +4019,7 @@ const useComboboxData = ({
3962
4019
  limit: Array.isArray(defaultValue) ? defaultValue.length : 1
3963
4020
  });
3964
4021
  },
3965
- enabled: !!defaultValue
4022
+ enabled: enabled && !!defaultValue
3966
4023
  });
3967
4024
  const { data, ...rest } = reactQuery.useInfiniteQuery({
3968
4025
  queryKey: [...queryKey, query2],
@@ -4016,6 +4073,8 @@ const Create = () => {
4016
4073
  };
4017
4074
  const CreateForm = () => {
4018
4075
  const { handleSuccess } = useRouteModal();
4076
+ const { hasPermission } = hooks.usePermissions();
4077
+ const canReadCustomers = hasPermission("customer:read");
4019
4078
  const form = reactHookForm.useForm({
4020
4079
  defaultValues: {
4021
4080
  region_id: "",
@@ -4158,8 +4217,16 @@ const CreateForm = () => {
4158
4217
  }
4159
4218
  ) }),
4160
4219
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4161
- /* @__PURE__ */ jsxRuntime.jsx(CustomerField$1, { control: form.control, setValue: form.setValue }),
4162
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4220
+ canReadCustomers && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4221
+ /* @__PURE__ */ jsxRuntime.jsx(
4222
+ CustomerField$1,
4223
+ {
4224
+ control: form.control,
4225
+ setValue: form.setValue
4226
+ }
4227
+ ),
4228
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
4229
+ ] }),
4163
4230
  /* @__PURE__ */ jsxRuntime.jsx(EmailField, { control: form.control }),
4164
4231
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4165
4232
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -4303,6 +4370,8 @@ const AddressField = ({ type, control, setValue }) => {
4303
4370
  const customerId = reactHookForm.useWatch({ control, name: "customer_id" });
4304
4371
  const addressId = reactHookForm.useWatch({ control, name: `${type}_id` });
4305
4372
  const sameAsShipping = reactHookForm.useWatch({ control, name: "same_as_shipping" });
4373
+ const { hasPermission } = hooks.usePermissions();
4374
+ const canReadAddresses = hasPermission("customer_address:read");
4306
4375
  const { customer } = useCustomer(
4307
4376
  customerId,
4308
4377
  {},
@@ -4335,7 +4404,7 @@ const AddressField = ({ type, control, setValue }) => {
4335
4404
  };
4336
4405
  });
4337
4406
  },
4338
- enabled: !!customerId
4407
+ enabled: !!customerId && canReadAddresses
4339
4408
  });
4340
4409
  const onSelectAddress = async (addressId2) => {
4341
4410
  if (!addressId2 || !customerId) {
@@ -4400,7 +4469,7 @@ const AddressField = ({ type, control, setValue }) => {
4400
4469
  }
4401
4470
  ),
4402
4471
  showFields && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
4403
- customerId && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
4472
+ customerId && canReadAddresses && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
4404
4473
  /* @__PURE__ */ jsxRuntime.jsx(
4405
4474
  Form$2.Field,
4406
4475
  {
@@ -4624,6 +4693,9 @@ const schema$6 = zod.z.object({
4624
4693
  }
4625
4694
  }
4626
4695
  });
4696
+ const handle$b = {
4697
+ permissions: CREATE_DRAFT_ORDER_PERMISSIONS
4698
+ };
4627
4699
  const PageSkeleton = ({
4628
4700
  mainSections = 2,
4629
4701
  sidebarSections = 1,
@@ -4674,6 +4746,8 @@ const DETAILS_PAGE_REGEX = /\/draft-orders\/[a-zA-Z0-9_-]+\/?$/;
4674
4746
  const ActiveOrderChange = ({ orderId }) => {
4675
4747
  const { order: preview } = useOrderPreview(orderId);
4676
4748
  const location = reactRouterDom.useLocation();
4749
+ const { hasPermission } = hooks.usePermissions();
4750
+ const canUpdate = hasPermission("order:update");
4677
4751
  const isPending = preview?.order_change?.status === "pending";
4678
4752
  const isDetailsPage = DETAILS_PAGE_REGEX.test(location.pathname);
4679
4753
  const { mutateAsync, isPending: isMutating } = useDraftOrderCancelEdit(orderId);
@@ -4706,28 +4780,30 @@ const ActiveOrderChange = ({ orderId }) => {
4706
4780
  ] }),
4707
4781
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4708
4782
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-pretty", children: noActions ? "There is a pending edit on this draft order with no changes. Click below to cancel it, or open one of the menus to start making changes." : "There is a pending edit on this draft order with changes. Click below to cancel it, or continue to complete the edit." }) }),
4709
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4710
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-component px-6 py-4 justify-end items-center flex gap-x-2", children: [
4711
- !noActions && /* @__PURE__ */ jsxRuntime.jsx(
4712
- ui.Button,
4713
- {
4714
- size: "small",
4715
- variant: "secondary",
4716
- isLoading: isMutating,
4717
- onClick: onCancel,
4718
- children: "Continue"
4719
- }
4720
- ),
4721
- /* @__PURE__ */ jsxRuntime.jsx(
4722
- ui.Button,
4723
- {
4724
- size: "small",
4725
- variant: "secondary",
4726
- isLoading: isMutating,
4727
- onClick: onCancel,
4728
- children: "Cancel"
4729
- }
4730
- )
4783
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4784
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
4785
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-component px-6 py-4 justify-end items-center flex gap-x-2", children: [
4786
+ !noActions && /* @__PURE__ */ jsxRuntime.jsx(
4787
+ ui.Button,
4788
+ {
4789
+ size: "small",
4790
+ variant: "secondary",
4791
+ isLoading: isMutating,
4792
+ onClick: onCancel,
4793
+ children: "Continue"
4794
+ }
4795
+ ),
4796
+ /* @__PURE__ */ jsxRuntime.jsx(
4797
+ ui.Button,
4798
+ {
4799
+ size: "small",
4800
+ variant: "secondary",
4801
+ isLoading: isMutating,
4802
+ onClick: onCancel,
4803
+ children: "Cancel"
4804
+ }
4805
+ )
4806
+ ] })
4731
4807
  ] })
4732
4808
  ] })
4733
4809
  }
@@ -4798,8 +4874,10 @@ const CollapsibleActivityItemList = ({
4798
4874
  ] });
4799
4875
  };
4800
4876
  const ActivityItem = ({ item, isFirst = false }) => {
4877
+ const { hasPermission } = hooks.usePermissions();
4878
+ const showUser = !!item.userId && hasPermission("user:read");
4801
4879
  const { user, isPending, isError, error } = useUser(item.userId, void 0, {
4802
- enabled: !!item.userId
4880
+ enabled: showUser
4803
4881
  });
4804
4882
  if (isError) {
4805
4883
  throw error;
@@ -4826,7 +4904,7 @@ const ActivityItem = ({ item, isFirst = false }) => {
4826
4904
  )
4827
4905
  ] }),
4828
4906
  item.content && renderContent(item.content),
4829
- item.userId && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-muted pt-2", children: isUserLoaded ? /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `/settings/users/${user.id}`, className: "w-fit", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-fit items-center gap-x-1.5", children: [
4907
+ showUser && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-muted pt-2", children: isUserLoaded ? /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `/settings/users/${user.id}`, className: "w-fit", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-fit items-center gap-x-1.5", children: [
4830
4908
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: "By" }),
4831
4909
  /* @__PURE__ */ jsxRuntime.jsx(
4832
4910
  ui.Avatar,
@@ -5055,44 +5133,51 @@ const CustomerSection = ({ order }) => {
5055
5133
  ] });
5056
5134
  };
5057
5135
  const Header = () => {
5136
+ const { hasAllPermissions } = hooks.usePermissions();
5137
+ const canTransfer = hasAllPermissions(TRANSFER_DRAFT_ORDER_PERMISSIONS);
5138
+ const canEdit = hasAllPermissions(EDIT_DRAFT_ORDER_PERMISSIONS);
5058
5139
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4 gap-2", children: [
5059
5140
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Customer" }),
5060
- /* @__PURE__ */ jsxRuntime.jsx(
5141
+ (canTransfer || canEdit) && /* @__PURE__ */ jsxRuntime.jsx(
5061
5142
  ActionMenu,
5062
5143
  {
5063
5144
  groups: [
5064
- {
5065
- actions: [
5066
- {
5067
- label: "Transfer ownership",
5068
- to: "transfer-ownership",
5069
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowPath, {})
5070
- }
5071
- ]
5072
- },
5073
- {
5074
- actions: [
5075
- {
5076
- label: "Edit shipping address",
5077
- to: "shipping-address",
5078
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.FlyingBox, {})
5079
- },
5080
- {
5081
- label: "Edit billing address",
5082
- to: "billing-address",
5083
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CurrencyDollar, {})
5084
- }
5085
- ]
5086
- },
5087
- {
5088
- actions: [
5089
- {
5090
- label: "Edit email",
5091
- to: `email`,
5092
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Envelope, {})
5093
- }
5094
- ]
5095
- }
5145
+ ...canTransfer ? [
5146
+ {
5147
+ actions: [
5148
+ {
5149
+ label: "Transfer ownership",
5150
+ to: "transfer-ownership",
5151
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowPath, {})
5152
+ }
5153
+ ]
5154
+ }
5155
+ ] : [],
5156
+ ...canEdit ? [
5157
+ {
5158
+ actions: [
5159
+ {
5160
+ label: "Edit shipping address",
5161
+ to: "shipping-address",
5162
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.FlyingBox, {})
5163
+ },
5164
+ {
5165
+ label: "Edit billing address",
5166
+ to: "billing-address",
5167
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CurrencyDollar, {})
5168
+ }
5169
+ ]
5170
+ },
5171
+ {
5172
+ actions: [
5173
+ {
5174
+ label: "Edit email",
5175
+ to: `email`,
5176
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Envelope, {})
5177
+ }
5178
+ ]
5179
+ }
5180
+ ] : []
5096
5181
  ]
5097
5182
  }
5098
5183
  )
@@ -5202,12 +5287,18 @@ const Addresses = ({ order }) => {
5202
5287
  };
5203
5288
  const GeneralSection = ({ order }) => {
5204
5289
  const navigate = reactRouterDom.useNavigate();
5290
+ const { hasPermission, hasAllPermissions } = hooks.usePermissions();
5291
+ const canReadRegion = hasPermission("region:read");
5292
+ const canEditSalesChannel = hasAllPermissions(
5293
+ EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
5294
+ );
5295
+ const canDelete = hasPermission("order:delete");
5205
5296
  const { mutateAsync: deleteDraftOrder, isPending: isDeleting } = useDeleteDraftOrder();
5206
5297
  const { region, isPending, isError, error } = useRegion(
5207
5298
  order.region_id,
5208
5299
  void 0,
5209
5300
  {
5210
- enabled: !!order.region_id
5301
+ enabled: canReadRegion && !!order.region_id
5211
5302
  }
5212
5303
  );
5213
5304
  const isRegionLoaded = !!region && !isPending;
@@ -5222,37 +5313,41 @@ const GeneralSection = ({ order }) => {
5222
5313
  order.display_id
5223
5314
  ] }),
5224
5315
  /* @__PURE__ */ jsxRuntime.jsx(ui.Copy, { content: `#${order.display_id}` }),
5225
- isRegionLoaded ? /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", rounded: "full", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `/settings/regions/${region?.id}`, children: region?.name }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "w-14 h-5 rounded-full" })
5316
+ canReadRegion && (isRegionLoaded ? /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", rounded: "full", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `/settings/regions/${region?.id}`, children: region?.name }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "w-14 h-5 rounded-full" }))
5226
5317
  ] }),
5227
5318
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: `${getFullDate({
5228
5319
  date: order.created_at,
5229
5320
  includeTime: true
5230
5321
  })} from ${order.sales_channel?.name}` })
5231
5322
  ] }),
5232
- /* @__PURE__ */ jsxRuntime.jsx(
5323
+ (canEditSalesChannel || canDelete) && /* @__PURE__ */ jsxRuntime.jsx(
5233
5324
  ActionMenu,
5234
5325
  {
5235
5326
  groups: [
5236
5327
  {
5237
5328
  actions: [
5238
- {
5239
- label: "Edit sales channel",
5240
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
5241
- to: "sales-channel"
5242
- },
5243
- {
5244
- label: "Delete draft order",
5245
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
5246
- onClick: async () => {
5247
- try {
5248
- await deleteDraftOrder(order.id);
5249
- navigate("/draft-orders");
5250
- } catch (error2) {
5251
- ui.toast.error(error2.message);
5252
- }
5253
- },
5254
- disabled: isDeleting
5255
- }
5329
+ ...canEditSalesChannel ? [
5330
+ {
5331
+ label: "Edit sales channel",
5332
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
5333
+ to: "sales-channel"
5334
+ }
5335
+ ] : [],
5336
+ ...canDelete ? [
5337
+ {
5338
+ label: "Delete draft order",
5339
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
5340
+ onClick: async () => {
5341
+ try {
5342
+ await deleteDraftOrder(order.id);
5343
+ navigate("/draft-orders");
5344
+ } catch (error2) {
5345
+ ui.toast.error(error2.message);
5346
+ }
5347
+ },
5348
+ disabled: isDeleting
5349
+ }
5350
+ ] : []
5256
5351
  ]
5257
5352
  }
5258
5353
  ]
@@ -5393,6 +5488,8 @@ const Copied = ({ style, value }) => {
5393
5488
  return /* @__PURE__ */ jsxRuntime.jsx("span", { style: { ...style, ...styl }, onClick: handler, children: /* @__PURE__ */ jsxRuntime.jsx(icons.SquareTwoStack, { className: "text-ui-contrast-fg-secondary" }) });
5394
5489
  };
5395
5490
  const MetadataSection = ({ order }) => {
5491
+ const { hasAllPermissions } = hooks.usePermissions();
5492
+ const canEdit = hasAllPermissions(EDIT_DRAFT_ORDER_PERMISSIONS);
5396
5493
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex items-center justify-between", children: [
5397
5494
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
5398
5495
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Metadata" }),
@@ -5401,7 +5498,7 @@ const MetadataSection = ({ order }) => {
5401
5498
  " keys"
5402
5499
  ] })
5403
5500
  ] }),
5404
- /* @__PURE__ */ jsxRuntime.jsx(
5501
+ canEdit && /* @__PURE__ */ jsxRuntime.jsx(
5405
5502
  ui.IconButton,
5406
5503
  {
5407
5504
  variant: "transparent",
@@ -5428,6 +5525,10 @@ const Thumbnail = ({ thumbnail, alt = "" }) => {
5428
5525
  };
5429
5526
  const ShippingSection = ({ order }) => {
5430
5527
  const orderHasShipping = order.shipping_methods.length > 0;
5528
+ const { hasAllPermissions } = hooks.usePermissions();
5529
+ const canEditShipping = hasAllPermissions(
5530
+ EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
5531
+ );
5431
5532
  const {
5432
5533
  shipping_options = [],
5433
5534
  isPending,
@@ -5481,8 +5582,10 @@ const ShippingSection = ({ order }) => {
5481
5582
  shipping_options,
5482
5583
  idx === data.length - 1
5483
5584
  ) }, profile.id)) }),
5484
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
5485
- /* @__PURE__ */ jsxRuntime.jsx(Footer$1, { isSomeProfilesAssigned })
5585
+ canEditShipping && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5586
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
5587
+ /* @__PURE__ */ jsxRuntime.jsx(Footer$1, { isSomeProfilesAssigned })
5588
+ ] })
5486
5589
  ] });
5487
5590
  };
5488
5591
  function renderShippingProfile(profile, shippingOptions, isLast) {
@@ -5737,31 +5840,41 @@ const getStylizedAmount = (amount, currencyCode) => {
5737
5840
  };
5738
5841
  const SummarySection = ({ order }) => {
5739
5842
  const promotions = order.promotions || [];
5843
+ const { hasAllPermissions, hasPermission } = hooks.usePermissions();
5844
+ const canEditItems = hasAllPermissions(EDIT_DRAFT_ORDER_PERMISSIONS);
5845
+ const canEditPromotions = hasAllPermissions(
5846
+ EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
5847
+ );
5848
+ const canConvert = hasPermission("order:update");
5740
5849
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0 overflow-hidden", children: [
5741
5850
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4 flex items-center justify-between gap-x-4", children: [
5742
5851
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Summary" }),
5743
- /* @__PURE__ */ jsxRuntime.jsx(
5852
+ (canEditItems || canEditPromotions) && /* @__PURE__ */ jsxRuntime.jsx(
5744
5853
  ActionMenu,
5745
5854
  {
5746
5855
  groups: [
5747
- {
5748
- actions: [
5749
- {
5750
- label: "Edit items",
5751
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
5752
- to: "items"
5753
- }
5754
- ]
5755
- },
5756
- {
5757
- actions: [
5758
- {
5759
- label: "Edit promotions",
5760
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ReceiptPercent, {}),
5761
- to: "promotions"
5762
- }
5763
- ]
5764
- }
5856
+ ...canEditItems ? [
5857
+ {
5858
+ actions: [
5859
+ {
5860
+ label: "Edit items",
5861
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
5862
+ to: "items"
5863
+ }
5864
+ ]
5865
+ }
5866
+ ] : [],
5867
+ ...canEditPromotions ? [
5868
+ {
5869
+ actions: [
5870
+ {
5871
+ label: "Edit promotions",
5872
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ReceiptPercent, {}),
5873
+ to: "promotions"
5874
+ }
5875
+ ]
5876
+ }
5877
+ ] : []
5765
5878
  ]
5766
5879
  }
5767
5880
  )
@@ -5790,8 +5903,10 @@ const SummarySection = ({ order }) => {
5790
5903
  itemCount: order.items?.reduce((acc, item) => acc + item.quantity, 0) || 0
5791
5904
  }
5792
5905
  ),
5793
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
5794
- /* @__PURE__ */ jsxRuntime.jsx(Footer, { order })
5906
+ canConvert && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5907
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
5908
+ /* @__PURE__ */ jsxRuntime.jsx(Footer, { order })
5909
+ ] })
5795
5910
  ] });
5796
5911
  };
5797
5912
  const Item$1 = ({ item, currencyCode }) => {
@@ -5926,8 +6041,9 @@ async function loader({ params }) {
5926
6041
  });
5927
6042
  return data;
5928
6043
  }
5929
- const handle = {
5930
- breadcrumb: (match) => `#${match.loaderData.order.display_id}`
6044
+ const handle$a = {
6045
+ breadcrumb: (match) => `#${match.loaderData.order.display_id}`,
6046
+ permissions: VIEW_DRAFT_ORDER_PERMISSIONS
5931
6047
  };
5932
6048
  const ID = () => {
5933
6049
  const { id } = reactRouterDom.useParams();
@@ -5971,7 +6087,7 @@ const ID = () => {
5971
6087
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ActiveOrderChange", children: /* @__PURE__ */ jsxRuntime.jsx(ActiveOrderChange, { orderId: order.id }) }),
5972
6088
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GeneralSection", children: /* @__PURE__ */ jsxRuntime.jsx(GeneralSection, { order }) }),
5973
6089
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "SummarySection", children: /* @__PURE__ */ jsxRuntime.jsx(SummarySection, { order }) }),
5974
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ShippingSection", children: /* @__PURE__ */ jsxRuntime.jsx(ShippingSection, { order }) }),
6090
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ShippingSection", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "shipping_option:read", children: /* @__PURE__ */ jsxRuntime.jsx(ShippingSection, { order }) }) }),
5975
6091
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "MetadataSection", children: /* @__PURE__ */ jsxRuntime.jsx(MetadataSection, { order }) }),
5976
6092
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "JsonViewSection", children: /* @__PURE__ */ jsxRuntime.jsx(JsonViewSection, { data: order }) })
5977
6093
  ] }),
@@ -6172,6 +6288,9 @@ const BillingAddressForm = ({ order }) => {
6172
6288
  ) });
6173
6289
  };
6174
6290
  const schema$5 = addressSchema;
6291
+ const handle$9 = {
6292
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
6293
+ };
6175
6294
  const CustomItems = () => {
6176
6295
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
6177
6296
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -6193,6 +6312,9 @@ const CustomItemsForm = () => {
6193
6312
  const schema$4 = zod.z.object({
6194
6313
  email: zod.z.string().email()
6195
6314
  });
6315
+ const handle$8 = {
6316
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
6317
+ };
6196
6318
  const Email = () => {
6197
6319
  const { id } = reactRouterDom.useParams();
6198
6320
  const { order, isPending, isError, error } = useOrder(id, {
@@ -6261,6 +6383,9 @@ const EmailForm = ({ order }) => {
6261
6383
  const schema$3 = zod.z.object({
6262
6384
  email: zod.z.string().email()
6263
6385
  });
6386
+ const handle$7 = {
6387
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
6388
+ };
6264
6389
  const NumberInput = React.forwardRef(
6265
6390
  ({
6266
6391
  value,
@@ -6476,6 +6601,8 @@ const ItemsForm = ({ preview, currencyCode }) => {
6476
6601
  );
6477
6602
  const { handleSuccess } = useRouteModal();
6478
6603
  const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
6604
+ const { hasPermission } = hooks.usePermissions();
6605
+ const canReadVariants = hasPermission("product_variant:read");
6479
6606
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
6480
6607
  const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
6481
6608
  const itemCount = preview.items?.reduce((acc, item) => acc + item.quantity, 0) || 0;
@@ -6565,7 +6692,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
6565
6692
  /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
6566
6693
  /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
6567
6694
  /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
6568
- /* @__PURE__ */ jsxRuntime.jsx(
6695
+ canReadVariants && /* @__PURE__ */ jsxRuntime.jsx(
6569
6696
  StackedModalTrigger$1,
6570
6697
  {
6571
6698
  type: "add-items",
@@ -7280,6 +7407,9 @@ const customItemSchema = zod.z.object({
7280
7407
  quantity: zod.z.number(),
7281
7408
  unit_price: zod.z.union([zod.z.number(), zod.z.string()])
7282
7409
  });
7410
+ const handle$6 = {
7411
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7412
+ };
7283
7413
  const InlineTip = React.forwardRef(
7284
7414
  ({ variant = "tip", label, className, children, ...props }, ref) => {
7285
7415
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -7630,6 +7760,9 @@ function getHasUneditableRows(metadata) {
7630
7760
  (value) => !EDITABLE_TYPES.includes(typeof value)
7631
7761
  );
7632
7762
  }
7763
+ const handle$5 = {
7764
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
7765
+ };
7633
7766
  const PROMOTION_QUERY_KEY = "promotions";
7634
7767
  const promotionsQueryKeys = {
7635
7768
  list: (query2) => [
@@ -7905,6 +8038,118 @@ function getPromotionIds(items, shippingMethods) {
7905
8038
  }
7906
8039
  return Array.from(promotionIds);
7907
8040
  }
8041
+ const handle$4 = {
8042
+ permissions: EDIT_DRAFT_ORDER_PROMOTIONS_PERMISSIONS
8043
+ };
8044
+ const SalesChannel = () => {
8045
+ const { id } = reactRouterDom.useParams();
8046
+ const { draft_order, isPending, isError, error } = useDraftOrder(
8047
+ id,
8048
+ {
8049
+ fields: "+sales_channel_id"
8050
+ },
8051
+ {
8052
+ enabled: !!id
8053
+ }
8054
+ );
8055
+ if (isError) {
8056
+ throw error;
8057
+ }
8058
+ const ISrEADY = !!draft_order && !isPending;
8059
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
8060
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
8061
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
8062
+ /* @__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" }) })
8063
+ ] }),
8064
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
8065
+ ] });
8066
+ };
8067
+ const SalesChannelForm = ({ order }) => {
8068
+ const form = reactHookForm.useForm({
8069
+ defaultValues: {
8070
+ sales_channel_id: order.sales_channel_id || ""
8071
+ },
8072
+ resolver: zod$1.zodResolver(schema$2)
8073
+ });
8074
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8075
+ const { handleSuccess } = useRouteModal();
8076
+ const onSubmit = form.handleSubmit(async (data) => {
8077
+ await mutateAsync(
8078
+ {
8079
+ sales_channel_id: data.sales_channel_id
8080
+ },
8081
+ {
8082
+ onSuccess: () => {
8083
+ ui.toast.success("Sales channel updated");
8084
+ handleSuccess();
8085
+ },
8086
+ onError: (error) => {
8087
+ ui.toast.error(error.message);
8088
+ }
8089
+ }
8090
+ );
8091
+ });
8092
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
8093
+ KeyboundForm,
8094
+ {
8095
+ className: "flex flex-1 flex-col overflow-hidden",
8096
+ onSubmit,
8097
+ children: [
8098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
8099
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
8100
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8101
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8102
+ ] }) })
8103
+ ]
8104
+ }
8105
+ ) });
8106
+ };
8107
+ const SalesChannelField = ({ control, order }) => {
8108
+ const salesChannels = useComboboxData({
8109
+ queryFn: async (params) => {
8110
+ return await sdk.admin.salesChannel.list(params);
8111
+ },
8112
+ queryKey: ["sales-channels"],
8113
+ getOptions: (data) => {
8114
+ return data.sales_channels.map((salesChannel) => ({
8115
+ label: salesChannel.name,
8116
+ value: salesChannel.id
8117
+ }));
8118
+ },
8119
+ defaultValue: order.sales_channel_id || void 0
8120
+ });
8121
+ return /* @__PURE__ */ jsxRuntime.jsx(
8122
+ Form$2.Field,
8123
+ {
8124
+ control,
8125
+ name: "sales_channel_id",
8126
+ render: ({ field }) => {
8127
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
8128
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
8129
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
8130
+ Combobox,
8131
+ {
8132
+ options: salesChannels.options,
8133
+ fetchNextPage: salesChannels.fetchNextPage,
8134
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
8135
+ searchValue: salesChannels.searchValue,
8136
+ onSearchValueChange: salesChannels.onSearchValueChange,
8137
+ placeholder: "Select sales channel",
8138
+ ...field
8139
+ }
8140
+ ) }),
8141
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
8142
+ ] });
8143
+ }
8144
+ }
8145
+ );
8146
+ };
8147
+ const schema$2 = zod.z.object({
8148
+ sales_channel_id: zod.z.string().min(1)
8149
+ });
8150
+ const handle$3 = {
8151
+ permissions: EDIT_DRAFT_ORDER_SALES_CHANNEL_PERMISSIONS
8152
+ };
7908
8153
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
7909
8154
  const Shipping = () => {
7910
8155
  const { id } = reactRouterDom.useParams();
@@ -8699,6 +8944,9 @@ const CustomAmountField = ({
8699
8944
  }
8700
8945
  );
8701
8946
  };
8947
+ const handle$2 = {
8948
+ permissions: EDIT_DRAFT_ORDER_SHIPPING_PERMISSIONS
8949
+ };
8702
8950
  const ShippingAddress = () => {
8703
8951
  const { id } = reactRouterDom.useParams();
8704
8952
  const { order, isPending, isError, error } = useOrder(id, {
@@ -8730,7 +8978,7 @@ const ShippingAddressForm = ({ order }) => {
8730
8978
  postal_code: order.shipping_address?.postal_code ?? "",
8731
8979
  phone: order.shipping_address?.phone ?? ""
8732
8980
  },
8733
- resolver: zod$1.zodResolver(schema$2)
8981
+ resolver: zod$1.zodResolver(schema$1)
8734
8982
  });
8735
8983
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8736
8984
  const { handleSuccess } = useRouteModal();
@@ -8900,7 +9148,10 @@ const ShippingAddressForm = ({ order }) => {
8900
9148
  }
8901
9149
  ) });
8902
9150
  };
8903
- const schema$2 = addressSchema;
9151
+ const schema$1 = addressSchema;
9152
+ const handle$1 = {
9153
+ permissions: EDIT_DRAFT_ORDER_PERMISSIONS
9154
+ };
8904
9155
  const TransferOwnership = () => {
8905
9156
  const { id } = reactRouterDom.useParams();
8906
9157
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -8923,7 +9174,7 @@ const TransferOwnershipForm = ({ order }) => {
8923
9174
  defaultValues: {
8924
9175
  customer_id: order.customer_id || ""
8925
9176
  },
8926
- resolver: zod$1.zodResolver(schema$1)
9177
+ resolver: zod$1.zodResolver(schema)
8927
9178
  });
8928
9179
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8929
9180
  const { handleSuccess } = useRouteModal();
@@ -9375,174 +9626,82 @@ const Illustration = () => {
9375
9626
  }
9376
9627
  );
9377
9628
  };
9378
- const schema$1 = zod.z.object({
9629
+ const schema = zod.z.object({
9379
9630
  customer_id: zod.z.string().min(1)
9380
9631
  });
9381
- const SalesChannel = () => {
9382
- const { id } = reactRouterDom.useParams();
9383
- const { draft_order, isPending, isError, error } = useDraftOrder(
9384
- id,
9385
- {
9386
- fields: "+sales_channel_id"
9387
- },
9388
- {
9389
- enabled: !!id
9390
- }
9391
- );
9392
- if (isError) {
9393
- throw error;
9394
- }
9395
- const ISrEADY = !!draft_order && !isPending;
9396
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9397
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9398
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
9399
- /* @__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" }) })
9400
- ] }),
9401
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
9402
- ] });
9403
- };
9404
- const SalesChannelForm = ({ order }) => {
9405
- const form = reactHookForm.useForm({
9406
- defaultValues: {
9407
- sales_channel_id: order.sales_channel_id || ""
9408
- },
9409
- resolver: zod$1.zodResolver(schema)
9410
- });
9411
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9412
- const { handleSuccess } = useRouteModal();
9413
- const onSubmit = form.handleSubmit(async (data) => {
9414
- await mutateAsync(
9415
- {
9416
- sales_channel_id: data.sales_channel_id
9417
- },
9418
- {
9419
- onSuccess: () => {
9420
- ui.toast.success("Sales channel updated");
9421
- handleSuccess();
9422
- },
9423
- onError: (error) => {
9424
- ui.toast.error(error.message);
9425
- }
9426
- }
9427
- );
9428
- });
9429
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9430
- KeyboundForm,
9431
- {
9432
- className: "flex flex-1 flex-col overflow-hidden",
9433
- onSubmit,
9434
- children: [
9435
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
9436
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9437
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9438
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9439
- ] }) })
9440
- ]
9441
- }
9442
- ) });
9443
- };
9444
- const SalesChannelField = ({ control, order }) => {
9445
- const salesChannels = useComboboxData({
9446
- queryFn: async (params) => {
9447
- return await sdk.admin.salesChannel.list(params);
9448
- },
9449
- queryKey: ["sales-channels"],
9450
- getOptions: (data) => {
9451
- return data.sales_channels.map((salesChannel) => ({
9452
- label: salesChannel.name,
9453
- value: salesChannel.id
9454
- }));
9455
- },
9456
- defaultValue: order.sales_channel_id || void 0
9457
- });
9458
- return /* @__PURE__ */ jsxRuntime.jsx(
9459
- Form$2.Field,
9460
- {
9461
- control,
9462
- name: "sales_channel_id",
9463
- render: ({ field }) => {
9464
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9465
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
9466
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9467
- Combobox,
9468
- {
9469
- options: salesChannels.options,
9470
- fetchNextPage: salesChannels.fetchNextPage,
9471
- isFetchingNextPage: salesChannels.isFetchingNextPage,
9472
- searchValue: salesChannels.searchValue,
9473
- onSearchValueChange: salesChannels.onSearchValueChange,
9474
- placeholder: "Select sales channel",
9475
- ...field
9476
- }
9477
- ) }),
9478
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9479
- ] });
9480
- }
9481
- }
9482
- );
9632
+ const handle = {
9633
+ permissions: TRANSFER_DRAFT_ORDER_PERMISSIONS
9483
9634
  };
9484
- const schema = zod.z.object({
9485
- sales_channel_id: zod.z.string().min(1)
9486
- });
9487
9635
  const widgetModule = { widgets: [] };
9488
9636
  const routeModule = {
9489
9637
  routes: [
9490
9638
  {
9491
9639
  Component: List,
9492
9640
  path: "/draft-orders",
9493
- handle: { label: config.label, translationNs: config.translationNs, ...handle$1 },
9641
+ handle: { label: config.label, translationNs: config.translationNs, permissions: config.permissions, ...handle$c },
9494
9642
  children: [
9495
9643
  {
9496
9644
  Component: Create,
9497
- path: "/draft-orders/create"
9645
+ path: "/draft-orders/create",
9646
+ handle: handle$b
9498
9647
  }
9499
9648
  ]
9500
9649
  },
9501
9650
  {
9502
9651
  Component: ID,
9503
9652
  path: "/draft-orders/:id",
9504
- handle,
9653
+ handle: handle$a,
9505
9654
  loader,
9506
9655
  children: [
9507
9656
  {
9508
9657
  Component: BillingAddress,
9509
- path: "/draft-orders/:id/billing-address"
9658
+ path: "/draft-orders/:id/billing-address",
9659
+ handle: handle$9
9510
9660
  },
9511
9661
  {
9512
9662
  Component: CustomItems,
9513
- path: "/draft-orders/:id/custom-items"
9663
+ path: "/draft-orders/:id/custom-items",
9664
+ handle: handle$8
9514
9665
  },
9515
9666
  {
9516
9667
  Component: Email,
9517
- path: "/draft-orders/:id/email"
9668
+ path: "/draft-orders/:id/email",
9669
+ handle: handle$7
9518
9670
  },
9519
9671
  {
9520
9672
  Component: Items,
9521
- path: "/draft-orders/:id/items"
9673
+ path: "/draft-orders/:id/items",
9674
+ handle: handle$6
9522
9675
  },
9523
9676
  {
9524
9677
  Component: Metadata,
9525
- path: "/draft-orders/:id/metadata"
9678
+ path: "/draft-orders/:id/metadata",
9679
+ handle: handle$5
9526
9680
  },
9527
9681
  {
9528
9682
  Component: Promotions,
9529
- path: "/draft-orders/:id/promotions"
9683
+ path: "/draft-orders/:id/promotions",
9684
+ handle: handle$4
9685
+ },
9686
+ {
9687
+ Component: SalesChannel,
9688
+ path: "/draft-orders/:id/sales-channel",
9689
+ handle: handle$3
9530
9690
  },
9531
9691
  {
9532
9692
  Component: Shipping,
9533
- path: "/draft-orders/:id/shipping"
9693
+ path: "/draft-orders/:id/shipping",
9694
+ handle: handle$2
9534
9695
  },
9535
9696
  {
9536
9697
  Component: ShippingAddress,
9537
- path: "/draft-orders/:id/shipping-address"
9698
+ path: "/draft-orders/:id/shipping-address",
9699
+ handle: handle$1
9538
9700
  },
9539
9701
  {
9540
9702
  Component: TransferOwnership,
9541
- path: "/draft-orders/:id/transfer-ownership"
9542
- },
9543
- {
9544
- Component: SalesChannel,
9545
- path: "/draft-orders/:id/sales-channel"
9703
+ path: "/draft-orders/:id/transfer-ownership",
9704
+ handle
9546
9705
  }
9547
9706
  ]
9548
9707
  }
@@ -9556,7 +9715,8 @@ const menuItemModule = {
9556
9715
  path: "/draft-orders",
9557
9716
  nested: "/orders",
9558
9717
  rank: void 0,
9559
- translationNs: void 0
9718
+ translationNs: void 0,
9719
+ permissions: config.permissions
9560
9720
  }
9561
9721
  ]
9562
9722
  };