@medusajs/draft-order 2.20.0 → 2.20.1

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.
@@ -5972,195 +5972,6 @@ const ID = () => {
5972
5972
  }
5973
5973
  );
5974
5974
  };
5975
- const BillingAddress = () => {
5976
- const { id } = useParams();
5977
- const { order, isPending, isError, error } = useOrder(id, {
5978
- fields: "+billing_address"
5979
- });
5980
- if (isError) {
5981
- throw error;
5982
- }
5983
- const isReady = !isPending && !!order;
5984
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
5985
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
5986
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
5987
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
5988
- ] }),
5989
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
5990
- ] });
5991
- };
5992
- const BillingAddressForm = ({ order }) => {
5993
- const form = useForm({
5994
- defaultValues: {
5995
- first_name: order.billing_address?.first_name ?? "",
5996
- last_name: order.billing_address?.last_name ?? "",
5997
- company: order.billing_address?.company ?? "",
5998
- address_1: order.billing_address?.address_1 ?? "",
5999
- address_2: order.billing_address?.address_2 ?? "",
6000
- city: order.billing_address?.city ?? "",
6001
- province: order.billing_address?.province ?? "",
6002
- country_code: order.billing_address?.country_code ?? "",
6003
- postal_code: order.billing_address?.postal_code ?? "",
6004
- phone: order.billing_address?.phone ?? ""
6005
- },
6006
- resolver: zodResolver(schema$5)
6007
- });
6008
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6009
- const { handleSuccess } = useRouteModal();
6010
- const onSubmit = form.handleSubmit(async (data) => {
6011
- await mutateAsync(
6012
- { billing_address: data },
6013
- {
6014
- onSuccess: () => {
6015
- handleSuccess();
6016
- },
6017
- onError: (error) => {
6018
- toast.error(error.message);
6019
- }
6020
- }
6021
- );
6022
- });
6023
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
6024
- KeyboundForm,
6025
- {
6026
- className: "flex flex-1 flex-col overflow-hidden",
6027
- onSubmit,
6028
- children: [
6029
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
6030
- /* @__PURE__ */ jsx(
6031
- Form$2.Field,
6032
- {
6033
- control: form.control,
6034
- name: "country_code",
6035
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6036
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
6037
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
6038
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6039
- ] })
6040
- }
6041
- ),
6042
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6043
- /* @__PURE__ */ jsx(
6044
- Form$2.Field,
6045
- {
6046
- control: form.control,
6047
- name: "first_name",
6048
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6049
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
6050
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6051
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6052
- ] })
6053
- }
6054
- ),
6055
- /* @__PURE__ */ jsx(
6056
- Form$2.Field,
6057
- {
6058
- control: form.control,
6059
- name: "last_name",
6060
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6061
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
6062
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6063
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6064
- ] })
6065
- }
6066
- )
6067
- ] }),
6068
- /* @__PURE__ */ jsx(
6069
- Form$2.Field,
6070
- {
6071
- control: form.control,
6072
- name: "company",
6073
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6074
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
6075
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6076
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6077
- ] })
6078
- }
6079
- ),
6080
- /* @__PURE__ */ jsx(
6081
- Form$2.Field,
6082
- {
6083
- control: form.control,
6084
- name: "address_1",
6085
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6086
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
6087
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6088
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6089
- ] })
6090
- }
6091
- ),
6092
- /* @__PURE__ */ jsx(
6093
- Form$2.Field,
6094
- {
6095
- control: form.control,
6096
- name: "address_2",
6097
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6098
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
6099
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6100
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6101
- ] })
6102
- }
6103
- ),
6104
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
6105
- /* @__PURE__ */ jsx(
6106
- Form$2.Field,
6107
- {
6108
- control: form.control,
6109
- name: "postal_code",
6110
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6111
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
6112
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6113
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6114
- ] })
6115
- }
6116
- ),
6117
- /* @__PURE__ */ jsx(
6118
- Form$2.Field,
6119
- {
6120
- control: form.control,
6121
- name: "city",
6122
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6123
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
6124
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6125
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6126
- ] })
6127
- }
6128
- )
6129
- ] }),
6130
- /* @__PURE__ */ jsx(
6131
- Form$2.Field,
6132
- {
6133
- control: form.control,
6134
- name: "province",
6135
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6136
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
6137
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6138
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6139
- ] })
6140
- }
6141
- ),
6142
- /* @__PURE__ */ jsx(
6143
- Form$2.Field,
6144
- {
6145
- control: form.control,
6146
- name: "phone",
6147
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6148
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
6149
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6150
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6151
- ] })
6152
- }
6153
- )
6154
- ] }) }),
6155
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6156
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6157
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
6158
- ] }) })
6159
- ]
6160
- }
6161
- ) });
6162
- };
6163
- const schema$5 = addressSchema;
6164
5975
  const CustomItems = () => {
6165
5976
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
6166
5977
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -6169,7 +5980,7 @@ const CustomItems = () => {
6169
5980
  };
6170
5981
  const CustomItemsForm = () => {
6171
5982
  const form = useForm({
6172
- resolver: zodResolver(schema$4)
5983
+ resolver: zodResolver(schema$5)
6173
5984
  });
6174
5985
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
6175
5986
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -6179,7 +5990,7 @@ const CustomItemsForm = () => {
6179
5990
  ] }) })
6180
5991
  ] }) });
6181
5992
  };
6182
- const schema$4 = z.object({
5993
+ const schema$5 = z.object({
6183
5994
  email: z.string().email()
6184
5995
  });
6185
5996
  const Email = () => {
@@ -6204,7 +6015,7 @@ const EmailForm = ({ order }) => {
6204
6015
  defaultValues: {
6205
6016
  email: order.email ?? ""
6206
6017
  },
6207
- resolver: zodResolver(schema$3)
6018
+ resolver: zodResolver(schema$4)
6208
6019
  });
6209
6020
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6210
6021
  const { handleSuccess } = useRouteModal();
@@ -6247,7 +6058,7 @@ const EmailForm = ({ order }) => {
6247
6058
  }
6248
6059
  ) });
6249
6060
  };
6250
- const schema$3 = z.object({
6061
+ const schema$4 = z.object({
6251
6062
  email: z.string().email()
6252
6063
  });
6253
6064
  const NumberInput = forwardRef(
@@ -7269,321 +7080,46 @@ const customItemSchema = z.object({
7269
7080
  quantity: z.number(),
7270
7081
  unit_price: z.union([z.number(), z.string()])
7271
7082
  });
7272
- const PROMOTION_QUERY_KEY = "promotions";
7273
- const promotionsQueryKeys = {
7274
- list: (query2) => [
7275
- PROMOTION_QUERY_KEY,
7276
- query2 ? query2 : void 0
7277
- ],
7278
- detail: (id, query2) => [
7279
- PROMOTION_QUERY_KEY,
7280
- id,
7281
- query2 ? query2 : void 0
7282
- ]
7283
- };
7284
- const usePromotions = (query2, options) => {
7285
- const { data, ...rest } = useQuery({
7286
- queryKey: promotionsQueryKeys.list(query2),
7287
- queryFn: async () => sdk.admin.promotion.list(query2),
7288
- ...options
7289
- });
7290
- return { ...data, ...rest };
7291
- };
7292
- const Promotions = () => {
7083
+ const BillingAddress = () => {
7293
7084
  const { id } = useParams();
7294
- const {
7295
- order: preview,
7296
- isError: isPreviewError,
7297
- error: previewError
7298
- } = useOrderPreview(id, void 0);
7299
- useInitiateOrderEdit({ preview });
7300
- const { onCancel } = useCancelOrderEdit({ preview });
7301
- if (isPreviewError) {
7302
- throw previewError;
7085
+ const { order, isPending, isError, error } = useOrder(id, {
7086
+ fields: "+billing_address"
7087
+ });
7088
+ if (isError) {
7089
+ throw error;
7303
7090
  }
7304
- const isReady = !!preview;
7305
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
7306
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
7307
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
7091
+ const isReady = !isPending && !!order;
7092
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7093
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7094
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
7095
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
7096
+ ] }),
7097
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
7308
7098
  ] });
7309
7099
  };
7310
- const PromotionForm = ({ preview }) => {
7311
- const { items, shipping_methods } = preview;
7312
- const [isSubmitting, setIsSubmitting] = useState(false);
7313
- const [comboboxValue, setComboboxValue] = useState("");
7314
- const { handleSuccess } = useRouteModal();
7315
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
7316
- const promoIds = getPromotionIds(items, shipping_methods);
7317
- const { promotions, isPending, isError, error } = usePromotions(
7318
- {
7319
- id: promoIds
7320
- },
7321
- {
7322
- enabled: !!promoIds.length
7323
- }
7324
- );
7325
- const comboboxData = useComboboxData({
7326
- queryKey: ["promotions", "combobox", promoIds],
7327
- queryFn: async (params) => {
7328
- return await sdk.admin.promotion.list({
7329
- ...params,
7330
- id: {
7331
- $nin: promoIds
7332
- }
7333
- });
7334
- },
7335
- getOptions: (data) => {
7336
- return data.promotions.map((promotion) => ({
7337
- label: promotion.code,
7338
- value: promotion.code
7339
- }));
7340
- }
7341
- });
7342
- const add = async (value) => {
7343
- if (!value) {
7344
- return;
7345
- }
7346
- addPromotions(
7347
- {
7348
- promo_codes: [value]
7349
- },
7350
- {
7351
- onError: (e) => {
7352
- toast.error(e.message);
7353
- comboboxData.onSearchValueChange("");
7354
- setComboboxValue("");
7355
- },
7356
- onSuccess: () => {
7357
- comboboxData.onSearchValueChange("");
7358
- setComboboxValue("");
7359
- }
7360
- }
7361
- );
7362
- };
7363
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
7364
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
7365
- const onSubmit = async () => {
7366
- setIsSubmitting(true);
7367
- let requestSucceeded = false;
7368
- await requestOrderEdit(void 0, {
7369
- onError: (e) => {
7370
- toast.error(e.message);
7371
- },
7372
- onSuccess: () => {
7373
- requestSucceeded = true;
7374
- }
7375
- });
7376
- if (!requestSucceeded) {
7377
- setIsSubmitting(false);
7378
- return;
7379
- }
7380
- await confirmOrderEdit(void 0, {
7381
- onError: (e) => {
7382
- toast.error(e.message);
7383
- },
7384
- onSuccess: () => {
7385
- handleSuccess();
7386
- },
7387
- onSettled: () => {
7388
- setIsSubmitting(false);
7389
- }
7390
- });
7391
- };
7392
- if (isError) {
7393
- throw error;
7394
- }
7395
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
7396
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
7397
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
7398
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
7399
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
7400
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
7401
- ] }),
7402
- /* @__PURE__ */ jsx(
7403
- Combobox,
7404
- {
7405
- id: "promotion-combobox",
7406
- "aria-describedby": "promotion-combobox-hint",
7407
- isFetchingNextPage: comboboxData.isFetchingNextPage,
7408
- fetchNextPage: comboboxData.fetchNextPage,
7409
- options: comboboxData.options,
7410
- onSearchValueChange: comboboxData.onSearchValueChange,
7411
- searchValue: comboboxData.searchValue,
7412
- disabled: comboboxData.disabled || isAddingPromotions,
7413
- onChange: add,
7414
- value: comboboxValue
7415
- }
7416
- )
7417
- ] }),
7418
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
7419
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
7420
- PromotionItem,
7421
- {
7422
- promotion,
7423
- orderId: preview.id,
7424
- isLoading: isPending
7425
- },
7426
- promotion.id
7427
- )) })
7428
- ] }) }),
7429
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7430
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7431
- /* @__PURE__ */ jsx(
7432
- Button,
7433
- {
7434
- size: "small",
7435
- type: "submit",
7436
- isLoading: isSubmitting || isAddingPromotions,
7437
- children: "Save"
7438
- }
7439
- )
7440
- ] }) })
7441
- ] });
7442
- };
7443
- const PromotionItem = ({
7444
- promotion,
7445
- orderId,
7446
- isLoading
7447
- }) => {
7448
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
7449
- const onRemove = async () => {
7450
- removePromotions(
7451
- {
7452
- promo_codes: [promotion.code]
7453
- },
7454
- {
7455
- onError: (e) => {
7456
- toast.error(e.message);
7457
- }
7458
- }
7459
- );
7460
- };
7461
- const displayValue = getDisplayValue(promotion);
7462
- return /* @__PURE__ */ jsxs(
7463
- "div",
7464
- {
7465
- className: clx(
7466
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
7467
- {
7468
- "animate-pulse": isLoading
7469
- }
7470
- ),
7471
- children: [
7472
- /* @__PURE__ */ jsxs("div", { children: [
7473
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
7474
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
7475
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
7476
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
7477
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
7478
- ] }),
7479
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
7480
- ] })
7481
- ] }),
7482
- /* @__PURE__ */ jsx(
7483
- IconButton,
7484
- {
7485
- size: "small",
7486
- type: "button",
7487
- variant: "transparent",
7488
- onClick: onRemove,
7489
- isLoading: isPending || isLoading,
7490
- children: /* @__PURE__ */ jsx(XMark, {})
7491
- }
7492
- )
7493
- ]
7494
- },
7495
- promotion.id
7496
- );
7497
- };
7498
- function getDisplayValue(promotion) {
7499
- const value = promotion.application_method?.value;
7500
- if (!value) {
7501
- return null;
7502
- }
7503
- if (promotion.application_method?.type === "fixed") {
7504
- const currency = promotion.application_method?.currency_code;
7505
- if (!currency) {
7506
- return null;
7507
- }
7508
- return getLocaleAmount(value, currency);
7509
- } else if (promotion.application_method?.type === "percentage") {
7510
- return formatPercentage(value);
7511
- }
7512
- return null;
7513
- }
7514
- const formatter = new Intl.NumberFormat([], {
7515
- style: "percent",
7516
- minimumFractionDigits: 2
7517
- });
7518
- const formatPercentage = (value, isPercentageValue = false) => {
7519
- let val = value || 0;
7520
- if (!isPercentageValue) {
7521
- val = val / 100;
7522
- }
7523
- return formatter.format(val);
7524
- };
7525
- function getPromotionIds(items, shippingMethods) {
7526
- const promotionIds = /* @__PURE__ */ new Set();
7527
- for (const item of items) {
7528
- if (item.adjustments) {
7529
- for (const adjustment of item.adjustments) {
7530
- if (adjustment.promotion_id) {
7531
- promotionIds.add(adjustment.promotion_id);
7532
- }
7533
- }
7534
- }
7535
- }
7536
- for (const shippingMethod of shippingMethods) {
7537
- if (shippingMethod.adjustments) {
7538
- for (const adjustment of shippingMethod.adjustments) {
7539
- if (adjustment.promotion_id) {
7540
- promotionIds.add(adjustment.promotion_id);
7541
- }
7542
- }
7543
- }
7544
- }
7545
- return Array.from(promotionIds);
7546
- }
7547
- const SalesChannel = () => {
7548
- const { id } = useParams();
7549
- const { draft_order, isPending, isError, error } = useDraftOrder(
7550
- id,
7551
- {
7552
- fields: "+sales_channel_id"
7553
- },
7554
- {
7555
- enabled: !!id
7556
- }
7557
- );
7558
- if (isError) {
7559
- throw error;
7560
- }
7561
- const ISrEADY = !!draft_order && !isPending;
7562
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7563
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7564
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
7565
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7566
- ] }),
7567
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
7568
- ] });
7569
- };
7570
- const SalesChannelForm = ({ order }) => {
7100
+ const BillingAddressForm = ({ order }) => {
7571
7101
  const form = useForm({
7572
7102
  defaultValues: {
7573
- sales_channel_id: order.sales_channel_id || ""
7103
+ first_name: order.billing_address?.first_name ?? "",
7104
+ last_name: order.billing_address?.last_name ?? "",
7105
+ company: order.billing_address?.company ?? "",
7106
+ address_1: order.billing_address?.address_1 ?? "",
7107
+ address_2: order.billing_address?.address_2 ?? "",
7108
+ city: order.billing_address?.city ?? "",
7109
+ province: order.billing_address?.province ?? "",
7110
+ country_code: order.billing_address?.country_code ?? "",
7111
+ postal_code: order.billing_address?.postal_code ?? "",
7112
+ phone: order.billing_address?.phone ?? ""
7574
7113
  },
7575
- resolver: zodResolver(schema$2)
7114
+ resolver: zodResolver(schema$3)
7576
7115
  });
7577
7116
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7578
7117
  const { handleSuccess } = useRouteModal();
7579
7118
  const onSubmit = form.handleSubmit(async (data) => {
7580
7119
  await mutateAsync(
7581
- {
7582
- sales_channel_id: data.sales_channel_id
7583
- },
7120
+ { billing_address: data },
7584
7121
  {
7585
7122
  onSuccess: () => {
7586
- toast.success("Sales channel updated");
7587
7123
  handleSuccess();
7588
7124
  },
7589
7125
  onError: (error) => {
@@ -7598,7 +7134,132 @@ const SalesChannelForm = ({ order }) => {
7598
7134
  className: "flex flex-1 flex-col overflow-hidden",
7599
7135
  onSubmit,
7600
7136
  children: [
7601
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
7137
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
7138
+ /* @__PURE__ */ jsx(
7139
+ Form$2.Field,
7140
+ {
7141
+ control: form.control,
7142
+ name: "country_code",
7143
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7144
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
7145
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
7146
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7147
+ ] })
7148
+ }
7149
+ ),
7150
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7151
+ /* @__PURE__ */ jsx(
7152
+ Form$2.Field,
7153
+ {
7154
+ control: form.control,
7155
+ name: "first_name",
7156
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7157
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
7158
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7159
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7160
+ ] })
7161
+ }
7162
+ ),
7163
+ /* @__PURE__ */ jsx(
7164
+ Form$2.Field,
7165
+ {
7166
+ control: form.control,
7167
+ name: "last_name",
7168
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7169
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
7170
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7171
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7172
+ ] })
7173
+ }
7174
+ )
7175
+ ] }),
7176
+ /* @__PURE__ */ jsx(
7177
+ Form$2.Field,
7178
+ {
7179
+ control: form.control,
7180
+ name: "company",
7181
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7182
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
7183
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7184
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7185
+ ] })
7186
+ }
7187
+ ),
7188
+ /* @__PURE__ */ jsx(
7189
+ Form$2.Field,
7190
+ {
7191
+ control: form.control,
7192
+ name: "address_1",
7193
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7194
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
7195
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7196
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7197
+ ] })
7198
+ }
7199
+ ),
7200
+ /* @__PURE__ */ jsx(
7201
+ Form$2.Field,
7202
+ {
7203
+ control: form.control,
7204
+ name: "address_2",
7205
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7206
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
7207
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7208
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7209
+ ] })
7210
+ }
7211
+ ),
7212
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7213
+ /* @__PURE__ */ jsx(
7214
+ Form$2.Field,
7215
+ {
7216
+ control: form.control,
7217
+ name: "postal_code",
7218
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7219
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
7220
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7221
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7222
+ ] })
7223
+ }
7224
+ ),
7225
+ /* @__PURE__ */ jsx(
7226
+ Form$2.Field,
7227
+ {
7228
+ control: form.control,
7229
+ name: "city",
7230
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7231
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
7232
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7233
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7234
+ ] })
7235
+ }
7236
+ )
7237
+ ] }),
7238
+ /* @__PURE__ */ jsx(
7239
+ Form$2.Field,
7240
+ {
7241
+ control: form.control,
7242
+ name: "province",
7243
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7244
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
7245
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7246
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7247
+ ] })
7248
+ }
7249
+ ),
7250
+ /* @__PURE__ */ jsx(
7251
+ Form$2.Field,
7252
+ {
7253
+ control: form.control,
7254
+ name: "phone",
7255
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7256
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
7257
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7258
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7259
+ ] })
7260
+ }
7261
+ )
7262
+ ] }) }),
7602
7263
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7603
7264
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7604
7265
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -7607,49 +7268,7 @@ const SalesChannelForm = ({ order }) => {
7607
7268
  }
7608
7269
  ) });
7609
7270
  };
7610
- const SalesChannelField = ({ control, order }) => {
7611
- const salesChannels = useComboboxData({
7612
- queryFn: async (params) => {
7613
- return await sdk.admin.salesChannel.list(params);
7614
- },
7615
- queryKey: ["sales-channels"],
7616
- getOptions: (data) => {
7617
- return data.sales_channels.map((salesChannel) => ({
7618
- label: salesChannel.name,
7619
- value: salesChannel.id
7620
- }));
7621
- },
7622
- defaultValue: order.sales_channel_id || void 0
7623
- });
7624
- return /* @__PURE__ */ jsx(
7625
- Form$2.Field,
7626
- {
7627
- control,
7628
- name: "sales_channel_id",
7629
- render: ({ field }) => {
7630
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7631
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
7632
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
7633
- Combobox,
7634
- {
7635
- options: salesChannels.options,
7636
- fetchNextPage: salesChannels.fetchNextPage,
7637
- isFetchingNextPage: salesChannels.isFetchingNextPage,
7638
- searchValue: salesChannels.searchValue,
7639
- onSearchValueChange: salesChannels.onSearchValueChange,
7640
- placeholder: "Select sales channel",
7641
- ...field
7642
- }
7643
- ) }),
7644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7645
- ] });
7646
- }
7647
- }
7648
- );
7649
- };
7650
- const schema$2 = z.object({
7651
- sales_channel_id: z.string().min(1)
7652
- });
7271
+ const schema$3 = addressSchema;
7653
7272
  const InlineTip = forwardRef(
7654
7273
  ({ variant = "tip", label, className, children, ...props }, ref) => {
7655
7274
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -7905,101 +7524,409 @@ const MetadataForm = ({ orderId, metadata }) => {
7905
7524
  };
7906
7525
  const GridInput = forwardRef(({ className, ...props }, ref) => {
7907
7526
  return /* @__PURE__ */ jsx(
7908
- "input",
7527
+ "input",
7528
+ {
7529
+ ref,
7530
+ ...props,
7531
+ autoComplete: "off",
7532
+ className: clx(
7533
+ "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",
7534
+ className
7535
+ )
7536
+ }
7537
+ );
7538
+ });
7539
+ GridInput.displayName = "MetadataForm.GridInput";
7540
+ const PlaceholderInner = () => {
7541
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
7542
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
7543
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7544
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
7545
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
7546
+ ] }) })
7547
+ ] });
7548
+ };
7549
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
7550
+ function getDefaultValues(metadata) {
7551
+ if (!metadata || !Object.keys(metadata).length) {
7552
+ return [
7553
+ {
7554
+ key: "",
7555
+ value: "",
7556
+ disabled: false
7557
+ }
7558
+ ];
7559
+ }
7560
+ return Object.entries(metadata).map(([key, value]) => {
7561
+ if (!EDITABLE_TYPES.includes(typeof value)) {
7562
+ return {
7563
+ key,
7564
+ value,
7565
+ disabled: true
7566
+ };
7567
+ }
7568
+ let stringValue = value;
7569
+ if (typeof value !== "string") {
7570
+ stringValue = JSON.stringify(value);
7571
+ }
7572
+ return {
7573
+ key,
7574
+ value: stringValue,
7575
+ original_key: key
7576
+ };
7577
+ });
7578
+ }
7579
+ function parseValues(values) {
7580
+ const metadata = values.metadata;
7581
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
7582
+ if (isEmpty) {
7583
+ return null;
7584
+ }
7585
+ const update = {};
7586
+ metadata.forEach((field) => {
7587
+ let key = field.key;
7588
+ let value = field.value;
7589
+ const disabled = field.disabled;
7590
+ if (!key || !value) {
7591
+ return;
7592
+ }
7593
+ if (disabled) {
7594
+ update[key] = value;
7595
+ return;
7596
+ }
7597
+ key = key.trim();
7598
+ value = value.trim();
7599
+ if (value === "true") {
7600
+ update[key] = true;
7601
+ } else if (value === "false") {
7602
+ update[key] = false;
7603
+ } else {
7604
+ const parsedNumber = parseFloat(value);
7605
+ if (!isNaN(parsedNumber)) {
7606
+ update[key] = parsedNumber;
7607
+ } else {
7608
+ update[key] = value;
7609
+ }
7610
+ }
7611
+ });
7612
+ return update;
7613
+ }
7614
+ function getHasUneditableRows(metadata) {
7615
+ if (!metadata) {
7616
+ return false;
7617
+ }
7618
+ return Object.values(metadata).some(
7619
+ (value) => !EDITABLE_TYPES.includes(typeof value)
7620
+ );
7621
+ }
7622
+ const SalesChannel = () => {
7623
+ const { id } = useParams();
7624
+ const { draft_order, isPending, isError, error } = useDraftOrder(
7625
+ id,
7626
+ {
7627
+ fields: "+sales_channel_id"
7628
+ },
7629
+ {
7630
+ enabled: !!id
7631
+ }
7632
+ );
7633
+ if (isError) {
7634
+ throw error;
7635
+ }
7636
+ const ISrEADY = !!draft_order && !isPending;
7637
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7638
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7639
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
7640
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7641
+ ] }),
7642
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
7643
+ ] });
7644
+ };
7645
+ const SalesChannelForm = ({ order }) => {
7646
+ const form = useForm({
7647
+ defaultValues: {
7648
+ sales_channel_id: order.sales_channel_id || ""
7649
+ },
7650
+ resolver: zodResolver(schema$2)
7651
+ });
7652
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7653
+ const { handleSuccess } = useRouteModal();
7654
+ const onSubmit = form.handleSubmit(async (data) => {
7655
+ await mutateAsync(
7656
+ {
7657
+ sales_channel_id: data.sales_channel_id
7658
+ },
7659
+ {
7660
+ onSuccess: () => {
7661
+ toast.success("Sales channel updated");
7662
+ handleSuccess();
7663
+ },
7664
+ onError: (error) => {
7665
+ toast.error(error.message);
7666
+ }
7667
+ }
7668
+ );
7669
+ });
7670
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7671
+ KeyboundForm,
7672
+ {
7673
+ className: "flex flex-1 flex-col overflow-hidden",
7674
+ onSubmit,
7675
+ children: [
7676
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
7677
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7678
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7679
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7680
+ ] }) })
7681
+ ]
7682
+ }
7683
+ ) });
7684
+ };
7685
+ const SalesChannelField = ({ control, order }) => {
7686
+ const salesChannels = useComboboxData({
7687
+ queryFn: async (params) => {
7688
+ return await sdk.admin.salesChannel.list(params);
7689
+ },
7690
+ queryKey: ["sales-channels"],
7691
+ getOptions: (data) => {
7692
+ return data.sales_channels.map((salesChannel) => ({
7693
+ label: salesChannel.name,
7694
+ value: salesChannel.id
7695
+ }));
7696
+ },
7697
+ defaultValue: order.sales_channel_id || void 0
7698
+ });
7699
+ return /* @__PURE__ */ jsx(
7700
+ Form$2.Field,
7909
7701
  {
7910
- ref,
7911
- ...props,
7912
- autoComplete: "off",
7913
- className: clx(
7914
- "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",
7915
- className
7916
- )
7702
+ control,
7703
+ name: "sales_channel_id",
7704
+ render: ({ field }) => {
7705
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7706
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
7707
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
7708
+ Combobox,
7709
+ {
7710
+ options: salesChannels.options,
7711
+ fetchNextPage: salesChannels.fetchNextPage,
7712
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
7713
+ searchValue: salesChannels.searchValue,
7714
+ onSearchValueChange: salesChannels.onSearchValueChange,
7715
+ placeholder: "Select sales channel",
7716
+ ...field
7717
+ }
7718
+ ) }),
7719
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7720
+ ] });
7721
+ }
7917
7722
  }
7918
7723
  );
7724
+ };
7725
+ const schema$2 = z.object({
7726
+ sales_channel_id: z.string().min(1)
7919
7727
  });
7920
- GridInput.displayName = "MetadataForm.GridInput";
7921
- const PlaceholderInner = () => {
7922
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
7923
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
7924
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
7925
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
7926
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
7927
- ] }) })
7728
+ const ShippingAddress = () => {
7729
+ const { id } = useParams();
7730
+ const { order, isPending, isError, error } = useOrder(id, {
7731
+ fields: "+shipping_address"
7732
+ });
7733
+ if (isError) {
7734
+ throw error;
7735
+ }
7736
+ const isReady = !isPending && !!order;
7737
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7738
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7739
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
7740
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
7741
+ ] }),
7742
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
7928
7743
  ] });
7929
7744
  };
7930
- const EDITABLE_TYPES = ["string", "number", "boolean"];
7931
- function getDefaultValues(metadata) {
7932
- if (!metadata || !Object.keys(metadata).length) {
7933
- return [
7745
+ const ShippingAddressForm = ({ order }) => {
7746
+ const form = useForm({
7747
+ defaultValues: {
7748
+ first_name: order.shipping_address?.first_name ?? "",
7749
+ last_name: order.shipping_address?.last_name ?? "",
7750
+ company: order.shipping_address?.company ?? "",
7751
+ address_1: order.shipping_address?.address_1 ?? "",
7752
+ address_2: order.shipping_address?.address_2 ?? "",
7753
+ city: order.shipping_address?.city ?? "",
7754
+ province: order.shipping_address?.province ?? "",
7755
+ country_code: order.shipping_address?.country_code ?? "",
7756
+ postal_code: order.shipping_address?.postal_code ?? "",
7757
+ phone: order.shipping_address?.phone ?? ""
7758
+ },
7759
+ resolver: zodResolver(schema$1)
7760
+ });
7761
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7762
+ const { handleSuccess } = useRouteModal();
7763
+ const onSubmit = form.handleSubmit(async (data) => {
7764
+ await mutateAsync(
7934
7765
  {
7935
- key: "",
7936
- value: "",
7937
- disabled: false
7766
+ shipping_address: {
7767
+ first_name: data.first_name,
7768
+ last_name: data.last_name,
7769
+ company: data.company,
7770
+ address_1: data.address_1,
7771
+ address_2: data.address_2,
7772
+ city: data.city,
7773
+ province: data.province,
7774
+ country_code: data.country_code,
7775
+ postal_code: data.postal_code,
7776
+ phone: data.phone
7777
+ }
7778
+ },
7779
+ {
7780
+ onSuccess: () => {
7781
+ handleSuccess();
7782
+ },
7783
+ onError: (error) => {
7784
+ toast.error(error.message);
7785
+ }
7938
7786
  }
7939
- ];
7940
- }
7941
- return Object.entries(metadata).map(([key, value]) => {
7942
- if (!EDITABLE_TYPES.includes(typeof value)) {
7943
- return {
7944
- key,
7945
- value,
7946
- disabled: true
7947
- };
7948
- }
7949
- let stringValue = value;
7950
- if (typeof value !== "string") {
7951
- stringValue = JSON.stringify(value);
7952
- }
7953
- return {
7954
- key,
7955
- value: stringValue,
7956
- original_key: key
7957
- };
7787
+ );
7958
7788
  });
7959
- }
7960
- function parseValues(values) {
7961
- const metadata = values.metadata;
7962
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
7963
- if (isEmpty) {
7964
- return null;
7965
- }
7966
- const update = {};
7967
- metadata.forEach((field) => {
7968
- let key = field.key;
7969
- let value = field.value;
7970
- const disabled = field.disabled;
7971
- if (!key || !value) {
7972
- return;
7973
- }
7974
- if (disabled) {
7975
- update[key] = value;
7976
- return;
7977
- }
7978
- key = key.trim();
7979
- value = value.trim();
7980
- if (value === "true") {
7981
- update[key] = true;
7982
- } else if (value === "false") {
7983
- update[key] = false;
7984
- } else {
7985
- const parsedNumber = parseFloat(value);
7986
- if (!isNaN(parsedNumber)) {
7987
- update[key] = parsedNumber;
7988
- } else {
7989
- update[key] = value;
7990
- }
7789
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7790
+ KeyboundForm,
7791
+ {
7792
+ className: "flex flex-1 flex-col overflow-hidden",
7793
+ onSubmit,
7794
+ children: [
7795
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
7796
+ /* @__PURE__ */ jsx(
7797
+ Form$2.Field,
7798
+ {
7799
+ control: form.control,
7800
+ name: "country_code",
7801
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7802
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
7803
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
7804
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7805
+ ] })
7806
+ }
7807
+ ),
7808
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7809
+ /* @__PURE__ */ jsx(
7810
+ Form$2.Field,
7811
+ {
7812
+ control: form.control,
7813
+ name: "first_name",
7814
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7815
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
7816
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7817
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7818
+ ] })
7819
+ }
7820
+ ),
7821
+ /* @__PURE__ */ jsx(
7822
+ Form$2.Field,
7823
+ {
7824
+ control: form.control,
7825
+ name: "last_name",
7826
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7827
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
7828
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7829
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7830
+ ] })
7831
+ }
7832
+ )
7833
+ ] }),
7834
+ /* @__PURE__ */ jsx(
7835
+ Form$2.Field,
7836
+ {
7837
+ control: form.control,
7838
+ name: "company",
7839
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7840
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
7841
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7842
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7843
+ ] })
7844
+ }
7845
+ ),
7846
+ /* @__PURE__ */ jsx(
7847
+ Form$2.Field,
7848
+ {
7849
+ control: form.control,
7850
+ name: "address_1",
7851
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7852
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
7853
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7854
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7855
+ ] })
7856
+ }
7857
+ ),
7858
+ /* @__PURE__ */ jsx(
7859
+ Form$2.Field,
7860
+ {
7861
+ control: form.control,
7862
+ name: "address_2",
7863
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7864
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
7865
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7866
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7867
+ ] })
7868
+ }
7869
+ ),
7870
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
7871
+ /* @__PURE__ */ jsx(
7872
+ Form$2.Field,
7873
+ {
7874
+ control: form.control,
7875
+ name: "postal_code",
7876
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7877
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
7878
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7879
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7880
+ ] })
7881
+ }
7882
+ ),
7883
+ /* @__PURE__ */ jsx(
7884
+ Form$2.Field,
7885
+ {
7886
+ control: form.control,
7887
+ name: "city",
7888
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7889
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
7890
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7891
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7892
+ ] })
7893
+ }
7894
+ )
7895
+ ] }),
7896
+ /* @__PURE__ */ jsx(
7897
+ Form$2.Field,
7898
+ {
7899
+ control: form.control,
7900
+ name: "province",
7901
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7902
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
7903
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7904
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7905
+ ] })
7906
+ }
7907
+ ),
7908
+ /* @__PURE__ */ jsx(
7909
+ Form$2.Field,
7910
+ {
7911
+ control: form.control,
7912
+ name: "phone",
7913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7914
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
7915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7917
+ ] })
7918
+ }
7919
+ )
7920
+ ] }) }),
7921
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7922
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7923
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7924
+ ] }) })
7925
+ ]
7991
7926
  }
7992
- });
7993
- return update;
7994
- }
7995
- function getHasUneditableRows(metadata) {
7996
- if (!metadata) {
7997
- return false;
7998
- }
7999
- return Object.values(metadata).some(
8000
- (value) => !EDITABLE_TYPES.includes(typeof value)
8001
- );
8002
- }
7927
+ ) });
7928
+ };
7929
+ const schema$1 = addressSchema;
8003
7930
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
8004
7931
  const Shipping = () => {
8005
7932
  const { id } = useParams();
@@ -8794,208 +8721,281 @@ const CustomAmountField = ({
8794
8721
  }
8795
8722
  );
8796
8723
  };
8797
- const ShippingAddress = () => {
8798
- const { id } = useParams();
8799
- const { order, isPending, isError, error } = useOrder(id, {
8800
- fields: "+shipping_address"
8724
+ const PROMOTION_QUERY_KEY = "promotions";
8725
+ const promotionsQueryKeys = {
8726
+ list: (query2) => [
8727
+ PROMOTION_QUERY_KEY,
8728
+ query2 ? query2 : void 0
8729
+ ],
8730
+ detail: (id, query2) => [
8731
+ PROMOTION_QUERY_KEY,
8732
+ id,
8733
+ query2 ? query2 : void 0
8734
+ ]
8735
+ };
8736
+ const usePromotions = (query2, options) => {
8737
+ const { data, ...rest } = useQuery({
8738
+ queryKey: promotionsQueryKeys.list(query2),
8739
+ queryFn: async () => sdk.admin.promotion.list(query2),
8740
+ ...options
8801
8741
  });
8802
- if (isError) {
8803
- throw error;
8742
+ return { ...data, ...rest };
8743
+ };
8744
+ const Promotions = () => {
8745
+ const { id } = useParams();
8746
+ const {
8747
+ order: preview,
8748
+ isError: isPreviewError,
8749
+ error: previewError
8750
+ } = useOrderPreview(id, void 0);
8751
+ useInitiateOrderEdit({ preview });
8752
+ const { onCancel } = useCancelOrderEdit({ preview });
8753
+ if (isPreviewError) {
8754
+ throw previewError;
8804
8755
  }
8805
- const isReady = !isPending && !!order;
8806
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
8807
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
8808
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
8809
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
8810
- ] }),
8811
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
8756
+ const isReady = !!preview;
8757
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
8758
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
8759
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
8812
8760
  ] });
8813
8761
  };
8814
- const ShippingAddressForm = ({ order }) => {
8815
- const form = useForm({
8816
- defaultValues: {
8817
- first_name: order.shipping_address?.first_name ?? "",
8818
- last_name: order.shipping_address?.last_name ?? "",
8819
- company: order.shipping_address?.company ?? "",
8820
- address_1: order.shipping_address?.address_1 ?? "",
8821
- address_2: order.shipping_address?.address_2 ?? "",
8822
- city: order.shipping_address?.city ?? "",
8823
- province: order.shipping_address?.province ?? "",
8824
- country_code: order.shipping_address?.country_code ?? "",
8825
- postal_code: order.shipping_address?.postal_code ?? "",
8826
- phone: order.shipping_address?.phone ?? ""
8762
+ const PromotionForm = ({ preview }) => {
8763
+ const { items, shipping_methods } = preview;
8764
+ const [isSubmitting, setIsSubmitting] = useState(false);
8765
+ const [comboboxValue, setComboboxValue] = useState("");
8766
+ const { handleSuccess } = useRouteModal();
8767
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
8768
+ const promoIds = getPromotionIds(items, shipping_methods);
8769
+ const { promotions, isPending, isError, error } = usePromotions(
8770
+ {
8771
+ id: promoIds
8827
8772
  },
8828
- resolver: zodResolver(schema$1)
8773
+ {
8774
+ enabled: !!promoIds.length
8775
+ }
8776
+ );
8777
+ const comboboxData = useComboboxData({
8778
+ queryKey: ["promotions", "combobox", promoIds],
8779
+ queryFn: async (params) => {
8780
+ return await sdk.admin.promotion.list({
8781
+ ...params,
8782
+ id: {
8783
+ $nin: promoIds
8784
+ }
8785
+ });
8786
+ },
8787
+ getOptions: (data) => {
8788
+ return data.promotions.map((promotion) => ({
8789
+ label: promotion.code,
8790
+ value: promotion.code
8791
+ }));
8792
+ }
8829
8793
  });
8830
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8831
- const { handleSuccess } = useRouteModal();
8832
- const onSubmit = form.handleSubmit(async (data) => {
8833
- await mutateAsync(
8794
+ const add = async (value) => {
8795
+ if (!value) {
8796
+ return;
8797
+ }
8798
+ addPromotions(
8834
8799
  {
8835
- shipping_address: {
8836
- first_name: data.first_name,
8837
- last_name: data.last_name,
8838
- company: data.company,
8839
- address_1: data.address_1,
8840
- address_2: data.address_2,
8841
- city: data.city,
8842
- province: data.province,
8843
- country_code: data.country_code,
8844
- postal_code: data.postal_code,
8845
- phone: data.phone
8800
+ promo_codes: [value]
8801
+ },
8802
+ {
8803
+ onError: (e) => {
8804
+ toast.error(e.message);
8805
+ comboboxData.onSearchValueChange("");
8806
+ setComboboxValue("");
8807
+ },
8808
+ onSuccess: () => {
8809
+ comboboxData.onSearchValueChange("");
8810
+ setComboboxValue("");
8811
+ }
8812
+ }
8813
+ );
8814
+ };
8815
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
8816
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
8817
+ const onSubmit = async () => {
8818
+ setIsSubmitting(true);
8819
+ let requestSucceeded = false;
8820
+ await requestOrderEdit(void 0, {
8821
+ onError: (e) => {
8822
+ toast.error(e.message);
8823
+ },
8824
+ onSuccess: () => {
8825
+ requestSucceeded = true;
8826
+ }
8827
+ });
8828
+ if (!requestSucceeded) {
8829
+ setIsSubmitting(false);
8830
+ return;
8831
+ }
8832
+ await confirmOrderEdit(void 0, {
8833
+ onError: (e) => {
8834
+ toast.error(e.message);
8835
+ },
8836
+ onSuccess: () => {
8837
+ handleSuccess();
8838
+ },
8839
+ onSettled: () => {
8840
+ setIsSubmitting(false);
8841
+ }
8842
+ });
8843
+ };
8844
+ if (isError) {
8845
+ throw error;
8846
+ }
8847
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
8848
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
8849
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
8850
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
8851
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
8852
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
8853
+ ] }),
8854
+ /* @__PURE__ */ jsx(
8855
+ Combobox,
8856
+ {
8857
+ id: "promotion-combobox",
8858
+ "aria-describedby": "promotion-combobox-hint",
8859
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
8860
+ fetchNextPage: comboboxData.fetchNextPage,
8861
+ options: comboboxData.options,
8862
+ onSearchValueChange: comboboxData.onSearchValueChange,
8863
+ searchValue: comboboxData.searchValue,
8864
+ disabled: comboboxData.disabled || isAddingPromotions,
8865
+ onChange: add,
8866
+ value: comboboxValue
8867
+ }
8868
+ )
8869
+ ] }),
8870
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
8871
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
8872
+ PromotionItem,
8873
+ {
8874
+ promotion,
8875
+ orderId: preview.id,
8876
+ isLoading: isPending
8877
+ },
8878
+ promotion.id
8879
+ )) })
8880
+ ] }) }),
8881
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
8882
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8883
+ /* @__PURE__ */ jsx(
8884
+ Button,
8885
+ {
8886
+ size: "small",
8887
+ type: "submit",
8888
+ isLoading: isSubmitting || isAddingPromotions,
8889
+ children: "Save"
8846
8890
  }
8891
+ )
8892
+ ] }) })
8893
+ ] });
8894
+ };
8895
+ const PromotionItem = ({
8896
+ promotion,
8897
+ orderId,
8898
+ isLoading
8899
+ }) => {
8900
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
8901
+ const onRemove = async () => {
8902
+ removePromotions(
8903
+ {
8904
+ promo_codes: [promotion.code]
8847
8905
  },
8848
8906
  {
8849
- onSuccess: () => {
8850
- handleSuccess();
8851
- },
8852
- onError: (error) => {
8853
- toast.error(error.message);
8907
+ onError: (e) => {
8908
+ toast.error(e.message);
8854
8909
  }
8855
8910
  }
8856
8911
  );
8857
- });
8858
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
8859
- KeyboundForm,
8912
+ };
8913
+ const displayValue = getDisplayValue(promotion);
8914
+ return /* @__PURE__ */ jsxs(
8915
+ "div",
8860
8916
  {
8861
- className: "flex flex-1 flex-col overflow-hidden",
8862
- onSubmit,
8917
+ className: clx(
8918
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
8919
+ {
8920
+ "animate-pulse": isLoading
8921
+ }
8922
+ ),
8863
8923
  children: [
8864
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
8865
- /* @__PURE__ */ jsx(
8866
- Form$2.Field,
8867
- {
8868
- control: form.control,
8869
- name: "country_code",
8870
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8871
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
8872
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
8873
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8874
- ] })
8875
- }
8876
- ),
8877
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8878
- /* @__PURE__ */ jsx(
8879
- Form$2.Field,
8880
- {
8881
- control: form.control,
8882
- name: "first_name",
8883
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8884
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
8885
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8886
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8887
- ] })
8888
- }
8889
- ),
8890
- /* @__PURE__ */ jsx(
8891
- Form$2.Field,
8892
- {
8893
- control: form.control,
8894
- name: "last_name",
8895
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8896
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
8897
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8898
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8899
- ] })
8900
- }
8901
- )
8902
- ] }),
8903
- /* @__PURE__ */ jsx(
8904
- Form$2.Field,
8905
- {
8906
- control: form.control,
8907
- name: "company",
8908
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8909
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
8910
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8911
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8912
- ] })
8913
- }
8914
- ),
8915
- /* @__PURE__ */ jsx(
8916
- Form$2.Field,
8917
- {
8918
- control: form.control,
8919
- name: "address_1",
8920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
8922
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8923
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8924
- ] })
8925
- }
8926
- ),
8927
- /* @__PURE__ */ jsx(
8928
- Form$2.Field,
8929
- {
8930
- control: form.control,
8931
- name: "address_2",
8932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8933
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
8934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8935
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8936
- ] })
8937
- }
8938
- ),
8939
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8940
- /* @__PURE__ */ jsx(
8941
- Form$2.Field,
8942
- {
8943
- control: form.control,
8944
- name: "postal_code",
8945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8946
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
8947
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8948
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8949
- ] })
8950
- }
8951
- ),
8952
- /* @__PURE__ */ jsx(
8953
- Form$2.Field,
8954
- {
8955
- control: form.control,
8956
- name: "city",
8957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8958
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
8959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8961
- ] })
8962
- }
8963
- )
8964
- ] }),
8965
- /* @__PURE__ */ jsx(
8966
- Form$2.Field,
8967
- {
8968
- control: form.control,
8969
- name: "province",
8970
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8971
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
8972
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8973
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8974
- ] })
8975
- }
8976
- ),
8977
- /* @__PURE__ */ jsx(
8978
- Form$2.Field,
8979
- {
8980
- control: form.control,
8981
- name: "phone",
8982
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8983
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
8984
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8985
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8986
- ] })
8987
- }
8988
- )
8989
- ] }) }),
8990
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
8991
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8992
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8993
- ] }) })
8924
+ /* @__PURE__ */ jsxs("div", { children: [
8925
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
8926
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
8927
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
8928
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
8929
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
8930
+ ] }),
8931
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
8932
+ ] })
8933
+ ] }),
8934
+ /* @__PURE__ */ jsx(
8935
+ IconButton,
8936
+ {
8937
+ size: "small",
8938
+ type: "button",
8939
+ variant: "transparent",
8940
+ onClick: onRemove,
8941
+ isLoading: isPending || isLoading,
8942
+ children: /* @__PURE__ */ jsx(XMark, {})
8943
+ }
8944
+ )
8994
8945
  ]
8946
+ },
8947
+ promotion.id
8948
+ );
8949
+ };
8950
+ function getDisplayValue(promotion) {
8951
+ const value = promotion.application_method?.value;
8952
+ if (!value) {
8953
+ return null;
8954
+ }
8955
+ if (promotion.application_method?.type === "fixed") {
8956
+ const currency = promotion.application_method?.currency_code;
8957
+ if (!currency) {
8958
+ return null;
8995
8959
  }
8996
- ) });
8960
+ return getLocaleAmount(value, currency);
8961
+ } else if (promotion.application_method?.type === "percentage") {
8962
+ return formatPercentage(value);
8963
+ }
8964
+ return null;
8965
+ }
8966
+ const formatter = new Intl.NumberFormat([], {
8967
+ style: "percent",
8968
+ minimumFractionDigits: 2
8969
+ });
8970
+ const formatPercentage = (value, isPercentageValue = false) => {
8971
+ let val = value || 0;
8972
+ if (!isPercentageValue) {
8973
+ val = val / 100;
8974
+ }
8975
+ return formatter.format(val);
8997
8976
  };
8998
- const schema$1 = addressSchema;
8977
+ function getPromotionIds(items, shippingMethods) {
8978
+ const promotionIds = /* @__PURE__ */ new Set();
8979
+ for (const item of items) {
8980
+ if (item.adjustments) {
8981
+ for (const adjustment of item.adjustments) {
8982
+ if (adjustment.promotion_id) {
8983
+ promotionIds.add(adjustment.promotion_id);
8984
+ }
8985
+ }
8986
+ }
8987
+ }
8988
+ for (const shippingMethod of shippingMethods) {
8989
+ if (shippingMethod.adjustments) {
8990
+ for (const adjustment of shippingMethod.adjustments) {
8991
+ if (adjustment.promotion_id) {
8992
+ promotionIds.add(adjustment.promotion_id);
8993
+ }
8994
+ }
8995
+ }
8996
+ }
8997
+ return Array.from(promotionIds);
8998
+ }
8999
8999
  const TransferOwnership = () => {
9000
9000
  const { id } = useParams();
9001
9001
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -9491,10 +9491,6 @@ const routeModule = {
9491
9491
  handle,
9492
9492
  loader,
9493
9493
  children: [
9494
- {
9495
- Component: BillingAddress,
9496
- path: "/draft-orders/:id/billing-address"
9497
- },
9498
9494
  {
9499
9495
  Component: CustomItems,
9500
9496
  path: "/draft-orders/:id/custom-items"
@@ -9508,24 +9504,28 @@ const routeModule = {
9508
9504
  path: "/draft-orders/:id/items"
9509
9505
  },
9510
9506
  {
9511
- Component: Promotions,
9512
- path: "/draft-orders/:id/promotions"
9507
+ Component: BillingAddress,
9508
+ path: "/draft-orders/:id/billing-address"
9509
+ },
9510
+ {
9511
+ Component: Metadata,
9512
+ path: "/draft-orders/:id/metadata"
9513
9513
  },
9514
9514
  {
9515
9515
  Component: SalesChannel,
9516
9516
  path: "/draft-orders/:id/sales-channel"
9517
9517
  },
9518
9518
  {
9519
- Component: Metadata,
9520
- path: "/draft-orders/:id/metadata"
9519
+ Component: ShippingAddress,
9520
+ path: "/draft-orders/:id/shipping-address"
9521
9521
  },
9522
9522
  {
9523
9523
  Component: Shipping,
9524
9524
  path: "/draft-orders/:id/shipping"
9525
9525
  },
9526
9526
  {
9527
- Component: ShippingAddress,
9528
- path: "/draft-orders/:id/shipping-address"
9527
+ Component: Promotions,
9528
+ path: "/draft-orders/:id/promotions"
9529
9529
  },
9530
9530
  {
9531
9531
  Component: TransferOwnership,