@medusajs/draft-order 2.10.2-snapshot-20250903073427 → 2.10.2-snapshot-20250903100537
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.
- package/.medusa/server/src/admin/index.js +930 -930
- package/.medusa/server/src/admin/index.mjs +930 -930
- package/package.json +23 -24
|
@@ -9560,6 +9560,27 @@ const ID = () => {
|
|
|
9560
9560
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
|
|
9561
9561
|
] });
|
|
9562
9562
|
};
|
|
9563
|
+
const CustomItems = () => {
|
|
9564
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9565
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9566
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9567
|
+
] });
|
|
9568
|
+
};
|
|
9569
|
+
const CustomItemsForm = () => {
|
|
9570
|
+
const form = reactHookForm.useForm({
|
|
9571
|
+
resolver: zod.zodResolver(schema$5)
|
|
9572
|
+
});
|
|
9573
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9574
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9575
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9576
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9577
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9578
|
+
] }) })
|
|
9579
|
+
] }) });
|
|
9580
|
+
};
|
|
9581
|
+
const schema$5 = objectType({
|
|
9582
|
+
email: stringType().email()
|
|
9583
|
+
});
|
|
9563
9584
|
const BillingAddress = () => {
|
|
9564
9585
|
const { id } = reactRouterDom.useParams();
|
|
9565
9586
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9592,7 +9613,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9592
9613
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9593
9614
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9594
9615
|
},
|
|
9595
|
-
resolver: zod.zodResolver(schema$
|
|
9616
|
+
resolver: zod.zodResolver(schema$4)
|
|
9596
9617
|
});
|
|
9597
9618
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9598
9619
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9749,26 +9770,73 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9749
9770
|
}
|
|
9750
9771
|
) });
|
|
9751
9772
|
};
|
|
9752
|
-
const schema$
|
|
9753
|
-
const
|
|
9773
|
+
const schema$4 = addressSchema;
|
|
9774
|
+
const Email = () => {
|
|
9775
|
+
const { id } = reactRouterDom.useParams();
|
|
9776
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9777
|
+
fields: "+email"
|
|
9778
|
+
});
|
|
9779
|
+
if (isError) {
|
|
9780
|
+
throw error;
|
|
9781
|
+
}
|
|
9782
|
+
const isReady = !isPending && !!order;
|
|
9754
9783
|
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9755
|
-
/* @__PURE__ */ jsxRuntime.
|
|
9756
|
-
|
|
9784
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
9785
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
9786
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9787
|
+
] }),
|
|
9788
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
9757
9789
|
] });
|
|
9758
9790
|
};
|
|
9759
|
-
const
|
|
9791
|
+
const EmailForm = ({ order }) => {
|
|
9760
9792
|
const form = reactHookForm.useForm({
|
|
9761
|
-
|
|
9793
|
+
defaultValues: {
|
|
9794
|
+
email: order.email ?? ""
|
|
9795
|
+
},
|
|
9796
|
+
resolver: zod.zodResolver(schema$3)
|
|
9762
9797
|
});
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9768
|
-
|
|
9769
|
-
|
|
9798
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9799
|
+
const { handleSuccess } = useRouteModal();
|
|
9800
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9801
|
+
await mutateAsync(
|
|
9802
|
+
{ email: data.email },
|
|
9803
|
+
{
|
|
9804
|
+
onSuccess: () => {
|
|
9805
|
+
handleSuccess();
|
|
9806
|
+
},
|
|
9807
|
+
onError: (error) => {
|
|
9808
|
+
ui.toast.error(error.message);
|
|
9809
|
+
}
|
|
9810
|
+
}
|
|
9811
|
+
);
|
|
9812
|
+
});
|
|
9813
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9814
|
+
KeyboundForm,
|
|
9815
|
+
{
|
|
9816
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9817
|
+
onSubmit,
|
|
9818
|
+
children: [
|
|
9819
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9820
|
+
Form$2.Field,
|
|
9821
|
+
{
|
|
9822
|
+
control: form.control,
|
|
9823
|
+
name: "email",
|
|
9824
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
9825
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
9826
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
9827
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
9828
|
+
] })
|
|
9829
|
+
}
|
|
9830
|
+
) }),
|
|
9831
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9832
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9833
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9834
|
+
] }) })
|
|
9835
|
+
]
|
|
9836
|
+
}
|
|
9837
|
+
) });
|
|
9770
9838
|
};
|
|
9771
|
-
const schema$
|
|
9839
|
+
const schema$3 = objectType({
|
|
9772
9840
|
email: stringType().email()
|
|
9773
9841
|
});
|
|
9774
9842
|
const InlineTip = React.forwardRef(
|
|
@@ -10121,26 +10189,6 @@ function getHasUneditableRows(metadata) {
|
|
|
10121
10189
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10122
10190
|
);
|
|
10123
10191
|
}
|
|
10124
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10125
|
-
const promotionsQueryKeys = {
|
|
10126
|
-
list: (query2) => [
|
|
10127
|
-
PROMOTION_QUERY_KEY,
|
|
10128
|
-
query2 ? query2 : void 0
|
|
10129
|
-
],
|
|
10130
|
-
detail: (id, query2) => [
|
|
10131
|
-
PROMOTION_QUERY_KEY,
|
|
10132
|
-
id,
|
|
10133
|
-
query2 ? query2 : void 0
|
|
10134
|
-
]
|
|
10135
|
-
};
|
|
10136
|
-
const usePromotions = (query2, options) => {
|
|
10137
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
10138
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10139
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10140
|
-
...options
|
|
10141
|
-
});
|
|
10142
|
-
return { ...data, ...rest };
|
|
10143
|
-
};
|
|
10144
10192
|
const useCancelOrderEdit = ({ preview }) => {
|
|
10145
10193
|
const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
|
|
10146
10194
|
const onCancel = React.useCallback(async () => {
|
|
@@ -10187,85 +10235,80 @@ const useInitiateOrderEdit = ({
|
|
|
10187
10235
|
run();
|
|
10188
10236
|
}, [preview, navigate, mutateAsync]);
|
|
10189
10237
|
};
|
|
10190
|
-
|
|
10238
|
+
function convertNumber(value) {
|
|
10239
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10240
|
+
}
|
|
10241
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
10242
|
+
const Shipping = () => {
|
|
10243
|
+
var _a;
|
|
10191
10244
|
const { id } = reactRouterDom.useParams();
|
|
10245
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10246
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
10247
|
+
});
|
|
10192
10248
|
const {
|
|
10193
10249
|
order: preview,
|
|
10250
|
+
isPending: isPreviewPending,
|
|
10194
10251
|
isError: isPreviewError,
|
|
10195
10252
|
error: previewError
|
|
10196
|
-
} = useOrderPreview(id
|
|
10253
|
+
} = useOrderPreview(id);
|
|
10197
10254
|
useInitiateOrderEdit({ preview });
|
|
10198
10255
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10256
|
+
if (isError) {
|
|
10257
|
+
throw error;
|
|
10258
|
+
}
|
|
10199
10259
|
if (isPreviewError) {
|
|
10200
10260
|
throw previewError;
|
|
10201
10261
|
}
|
|
10202
|
-
const
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10262
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
10263
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
10264
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
10265
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
10266
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10267
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
10268
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
10269
|
+
] }) }) }),
|
|
10270
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
10271
|
+
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10272
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
10273
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10274
|
+
] }) });
|
|
10207
10275
|
};
|
|
10208
|
-
const
|
|
10209
|
-
|
|
10276
|
+
const ShippingForm = ({ preview, order }) => {
|
|
10277
|
+
var _a;
|
|
10278
|
+
const { setIsOpen } = useStackedModal();
|
|
10210
10279
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10211
|
-
const [
|
|
10212
|
-
const
|
|
10213
|
-
const {
|
|
10214
|
-
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
10215
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10280
|
+
const [data, setData] = React.useState(null);
|
|
10281
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
10282
|
+
const { shipping_options } = useShippingOptions(
|
|
10216
10283
|
{
|
|
10217
|
-
|
|
10284
|
+
id: appliedShippingOptionIds,
|
|
10285
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
10218
10286
|
},
|
|
10219
10287
|
{
|
|
10220
|
-
enabled:
|
|
10288
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
10221
10289
|
}
|
|
10222
10290
|
);
|
|
10223
|
-
const
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
return data.promotions.map((promotion) => ({
|
|
10235
|
-
label: promotion.code,
|
|
10236
|
-
value: promotion.code
|
|
10237
|
-
}));
|
|
10238
|
-
}
|
|
10239
|
-
});
|
|
10240
|
-
const add = async (value) => {
|
|
10241
|
-
if (!value) {
|
|
10242
|
-
return;
|
|
10243
|
-
}
|
|
10244
|
-
addPromotions(
|
|
10245
|
-
{
|
|
10246
|
-
promo_codes: [value]
|
|
10247
|
-
},
|
|
10248
|
-
{
|
|
10249
|
-
onError: (e) => {
|
|
10250
|
-
ui.toast.error(e.message);
|
|
10251
|
-
comboboxData.onSearchValueChange("");
|
|
10252
|
-
setComboboxValue("");
|
|
10253
|
-
},
|
|
10254
|
-
onSuccess: () => {
|
|
10255
|
-
comboboxData.onSearchValueChange("");
|
|
10256
|
-
setComboboxValue("");
|
|
10257
|
-
}
|
|
10258
|
-
}
|
|
10259
|
-
);
|
|
10260
|
-
};
|
|
10291
|
+
const uniqueShippingProfiles = React.useMemo(() => {
|
|
10292
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
10293
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
10294
|
+
profiles.set(profile.id, profile);
|
|
10295
|
+
});
|
|
10296
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
10297
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
10298
|
+
});
|
|
10299
|
+
return Array.from(profiles.values());
|
|
10300
|
+
}, [order.items, shipping_options]);
|
|
10301
|
+
const { handleSuccess } = useRouteModal();
|
|
10261
10302
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10262
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10303
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10304
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
10305
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
10263
10306
|
const onSubmit = async () => {
|
|
10264
10307
|
setIsSubmitting(true);
|
|
10265
10308
|
let requestSucceeded = false;
|
|
10266
10309
|
await requestOrderEdit(void 0, {
|
|
10267
10310
|
onError: (e) => {
|
|
10268
|
-
ui.toast.error(e.message);
|
|
10311
|
+
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
10269
10312
|
},
|
|
10270
10313
|
onSuccess: () => {
|
|
10271
10314
|
requestSucceeded = true;
|
|
@@ -10277,7 +10320,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
10277
10320
|
}
|
|
10278
10321
|
await confirmOrderEdit(void 0, {
|
|
10279
10322
|
onError: (e) => {
|
|
10280
|
-
ui.toast.error(e.message);
|
|
10323
|
+
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10281
10324
|
},
|
|
10282
10325
|
onSuccess: () => {
|
|
10283
10326
|
handleSuccess();
|
|
@@ -10287,388 +10330,30 @@ const PromotionForm = ({ preview }) => {
|
|
|
10287
10330
|
}
|
|
10288
10331
|
});
|
|
10289
10332
|
};
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
}
|
|
10314
|
-
)
|
|
10315
|
-
] }),
|
|
10316
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10317
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10318
|
-
PromotionItem,
|
|
10319
|
-
{
|
|
10320
|
-
promotion,
|
|
10321
|
-
orderId: preview.id,
|
|
10322
|
-
isLoading: isPending
|
|
10323
|
-
},
|
|
10324
|
-
promotion.id
|
|
10325
|
-
)) })
|
|
10326
|
-
] }) }),
|
|
10327
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10328
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10329
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10330
|
-
ui.Button,
|
|
10331
|
-
{
|
|
10332
|
-
size: "small",
|
|
10333
|
-
type: "submit",
|
|
10334
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10335
|
-
children: "Save"
|
|
10336
|
-
}
|
|
10337
|
-
)
|
|
10338
|
-
] }) })
|
|
10339
|
-
] });
|
|
10340
|
-
};
|
|
10341
|
-
const PromotionItem = ({
|
|
10342
|
-
promotion,
|
|
10343
|
-
orderId,
|
|
10344
|
-
isLoading
|
|
10345
|
-
}) => {
|
|
10346
|
-
var _a;
|
|
10347
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10348
|
-
const onRemove = async () => {
|
|
10349
|
-
removePromotions(
|
|
10350
|
-
{
|
|
10351
|
-
promo_codes: [promotion.code]
|
|
10352
|
-
},
|
|
10353
|
-
{
|
|
10354
|
-
onError: (e) => {
|
|
10355
|
-
ui.toast.error(e.message);
|
|
10356
|
-
}
|
|
10357
|
-
}
|
|
10358
|
-
);
|
|
10359
|
-
};
|
|
10360
|
-
const displayValue = getDisplayValue(promotion);
|
|
10361
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10362
|
-
"div",
|
|
10363
|
-
{
|
|
10364
|
-
className: ui.clx(
|
|
10365
|
-
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
10366
|
-
{
|
|
10367
|
-
"animate-pulse": isLoading
|
|
10368
|
-
}
|
|
10369
|
-
),
|
|
10370
|
-
children: [
|
|
10371
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10372
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
10373
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
10374
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
10375
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
10376
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
10377
|
-
] }),
|
|
10378
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
10379
|
-
] })
|
|
10380
|
-
] }),
|
|
10381
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10382
|
-
ui.IconButton,
|
|
10383
|
-
{
|
|
10384
|
-
size: "small",
|
|
10385
|
-
type: "button",
|
|
10386
|
-
variant: "transparent",
|
|
10387
|
-
onClick: onRemove,
|
|
10388
|
-
isLoading: isPending || isLoading,
|
|
10389
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
10390
|
-
}
|
|
10391
|
-
)
|
|
10392
|
-
]
|
|
10393
|
-
},
|
|
10394
|
-
promotion.id
|
|
10395
|
-
);
|
|
10396
|
-
};
|
|
10397
|
-
function getDisplayValue(promotion) {
|
|
10398
|
-
var _a, _b, _c, _d;
|
|
10399
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
10400
|
-
if (!value) {
|
|
10401
|
-
return null;
|
|
10402
|
-
}
|
|
10403
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
10404
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
10405
|
-
if (!currency) {
|
|
10406
|
-
return null;
|
|
10407
|
-
}
|
|
10408
|
-
return getLocaleAmount(value, currency);
|
|
10409
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
10410
|
-
return formatPercentage(value);
|
|
10411
|
-
}
|
|
10412
|
-
return null;
|
|
10413
|
-
}
|
|
10414
|
-
const formatter = new Intl.NumberFormat([], {
|
|
10415
|
-
style: "percent",
|
|
10416
|
-
minimumFractionDigits: 2
|
|
10417
|
-
});
|
|
10418
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
10419
|
-
let val = value || 0;
|
|
10420
|
-
if (!isPercentageValue) {
|
|
10421
|
-
val = val / 100;
|
|
10422
|
-
}
|
|
10423
|
-
return formatter.format(val);
|
|
10424
|
-
};
|
|
10425
|
-
function getPromotionCodes(items, shippingMethods) {
|
|
10426
|
-
const codes = /* @__PURE__ */ new Set();
|
|
10427
|
-
for (const item of items) {
|
|
10428
|
-
if (item.adjustments) {
|
|
10429
|
-
for (const adjustment of item.adjustments) {
|
|
10430
|
-
if (adjustment.code) {
|
|
10431
|
-
codes.add(adjustment.code);
|
|
10432
|
-
}
|
|
10433
|
-
}
|
|
10434
|
-
}
|
|
10435
|
-
}
|
|
10436
|
-
for (const shippingMethod of shippingMethods) {
|
|
10437
|
-
if (shippingMethod.adjustments) {
|
|
10438
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
10439
|
-
if (adjustment.code) {
|
|
10440
|
-
codes.add(adjustment.code);
|
|
10441
|
-
}
|
|
10442
|
-
}
|
|
10443
|
-
}
|
|
10444
|
-
}
|
|
10445
|
-
return Array.from(codes);
|
|
10446
|
-
}
|
|
10447
|
-
const SalesChannel = () => {
|
|
10448
|
-
const { id } = reactRouterDom.useParams();
|
|
10449
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10450
|
-
id,
|
|
10451
|
-
{
|
|
10452
|
-
fields: "+sales_channel_id"
|
|
10453
|
-
},
|
|
10454
|
-
{
|
|
10455
|
-
enabled: !!id
|
|
10456
|
-
}
|
|
10457
|
-
);
|
|
10458
|
-
if (isError) {
|
|
10459
|
-
throw error;
|
|
10460
|
-
}
|
|
10461
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
10462
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10463
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
10464
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
10465
|
-
/* @__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" }) })
|
|
10466
|
-
] }),
|
|
10467
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
10468
|
-
] });
|
|
10469
|
-
};
|
|
10470
|
-
const SalesChannelForm = ({ order }) => {
|
|
10471
|
-
const form = reactHookForm.useForm({
|
|
10472
|
-
defaultValues: {
|
|
10473
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
10474
|
-
},
|
|
10475
|
-
resolver: zod.zodResolver(schema$3)
|
|
10476
|
-
});
|
|
10477
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10478
|
-
const { handleSuccess } = useRouteModal();
|
|
10479
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10480
|
-
await mutateAsync(
|
|
10481
|
-
{
|
|
10482
|
-
sales_channel_id: data.sales_channel_id
|
|
10483
|
-
},
|
|
10484
|
-
{
|
|
10485
|
-
onSuccess: () => {
|
|
10486
|
-
ui.toast.success("Sales channel updated");
|
|
10487
|
-
handleSuccess();
|
|
10488
|
-
},
|
|
10489
|
-
onError: (error) => {
|
|
10490
|
-
ui.toast.error(error.message);
|
|
10491
|
-
}
|
|
10492
|
-
}
|
|
10493
|
-
);
|
|
10494
|
-
});
|
|
10495
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10496
|
-
KeyboundForm,
|
|
10497
|
-
{
|
|
10498
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10499
|
-
onSubmit,
|
|
10500
|
-
children: [
|
|
10501
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
10502
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10503
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10504
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10505
|
-
] }) })
|
|
10506
|
-
]
|
|
10507
|
-
}
|
|
10508
|
-
) });
|
|
10509
|
-
};
|
|
10510
|
-
const SalesChannelField = ({ control, order }) => {
|
|
10511
|
-
const salesChannels = useComboboxData({
|
|
10512
|
-
queryFn: async (params) => {
|
|
10513
|
-
return await sdk.admin.salesChannel.list(params);
|
|
10514
|
-
},
|
|
10515
|
-
queryKey: ["sales-channels"],
|
|
10516
|
-
getOptions: (data) => {
|
|
10517
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
10518
|
-
label: salesChannel.name,
|
|
10519
|
-
value: salesChannel.id
|
|
10520
|
-
}));
|
|
10521
|
-
},
|
|
10522
|
-
defaultValue: order.sales_channel_id || void 0
|
|
10523
|
-
});
|
|
10524
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10525
|
-
Form$2.Field,
|
|
10526
|
-
{
|
|
10527
|
-
control,
|
|
10528
|
-
name: "sales_channel_id",
|
|
10529
|
-
render: ({ field }) => {
|
|
10530
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
10531
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
10532
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10533
|
-
Combobox,
|
|
10534
|
-
{
|
|
10535
|
-
options: salesChannels.options,
|
|
10536
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
10537
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
10538
|
-
searchValue: salesChannels.searchValue,
|
|
10539
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
10540
|
-
placeholder: "Select sales channel",
|
|
10541
|
-
...field
|
|
10542
|
-
}
|
|
10543
|
-
) }),
|
|
10544
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
10545
|
-
] });
|
|
10546
|
-
}
|
|
10547
|
-
}
|
|
10548
|
-
);
|
|
10549
|
-
};
|
|
10550
|
-
const schema$3 = objectType({
|
|
10551
|
-
sales_channel_id: stringType().min(1)
|
|
10552
|
-
});
|
|
10553
|
-
function convertNumber(value) {
|
|
10554
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10555
|
-
}
|
|
10556
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
10557
|
-
const Shipping = () => {
|
|
10558
|
-
var _a;
|
|
10559
|
-
const { id } = reactRouterDom.useParams();
|
|
10560
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10561
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
10562
|
-
});
|
|
10563
|
-
const {
|
|
10564
|
-
order: preview,
|
|
10565
|
-
isPending: isPreviewPending,
|
|
10566
|
-
isError: isPreviewError,
|
|
10567
|
-
error: previewError
|
|
10568
|
-
} = useOrderPreview(id);
|
|
10569
|
-
useInitiateOrderEdit({ preview });
|
|
10570
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10571
|
-
if (isError) {
|
|
10572
|
-
throw error;
|
|
10573
|
-
}
|
|
10574
|
-
if (isPreviewError) {
|
|
10575
|
-
throw previewError;
|
|
10576
|
-
}
|
|
10577
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
10578
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
10579
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
10580
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
10581
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10582
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
10583
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
10584
|
-
] }) }) }),
|
|
10585
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
10586
|
-
] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10587
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
10588
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10589
|
-
] }) });
|
|
10590
|
-
};
|
|
10591
|
-
const ShippingForm = ({ preview, order }) => {
|
|
10592
|
-
var _a;
|
|
10593
|
-
const { setIsOpen } = useStackedModal();
|
|
10594
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10595
|
-
const [data, setData] = React.useState(null);
|
|
10596
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
10597
|
-
const { shipping_options } = useShippingOptions(
|
|
10598
|
-
{
|
|
10599
|
-
id: appliedShippingOptionIds,
|
|
10600
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
10601
|
-
},
|
|
10602
|
-
{
|
|
10603
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
10604
|
-
}
|
|
10605
|
-
);
|
|
10606
|
-
const uniqueShippingProfiles = React.useMemo(() => {
|
|
10607
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
10608
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
10609
|
-
profiles.set(profile.id, profile);
|
|
10610
|
-
});
|
|
10611
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
10612
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
10613
|
-
});
|
|
10614
|
-
return Array.from(profiles.values());
|
|
10615
|
-
}, [order.items, shipping_options]);
|
|
10616
|
-
const { handleSuccess } = useRouteModal();
|
|
10617
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10618
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10619
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
10620
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
10621
|
-
const onSubmit = async () => {
|
|
10622
|
-
setIsSubmitting(true);
|
|
10623
|
-
let requestSucceeded = false;
|
|
10624
|
-
await requestOrderEdit(void 0, {
|
|
10625
|
-
onError: (e) => {
|
|
10626
|
-
ui.toast.error(`Failed to request order edit: ${e.message}`);
|
|
10627
|
-
},
|
|
10628
|
-
onSuccess: () => {
|
|
10629
|
-
requestSucceeded = true;
|
|
10630
|
-
}
|
|
10631
|
-
});
|
|
10632
|
-
if (!requestSucceeded) {
|
|
10633
|
-
setIsSubmitting(false);
|
|
10634
|
-
return;
|
|
10635
|
-
}
|
|
10636
|
-
await confirmOrderEdit(void 0, {
|
|
10637
|
-
onError: (e) => {
|
|
10638
|
-
ui.toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
10639
|
-
},
|
|
10640
|
-
onSuccess: () => {
|
|
10641
|
-
handleSuccess();
|
|
10642
|
-
},
|
|
10643
|
-
onSettled: () => {
|
|
10644
|
-
setIsSubmitting(false);
|
|
10645
|
-
}
|
|
10646
|
-
});
|
|
10647
|
-
};
|
|
10648
|
-
const onKeydown = React.useCallback(
|
|
10649
|
-
(e) => {
|
|
10650
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10651
|
-
if (data || isSubmitting) {
|
|
10652
|
-
return;
|
|
10653
|
-
}
|
|
10654
|
-
onSubmit();
|
|
10655
|
-
}
|
|
10656
|
-
},
|
|
10657
|
-
[data, isSubmitting, onSubmit]
|
|
10658
|
-
);
|
|
10659
|
-
React.useEffect(() => {
|
|
10660
|
-
document.addEventListener("keydown", onKeydown);
|
|
10661
|
-
return () => {
|
|
10662
|
-
document.removeEventListener("keydown", onKeydown);
|
|
10663
|
-
};
|
|
10664
|
-
}, [onKeydown]);
|
|
10665
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10666
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
10667
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10668
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10669
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10670
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
10671
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
|
|
10333
|
+
const onKeydown = React.useCallback(
|
|
10334
|
+
(e) => {
|
|
10335
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10336
|
+
if (data || isSubmitting) {
|
|
10337
|
+
return;
|
|
10338
|
+
}
|
|
10339
|
+
onSubmit();
|
|
10340
|
+
}
|
|
10341
|
+
},
|
|
10342
|
+
[data, isSubmitting, onSubmit]
|
|
10343
|
+
);
|
|
10344
|
+
React.useEffect(() => {
|
|
10345
|
+
document.addEventListener("keydown", onKeydown);
|
|
10346
|
+
return () => {
|
|
10347
|
+
document.removeEventListener("keydown", onKeydown);
|
|
10348
|
+
};
|
|
10349
|
+
}, [onKeydown]);
|
|
10350
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
10351
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
|
|
10352
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10353
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10354
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10355
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
10356
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
|
|
10672
10357
|
] }),
|
|
10673
10358
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10674
10359
|
/* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
|
|
@@ -10937,429 +10622,812 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
10937
10622
|
] })
|
|
10938
10623
|
]
|
|
10939
10624
|
},
|
|
10940
|
-
profile.id
|
|
10941
|
-
);
|
|
10942
|
-
}) })
|
|
10943
|
-
] }) })
|
|
10944
|
-
] }) }),
|
|
10945
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10946
|
-
StackedFocusModal,
|
|
10947
|
-
{
|
|
10948
|
-
id: STACKED_FOCUS_MODAL_ID,
|
|
10949
|
-
onOpenChangeCallback: (open) => {
|
|
10950
|
-
if (!open) {
|
|
10951
|
-
setData(null);
|
|
10625
|
+
profile.id
|
|
10626
|
+
);
|
|
10627
|
+
}) })
|
|
10628
|
+
] }) })
|
|
10629
|
+
] }) }),
|
|
10630
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10631
|
+
StackedFocusModal,
|
|
10632
|
+
{
|
|
10633
|
+
id: STACKED_FOCUS_MODAL_ID,
|
|
10634
|
+
onOpenChangeCallback: (open) => {
|
|
10635
|
+
if (!open) {
|
|
10636
|
+
setData(null);
|
|
10637
|
+
}
|
|
10638
|
+
return open;
|
|
10639
|
+
},
|
|
10640
|
+
children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
|
|
10641
|
+
}
|
|
10642
|
+
)
|
|
10643
|
+
] }),
|
|
10644
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
|
|
10645
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10646
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10647
|
+
ui.Button,
|
|
10648
|
+
{
|
|
10649
|
+
size: "small",
|
|
10650
|
+
type: "button",
|
|
10651
|
+
isLoading: isSubmitting,
|
|
10652
|
+
onClick: onSubmit,
|
|
10653
|
+
children: "Save"
|
|
10654
|
+
}
|
|
10655
|
+
)
|
|
10656
|
+
] }) })
|
|
10657
|
+
] });
|
|
10658
|
+
};
|
|
10659
|
+
const StackedModalTrigger$1 = ({
|
|
10660
|
+
shippingProfileId,
|
|
10661
|
+
shippingOption,
|
|
10662
|
+
shippingMethod,
|
|
10663
|
+
setData,
|
|
10664
|
+
children
|
|
10665
|
+
}) => {
|
|
10666
|
+
const { setIsOpen, getIsOpen } = useStackedModal();
|
|
10667
|
+
const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
|
|
10668
|
+
const onToggle = () => {
|
|
10669
|
+
if (isOpen) {
|
|
10670
|
+
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
10671
|
+
setData(null);
|
|
10672
|
+
} else {
|
|
10673
|
+
setIsOpen(STACKED_FOCUS_MODAL_ID, true);
|
|
10674
|
+
setData({
|
|
10675
|
+
shippingProfileId,
|
|
10676
|
+
shippingOption,
|
|
10677
|
+
shippingMethod
|
|
10678
|
+
});
|
|
10679
|
+
}
|
|
10680
|
+
};
|
|
10681
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10682
|
+
ui.Button,
|
|
10683
|
+
{
|
|
10684
|
+
size: "small",
|
|
10685
|
+
variant: "secondary",
|
|
10686
|
+
onClick: onToggle,
|
|
10687
|
+
className: "text-ui-fg-primary shrink-0",
|
|
10688
|
+
children
|
|
10689
|
+
}
|
|
10690
|
+
);
|
|
10691
|
+
};
|
|
10692
|
+
const ShippingProfileForm = ({
|
|
10693
|
+
data,
|
|
10694
|
+
order,
|
|
10695
|
+
preview
|
|
10696
|
+
}) => {
|
|
10697
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10698
|
+
const { setIsOpen } = useStackedModal();
|
|
10699
|
+
const form = reactHookForm.useForm({
|
|
10700
|
+
resolver: zod.zodResolver(shippingMethodSchema),
|
|
10701
|
+
defaultValues: {
|
|
10702
|
+
location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
|
|
10703
|
+
shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
|
|
10704
|
+
custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
|
|
10705
|
+
}
|
|
10706
|
+
});
|
|
10707
|
+
const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
|
|
10708
|
+
const {
|
|
10709
|
+
mutateAsync: updateShippingMethod,
|
|
10710
|
+
isPending: isUpdatingShippingMethod
|
|
10711
|
+
} = useDraftOrderUpdateShippingMethod(order.id);
|
|
10712
|
+
const onSubmit = form.handleSubmit(async (values) => {
|
|
10713
|
+
if (lodash.isEqual(values, form.formState.defaultValues)) {
|
|
10714
|
+
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
10715
|
+
return;
|
|
10716
|
+
}
|
|
10717
|
+
if (data.shippingMethod) {
|
|
10718
|
+
await updateShippingMethod(
|
|
10719
|
+
{
|
|
10720
|
+
method_id: data.shippingMethod.id,
|
|
10721
|
+
shipping_option_id: values.shipping_option_id,
|
|
10722
|
+
custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
|
|
10723
|
+
},
|
|
10724
|
+
{
|
|
10725
|
+
onError: (e) => {
|
|
10726
|
+
ui.toast.error(e.message);
|
|
10727
|
+
},
|
|
10728
|
+
onSuccess: () => {
|
|
10729
|
+
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
10730
|
+
}
|
|
10731
|
+
}
|
|
10732
|
+
);
|
|
10733
|
+
return;
|
|
10734
|
+
}
|
|
10735
|
+
await addShippingMethod(
|
|
10736
|
+
{
|
|
10737
|
+
shipping_option_id: values.shipping_option_id,
|
|
10738
|
+
custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
|
|
10739
|
+
},
|
|
10740
|
+
{
|
|
10741
|
+
onError: (e) => {
|
|
10742
|
+
ui.toast.error(e.message);
|
|
10743
|
+
},
|
|
10744
|
+
onSuccess: () => {
|
|
10745
|
+
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
10746
|
+
}
|
|
10747
|
+
}
|
|
10748
|
+
);
|
|
10749
|
+
});
|
|
10750
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10751
|
+
KeyboundForm,
|
|
10752
|
+
{
|
|
10753
|
+
className: "flex h-full flex-col overflow-hidden",
|
|
10754
|
+
onSubmit,
|
|
10755
|
+
children: [
|
|
10756
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
|
|
10757
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10758
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10759
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
10760
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
|
|
10761
|
+
] }),
|
|
10762
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10763
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10764
|
+
LocationField,
|
|
10765
|
+
{
|
|
10766
|
+
control: form.control,
|
|
10767
|
+
setValue: form.setValue
|
|
10768
|
+
}
|
|
10769
|
+
),
|
|
10770
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10771
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10772
|
+
ShippingOptionField,
|
|
10773
|
+
{
|
|
10774
|
+
shippingProfileId: data.shippingProfileId,
|
|
10775
|
+
preview,
|
|
10776
|
+
control: form.control
|
|
10777
|
+
}
|
|
10778
|
+
),
|
|
10779
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10780
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10781
|
+
CustomAmountField,
|
|
10782
|
+
{
|
|
10783
|
+
control: form.control,
|
|
10784
|
+
currencyCode: order.currency_code
|
|
10785
|
+
}
|
|
10786
|
+
),
|
|
10787
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10788
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10789
|
+
ItemsPreview,
|
|
10790
|
+
{
|
|
10791
|
+
order,
|
|
10792
|
+
shippingProfileId: data.shippingProfileId
|
|
10793
|
+
}
|
|
10794
|
+
)
|
|
10795
|
+
] }) }) }),
|
|
10796
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
|
|
10797
|
+
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10798
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10799
|
+
ui.Button,
|
|
10800
|
+
{
|
|
10801
|
+
size: "small",
|
|
10802
|
+
type: "submit",
|
|
10803
|
+
isLoading: isPending || isUpdatingShippingMethod,
|
|
10804
|
+
children: data.shippingMethod ? "Update" : "Add"
|
|
10805
|
+
}
|
|
10806
|
+
)
|
|
10807
|
+
] }) })
|
|
10808
|
+
]
|
|
10809
|
+
}
|
|
10810
|
+
) }) });
|
|
10811
|
+
};
|
|
10812
|
+
const shippingMethodSchema = objectType({
|
|
10813
|
+
location_id: stringType(),
|
|
10814
|
+
shipping_option_id: stringType(),
|
|
10815
|
+
custom_amount: unionType([numberType(), stringType()]).optional()
|
|
10816
|
+
});
|
|
10817
|
+
const ItemsPreview = ({ order, shippingProfileId }) => {
|
|
10818
|
+
const matches = order.items.filter(
|
|
10819
|
+
(item) => {
|
|
10820
|
+
var _a, _b, _c;
|
|
10821
|
+
return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
|
|
10822
|
+
}
|
|
10823
|
+
);
|
|
10824
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10825
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10826
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
|
|
10827
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
|
|
10828
|
+
] }) }),
|
|
10829
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10830
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
|
|
10831
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10832
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
|
|
10833
|
+
] }),
|
|
10834
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
10835
|
+
"div",
|
|
10836
|
+
{
|
|
10837
|
+
className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
|
|
10838
|
+
children: [
|
|
10839
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
10840
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10841
|
+
Thumbnail,
|
|
10842
|
+
{
|
|
10843
|
+
thumbnail: item.thumbnail,
|
|
10844
|
+
alt: item.product_title ?? void 0
|
|
10845
|
+
}
|
|
10846
|
+
),
|
|
10847
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10848
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
10849
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
10850
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10851
|
+
ui.Text,
|
|
10852
|
+
{
|
|
10853
|
+
size: "small",
|
|
10854
|
+
leading: "compact",
|
|
10855
|
+
className: "text-ui-fg-subtle",
|
|
10856
|
+
children: [
|
|
10857
|
+
"(",
|
|
10858
|
+
item.variant_title,
|
|
10859
|
+
")"
|
|
10860
|
+
]
|
|
10861
|
+
}
|
|
10862
|
+
)
|
|
10863
|
+
] }),
|
|
10864
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10865
|
+
ui.Text,
|
|
10866
|
+
{
|
|
10867
|
+
size: "small",
|
|
10868
|
+
leading: "compact",
|
|
10869
|
+
className: "text-ui-fg-subtle",
|
|
10870
|
+
children: item.variant_sku
|
|
10871
|
+
}
|
|
10872
|
+
)
|
|
10873
|
+
] })
|
|
10874
|
+
] }),
|
|
10875
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
10876
|
+
ui.Text,
|
|
10877
|
+
{
|
|
10878
|
+
size: "small",
|
|
10879
|
+
leading: "compact",
|
|
10880
|
+
className: "text-ui-fg-subtle",
|
|
10881
|
+
children: [
|
|
10882
|
+
item.quantity,
|
|
10883
|
+
"x"
|
|
10884
|
+
]
|
|
10885
|
+
}
|
|
10886
|
+
)
|
|
10887
|
+
]
|
|
10888
|
+
},
|
|
10889
|
+
item.id
|
|
10890
|
+
)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
10891
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10892
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10893
|
+
'No items found for "',
|
|
10894
|
+
query,
|
|
10895
|
+
'".'
|
|
10896
|
+
] })
|
|
10897
|
+
] }) })
|
|
10898
|
+
] })
|
|
10899
|
+
] });
|
|
10900
|
+
};
|
|
10901
|
+
const LocationField = ({ control, setValue }) => {
|
|
10902
|
+
const locations = useComboboxData({
|
|
10903
|
+
queryKey: ["locations"],
|
|
10904
|
+
queryFn: async (params) => {
|
|
10905
|
+
return await sdk.admin.stockLocation.list(params);
|
|
10906
|
+
},
|
|
10907
|
+
getOptions: (data) => {
|
|
10908
|
+
return data.stock_locations.map((location) => ({
|
|
10909
|
+
label: location.name,
|
|
10910
|
+
value: location.id
|
|
10911
|
+
}));
|
|
10912
|
+
}
|
|
10913
|
+
});
|
|
10914
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10915
|
+
Form$2.Field,
|
|
10916
|
+
{
|
|
10917
|
+
control,
|
|
10918
|
+
name: "location_id",
|
|
10919
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
10920
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10921
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
10922
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
|
|
10923
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
|
|
10924
|
+
] }),
|
|
10925
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10926
|
+
Combobox,
|
|
10927
|
+
{
|
|
10928
|
+
options: locations.options,
|
|
10929
|
+
fetchNextPage: locations.fetchNextPage,
|
|
10930
|
+
isFetchingNextPage: locations.isFetchingNextPage,
|
|
10931
|
+
searchValue: locations.searchValue,
|
|
10932
|
+
onSearchValueChange: locations.onSearchValueChange,
|
|
10933
|
+
placeholder: "Select location",
|
|
10934
|
+
onChange: (value) => {
|
|
10935
|
+
setValue("shipping_option_id", "", {
|
|
10936
|
+
shouldDirty: true,
|
|
10937
|
+
shouldTouch: true
|
|
10938
|
+
});
|
|
10939
|
+
onChange(value);
|
|
10940
|
+
},
|
|
10941
|
+
...field
|
|
10952
10942
|
}
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10943
|
+
) })
|
|
10944
|
+
] }) });
|
|
10945
|
+
}
|
|
10946
|
+
}
|
|
10947
|
+
);
|
|
10948
|
+
};
|
|
10949
|
+
const ShippingOptionField = ({
|
|
10950
|
+
shippingProfileId,
|
|
10951
|
+
preview,
|
|
10952
|
+
control
|
|
10953
|
+
}) => {
|
|
10954
|
+
var _a;
|
|
10955
|
+
const locationId = reactHookForm.useWatch({ control, name: "location_id" });
|
|
10956
|
+
const shippingOptions = useComboboxData({
|
|
10957
|
+
queryKey: ["shipping_options", locationId, shippingProfileId],
|
|
10958
|
+
queryFn: async (params) => {
|
|
10959
|
+
return await sdk.admin.shippingOption.list({
|
|
10960
|
+
...params,
|
|
10961
|
+
stock_location_id: locationId,
|
|
10962
|
+
shipping_profile_id: shippingProfileId
|
|
10963
|
+
});
|
|
10964
|
+
},
|
|
10965
|
+
getOptions: (data) => {
|
|
10966
|
+
return data.shipping_options.map((option) => {
|
|
10967
|
+
var _a2;
|
|
10968
|
+
if ((_a2 = option.rules) == null ? void 0 : _a2.find(
|
|
10969
|
+
(r) => r.attribute === "is_return" && r.value === "true"
|
|
10970
|
+
)) {
|
|
10971
|
+
return void 0;
|
|
10972
|
+
}
|
|
10973
|
+
return {
|
|
10974
|
+
label: option.name,
|
|
10975
|
+
value: option.id
|
|
10976
|
+
};
|
|
10977
|
+
}).filter(Boolean);
|
|
10978
|
+
},
|
|
10979
|
+
enabled: !!locationId && !!shippingProfileId,
|
|
10980
|
+
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
10981
|
+
});
|
|
10982
|
+
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
10983
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
10984
|
+
Form$2.Field,
|
|
10985
|
+
{
|
|
10986
|
+
control,
|
|
10987
|
+
name: "shipping_option_id",
|
|
10988
|
+
render: ({ field }) => {
|
|
10989
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10990
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10991
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
|
|
10992
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
10993
|
+
] }),
|
|
10994
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10995
|
+
ConditionalTooltip,
|
|
10996
|
+
{
|
|
10997
|
+
content: tooltipContent,
|
|
10998
|
+
showTooltip: !locationId || !shippingProfileId,
|
|
10999
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11000
|
+
Combobox,
|
|
11001
|
+
{
|
|
11002
|
+
options: shippingOptions.options,
|
|
11003
|
+
fetchNextPage: shippingOptions.fetchNextPage,
|
|
11004
|
+
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
11005
|
+
searchValue: shippingOptions.searchValue,
|
|
11006
|
+
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
11007
|
+
placeholder: "Select shipping option",
|
|
11008
|
+
...field,
|
|
11009
|
+
disabled: !locationId || !shippingProfileId
|
|
11010
|
+
}
|
|
11011
|
+
) }) })
|
|
11012
|
+
}
|
|
11013
|
+
)
|
|
11014
|
+
] }) });
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
);
|
|
11018
|
+
};
|
|
11019
|
+
const CustomAmountField = ({
|
|
11020
|
+
control,
|
|
11021
|
+
currencyCode
|
|
11022
|
+
}) => {
|
|
11023
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11024
|
+
Form$2.Field,
|
|
11025
|
+
{
|
|
11026
|
+
control,
|
|
11027
|
+
name: "custom_amount",
|
|
11028
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
11029
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11030
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11031
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
11032
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
11033
|
+
] }),
|
|
11034
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11035
|
+
ui.CurrencyInput,
|
|
11036
|
+
{
|
|
11037
|
+
...field,
|
|
11038
|
+
onValueChange: (value) => onChange(value),
|
|
11039
|
+
symbol: getNativeSymbol(currencyCode),
|
|
11040
|
+
code: currencyCode
|
|
11041
|
+
}
|
|
11042
|
+
) })
|
|
11043
|
+
] });
|
|
11044
|
+
}
|
|
11045
|
+
}
|
|
11046
|
+
);
|
|
11047
|
+
};
|
|
11048
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11049
|
+
const promotionsQueryKeys = {
|
|
11050
|
+
list: (query2) => [
|
|
11051
|
+
PROMOTION_QUERY_KEY,
|
|
11052
|
+
query2 ? query2 : void 0
|
|
11053
|
+
],
|
|
11054
|
+
detail: (id, query2) => [
|
|
11055
|
+
PROMOTION_QUERY_KEY,
|
|
11056
|
+
id,
|
|
11057
|
+
query2 ? query2 : void 0
|
|
11058
|
+
]
|
|
11059
|
+
};
|
|
11060
|
+
const usePromotions = (query2, options) => {
|
|
11061
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11062
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11063
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11064
|
+
...options
|
|
11065
|
+
});
|
|
11066
|
+
return { ...data, ...rest };
|
|
11067
|
+
};
|
|
11068
|
+
const Promotions = () => {
|
|
11069
|
+
const { id } = reactRouterDom.useParams();
|
|
11070
|
+
const {
|
|
11071
|
+
order: preview,
|
|
11072
|
+
isError: isPreviewError,
|
|
11073
|
+
error: previewError
|
|
11074
|
+
} = useOrderPreview(id, void 0);
|
|
11075
|
+
useInitiateOrderEdit({ preview });
|
|
11076
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11077
|
+
if (isPreviewError) {
|
|
11078
|
+
throw previewError;
|
|
11079
|
+
}
|
|
11080
|
+
const isReady = !!preview;
|
|
11081
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11082
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11083
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11084
|
+
] });
|
|
11085
|
+
};
|
|
11086
|
+
const PromotionForm = ({ preview }) => {
|
|
11087
|
+
const { items, shipping_methods } = preview;
|
|
11088
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11089
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11090
|
+
const { handleSuccess } = useRouteModal();
|
|
11091
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11092
|
+
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
11093
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11094
|
+
{
|
|
11095
|
+
code: promoCodes
|
|
11096
|
+
},
|
|
11097
|
+
{
|
|
11098
|
+
enabled: !!promoCodes.length
|
|
11099
|
+
}
|
|
11100
|
+
);
|
|
11101
|
+
const comboboxData = useComboboxData({
|
|
11102
|
+
queryKey: ["promotions", "combobox", promoCodes],
|
|
11103
|
+
queryFn: async (params) => {
|
|
11104
|
+
return await sdk.admin.promotion.list({
|
|
11105
|
+
...params,
|
|
11106
|
+
code: {
|
|
11107
|
+
$nin: promoCodes
|
|
10956
11108
|
}
|
|
10957
|
-
)
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
11109
|
+
});
|
|
11110
|
+
},
|
|
11111
|
+
getOptions: (data) => {
|
|
11112
|
+
return data.promotions.map((promotion) => ({
|
|
11113
|
+
label: promotion.code,
|
|
11114
|
+
value: promotion.code
|
|
11115
|
+
}));
|
|
11116
|
+
}
|
|
11117
|
+
});
|
|
11118
|
+
const add = async (value) => {
|
|
11119
|
+
if (!value) {
|
|
11120
|
+
return;
|
|
11121
|
+
}
|
|
11122
|
+
addPromotions(
|
|
11123
|
+
{
|
|
11124
|
+
promo_codes: [value]
|
|
11125
|
+
},
|
|
11126
|
+
{
|
|
11127
|
+
onError: (e) => {
|
|
11128
|
+
ui.toast.error(e.message);
|
|
11129
|
+
comboboxData.onSearchValueChange("");
|
|
11130
|
+
setComboboxValue("");
|
|
11131
|
+
},
|
|
11132
|
+
onSuccess: () => {
|
|
11133
|
+
comboboxData.onSearchValueChange("");
|
|
11134
|
+
setComboboxValue("");
|
|
11135
|
+
}
|
|
11136
|
+
}
|
|
11137
|
+
);
|
|
11138
|
+
};
|
|
11139
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11140
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11141
|
+
const onSubmit = async () => {
|
|
11142
|
+
setIsSubmitting(true);
|
|
11143
|
+
let requestSucceeded = false;
|
|
11144
|
+
await requestOrderEdit(void 0, {
|
|
11145
|
+
onError: (e) => {
|
|
11146
|
+
ui.toast.error(e.message);
|
|
11147
|
+
},
|
|
11148
|
+
onSuccess: () => {
|
|
11149
|
+
requestSucceeded = true;
|
|
11150
|
+
}
|
|
11151
|
+
});
|
|
11152
|
+
if (!requestSucceeded) {
|
|
11153
|
+
setIsSubmitting(false);
|
|
11154
|
+
return;
|
|
11155
|
+
}
|
|
11156
|
+
await confirmOrderEdit(void 0, {
|
|
11157
|
+
onError: (e) => {
|
|
11158
|
+
ui.toast.error(e.message);
|
|
11159
|
+
},
|
|
11160
|
+
onSuccess: () => {
|
|
11161
|
+
handleSuccess();
|
|
11162
|
+
},
|
|
11163
|
+
onSettled: () => {
|
|
11164
|
+
setIsSubmitting(false);
|
|
11165
|
+
}
|
|
11166
|
+
});
|
|
11167
|
+
};
|
|
11168
|
+
if (isError) {
|
|
11169
|
+
throw error;
|
|
11170
|
+
}
|
|
11171
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11172
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11173
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11174
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11175
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11176
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11177
|
+
] }),
|
|
11178
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11179
|
+
Combobox,
|
|
11180
|
+
{
|
|
11181
|
+
id: "promotion-combobox",
|
|
11182
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11183
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11184
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11185
|
+
options: comboboxData.options,
|
|
11186
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11187
|
+
searchValue: comboboxData.searchValue,
|
|
11188
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11189
|
+
onChange: add,
|
|
11190
|
+
value: comboboxValue
|
|
11191
|
+
}
|
|
11192
|
+
)
|
|
11193
|
+
] }),
|
|
11194
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11195
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11196
|
+
PromotionItem,
|
|
11197
|
+
{
|
|
11198
|
+
promotion,
|
|
11199
|
+
orderId: preview.id,
|
|
11200
|
+
isLoading: isPending
|
|
11201
|
+
},
|
|
11202
|
+
promotion.id
|
|
11203
|
+
)) })
|
|
11204
|
+
] }) }),
|
|
11205
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11206
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10961
11207
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10962
11208
|
ui.Button,
|
|
10963
11209
|
{
|
|
10964
11210
|
size: "small",
|
|
10965
|
-
type: "
|
|
10966
|
-
isLoading: isSubmitting,
|
|
10967
|
-
onClick: onSubmit,
|
|
11211
|
+
type: "submit",
|
|
11212
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10968
11213
|
children: "Save"
|
|
10969
11214
|
}
|
|
10970
11215
|
)
|
|
10971
11216
|
] }) })
|
|
10972
11217
|
] });
|
|
10973
11218
|
};
|
|
10974
|
-
const
|
|
10975
|
-
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
setData,
|
|
10979
|
-
children
|
|
11219
|
+
const PromotionItem = ({
|
|
11220
|
+
promotion,
|
|
11221
|
+
orderId,
|
|
11222
|
+
isLoading
|
|
10980
11223
|
}) => {
|
|
10981
|
-
|
|
10982
|
-
const
|
|
10983
|
-
const
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
}
|
|
11224
|
+
var _a;
|
|
11225
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11226
|
+
const onRemove = async () => {
|
|
11227
|
+
removePromotions(
|
|
11228
|
+
{
|
|
11229
|
+
promo_codes: [promotion.code]
|
|
11230
|
+
},
|
|
11231
|
+
{
|
|
11232
|
+
onError: (e) => {
|
|
11233
|
+
ui.toast.error(e.message);
|
|
11234
|
+
}
|
|
11235
|
+
}
|
|
11236
|
+
);
|
|
10995
11237
|
};
|
|
10996
|
-
|
|
10997
|
-
|
|
11238
|
+
const displayValue = getDisplayValue(promotion);
|
|
11239
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11240
|
+
"div",
|
|
10998
11241
|
{
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
onClick: onToggle,
|
|
11002
|
-
className: "text-ui-fg-primary shrink-0",
|
|
11003
|
-
children
|
|
11004
|
-
}
|
|
11005
|
-
);
|
|
11006
|
-
};
|
|
11007
|
-
const ShippingProfileForm = ({
|
|
11008
|
-
data,
|
|
11009
|
-
order,
|
|
11010
|
-
preview
|
|
11011
|
-
}) => {
|
|
11012
|
-
var _a, _b, _c, _d, _e, _f;
|
|
11013
|
-
const { setIsOpen } = useStackedModal();
|
|
11014
|
-
const form = reactHookForm.useForm({
|
|
11015
|
-
resolver: zod.zodResolver(shippingMethodSchema),
|
|
11016
|
-
defaultValues: {
|
|
11017
|
-
location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
|
|
11018
|
-
shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
|
|
11019
|
-
custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
|
|
11020
|
-
}
|
|
11021
|
-
});
|
|
11022
|
-
const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
|
|
11023
|
-
const {
|
|
11024
|
-
mutateAsync: updateShippingMethod,
|
|
11025
|
-
isPending: isUpdatingShippingMethod
|
|
11026
|
-
} = useDraftOrderUpdateShippingMethod(order.id);
|
|
11027
|
-
const onSubmit = form.handleSubmit(async (values) => {
|
|
11028
|
-
if (lodash.isEqual(values, form.formState.defaultValues)) {
|
|
11029
|
-
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
11030
|
-
return;
|
|
11031
|
-
}
|
|
11032
|
-
if (data.shippingMethod) {
|
|
11033
|
-
await updateShippingMethod(
|
|
11034
|
-
{
|
|
11035
|
-
method_id: data.shippingMethod.id,
|
|
11036
|
-
shipping_option_id: values.shipping_option_id,
|
|
11037
|
-
custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
|
|
11038
|
-
},
|
|
11242
|
+
className: ui.clx(
|
|
11243
|
+
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
11039
11244
|
{
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11245
|
+
"animate-pulse": isLoading
|
|
11246
|
+
}
|
|
11247
|
+
),
|
|
11248
|
+
children: [
|
|
11249
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11250
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11251
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
11252
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11253
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11254
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11255
|
+
] }),
|
|
11256
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11257
|
+
] })
|
|
11258
|
+
] }),
|
|
11259
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11260
|
+
ui.IconButton,
|
|
11261
|
+
{
|
|
11262
|
+
size: "small",
|
|
11263
|
+
type: "button",
|
|
11264
|
+
variant: "transparent",
|
|
11265
|
+
onClick: onRemove,
|
|
11266
|
+
isLoading: isPending || isLoading,
|
|
11267
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11045
11268
|
}
|
|
11269
|
+
)
|
|
11270
|
+
]
|
|
11271
|
+
},
|
|
11272
|
+
promotion.id
|
|
11273
|
+
);
|
|
11274
|
+
};
|
|
11275
|
+
function getDisplayValue(promotion) {
|
|
11276
|
+
var _a, _b, _c, _d;
|
|
11277
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11278
|
+
if (!value) {
|
|
11279
|
+
return null;
|
|
11280
|
+
}
|
|
11281
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11282
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11283
|
+
if (!currency) {
|
|
11284
|
+
return null;
|
|
11285
|
+
}
|
|
11286
|
+
return getLocaleAmount(value, currency);
|
|
11287
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11288
|
+
return formatPercentage(value);
|
|
11289
|
+
}
|
|
11290
|
+
return null;
|
|
11291
|
+
}
|
|
11292
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11293
|
+
style: "percent",
|
|
11294
|
+
minimumFractionDigits: 2
|
|
11295
|
+
});
|
|
11296
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11297
|
+
let val = value || 0;
|
|
11298
|
+
if (!isPercentageValue) {
|
|
11299
|
+
val = val / 100;
|
|
11300
|
+
}
|
|
11301
|
+
return formatter.format(val);
|
|
11302
|
+
};
|
|
11303
|
+
function getPromotionCodes(items, shippingMethods) {
|
|
11304
|
+
const codes = /* @__PURE__ */ new Set();
|
|
11305
|
+
for (const item of items) {
|
|
11306
|
+
if (item.adjustments) {
|
|
11307
|
+
for (const adjustment of item.adjustments) {
|
|
11308
|
+
if (adjustment.code) {
|
|
11309
|
+
codes.add(adjustment.code);
|
|
11046
11310
|
}
|
|
11047
|
-
|
|
11048
|
-
return;
|
|
11311
|
+
}
|
|
11049
11312
|
}
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
onError: (e) => {
|
|
11057
|
-
ui.toast.error(e.message);
|
|
11058
|
-
},
|
|
11059
|
-
onSuccess: () => {
|
|
11060
|
-
setIsOpen(STACKED_FOCUS_MODAL_ID, false);
|
|
11313
|
+
}
|
|
11314
|
+
for (const shippingMethod of shippingMethods) {
|
|
11315
|
+
if (shippingMethod.adjustments) {
|
|
11316
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11317
|
+
if (adjustment.code) {
|
|
11318
|
+
codes.add(adjustment.code);
|
|
11061
11319
|
}
|
|
11062
11320
|
}
|
|
11063
|
-
);
|
|
11064
|
-
});
|
|
11065
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11066
|
-
KeyboundForm,
|
|
11067
|
-
{
|
|
11068
|
-
className: "flex h-full flex-col overflow-hidden",
|
|
11069
|
-
onSubmit,
|
|
11070
|
-
children: [
|
|
11071
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
|
|
11072
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
11073
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11074
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
|
|
11075
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
|
|
11076
|
-
] }),
|
|
11077
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11078
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11079
|
-
LocationField,
|
|
11080
|
-
{
|
|
11081
|
-
control: form.control,
|
|
11082
|
-
setValue: form.setValue
|
|
11083
|
-
}
|
|
11084
|
-
),
|
|
11085
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11086
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11087
|
-
ShippingOptionField,
|
|
11088
|
-
{
|
|
11089
|
-
shippingProfileId: data.shippingProfileId,
|
|
11090
|
-
preview,
|
|
11091
|
-
control: form.control
|
|
11092
|
-
}
|
|
11093
|
-
),
|
|
11094
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11095
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11096
|
-
CustomAmountField,
|
|
11097
|
-
{
|
|
11098
|
-
control: form.control,
|
|
11099
|
-
currencyCode: order.currency_code
|
|
11100
|
-
}
|
|
11101
|
-
),
|
|
11102
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11103
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11104
|
-
ItemsPreview,
|
|
11105
|
-
{
|
|
11106
|
-
order,
|
|
11107
|
-
shippingProfileId: data.shippingProfileId
|
|
11108
|
-
}
|
|
11109
|
-
)
|
|
11110
|
-
] }) }) }),
|
|
11111
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
|
|
11112
|
-
/* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11113
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11114
|
-
ui.Button,
|
|
11115
|
-
{
|
|
11116
|
-
size: "small",
|
|
11117
|
-
type: "submit",
|
|
11118
|
-
isLoading: isPending || isUpdatingShippingMethod,
|
|
11119
|
-
children: data.shippingMethod ? "Update" : "Add"
|
|
11120
|
-
}
|
|
11121
|
-
)
|
|
11122
|
-
] }) })
|
|
11123
|
-
]
|
|
11124
11321
|
}
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11322
|
+
}
|
|
11323
|
+
return Array.from(codes);
|
|
11324
|
+
}
|
|
11325
|
+
const SalesChannel = () => {
|
|
11326
|
+
const { id } = reactRouterDom.useParams();
|
|
11327
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11328
|
+
id,
|
|
11329
|
+
{
|
|
11330
|
+
fields: "+sales_channel_id"
|
|
11331
|
+
},
|
|
11332
|
+
{
|
|
11333
|
+
enabled: !!id
|
|
11137
11334
|
}
|
|
11138
11335
|
);
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11145
|
-
/* @__PURE__ */ jsxRuntime.
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11150
|
-
"div",
|
|
11151
|
-
{
|
|
11152
|
-
className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
|
|
11153
|
-
children: [
|
|
11154
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
11155
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11156
|
-
Thumbnail,
|
|
11157
|
-
{
|
|
11158
|
-
thumbnail: item.thumbnail,
|
|
11159
|
-
alt: item.product_title ?? void 0
|
|
11160
|
-
}
|
|
11161
|
-
),
|
|
11162
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11163
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
11164
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
11165
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11166
|
-
ui.Text,
|
|
11167
|
-
{
|
|
11168
|
-
size: "small",
|
|
11169
|
-
leading: "compact",
|
|
11170
|
-
className: "text-ui-fg-subtle",
|
|
11171
|
-
children: [
|
|
11172
|
-
"(",
|
|
11173
|
-
item.variant_title,
|
|
11174
|
-
")"
|
|
11175
|
-
]
|
|
11176
|
-
}
|
|
11177
|
-
)
|
|
11178
|
-
] }),
|
|
11179
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11180
|
-
ui.Text,
|
|
11181
|
-
{
|
|
11182
|
-
size: "small",
|
|
11183
|
-
leading: "compact",
|
|
11184
|
-
className: "text-ui-fg-subtle",
|
|
11185
|
-
children: item.variant_sku
|
|
11186
|
-
}
|
|
11187
|
-
)
|
|
11188
|
-
] })
|
|
11189
|
-
] }),
|
|
11190
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11191
|
-
ui.Text,
|
|
11192
|
-
{
|
|
11193
|
-
size: "small",
|
|
11194
|
-
leading: "compact",
|
|
11195
|
-
className: "text-ui-fg-subtle",
|
|
11196
|
-
children: [
|
|
11197
|
-
item.quantity,
|
|
11198
|
-
"x"
|
|
11199
|
-
]
|
|
11200
|
-
}
|
|
11201
|
-
)
|
|
11202
|
-
]
|
|
11203
|
-
},
|
|
11204
|
-
item.id
|
|
11205
|
-
)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
11206
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
11207
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
11208
|
-
'No items found for "',
|
|
11209
|
-
query,
|
|
11210
|
-
'".'
|
|
11211
|
-
] })
|
|
11212
|
-
] }) })
|
|
11213
|
-
] })
|
|
11336
|
+
if (isError) {
|
|
11337
|
+
throw error;
|
|
11338
|
+
}
|
|
11339
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11340
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11341
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11342
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11343
|
+
/* @__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" }) })
|
|
11344
|
+
] }),
|
|
11345
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11214
11346
|
] });
|
|
11215
11347
|
};
|
|
11216
|
-
const
|
|
11217
|
-
const
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
return await sdk.admin.stockLocation.list(params);
|
|
11348
|
+
const SalesChannelForm = ({ order }) => {
|
|
11349
|
+
const form = reactHookForm.useForm({
|
|
11350
|
+
defaultValues: {
|
|
11351
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11221
11352
|
},
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11353
|
+
resolver: zod.zodResolver(schema$2)
|
|
11354
|
+
});
|
|
11355
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11356
|
+
const { handleSuccess } = useRouteModal();
|
|
11357
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11358
|
+
await mutateAsync(
|
|
11359
|
+
{
|
|
11360
|
+
sales_channel_id: data.sales_channel_id
|
|
11361
|
+
},
|
|
11362
|
+
{
|
|
11363
|
+
onSuccess: () => {
|
|
11364
|
+
ui.toast.success("Sales channel updated");
|
|
11365
|
+
handleSuccess();
|
|
11366
|
+
},
|
|
11367
|
+
onError: (error) => {
|
|
11368
|
+
ui.toast.error(error.message);
|
|
11369
|
+
}
|
|
11370
|
+
}
|
|
11371
|
+
);
|
|
11228
11372
|
});
|
|
11229
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11230
|
-
|
|
11373
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11374
|
+
KeyboundForm,
|
|
11231
11375
|
{
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
Combobox,
|
|
11242
|
-
{
|
|
11243
|
-
options: locations.options,
|
|
11244
|
-
fetchNextPage: locations.fetchNextPage,
|
|
11245
|
-
isFetchingNextPage: locations.isFetchingNextPage,
|
|
11246
|
-
searchValue: locations.searchValue,
|
|
11247
|
-
onSearchValueChange: locations.onSearchValueChange,
|
|
11248
|
-
placeholder: "Select location",
|
|
11249
|
-
onChange: (value) => {
|
|
11250
|
-
setValue("shipping_option_id", "", {
|
|
11251
|
-
shouldDirty: true,
|
|
11252
|
-
shouldTouch: true
|
|
11253
|
-
});
|
|
11254
|
-
onChange(value);
|
|
11255
|
-
},
|
|
11256
|
-
...field
|
|
11257
|
-
}
|
|
11258
|
-
) })
|
|
11259
|
-
] }) });
|
|
11260
|
-
}
|
|
11376
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11377
|
+
onSubmit,
|
|
11378
|
+
children: [
|
|
11379
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11380
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11381
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11382
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11383
|
+
] }) })
|
|
11384
|
+
]
|
|
11261
11385
|
}
|
|
11262
|
-
);
|
|
11386
|
+
) });
|
|
11263
11387
|
};
|
|
11264
|
-
const
|
|
11265
|
-
|
|
11266
|
-
preview,
|
|
11267
|
-
control
|
|
11268
|
-
}) => {
|
|
11269
|
-
var _a;
|
|
11270
|
-
const locationId = reactHookForm.useWatch({ control, name: "location_id" });
|
|
11271
|
-
const shippingOptions = useComboboxData({
|
|
11272
|
-
queryKey: ["shipping_options", locationId, shippingProfileId],
|
|
11388
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11389
|
+
const salesChannels = useComboboxData({
|
|
11273
11390
|
queryFn: async (params) => {
|
|
11274
|
-
return await sdk.admin.
|
|
11275
|
-
...params,
|
|
11276
|
-
stock_location_id: locationId,
|
|
11277
|
-
shipping_profile_id: shippingProfileId
|
|
11278
|
-
});
|
|
11391
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11279
11392
|
},
|
|
11393
|
+
queryKey: ["sales-channels"],
|
|
11280
11394
|
getOptions: (data) => {
|
|
11281
|
-
return data.
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
)) {
|
|
11286
|
-
return void 0;
|
|
11287
|
-
}
|
|
11288
|
-
return {
|
|
11289
|
-
label: option.name,
|
|
11290
|
-
value: option.id
|
|
11291
|
-
};
|
|
11292
|
-
}).filter(Boolean);
|
|
11395
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11396
|
+
label: salesChannel.name,
|
|
11397
|
+
value: salesChannel.id
|
|
11398
|
+
}));
|
|
11293
11399
|
},
|
|
11294
|
-
|
|
11295
|
-
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
11400
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11296
11401
|
});
|
|
11297
|
-
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
11298
11402
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11299
11403
|
Form$2.Field,
|
|
11300
11404
|
{
|
|
11301
11405
|
control,
|
|
11302
|
-
name: "
|
|
11406
|
+
name: "sales_channel_id",
|
|
11303
11407
|
render: ({ field }) => {
|
|
11304
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
11305
|
-
/* @__PURE__ */ jsxRuntime.
|
|
11306
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
|
|
11307
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
11308
|
-
] }),
|
|
11309
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11310
|
-
ConditionalTooltip,
|
|
11311
|
-
{
|
|
11312
|
-
content: tooltipContent,
|
|
11313
|
-
showTooltip: !locationId || !shippingProfileId,
|
|
11314
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11315
|
-
Combobox,
|
|
11316
|
-
{
|
|
11317
|
-
options: shippingOptions.options,
|
|
11318
|
-
fetchNextPage: shippingOptions.fetchNextPage,
|
|
11319
|
-
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
11320
|
-
searchValue: shippingOptions.searchValue,
|
|
11321
|
-
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
11322
|
-
placeholder: "Select shipping option",
|
|
11323
|
-
...field,
|
|
11324
|
-
disabled: !locationId || !shippingProfileId
|
|
11325
|
-
}
|
|
11326
|
-
) }) })
|
|
11327
|
-
}
|
|
11328
|
-
)
|
|
11329
|
-
] }) });
|
|
11330
|
-
}
|
|
11331
|
-
}
|
|
11332
|
-
);
|
|
11333
|
-
};
|
|
11334
|
-
const CustomAmountField = ({
|
|
11335
|
-
control,
|
|
11336
|
-
currencyCode
|
|
11337
|
-
}) => {
|
|
11338
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11339
|
-
Form$2.Field,
|
|
11340
|
-
{
|
|
11341
|
-
control,
|
|
11342
|
-
name: "custom_amount",
|
|
11343
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
11344
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
11345
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11346
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
11347
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
11348
|
-
] }),
|
|
11408
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11409
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11349
11410
|
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11350
|
-
|
|
11411
|
+
Combobox,
|
|
11351
11412
|
{
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
|
|
11355
|
-
|
|
11413
|
+
options: salesChannels.options,
|
|
11414
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11415
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11416
|
+
searchValue: salesChannels.searchValue,
|
|
11417
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11418
|
+
placeholder: "Select sales channel",
|
|
11419
|
+
...field
|
|
11356
11420
|
}
|
|
11357
|
-
) })
|
|
11421
|
+
) }),
|
|
11422
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11358
11423
|
] });
|
|
11359
11424
|
}
|
|
11360
11425
|
}
|
|
11361
11426
|
);
|
|
11362
11427
|
};
|
|
11428
|
+
const schema$2 = objectType({
|
|
11429
|
+
sales_channel_id: stringType().min(1)
|
|
11430
|
+
});
|
|
11363
11431
|
const ShippingAddress = () => {
|
|
11364
11432
|
const { id } = reactRouterDom.useParams();
|
|
11365
11433
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -11392,7 +11460,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11392
11460
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11393
11461
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
11394
11462
|
},
|
|
11395
|
-
resolver: zod.zodResolver(schema$
|
|
11463
|
+
resolver: zod.zodResolver(schema$1)
|
|
11396
11464
|
});
|
|
11397
11465
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11398
11466
|
const { handleSuccess } = useRouteModal();
|
|
@@ -11562,7 +11630,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
11562
11630
|
}
|
|
11563
11631
|
) });
|
|
11564
11632
|
};
|
|
11565
|
-
const schema$
|
|
11633
|
+
const schema$1 = addressSchema;
|
|
11566
11634
|
const TransferOwnership = () => {
|
|
11567
11635
|
const { id } = reactRouterDom.useParams();
|
|
11568
11636
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -11586,7 +11654,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
11586
11654
|
defaultValues: {
|
|
11587
11655
|
customer_id: order.customer_id || ""
|
|
11588
11656
|
},
|
|
11589
|
-
resolver: zod.zodResolver(schema
|
|
11657
|
+
resolver: zod.zodResolver(schema)
|
|
11590
11658
|
});
|
|
11591
11659
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11592
11660
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12036,76 +12104,8 @@ const Illustration = () => {
|
|
|
12036
12104
|
}
|
|
12037
12105
|
);
|
|
12038
12106
|
};
|
|
12039
|
-
const schema$1 = objectType({
|
|
12040
|
-
customer_id: stringType().min(1)
|
|
12041
|
-
});
|
|
12042
|
-
const Email = () => {
|
|
12043
|
-
const { id } = reactRouterDom.useParams();
|
|
12044
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
12045
|
-
fields: "+email"
|
|
12046
|
-
});
|
|
12047
|
-
if (isError) {
|
|
12048
|
-
throw error;
|
|
12049
|
-
}
|
|
12050
|
-
const isReady = !isPending && !!order;
|
|
12051
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12052
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12053
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
|
|
12054
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
12055
|
-
] }),
|
|
12056
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
|
|
12057
|
-
] });
|
|
12058
|
-
};
|
|
12059
|
-
const EmailForm = ({ order }) => {
|
|
12060
|
-
const form = reactHookForm.useForm({
|
|
12061
|
-
defaultValues: {
|
|
12062
|
-
email: order.email ?? ""
|
|
12063
|
-
},
|
|
12064
|
-
resolver: zod.zodResolver(schema)
|
|
12065
|
-
});
|
|
12066
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12067
|
-
const { handleSuccess } = useRouteModal();
|
|
12068
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12069
|
-
await mutateAsync(
|
|
12070
|
-
{ email: data.email },
|
|
12071
|
-
{
|
|
12072
|
-
onSuccess: () => {
|
|
12073
|
-
handleSuccess();
|
|
12074
|
-
},
|
|
12075
|
-
onError: (error) => {
|
|
12076
|
-
ui.toast.error(error.message);
|
|
12077
|
-
}
|
|
12078
|
-
}
|
|
12079
|
-
);
|
|
12080
|
-
});
|
|
12081
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12082
|
-
KeyboundForm,
|
|
12083
|
-
{
|
|
12084
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12085
|
-
onSubmit,
|
|
12086
|
-
children: [
|
|
12087
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12088
|
-
Form$2.Field,
|
|
12089
|
-
{
|
|
12090
|
-
control: form.control,
|
|
12091
|
-
name: "email",
|
|
12092
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12093
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
|
|
12094
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
|
|
12095
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12096
|
-
] })
|
|
12097
|
-
}
|
|
12098
|
-
) }),
|
|
12099
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12100
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12101
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12102
|
-
] }) })
|
|
12103
|
-
]
|
|
12104
|
-
}
|
|
12105
|
-
) });
|
|
12106
|
-
};
|
|
12107
12107
|
const schema = objectType({
|
|
12108
|
-
|
|
12108
|
+
customer_id: stringType().min(1)
|
|
12109
12109
|
});
|
|
12110
12110
|
const NumberInput = React.forwardRef(
|
|
12111
12111
|
({
|
|
@@ -13052,18 +13052,26 @@ const routeModule = {
|
|
|
13052
13052
|
handle,
|
|
13053
13053
|
loader,
|
|
13054
13054
|
children: [
|
|
13055
|
+
{
|
|
13056
|
+
Component: CustomItems,
|
|
13057
|
+
path: "/draft-orders/:id/custom-items"
|
|
13058
|
+
},
|
|
13055
13059
|
{
|
|
13056
13060
|
Component: BillingAddress,
|
|
13057
13061
|
path: "/draft-orders/:id/billing-address"
|
|
13058
13062
|
},
|
|
13059
13063
|
{
|
|
13060
|
-
Component:
|
|
13061
|
-
path: "/draft-orders/:id/
|
|
13064
|
+
Component: Email,
|
|
13065
|
+
path: "/draft-orders/:id/email"
|
|
13062
13066
|
},
|
|
13063
13067
|
{
|
|
13064
13068
|
Component: Metadata,
|
|
13065
13069
|
path: "/draft-orders/:id/metadata"
|
|
13066
13070
|
},
|
|
13071
|
+
{
|
|
13072
|
+
Component: Shipping,
|
|
13073
|
+
path: "/draft-orders/:id/shipping"
|
|
13074
|
+
},
|
|
13067
13075
|
{
|
|
13068
13076
|
Component: Promotions,
|
|
13069
13077
|
path: "/draft-orders/:id/promotions"
|
|
@@ -13072,10 +13080,6 @@ const routeModule = {
|
|
|
13072
13080
|
Component: SalesChannel,
|
|
13073
13081
|
path: "/draft-orders/:id/sales-channel"
|
|
13074
13082
|
},
|
|
13075
|
-
{
|
|
13076
|
-
Component: Shipping,
|
|
13077
|
-
path: "/draft-orders/:id/shipping"
|
|
13078
|
-
},
|
|
13079
13083
|
{
|
|
13080
13084
|
Component: ShippingAddress,
|
|
13081
13085
|
path: "/draft-orders/:id/shipping-address"
|
|
@@ -13084,10 +13088,6 @@ const routeModule = {
|
|
|
13084
13088
|
Component: TransferOwnership,
|
|
13085
13089
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13086
13090
|
},
|
|
13087
|
-
{
|
|
13088
|
-
Component: Email,
|
|
13089
|
-
path: "/draft-orders/:id/email"
|
|
13090
|
-
},
|
|
13091
13091
|
{
|
|
13092
13092
|
Component: Items,
|
|
13093
13093
|
path: "/draft-orders/:id/items"
|