@medusajs/draft-order 2.11.4-snapshot-20251107133446 → 2.11.4-snapshot-20251107205323
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 +542 -538
- package/.medusa/server/src/admin/index.mjs +542 -538
- package/package.json +16 -16
|
@@ -345,10 +345,14 @@ const DataTableAction = ({
|
|
|
345
345
|
}
|
|
346
346
|
return /* @__PURE__ */ jsx(Button, { ...buttonProps, onClick: props.onClick, children: label });
|
|
347
347
|
};
|
|
348
|
+
const backendUrl = __BACKEND_URL__ ?? "/";
|
|
349
|
+
const authType = __AUTH_TYPE__ ?? "session";
|
|
350
|
+
const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
|
|
348
351
|
const sdk = new Medusa({
|
|
349
|
-
baseUrl:
|
|
352
|
+
baseUrl: backendUrl,
|
|
350
353
|
auth: {
|
|
351
|
-
type:
|
|
354
|
+
type: authType,
|
|
355
|
+
jwtTokenStorageKey
|
|
352
356
|
}
|
|
353
357
|
});
|
|
354
358
|
const CUSTOMER_QUERY_KEY = "customers";
|
|
@@ -9751,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9751
9755
|
) });
|
|
9752
9756
|
};
|
|
9753
9757
|
const schema$5 = addressSchema;
|
|
9758
|
+
const CustomItems = () => {
|
|
9759
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9760
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9761
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9762
|
+
] });
|
|
9763
|
+
};
|
|
9764
|
+
const CustomItemsForm = () => {
|
|
9765
|
+
const form = useForm({
|
|
9766
|
+
resolver: zodResolver(schema$4)
|
|
9767
|
+
});
|
|
9768
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9769
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9770
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9771
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9772
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9773
|
+
] }) })
|
|
9774
|
+
] }) });
|
|
9775
|
+
};
|
|
9776
|
+
const schema$4 = objectType({
|
|
9777
|
+
email: stringType().email()
|
|
9778
|
+
});
|
|
9754
9779
|
const Email = () => {
|
|
9755
9780
|
const { id } = useParams();
|
|
9756
9781
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9773,7 +9798,7 @@ const EmailForm = ({ order }) => {
|
|
|
9773
9798
|
defaultValues: {
|
|
9774
9799
|
email: order.email ?? ""
|
|
9775
9800
|
},
|
|
9776
|
-
resolver: zodResolver(schema$
|
|
9801
|
+
resolver: zodResolver(schema$3)
|
|
9777
9802
|
});
|
|
9778
9803
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9779
9804
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9816,27 +9841,6 @@ const EmailForm = ({ order }) => {
|
|
|
9816
9841
|
}
|
|
9817
9842
|
) });
|
|
9818
9843
|
};
|
|
9819
|
-
const schema$4 = objectType({
|
|
9820
|
-
email: stringType().email()
|
|
9821
|
-
});
|
|
9822
|
-
const CustomItems = () => {
|
|
9823
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9824
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9825
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9826
|
-
] });
|
|
9827
|
-
};
|
|
9828
|
-
const CustomItemsForm = () => {
|
|
9829
|
-
const form = useForm({
|
|
9830
|
-
resolver: zodResolver(schema$3)
|
|
9831
|
-
});
|
|
9832
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9833
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9834
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9835
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9836
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9837
|
-
] }) })
|
|
9838
|
-
] }) });
|
|
9839
|
-
};
|
|
9840
9844
|
const schema$3 = objectType({
|
|
9841
9845
|
email: stringType().email()
|
|
9842
9846
|
});
|
|
@@ -11164,460 +11168,183 @@ function getHasUneditableRows(metadata) {
|
|
|
11164
11168
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11165
11169
|
);
|
|
11166
11170
|
}
|
|
11167
|
-
const
|
|
11168
|
-
const
|
|
11169
|
-
|
|
11170
|
-
PROMOTION_QUERY_KEY,
|
|
11171
|
-
query2 ? query2 : void 0
|
|
11172
|
-
],
|
|
11173
|
-
detail: (id, query2) => [
|
|
11174
|
-
PROMOTION_QUERY_KEY,
|
|
11171
|
+
const SalesChannel = () => {
|
|
11172
|
+
const { id } = useParams();
|
|
11173
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11175
11174
|
id,
|
|
11176
|
-
|
|
11177
|
-
|
|
11175
|
+
{
|
|
11176
|
+
fields: "+sales_channel_id"
|
|
11177
|
+
},
|
|
11178
|
+
{
|
|
11179
|
+
enabled: !!id
|
|
11180
|
+
}
|
|
11181
|
+
);
|
|
11182
|
+
if (isError) {
|
|
11183
|
+
throw error;
|
|
11184
|
+
}
|
|
11185
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11186
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11187
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11188
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11189
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11190
|
+
] }),
|
|
11191
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11192
|
+
] });
|
|
11178
11193
|
};
|
|
11179
|
-
const
|
|
11180
|
-
const
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
|
|
11194
|
+
const SalesChannelForm = ({ order }) => {
|
|
11195
|
+
const form = useForm({
|
|
11196
|
+
defaultValues: {
|
|
11197
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11198
|
+
},
|
|
11199
|
+
resolver: zodResolver(schema$2)
|
|
11184
11200
|
});
|
|
11185
|
-
|
|
11201
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11202
|
+
const { handleSuccess } = useRouteModal();
|
|
11203
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11204
|
+
await mutateAsync(
|
|
11205
|
+
{
|
|
11206
|
+
sales_channel_id: data.sales_channel_id
|
|
11207
|
+
},
|
|
11208
|
+
{
|
|
11209
|
+
onSuccess: () => {
|
|
11210
|
+
toast.success("Sales channel updated");
|
|
11211
|
+
handleSuccess();
|
|
11212
|
+
},
|
|
11213
|
+
onError: (error) => {
|
|
11214
|
+
toast.error(error.message);
|
|
11215
|
+
}
|
|
11216
|
+
}
|
|
11217
|
+
);
|
|
11218
|
+
});
|
|
11219
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11220
|
+
KeyboundForm,
|
|
11221
|
+
{
|
|
11222
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11223
|
+
onSubmit,
|
|
11224
|
+
children: [
|
|
11225
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11226
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11227
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11228
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11229
|
+
] }) })
|
|
11230
|
+
]
|
|
11231
|
+
}
|
|
11232
|
+
) });
|
|
11186
11233
|
};
|
|
11187
|
-
const
|
|
11234
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11235
|
+
const salesChannels = useComboboxData({
|
|
11236
|
+
queryFn: async (params) => {
|
|
11237
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11238
|
+
},
|
|
11239
|
+
queryKey: ["sales-channels"],
|
|
11240
|
+
getOptions: (data) => {
|
|
11241
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11242
|
+
label: salesChannel.name,
|
|
11243
|
+
value: salesChannel.id
|
|
11244
|
+
}));
|
|
11245
|
+
},
|
|
11246
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11247
|
+
});
|
|
11248
|
+
return /* @__PURE__ */ jsx(
|
|
11249
|
+
Form$2.Field,
|
|
11250
|
+
{
|
|
11251
|
+
control,
|
|
11252
|
+
name: "sales_channel_id",
|
|
11253
|
+
render: ({ field }) => {
|
|
11254
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11255
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11256
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11257
|
+
Combobox,
|
|
11258
|
+
{
|
|
11259
|
+
options: salesChannels.options,
|
|
11260
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11261
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11262
|
+
searchValue: salesChannels.searchValue,
|
|
11263
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11264
|
+
placeholder: "Select sales channel",
|
|
11265
|
+
...field
|
|
11266
|
+
}
|
|
11267
|
+
) }),
|
|
11268
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11269
|
+
] });
|
|
11270
|
+
}
|
|
11271
|
+
}
|
|
11272
|
+
);
|
|
11273
|
+
};
|
|
11274
|
+
const schema$2 = objectType({
|
|
11275
|
+
sales_channel_id: stringType().min(1)
|
|
11276
|
+
});
|
|
11277
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11278
|
+
const Shipping = () => {
|
|
11279
|
+
var _a;
|
|
11188
11280
|
const { id } = useParams();
|
|
11281
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11282
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11283
|
+
});
|
|
11189
11284
|
const {
|
|
11190
11285
|
order: preview,
|
|
11286
|
+
isPending: isPreviewPending,
|
|
11191
11287
|
isError: isPreviewError,
|
|
11192
11288
|
error: previewError
|
|
11193
|
-
} = useOrderPreview(id
|
|
11289
|
+
} = useOrderPreview(id);
|
|
11194
11290
|
useInitiateOrderEdit({ preview });
|
|
11195
11291
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11292
|
+
if (isError) {
|
|
11293
|
+
throw error;
|
|
11294
|
+
}
|
|
11196
11295
|
if (isPreviewError) {
|
|
11197
11296
|
throw previewError;
|
|
11198
11297
|
}
|
|
11199
|
-
const
|
|
11200
|
-
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11298
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11299
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11300
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11301
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11302
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
11303
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11304
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11305
|
+
] }) }) }),
|
|
11306
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11307
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11308
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11309
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11310
|
+
] }) });
|
|
11204
11311
|
};
|
|
11205
|
-
const
|
|
11206
|
-
|
|
11312
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11313
|
+
var _a;
|
|
11314
|
+
const { setIsOpen } = useStackedModal();
|
|
11207
11315
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11208
|
-
const [
|
|
11209
|
-
const
|
|
11210
|
-
const {
|
|
11211
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11212
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11316
|
+
const [data, setData] = useState(null);
|
|
11317
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11318
|
+
const { shipping_options } = useShippingOptions(
|
|
11213
11319
|
{
|
|
11214
|
-
id:
|
|
11320
|
+
id: appliedShippingOptionIds,
|
|
11321
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11215
11322
|
},
|
|
11216
11323
|
{
|
|
11217
|
-
enabled:
|
|
11324
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11218
11325
|
}
|
|
11219
11326
|
);
|
|
11220
|
-
const
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
addPromotions(
|
|
11242
|
-
{
|
|
11243
|
-
promo_codes: [value]
|
|
11244
|
-
},
|
|
11245
|
-
{
|
|
11246
|
-
onError: (e) => {
|
|
11247
|
-
toast.error(e.message);
|
|
11248
|
-
comboboxData.onSearchValueChange("");
|
|
11249
|
-
setComboboxValue("");
|
|
11250
|
-
},
|
|
11251
|
-
onSuccess: () => {
|
|
11252
|
-
comboboxData.onSearchValueChange("");
|
|
11253
|
-
setComboboxValue("");
|
|
11254
|
-
}
|
|
11255
|
-
}
|
|
11256
|
-
);
|
|
11257
|
-
};
|
|
11258
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11259
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11260
|
-
const onSubmit = async () => {
|
|
11261
|
-
setIsSubmitting(true);
|
|
11262
|
-
let requestSucceeded = false;
|
|
11263
|
-
await requestOrderEdit(void 0, {
|
|
11264
|
-
onError: (e) => {
|
|
11265
|
-
toast.error(e.message);
|
|
11266
|
-
},
|
|
11267
|
-
onSuccess: () => {
|
|
11268
|
-
requestSucceeded = true;
|
|
11269
|
-
}
|
|
11270
|
-
});
|
|
11271
|
-
if (!requestSucceeded) {
|
|
11272
|
-
setIsSubmitting(false);
|
|
11273
|
-
return;
|
|
11274
|
-
}
|
|
11275
|
-
await confirmOrderEdit(void 0, {
|
|
11276
|
-
onError: (e) => {
|
|
11277
|
-
toast.error(e.message);
|
|
11278
|
-
},
|
|
11279
|
-
onSuccess: () => {
|
|
11280
|
-
handleSuccess();
|
|
11281
|
-
},
|
|
11282
|
-
onSettled: () => {
|
|
11283
|
-
setIsSubmitting(false);
|
|
11284
|
-
}
|
|
11285
|
-
});
|
|
11286
|
-
};
|
|
11287
|
-
if (isError) {
|
|
11288
|
-
throw error;
|
|
11289
|
-
}
|
|
11290
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11291
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11292
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11293
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11294
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11295
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11296
|
-
] }),
|
|
11297
|
-
/* @__PURE__ */ jsx(
|
|
11298
|
-
Combobox,
|
|
11299
|
-
{
|
|
11300
|
-
id: "promotion-combobox",
|
|
11301
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11302
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11303
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11304
|
-
options: comboboxData.options,
|
|
11305
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11306
|
-
searchValue: comboboxData.searchValue,
|
|
11307
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11308
|
-
onChange: add,
|
|
11309
|
-
value: comboboxValue
|
|
11310
|
-
}
|
|
11311
|
-
)
|
|
11312
|
-
] }),
|
|
11313
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11314
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11315
|
-
PromotionItem,
|
|
11316
|
-
{
|
|
11317
|
-
promotion,
|
|
11318
|
-
orderId: preview.id,
|
|
11319
|
-
isLoading: isPending
|
|
11320
|
-
},
|
|
11321
|
-
promotion.id
|
|
11322
|
-
)) })
|
|
11323
|
-
] }) }),
|
|
11324
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11325
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11326
|
-
/* @__PURE__ */ jsx(
|
|
11327
|
-
Button,
|
|
11328
|
-
{
|
|
11329
|
-
size: "small",
|
|
11330
|
-
type: "submit",
|
|
11331
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11332
|
-
children: "Save"
|
|
11333
|
-
}
|
|
11334
|
-
)
|
|
11335
|
-
] }) })
|
|
11336
|
-
] });
|
|
11337
|
-
};
|
|
11338
|
-
const PromotionItem = ({
|
|
11339
|
-
promotion,
|
|
11340
|
-
orderId,
|
|
11341
|
-
isLoading
|
|
11342
|
-
}) => {
|
|
11343
|
-
var _a;
|
|
11344
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11345
|
-
const onRemove = async () => {
|
|
11346
|
-
removePromotions(
|
|
11347
|
-
{
|
|
11348
|
-
promo_codes: [promotion.code]
|
|
11349
|
-
},
|
|
11350
|
-
{
|
|
11351
|
-
onError: (e) => {
|
|
11352
|
-
toast.error(e.message);
|
|
11353
|
-
}
|
|
11354
|
-
}
|
|
11355
|
-
);
|
|
11356
|
-
};
|
|
11357
|
-
const displayValue = getDisplayValue(promotion);
|
|
11358
|
-
return /* @__PURE__ */ jsxs(
|
|
11359
|
-
"div",
|
|
11360
|
-
{
|
|
11361
|
-
className: clx(
|
|
11362
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11363
|
-
{
|
|
11364
|
-
"animate-pulse": isLoading
|
|
11365
|
-
}
|
|
11366
|
-
),
|
|
11367
|
-
children: [
|
|
11368
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11369
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11370
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11371
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11372
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11373
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11374
|
-
] }),
|
|
11375
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11376
|
-
] })
|
|
11377
|
-
] }),
|
|
11378
|
-
/* @__PURE__ */ jsx(
|
|
11379
|
-
IconButton,
|
|
11380
|
-
{
|
|
11381
|
-
size: "small",
|
|
11382
|
-
type: "button",
|
|
11383
|
-
variant: "transparent",
|
|
11384
|
-
onClick: onRemove,
|
|
11385
|
-
isLoading: isPending || isLoading,
|
|
11386
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11387
|
-
}
|
|
11388
|
-
)
|
|
11389
|
-
]
|
|
11390
|
-
},
|
|
11391
|
-
promotion.id
|
|
11392
|
-
);
|
|
11393
|
-
};
|
|
11394
|
-
function getDisplayValue(promotion) {
|
|
11395
|
-
var _a, _b, _c, _d;
|
|
11396
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11397
|
-
if (!value) {
|
|
11398
|
-
return null;
|
|
11399
|
-
}
|
|
11400
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11401
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11402
|
-
if (!currency) {
|
|
11403
|
-
return null;
|
|
11404
|
-
}
|
|
11405
|
-
return getLocaleAmount(value, currency);
|
|
11406
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11407
|
-
return formatPercentage(value);
|
|
11408
|
-
}
|
|
11409
|
-
return null;
|
|
11410
|
-
}
|
|
11411
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11412
|
-
style: "percent",
|
|
11413
|
-
minimumFractionDigits: 2
|
|
11414
|
-
});
|
|
11415
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11416
|
-
let val = value || 0;
|
|
11417
|
-
if (!isPercentageValue) {
|
|
11418
|
-
val = val / 100;
|
|
11419
|
-
}
|
|
11420
|
-
return formatter.format(val);
|
|
11421
|
-
};
|
|
11422
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11423
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11424
|
-
for (const item of items) {
|
|
11425
|
-
if (item.adjustments) {
|
|
11426
|
-
for (const adjustment of item.adjustments) {
|
|
11427
|
-
if (adjustment.promotion_id) {
|
|
11428
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11429
|
-
}
|
|
11430
|
-
}
|
|
11431
|
-
}
|
|
11432
|
-
}
|
|
11433
|
-
for (const shippingMethod of shippingMethods) {
|
|
11434
|
-
if (shippingMethod.adjustments) {
|
|
11435
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11436
|
-
if (adjustment.promotion_id) {
|
|
11437
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11438
|
-
}
|
|
11439
|
-
}
|
|
11440
|
-
}
|
|
11441
|
-
}
|
|
11442
|
-
return Array.from(promotionIds);
|
|
11443
|
-
}
|
|
11444
|
-
const SalesChannel = () => {
|
|
11445
|
-
const { id } = useParams();
|
|
11446
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11447
|
-
id,
|
|
11448
|
-
{
|
|
11449
|
-
fields: "+sales_channel_id"
|
|
11450
|
-
},
|
|
11451
|
-
{
|
|
11452
|
-
enabled: !!id
|
|
11453
|
-
}
|
|
11454
|
-
);
|
|
11455
|
-
if (isError) {
|
|
11456
|
-
throw error;
|
|
11457
|
-
}
|
|
11458
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11459
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11460
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11461
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11462
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11463
|
-
] }),
|
|
11464
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11465
|
-
] });
|
|
11466
|
-
};
|
|
11467
|
-
const SalesChannelForm = ({ order }) => {
|
|
11468
|
-
const form = useForm({
|
|
11469
|
-
defaultValues: {
|
|
11470
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11471
|
-
},
|
|
11472
|
-
resolver: zodResolver(schema$2)
|
|
11473
|
-
});
|
|
11474
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11475
|
-
const { handleSuccess } = useRouteModal();
|
|
11476
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11477
|
-
await mutateAsync(
|
|
11478
|
-
{
|
|
11479
|
-
sales_channel_id: data.sales_channel_id
|
|
11480
|
-
},
|
|
11481
|
-
{
|
|
11482
|
-
onSuccess: () => {
|
|
11483
|
-
toast.success("Sales channel updated");
|
|
11484
|
-
handleSuccess();
|
|
11485
|
-
},
|
|
11486
|
-
onError: (error) => {
|
|
11487
|
-
toast.error(error.message);
|
|
11488
|
-
}
|
|
11489
|
-
}
|
|
11490
|
-
);
|
|
11491
|
-
});
|
|
11492
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11493
|
-
KeyboundForm,
|
|
11494
|
-
{
|
|
11495
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11496
|
-
onSubmit,
|
|
11497
|
-
children: [
|
|
11498
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11499
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11500
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11501
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11502
|
-
] }) })
|
|
11503
|
-
]
|
|
11504
|
-
}
|
|
11505
|
-
) });
|
|
11506
|
-
};
|
|
11507
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11508
|
-
const salesChannels = useComboboxData({
|
|
11509
|
-
queryFn: async (params) => {
|
|
11510
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11511
|
-
},
|
|
11512
|
-
queryKey: ["sales-channels"],
|
|
11513
|
-
getOptions: (data) => {
|
|
11514
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11515
|
-
label: salesChannel.name,
|
|
11516
|
-
value: salesChannel.id
|
|
11517
|
-
}));
|
|
11518
|
-
},
|
|
11519
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11520
|
-
});
|
|
11521
|
-
return /* @__PURE__ */ jsx(
|
|
11522
|
-
Form$2.Field,
|
|
11523
|
-
{
|
|
11524
|
-
control,
|
|
11525
|
-
name: "sales_channel_id",
|
|
11526
|
-
render: ({ field }) => {
|
|
11527
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11528
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11529
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11530
|
-
Combobox,
|
|
11531
|
-
{
|
|
11532
|
-
options: salesChannels.options,
|
|
11533
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11534
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11535
|
-
searchValue: salesChannels.searchValue,
|
|
11536
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11537
|
-
placeholder: "Select sales channel",
|
|
11538
|
-
...field
|
|
11539
|
-
}
|
|
11540
|
-
) }),
|
|
11541
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11542
|
-
] });
|
|
11543
|
-
}
|
|
11544
|
-
}
|
|
11545
|
-
);
|
|
11546
|
-
};
|
|
11547
|
-
const schema$2 = objectType({
|
|
11548
|
-
sales_channel_id: stringType().min(1)
|
|
11549
|
-
});
|
|
11550
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11551
|
-
const Shipping = () => {
|
|
11552
|
-
var _a;
|
|
11553
|
-
const { id } = useParams();
|
|
11554
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11555
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11556
|
-
});
|
|
11557
|
-
const {
|
|
11558
|
-
order: preview,
|
|
11559
|
-
isPending: isPreviewPending,
|
|
11560
|
-
isError: isPreviewError,
|
|
11561
|
-
error: previewError
|
|
11562
|
-
} = useOrderPreview(id);
|
|
11563
|
-
useInitiateOrderEdit({ preview });
|
|
11564
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11565
|
-
if (isError) {
|
|
11566
|
-
throw error;
|
|
11567
|
-
}
|
|
11568
|
-
if (isPreviewError) {
|
|
11569
|
-
throw previewError;
|
|
11570
|
-
}
|
|
11571
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11572
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11573
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11574
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11575
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
11576
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11577
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11578
|
-
] }) }) }),
|
|
11579
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11580
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11581
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11582
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11583
|
-
] }) });
|
|
11584
|
-
};
|
|
11585
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11586
|
-
var _a;
|
|
11587
|
-
const { setIsOpen } = useStackedModal();
|
|
11588
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11589
|
-
const [data, setData] = useState(null);
|
|
11590
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11591
|
-
const { shipping_options } = useShippingOptions(
|
|
11592
|
-
{
|
|
11593
|
-
id: appliedShippingOptionIds,
|
|
11594
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11595
|
-
},
|
|
11596
|
-
{
|
|
11597
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11598
|
-
}
|
|
11599
|
-
);
|
|
11600
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
11601
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
11602
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11603
|
-
profiles.set(profile.id, profile);
|
|
11604
|
-
});
|
|
11605
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11606
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11607
|
-
});
|
|
11608
|
-
return Array.from(profiles.values());
|
|
11609
|
-
}, [order.items, shipping_options]);
|
|
11610
|
-
const { handleSuccess } = useRouteModal();
|
|
11611
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11612
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11613
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11614
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11615
|
-
const onSubmit = async () => {
|
|
11616
|
-
setIsSubmitting(true);
|
|
11617
|
-
let requestSucceeded = false;
|
|
11618
|
-
await requestOrderEdit(void 0, {
|
|
11619
|
-
onError: (e) => {
|
|
11620
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11327
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
11328
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
11329
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11330
|
+
profiles.set(profile.id, profile);
|
|
11331
|
+
});
|
|
11332
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11333
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11334
|
+
});
|
|
11335
|
+
return Array.from(profiles.values());
|
|
11336
|
+
}, [order.items, shipping_options]);
|
|
11337
|
+
const { handleSuccess } = useRouteModal();
|
|
11338
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11339
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11340
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11341
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11342
|
+
const onSubmit = async () => {
|
|
11343
|
+
setIsSubmitting(true);
|
|
11344
|
+
let requestSucceeded = false;
|
|
11345
|
+
await requestOrderEdit(void 0, {
|
|
11346
|
+
onError: (e) => {
|
|
11347
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11621
11348
|
},
|
|
11622
11349
|
onSuccess: () => {
|
|
11623
11350
|
requestSucceeded = true;
|
|
@@ -12953,86 +12680,363 @@ const Illustration = () => {
|
|
|
12953
12680
|
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12954
12681
|
"path",
|
|
12955
12682
|
{
|
|
12956
|
-
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12957
|
-
stroke: "#A1A1AA",
|
|
12958
|
-
strokeWidth: "1.5",
|
|
12959
|
-
strokeLinecap: "round",
|
|
12960
|
-
strokeLinejoin: "round"
|
|
12683
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12684
|
+
stroke: "#A1A1AA",
|
|
12685
|
+
strokeWidth: "1.5",
|
|
12686
|
+
strokeLinecap: "round",
|
|
12687
|
+
strokeLinejoin: "round"
|
|
12688
|
+
}
|
|
12689
|
+
) }),
|
|
12690
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12691
|
+
"path",
|
|
12692
|
+
{
|
|
12693
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12694
|
+
stroke: "#A1A1AA",
|
|
12695
|
+
strokeWidth: "1.5",
|
|
12696
|
+
strokeLinecap: "round",
|
|
12697
|
+
strokeLinejoin: "round"
|
|
12698
|
+
}
|
|
12699
|
+
) }),
|
|
12700
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12701
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12702
|
+
"rect",
|
|
12703
|
+
{
|
|
12704
|
+
width: "12",
|
|
12705
|
+
height: "12",
|
|
12706
|
+
fill: "white",
|
|
12707
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12708
|
+
}
|
|
12709
|
+
) }),
|
|
12710
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12711
|
+
"rect",
|
|
12712
|
+
{
|
|
12713
|
+
width: "12",
|
|
12714
|
+
height: "12",
|
|
12715
|
+
fill: "white",
|
|
12716
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12717
|
+
}
|
|
12718
|
+
) }),
|
|
12719
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12720
|
+
"rect",
|
|
12721
|
+
{
|
|
12722
|
+
width: "12",
|
|
12723
|
+
height: "12",
|
|
12724
|
+
fill: "white",
|
|
12725
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12726
|
+
}
|
|
12727
|
+
) }),
|
|
12728
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12729
|
+
"rect",
|
|
12730
|
+
{
|
|
12731
|
+
width: "12",
|
|
12732
|
+
height: "12",
|
|
12733
|
+
fill: "white",
|
|
12734
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12735
|
+
}
|
|
12736
|
+
) }),
|
|
12737
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12738
|
+
"rect",
|
|
12739
|
+
{
|
|
12740
|
+
width: "12",
|
|
12741
|
+
height: "12",
|
|
12742
|
+
fill: "white",
|
|
12743
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12744
|
+
}
|
|
12745
|
+
) }),
|
|
12746
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12747
|
+
"rect",
|
|
12748
|
+
{
|
|
12749
|
+
width: "12",
|
|
12750
|
+
height: "12",
|
|
12751
|
+
fill: "white",
|
|
12752
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12753
|
+
}
|
|
12754
|
+
) })
|
|
12755
|
+
] })
|
|
12756
|
+
]
|
|
12757
|
+
}
|
|
12758
|
+
);
|
|
12759
|
+
};
|
|
12760
|
+
const schema = objectType({
|
|
12761
|
+
customer_id: stringType().min(1)
|
|
12762
|
+
});
|
|
12763
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
12764
|
+
const promotionsQueryKeys = {
|
|
12765
|
+
list: (query2) => [
|
|
12766
|
+
PROMOTION_QUERY_KEY,
|
|
12767
|
+
query2 ? query2 : void 0
|
|
12768
|
+
],
|
|
12769
|
+
detail: (id, query2) => [
|
|
12770
|
+
PROMOTION_QUERY_KEY,
|
|
12771
|
+
id,
|
|
12772
|
+
query2 ? query2 : void 0
|
|
12773
|
+
]
|
|
12774
|
+
};
|
|
12775
|
+
const usePromotions = (query2, options) => {
|
|
12776
|
+
const { data, ...rest } = useQuery({
|
|
12777
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
12778
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12779
|
+
...options
|
|
12780
|
+
});
|
|
12781
|
+
return { ...data, ...rest };
|
|
12782
|
+
};
|
|
12783
|
+
const Promotions = () => {
|
|
12784
|
+
const { id } = useParams();
|
|
12785
|
+
const {
|
|
12786
|
+
order: preview,
|
|
12787
|
+
isError: isPreviewError,
|
|
12788
|
+
error: previewError
|
|
12789
|
+
} = useOrderPreview(id, void 0);
|
|
12790
|
+
useInitiateOrderEdit({ preview });
|
|
12791
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12792
|
+
if (isPreviewError) {
|
|
12793
|
+
throw previewError;
|
|
12794
|
+
}
|
|
12795
|
+
const isReady = !!preview;
|
|
12796
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
12797
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
12798
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
12799
|
+
] });
|
|
12800
|
+
};
|
|
12801
|
+
const PromotionForm = ({ preview }) => {
|
|
12802
|
+
const { items, shipping_methods } = preview;
|
|
12803
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12804
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
12805
|
+
const { handleSuccess } = useRouteModal();
|
|
12806
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
12807
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
12808
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
12809
|
+
{
|
|
12810
|
+
id: promoIds
|
|
12811
|
+
},
|
|
12812
|
+
{
|
|
12813
|
+
enabled: !!promoIds.length
|
|
12814
|
+
}
|
|
12815
|
+
);
|
|
12816
|
+
const comboboxData = useComboboxData({
|
|
12817
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
12818
|
+
queryFn: async (params) => {
|
|
12819
|
+
return await sdk.admin.promotion.list({
|
|
12820
|
+
...params,
|
|
12821
|
+
id: {
|
|
12822
|
+
$nin: promoIds
|
|
12823
|
+
}
|
|
12824
|
+
});
|
|
12825
|
+
},
|
|
12826
|
+
getOptions: (data) => {
|
|
12827
|
+
return data.promotions.map((promotion) => ({
|
|
12828
|
+
label: promotion.code,
|
|
12829
|
+
value: promotion.code
|
|
12830
|
+
}));
|
|
12831
|
+
}
|
|
12832
|
+
});
|
|
12833
|
+
const add = async (value) => {
|
|
12834
|
+
if (!value) {
|
|
12835
|
+
return;
|
|
12836
|
+
}
|
|
12837
|
+
addPromotions(
|
|
12838
|
+
{
|
|
12839
|
+
promo_codes: [value]
|
|
12840
|
+
},
|
|
12841
|
+
{
|
|
12842
|
+
onError: (e) => {
|
|
12843
|
+
toast.error(e.message);
|
|
12844
|
+
comboboxData.onSearchValueChange("");
|
|
12845
|
+
setComboboxValue("");
|
|
12846
|
+
},
|
|
12847
|
+
onSuccess: () => {
|
|
12848
|
+
comboboxData.onSearchValueChange("");
|
|
12849
|
+
setComboboxValue("");
|
|
12850
|
+
}
|
|
12851
|
+
}
|
|
12852
|
+
);
|
|
12853
|
+
};
|
|
12854
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12855
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12856
|
+
const onSubmit = async () => {
|
|
12857
|
+
setIsSubmitting(true);
|
|
12858
|
+
let requestSucceeded = false;
|
|
12859
|
+
await requestOrderEdit(void 0, {
|
|
12860
|
+
onError: (e) => {
|
|
12861
|
+
toast.error(e.message);
|
|
12862
|
+
},
|
|
12863
|
+
onSuccess: () => {
|
|
12864
|
+
requestSucceeded = true;
|
|
12865
|
+
}
|
|
12866
|
+
});
|
|
12867
|
+
if (!requestSucceeded) {
|
|
12868
|
+
setIsSubmitting(false);
|
|
12869
|
+
return;
|
|
12870
|
+
}
|
|
12871
|
+
await confirmOrderEdit(void 0, {
|
|
12872
|
+
onError: (e) => {
|
|
12873
|
+
toast.error(e.message);
|
|
12874
|
+
},
|
|
12875
|
+
onSuccess: () => {
|
|
12876
|
+
handleSuccess();
|
|
12877
|
+
},
|
|
12878
|
+
onSettled: () => {
|
|
12879
|
+
setIsSubmitting(false);
|
|
12880
|
+
}
|
|
12881
|
+
});
|
|
12882
|
+
};
|
|
12883
|
+
if (isError) {
|
|
12884
|
+
throw error;
|
|
12885
|
+
}
|
|
12886
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12887
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12888
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12889
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12890
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12891
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12892
|
+
] }),
|
|
12893
|
+
/* @__PURE__ */ jsx(
|
|
12894
|
+
Combobox,
|
|
12895
|
+
{
|
|
12896
|
+
id: "promotion-combobox",
|
|
12897
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
12898
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
12899
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
12900
|
+
options: comboboxData.options,
|
|
12901
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12902
|
+
searchValue: comboboxData.searchValue,
|
|
12903
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12904
|
+
onChange: add,
|
|
12905
|
+
value: comboboxValue
|
|
12961
12906
|
}
|
|
12962
|
-
)
|
|
12963
|
-
|
|
12964
|
-
|
|
12907
|
+
)
|
|
12908
|
+
] }),
|
|
12909
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12910
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
12911
|
+
PromotionItem,
|
|
12912
|
+
{
|
|
12913
|
+
promotion,
|
|
12914
|
+
orderId: preview.id,
|
|
12915
|
+
isLoading: isPending
|
|
12916
|
+
},
|
|
12917
|
+
promotion.id
|
|
12918
|
+
)) })
|
|
12919
|
+
] }) }),
|
|
12920
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12921
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12922
|
+
/* @__PURE__ */ jsx(
|
|
12923
|
+
Button,
|
|
12924
|
+
{
|
|
12925
|
+
size: "small",
|
|
12926
|
+
type: "submit",
|
|
12927
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
12928
|
+
children: "Save"
|
|
12929
|
+
}
|
|
12930
|
+
)
|
|
12931
|
+
] }) })
|
|
12932
|
+
] });
|
|
12933
|
+
};
|
|
12934
|
+
const PromotionItem = ({
|
|
12935
|
+
promotion,
|
|
12936
|
+
orderId,
|
|
12937
|
+
isLoading
|
|
12938
|
+
}) => {
|
|
12939
|
+
var _a;
|
|
12940
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12941
|
+
const onRemove = async () => {
|
|
12942
|
+
removePromotions(
|
|
12943
|
+
{
|
|
12944
|
+
promo_codes: [promotion.code]
|
|
12945
|
+
},
|
|
12946
|
+
{
|
|
12947
|
+
onError: (e) => {
|
|
12948
|
+
toast.error(e.message);
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
12951
|
+
);
|
|
12952
|
+
};
|
|
12953
|
+
const displayValue = getDisplayValue(promotion);
|
|
12954
|
+
return /* @__PURE__ */ jsxs(
|
|
12955
|
+
"div",
|
|
12956
|
+
{
|
|
12957
|
+
className: clx(
|
|
12958
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12959
|
+
{
|
|
12960
|
+
"animate-pulse": isLoading
|
|
12961
|
+
}
|
|
12962
|
+
),
|
|
12963
|
+
children: [
|
|
12964
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12965
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12966
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12967
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12968
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12969
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
12970
|
+
] }),
|
|
12971
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
12972
|
+
] })
|
|
12973
|
+
] }),
|
|
12974
|
+
/* @__PURE__ */ jsx(
|
|
12975
|
+
IconButton,
|
|
12965
12976
|
{
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12977
|
+
size: "small",
|
|
12978
|
+
type: "button",
|
|
12979
|
+
variant: "transparent",
|
|
12980
|
+
onClick: onRemove,
|
|
12981
|
+
isLoading: isPending || isLoading,
|
|
12982
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12971
12983
|
}
|
|
12972
|
-
)
|
|
12973
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12974
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12975
|
-
"rect",
|
|
12976
|
-
{
|
|
12977
|
-
width: "12",
|
|
12978
|
-
height: "12",
|
|
12979
|
-
fill: "white",
|
|
12980
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12981
|
-
}
|
|
12982
|
-
) }),
|
|
12983
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12984
|
-
"rect",
|
|
12985
|
-
{
|
|
12986
|
-
width: "12",
|
|
12987
|
-
height: "12",
|
|
12988
|
-
fill: "white",
|
|
12989
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12990
|
-
}
|
|
12991
|
-
) }),
|
|
12992
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12993
|
-
"rect",
|
|
12994
|
-
{
|
|
12995
|
-
width: "12",
|
|
12996
|
-
height: "12",
|
|
12997
|
-
fill: "white",
|
|
12998
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12999
|
-
}
|
|
13000
|
-
) }),
|
|
13001
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13002
|
-
"rect",
|
|
13003
|
-
{
|
|
13004
|
-
width: "12",
|
|
13005
|
-
height: "12",
|
|
13006
|
-
fill: "white",
|
|
13007
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13008
|
-
}
|
|
13009
|
-
) }),
|
|
13010
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13011
|
-
"rect",
|
|
13012
|
-
{
|
|
13013
|
-
width: "12",
|
|
13014
|
-
height: "12",
|
|
13015
|
-
fill: "white",
|
|
13016
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13017
|
-
}
|
|
13018
|
-
) }),
|
|
13019
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13020
|
-
"rect",
|
|
13021
|
-
{
|
|
13022
|
-
width: "12",
|
|
13023
|
-
height: "12",
|
|
13024
|
-
fill: "white",
|
|
13025
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13026
|
-
}
|
|
13027
|
-
) })
|
|
13028
|
-
] })
|
|
12984
|
+
)
|
|
13029
12985
|
]
|
|
13030
|
-
}
|
|
12986
|
+
},
|
|
12987
|
+
promotion.id
|
|
13031
12988
|
);
|
|
13032
12989
|
};
|
|
13033
|
-
|
|
13034
|
-
|
|
12990
|
+
function getDisplayValue(promotion) {
|
|
12991
|
+
var _a, _b, _c, _d;
|
|
12992
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
12993
|
+
if (!value) {
|
|
12994
|
+
return null;
|
|
12995
|
+
}
|
|
12996
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
12997
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
12998
|
+
if (!currency) {
|
|
12999
|
+
return null;
|
|
13000
|
+
}
|
|
13001
|
+
return getLocaleAmount(value, currency);
|
|
13002
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
13003
|
+
return formatPercentage(value);
|
|
13004
|
+
}
|
|
13005
|
+
return null;
|
|
13006
|
+
}
|
|
13007
|
+
const formatter = new Intl.NumberFormat([], {
|
|
13008
|
+
style: "percent",
|
|
13009
|
+
minimumFractionDigits: 2
|
|
13035
13010
|
});
|
|
13011
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
13012
|
+
let val = value || 0;
|
|
13013
|
+
if (!isPercentageValue) {
|
|
13014
|
+
val = val / 100;
|
|
13015
|
+
}
|
|
13016
|
+
return formatter.format(val);
|
|
13017
|
+
};
|
|
13018
|
+
function getPromotionIds(items, shippingMethods) {
|
|
13019
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
13020
|
+
for (const item of items) {
|
|
13021
|
+
if (item.adjustments) {
|
|
13022
|
+
for (const adjustment of item.adjustments) {
|
|
13023
|
+
if (adjustment.promotion_id) {
|
|
13024
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13025
|
+
}
|
|
13026
|
+
}
|
|
13027
|
+
}
|
|
13028
|
+
}
|
|
13029
|
+
for (const shippingMethod of shippingMethods) {
|
|
13030
|
+
if (shippingMethod.adjustments) {
|
|
13031
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
13032
|
+
if (adjustment.promotion_id) {
|
|
13033
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13034
|
+
}
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
}
|
|
13038
|
+
return Array.from(promotionIds);
|
|
13039
|
+
}
|
|
13036
13040
|
const widgetModule = { widgets: [] };
|
|
13037
13041
|
const routeModule = {
|
|
13038
13042
|
routes: [
|
|
@@ -13057,14 +13061,14 @@ const routeModule = {
|
|
|
13057
13061
|
Component: BillingAddress,
|
|
13058
13062
|
path: "/draft-orders/:id/billing-address"
|
|
13059
13063
|
},
|
|
13060
|
-
{
|
|
13061
|
-
Component: Email,
|
|
13062
|
-
path: "/draft-orders/:id/email"
|
|
13063
|
-
},
|
|
13064
13064
|
{
|
|
13065
13065
|
Component: CustomItems,
|
|
13066
13066
|
path: "/draft-orders/:id/custom-items"
|
|
13067
13067
|
},
|
|
13068
|
+
{
|
|
13069
|
+
Component: Email,
|
|
13070
|
+
path: "/draft-orders/:id/email"
|
|
13071
|
+
},
|
|
13068
13072
|
{
|
|
13069
13073
|
Component: Items,
|
|
13070
13074
|
path: "/draft-orders/:id/items"
|
|
@@ -13073,10 +13077,6 @@ const routeModule = {
|
|
|
13073
13077
|
Component: Metadata,
|
|
13074
13078
|
path: "/draft-orders/:id/metadata"
|
|
13075
13079
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Promotions,
|
|
13078
|
-
path: "/draft-orders/:id/promotions"
|
|
13079
|
-
},
|
|
13080
13080
|
{
|
|
13081
13081
|
Component: SalesChannel,
|
|
13082
13082
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13092,6 +13092,10 @@ const routeModule = {
|
|
|
13092
13092
|
{
|
|
13093
13093
|
Component: TransferOwnership,
|
|
13094
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: Promotions,
|
|
13098
|
+
path: "/draft-orders/:id/promotions"
|
|
13095
13099
|
}
|
|
13096
13100
|
]
|
|
13097
13101
|
}
|