@medusajs/draft-order 2.11.4-snapshot-20251107110738 → 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 +664 -660
- package/.medusa/server/src/admin/index.mjs +664 -660
- 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,7 +9841,7 @@ const EmailForm = ({ order }) => {
|
|
|
9816
9841
|
}
|
|
9817
9842
|
) });
|
|
9818
9843
|
};
|
|
9819
|
-
const schema$
|
|
9844
|
+
const schema$3 = objectType({
|
|
9820
9845
|
email: stringType().email()
|
|
9821
9846
|
});
|
|
9822
9847
|
const NumberInput = forwardRef(
|
|
@@ -11143,105 +11168,183 @@ function getHasUneditableRows(metadata) {
|
|
|
11143
11168
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11144
11169
|
);
|
|
11145
11170
|
}
|
|
11146
|
-
const
|
|
11147
|
-
const
|
|
11148
|
-
|
|
11149
|
-
PROMOTION_QUERY_KEY,
|
|
11150
|
-
query2 ? query2 : void 0
|
|
11151
|
-
],
|
|
11152
|
-
detail: (id, query2) => [
|
|
11153
|
-
PROMOTION_QUERY_KEY,
|
|
11171
|
+
const SalesChannel = () => {
|
|
11172
|
+
const { id } = useParams();
|
|
11173
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11154
11174
|
id,
|
|
11155
|
-
|
|
11156
|
-
|
|
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
|
+
] });
|
|
11157
11193
|
};
|
|
11158
|
-
const
|
|
11159
|
-
const
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11194
|
+
const SalesChannelForm = ({ order }) => {
|
|
11195
|
+
const form = useForm({
|
|
11196
|
+
defaultValues: {
|
|
11197
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11198
|
+
},
|
|
11199
|
+
resolver: zodResolver(schema$2)
|
|
11163
11200
|
});
|
|
11164
|
-
|
|
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
|
+
) });
|
|
11165
11233
|
};
|
|
11166
|
-
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;
|
|
11167
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
|
+
});
|
|
11168
11284
|
const {
|
|
11169
11285
|
order: preview,
|
|
11286
|
+
isPending: isPreviewPending,
|
|
11170
11287
|
isError: isPreviewError,
|
|
11171
11288
|
error: previewError
|
|
11172
|
-
} = useOrderPreview(id
|
|
11289
|
+
} = useOrderPreview(id);
|
|
11173
11290
|
useInitiateOrderEdit({ preview });
|
|
11174
11291
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11292
|
+
if (isError) {
|
|
11293
|
+
throw error;
|
|
11294
|
+
}
|
|
11175
11295
|
if (isPreviewError) {
|
|
11176
11296
|
throw previewError;
|
|
11177
11297
|
}
|
|
11178
|
-
const
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
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
|
+
] }) });
|
|
11183
11311
|
};
|
|
11184
|
-
const
|
|
11185
|
-
|
|
11312
|
+
const ShippingForm = ({ preview, order }) => {
|
|
11313
|
+
var _a;
|
|
11314
|
+
const { setIsOpen } = useStackedModal();
|
|
11186
11315
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11187
|
-
const [
|
|
11188
|
-
const
|
|
11189
|
-
const {
|
|
11190
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11191
|
-
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(
|
|
11192
11319
|
{
|
|
11193
|
-
id:
|
|
11320
|
+
id: appliedShippingOptionIds,
|
|
11321
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11194
11322
|
},
|
|
11195
11323
|
{
|
|
11196
|
-
enabled:
|
|
11324
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11197
11325
|
}
|
|
11198
11326
|
);
|
|
11199
|
-
const
|
|
11200
|
-
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
return data.promotions.map((promotion) => ({
|
|
11211
|
-
label: promotion.code,
|
|
11212
|
-
value: promotion.code
|
|
11213
|
-
}));
|
|
11214
|
-
}
|
|
11215
|
-
});
|
|
11216
|
-
const add = async (value) => {
|
|
11217
|
-
if (!value) {
|
|
11218
|
-
return;
|
|
11219
|
-
}
|
|
11220
|
-
addPromotions(
|
|
11221
|
-
{
|
|
11222
|
-
promo_codes: [value]
|
|
11223
|
-
},
|
|
11224
|
-
{
|
|
11225
|
-
onError: (e) => {
|
|
11226
|
-
toast.error(e.message);
|
|
11227
|
-
comboboxData.onSearchValueChange("");
|
|
11228
|
-
setComboboxValue("");
|
|
11229
|
-
},
|
|
11230
|
-
onSuccess: () => {
|
|
11231
|
-
comboboxData.onSearchValueChange("");
|
|
11232
|
-
setComboboxValue("");
|
|
11233
|
-
}
|
|
11234
|
-
}
|
|
11235
|
-
);
|
|
11236
|
-
};
|
|
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();
|
|
11237
11338
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11238
|
-
const { mutateAsync: requestOrderEdit } =
|
|
11339
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11340
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11341
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11239
11342
|
const onSubmit = async () => {
|
|
11240
11343
|
setIsSubmitting(true);
|
|
11241
11344
|
let requestSucceeded = false;
|
|
11242
11345
|
await requestOrderEdit(void 0, {
|
|
11243
11346
|
onError: (e) => {
|
|
11244
|
-
toast.error(e.message);
|
|
11347
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11245
11348
|
},
|
|
11246
11349
|
onSuccess: () => {
|
|
11247
11350
|
requestSucceeded = true;
|
|
@@ -11253,383 +11356,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
11253
11356
|
}
|
|
11254
11357
|
await confirmOrderEdit(void 0, {
|
|
11255
11358
|
onError: (e) => {
|
|
11256
|
-
toast.error(e.message);
|
|
11257
|
-
},
|
|
11258
|
-
onSuccess: () => {
|
|
11259
|
-
handleSuccess();
|
|
11260
|
-
},
|
|
11261
|
-
onSettled: () => {
|
|
11262
|
-
setIsSubmitting(false);
|
|
11263
|
-
}
|
|
11264
|
-
});
|
|
11265
|
-
};
|
|
11266
|
-
if (isError) {
|
|
11267
|
-
throw error;
|
|
11268
|
-
}
|
|
11269
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11270
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11271
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11272
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11273
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11274
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11275
|
-
] }),
|
|
11276
|
-
/* @__PURE__ */ jsx(
|
|
11277
|
-
Combobox,
|
|
11278
|
-
{
|
|
11279
|
-
id: "promotion-combobox",
|
|
11280
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11281
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11282
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11283
|
-
options: comboboxData.options,
|
|
11284
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11285
|
-
searchValue: comboboxData.searchValue,
|
|
11286
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11287
|
-
onChange: add,
|
|
11288
|
-
value: comboboxValue
|
|
11289
|
-
}
|
|
11290
|
-
)
|
|
11291
|
-
] }),
|
|
11292
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11293
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11294
|
-
PromotionItem,
|
|
11295
|
-
{
|
|
11296
|
-
promotion,
|
|
11297
|
-
orderId: preview.id,
|
|
11298
|
-
isLoading: isPending
|
|
11299
|
-
},
|
|
11300
|
-
promotion.id
|
|
11301
|
-
)) })
|
|
11302
|
-
] }) }),
|
|
11303
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11304
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11305
|
-
/* @__PURE__ */ jsx(
|
|
11306
|
-
Button,
|
|
11307
|
-
{
|
|
11308
|
-
size: "small",
|
|
11309
|
-
type: "submit",
|
|
11310
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11311
|
-
children: "Save"
|
|
11312
|
-
}
|
|
11313
|
-
)
|
|
11314
|
-
] }) })
|
|
11315
|
-
] });
|
|
11316
|
-
};
|
|
11317
|
-
const PromotionItem = ({
|
|
11318
|
-
promotion,
|
|
11319
|
-
orderId,
|
|
11320
|
-
isLoading
|
|
11321
|
-
}) => {
|
|
11322
|
-
var _a;
|
|
11323
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11324
|
-
const onRemove = async () => {
|
|
11325
|
-
removePromotions(
|
|
11326
|
-
{
|
|
11327
|
-
promo_codes: [promotion.code]
|
|
11328
|
-
},
|
|
11329
|
-
{
|
|
11330
|
-
onError: (e) => {
|
|
11331
|
-
toast.error(e.message);
|
|
11332
|
-
}
|
|
11333
|
-
}
|
|
11334
|
-
);
|
|
11335
|
-
};
|
|
11336
|
-
const displayValue = getDisplayValue(promotion);
|
|
11337
|
-
return /* @__PURE__ */ jsxs(
|
|
11338
|
-
"div",
|
|
11339
|
-
{
|
|
11340
|
-
className: clx(
|
|
11341
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11342
|
-
{
|
|
11343
|
-
"animate-pulse": isLoading
|
|
11344
|
-
}
|
|
11345
|
-
),
|
|
11346
|
-
children: [
|
|
11347
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11348
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11349
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11350
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11351
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11352
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11353
|
-
] }),
|
|
11354
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11355
|
-
] })
|
|
11356
|
-
] }),
|
|
11357
|
-
/* @__PURE__ */ jsx(
|
|
11358
|
-
IconButton,
|
|
11359
|
-
{
|
|
11360
|
-
size: "small",
|
|
11361
|
-
type: "button",
|
|
11362
|
-
variant: "transparent",
|
|
11363
|
-
onClick: onRemove,
|
|
11364
|
-
isLoading: isPending || isLoading,
|
|
11365
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11366
|
-
}
|
|
11367
|
-
)
|
|
11368
|
-
]
|
|
11369
|
-
},
|
|
11370
|
-
promotion.id
|
|
11371
|
-
);
|
|
11372
|
-
};
|
|
11373
|
-
function getDisplayValue(promotion) {
|
|
11374
|
-
var _a, _b, _c, _d;
|
|
11375
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11376
|
-
if (!value) {
|
|
11377
|
-
return null;
|
|
11378
|
-
}
|
|
11379
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11380
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11381
|
-
if (!currency) {
|
|
11382
|
-
return null;
|
|
11383
|
-
}
|
|
11384
|
-
return getLocaleAmount(value, currency);
|
|
11385
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11386
|
-
return formatPercentage(value);
|
|
11387
|
-
}
|
|
11388
|
-
return null;
|
|
11389
|
-
}
|
|
11390
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11391
|
-
style: "percent",
|
|
11392
|
-
minimumFractionDigits: 2
|
|
11393
|
-
});
|
|
11394
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11395
|
-
let val = value || 0;
|
|
11396
|
-
if (!isPercentageValue) {
|
|
11397
|
-
val = val / 100;
|
|
11398
|
-
}
|
|
11399
|
-
return formatter.format(val);
|
|
11400
|
-
};
|
|
11401
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11402
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11403
|
-
for (const item of items) {
|
|
11404
|
-
if (item.adjustments) {
|
|
11405
|
-
for (const adjustment of item.adjustments) {
|
|
11406
|
-
if (adjustment.promotion_id) {
|
|
11407
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11408
|
-
}
|
|
11409
|
-
}
|
|
11410
|
-
}
|
|
11411
|
-
}
|
|
11412
|
-
for (const shippingMethod of shippingMethods) {
|
|
11413
|
-
if (shippingMethod.adjustments) {
|
|
11414
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11415
|
-
if (adjustment.promotion_id) {
|
|
11416
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11417
|
-
}
|
|
11418
|
-
}
|
|
11419
|
-
}
|
|
11420
|
-
}
|
|
11421
|
-
return Array.from(promotionIds);
|
|
11422
|
-
}
|
|
11423
|
-
const CustomItems = () => {
|
|
11424
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11425
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
11426
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
11427
|
-
] });
|
|
11428
|
-
};
|
|
11429
|
-
const CustomItemsForm = () => {
|
|
11430
|
-
const form = useForm({
|
|
11431
|
-
resolver: zodResolver(schema$3)
|
|
11432
|
-
});
|
|
11433
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
11434
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
11435
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11436
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11437
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
11438
|
-
] }) })
|
|
11439
|
-
] }) });
|
|
11440
|
-
};
|
|
11441
|
-
const schema$3 = objectType({
|
|
11442
|
-
email: stringType().email()
|
|
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}`);
|
|
11621
|
-
},
|
|
11622
|
-
onSuccess: () => {
|
|
11623
|
-
requestSucceeded = true;
|
|
11624
|
-
}
|
|
11625
|
-
});
|
|
11626
|
-
if (!requestSucceeded) {
|
|
11627
|
-
setIsSubmitting(false);
|
|
11628
|
-
return;
|
|
11629
|
-
}
|
|
11630
|
-
await confirmOrderEdit(void 0, {
|
|
11631
|
-
onError: (e) => {
|
|
11632
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11359
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11633
11360
|
},
|
|
11634
11361
|
onSuccess: () => {
|
|
11635
11362
|
handleSuccess();
|
|
@@ -12340,20 +12067,223 @@ const CustomAmountField = ({
|
|
|
12340
12067
|
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
12341
12068
|
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
12342
12069
|
] }),
|
|
12343
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12344
|
-
CurrencyInput,
|
|
12070
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12071
|
+
CurrencyInput,
|
|
12072
|
+
{
|
|
12073
|
+
...field,
|
|
12074
|
+
onValueChange: (value) => onChange(value),
|
|
12075
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12076
|
+
code: currencyCode
|
|
12077
|
+
}
|
|
12078
|
+
) })
|
|
12079
|
+
] });
|
|
12080
|
+
}
|
|
12081
|
+
}
|
|
12082
|
+
);
|
|
12083
|
+
};
|
|
12084
|
+
const ShippingAddress = () => {
|
|
12085
|
+
const { id } = useParams();
|
|
12086
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12087
|
+
fields: "+shipping_address"
|
|
12088
|
+
});
|
|
12089
|
+
if (isError) {
|
|
12090
|
+
throw error;
|
|
12091
|
+
}
|
|
12092
|
+
const isReady = !isPending && !!order;
|
|
12093
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12094
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12095
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
|
|
12096
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
12097
|
+
] }),
|
|
12098
|
+
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
12099
|
+
] });
|
|
12100
|
+
};
|
|
12101
|
+
const ShippingAddressForm = ({ order }) => {
|
|
12102
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12103
|
+
const form = useForm({
|
|
12104
|
+
defaultValues: {
|
|
12105
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12106
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12107
|
+
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12108
|
+
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12109
|
+
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12110
|
+
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12111
|
+
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12112
|
+
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12113
|
+
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12114
|
+
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12115
|
+
},
|
|
12116
|
+
resolver: zodResolver(schema$1)
|
|
12117
|
+
});
|
|
12118
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12119
|
+
const { handleSuccess } = useRouteModal();
|
|
12120
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12121
|
+
await mutateAsync(
|
|
12122
|
+
{
|
|
12123
|
+
shipping_address: {
|
|
12124
|
+
first_name: data.first_name,
|
|
12125
|
+
last_name: data.last_name,
|
|
12126
|
+
company: data.company,
|
|
12127
|
+
address_1: data.address_1,
|
|
12128
|
+
address_2: data.address_2,
|
|
12129
|
+
city: data.city,
|
|
12130
|
+
province: data.province,
|
|
12131
|
+
country_code: data.country_code,
|
|
12132
|
+
postal_code: data.postal_code,
|
|
12133
|
+
phone: data.phone
|
|
12134
|
+
}
|
|
12135
|
+
},
|
|
12136
|
+
{
|
|
12137
|
+
onSuccess: () => {
|
|
12138
|
+
handleSuccess();
|
|
12139
|
+
},
|
|
12140
|
+
onError: (error) => {
|
|
12141
|
+
toast.error(error.message);
|
|
12142
|
+
}
|
|
12143
|
+
}
|
|
12144
|
+
);
|
|
12145
|
+
});
|
|
12146
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12147
|
+
KeyboundForm,
|
|
12148
|
+
{
|
|
12149
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12150
|
+
onSubmit,
|
|
12151
|
+
children: [
|
|
12152
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
12153
|
+
/* @__PURE__ */ jsx(
|
|
12154
|
+
Form$2.Field,
|
|
12155
|
+
{
|
|
12156
|
+
control: form.control,
|
|
12157
|
+
name: "country_code",
|
|
12158
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12159
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12160
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12161
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12162
|
+
] })
|
|
12163
|
+
}
|
|
12164
|
+
),
|
|
12165
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12166
|
+
/* @__PURE__ */ jsx(
|
|
12167
|
+
Form$2.Field,
|
|
12168
|
+
{
|
|
12169
|
+
control: form.control,
|
|
12170
|
+
name: "first_name",
|
|
12171
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12172
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12173
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12174
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12175
|
+
] })
|
|
12176
|
+
}
|
|
12177
|
+
),
|
|
12178
|
+
/* @__PURE__ */ jsx(
|
|
12179
|
+
Form$2.Field,
|
|
12180
|
+
{
|
|
12181
|
+
control: form.control,
|
|
12182
|
+
name: "last_name",
|
|
12183
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12184
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12185
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12186
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12187
|
+
] })
|
|
12188
|
+
}
|
|
12189
|
+
)
|
|
12190
|
+
] }),
|
|
12191
|
+
/* @__PURE__ */ jsx(
|
|
12192
|
+
Form$2.Field,
|
|
12193
|
+
{
|
|
12194
|
+
control: form.control,
|
|
12195
|
+
name: "company",
|
|
12196
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12197
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12198
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12199
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12200
|
+
] })
|
|
12201
|
+
}
|
|
12202
|
+
),
|
|
12203
|
+
/* @__PURE__ */ jsx(
|
|
12204
|
+
Form$2.Field,
|
|
12205
|
+
{
|
|
12206
|
+
control: form.control,
|
|
12207
|
+
name: "address_1",
|
|
12208
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12209
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12210
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12211
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12212
|
+
] })
|
|
12213
|
+
}
|
|
12214
|
+
),
|
|
12215
|
+
/* @__PURE__ */ jsx(
|
|
12216
|
+
Form$2.Field,
|
|
12217
|
+
{
|
|
12218
|
+
control: form.control,
|
|
12219
|
+
name: "address_2",
|
|
12220
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12221
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12222
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12223
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12224
|
+
] })
|
|
12225
|
+
}
|
|
12226
|
+
),
|
|
12227
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12228
|
+
/* @__PURE__ */ jsx(
|
|
12229
|
+
Form$2.Field,
|
|
12230
|
+
{
|
|
12231
|
+
control: form.control,
|
|
12232
|
+
name: "postal_code",
|
|
12233
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12234
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12235
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12236
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12237
|
+
] })
|
|
12238
|
+
}
|
|
12239
|
+
),
|
|
12240
|
+
/* @__PURE__ */ jsx(
|
|
12241
|
+
Form$2.Field,
|
|
12242
|
+
{
|
|
12243
|
+
control: form.control,
|
|
12244
|
+
name: "city",
|
|
12245
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12246
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12247
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12248
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12249
|
+
] })
|
|
12250
|
+
}
|
|
12251
|
+
)
|
|
12252
|
+
] }),
|
|
12253
|
+
/* @__PURE__ */ jsx(
|
|
12254
|
+
Form$2.Field,
|
|
12345
12255
|
{
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
|
|
12349
|
-
|
|
12256
|
+
control: form.control,
|
|
12257
|
+
name: "province",
|
|
12258
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12259
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12260
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12261
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12262
|
+
] })
|
|
12350
12263
|
}
|
|
12351
|
-
)
|
|
12352
|
-
|
|
12353
|
-
|
|
12264
|
+
),
|
|
12265
|
+
/* @__PURE__ */ jsx(
|
|
12266
|
+
Form$2.Field,
|
|
12267
|
+
{
|
|
12268
|
+
control: form.control,
|
|
12269
|
+
name: "phone",
|
|
12270
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12271
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12272
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12273
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12274
|
+
] })
|
|
12275
|
+
}
|
|
12276
|
+
)
|
|
12277
|
+
] }) }),
|
|
12278
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12279
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12280
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12281
|
+
] }) })
|
|
12282
|
+
]
|
|
12354
12283
|
}
|
|
12355
|
-
);
|
|
12284
|
+
) });
|
|
12356
12285
|
};
|
|
12286
|
+
const schema$1 = addressSchema;
|
|
12357
12287
|
const TransferOwnership = () => {
|
|
12358
12288
|
const { id } = useParams();
|
|
12359
12289
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12377,7 +12307,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12377
12307
|
defaultValues: {
|
|
12378
12308
|
customer_id: order.customer_id || ""
|
|
12379
12309
|
},
|
|
12380
|
-
resolver: zodResolver(schema
|
|
12310
|
+
resolver: zodResolver(schema)
|
|
12381
12311
|
});
|
|
12382
12312
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12383
12313
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12827,212 +12757,286 @@ const Illustration = () => {
|
|
|
12827
12757
|
}
|
|
12828
12758
|
);
|
|
12829
12759
|
};
|
|
12830
|
-
const schema
|
|
12760
|
+
const schema = objectType({
|
|
12831
12761
|
customer_id: stringType().min(1)
|
|
12832
12762
|
});
|
|
12833
|
-
const
|
|
12834
|
-
|
|
12835
|
-
|
|
12836
|
-
|
|
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
|
|
12837
12780
|
});
|
|
12838
|
-
|
|
12839
|
-
|
|
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;
|
|
12840
12794
|
}
|
|
12841
|
-
const isReady =
|
|
12842
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12843
|
-
/* @__PURE__ */
|
|
12844
|
-
|
|
12845
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
12846
|
-
] }),
|
|
12847
|
-
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
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 })
|
|
12848
12799
|
] });
|
|
12849
12800
|
};
|
|
12850
|
-
const
|
|
12851
|
-
|
|
12852
|
-
const
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12861
|
-
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12862
|
-
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12863
|
-
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
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
|
|
12864
12811
|
},
|
|
12865
|
-
|
|
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
|
+
}
|
|
12866
12832
|
});
|
|
12867
|
-
const
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12833
|
+
const add = async (value) => {
|
|
12834
|
+
if (!value) {
|
|
12835
|
+
return;
|
|
12836
|
+
}
|
|
12837
|
+
addPromotions(
|
|
12871
12838
|
{
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
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
|
|
12906
|
+
}
|
|
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"
|
|
12883
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]
|
|
12884
12945
|
},
|
|
12885
12946
|
{
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
},
|
|
12889
|
-
onError: (error) => {
|
|
12890
|
-
toast.error(error.message);
|
|
12947
|
+
onError: (e) => {
|
|
12948
|
+
toast.error(e.message);
|
|
12891
12949
|
}
|
|
12892
12950
|
}
|
|
12893
12951
|
);
|
|
12894
|
-
}
|
|
12895
|
-
|
|
12896
|
-
|
|
12952
|
+
};
|
|
12953
|
+
const displayValue = getDisplayValue(promotion);
|
|
12954
|
+
return /* @__PURE__ */ jsxs(
|
|
12955
|
+
"div",
|
|
12897
12956
|
{
|
|
12898
|
-
className:
|
|
12899
|
-
|
|
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
|
+
),
|
|
12900
12963
|
children: [
|
|
12901
|
-
/* @__PURE__ */
|
|
12902
|
-
/* @__PURE__ */ jsx(
|
|
12903
|
-
|
|
12904
|
-
{
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12923
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12924
|
-
] })
|
|
12925
|
-
}
|
|
12926
|
-
),
|
|
12927
|
-
/* @__PURE__ */ jsx(
|
|
12928
|
-
Form$2.Field,
|
|
12929
|
-
{
|
|
12930
|
-
control: form.control,
|
|
12931
|
-
name: "last_name",
|
|
12932
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12933
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12934
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12935
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12936
|
-
] })
|
|
12937
|
-
}
|
|
12938
|
-
)
|
|
12939
|
-
] }),
|
|
12940
|
-
/* @__PURE__ */ jsx(
|
|
12941
|
-
Form$2.Field,
|
|
12942
|
-
{
|
|
12943
|
-
control: form.control,
|
|
12944
|
-
name: "company",
|
|
12945
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12946
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12947
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12948
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12949
|
-
] })
|
|
12950
|
-
}
|
|
12951
|
-
),
|
|
12952
|
-
/* @__PURE__ */ jsx(
|
|
12953
|
-
Form$2.Field,
|
|
12954
|
-
{
|
|
12955
|
-
control: form.control,
|
|
12956
|
-
name: "address_1",
|
|
12957
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12958
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12959
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12960
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12961
|
-
] })
|
|
12962
|
-
}
|
|
12963
|
-
),
|
|
12964
|
-
/* @__PURE__ */ jsx(
|
|
12965
|
-
Form$2.Field,
|
|
12966
|
-
{
|
|
12967
|
-
control: form.control,
|
|
12968
|
-
name: "address_2",
|
|
12969
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12970
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12971
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12972
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12973
|
-
] })
|
|
12974
|
-
}
|
|
12975
|
-
),
|
|
12976
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12977
|
-
/* @__PURE__ */ jsx(
|
|
12978
|
-
Form$2.Field,
|
|
12979
|
-
{
|
|
12980
|
-
control: form.control,
|
|
12981
|
-
name: "postal_code",
|
|
12982
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12983
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12984
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12985
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12986
|
-
] })
|
|
12987
|
-
}
|
|
12988
|
-
),
|
|
12989
|
-
/* @__PURE__ */ jsx(
|
|
12990
|
-
Form$2.Field,
|
|
12991
|
-
{
|
|
12992
|
-
control: form.control,
|
|
12993
|
-
name: "city",
|
|
12994
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12995
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12996
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12997
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12998
|
-
] })
|
|
12999
|
-
}
|
|
13000
|
-
)
|
|
13001
|
-
] }),
|
|
13002
|
-
/* @__PURE__ */ jsx(
|
|
13003
|
-
Form$2.Field,
|
|
13004
|
-
{
|
|
13005
|
-
control: form.control,
|
|
13006
|
-
name: "province",
|
|
13007
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13008
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13009
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13010
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13011
|
-
] })
|
|
13012
|
-
}
|
|
13013
|
-
),
|
|
13014
|
-
/* @__PURE__ */ jsx(
|
|
13015
|
-
Form$2.Field,
|
|
13016
|
-
{
|
|
13017
|
-
control: form.control,
|
|
13018
|
-
name: "phone",
|
|
13019
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13020
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13021
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13022
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13023
|
-
] })
|
|
13024
|
-
}
|
|
13025
|
-
)
|
|
13026
|
-
] }) }),
|
|
13027
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13028
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13029
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13030
|
-
] }) })
|
|
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,
|
|
12976
|
+
{
|
|
12977
|
+
size: "small",
|
|
12978
|
+
type: "button",
|
|
12979
|
+
variant: "transparent",
|
|
12980
|
+
onClick: onRemove,
|
|
12981
|
+
isLoading: isPending || isLoading,
|
|
12982
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12983
|
+
}
|
|
12984
|
+
)
|
|
13031
12985
|
]
|
|
12986
|
+
},
|
|
12987
|
+
promotion.id
|
|
12988
|
+
);
|
|
12989
|
+
};
|
|
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;
|
|
13032
13000
|
}
|
|
13033
|
-
|
|
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
|
|
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);
|
|
13034
13017
|
};
|
|
13035
|
-
|
|
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,6 +13061,10 @@ const routeModule = {
|
|
|
13057
13061
|
Component: BillingAddress,
|
|
13058
13062
|
path: "/draft-orders/:id/billing-address"
|
|
13059
13063
|
},
|
|
13064
|
+
{
|
|
13065
|
+
Component: CustomItems,
|
|
13066
|
+
path: "/draft-orders/:id/custom-items"
|
|
13067
|
+
},
|
|
13060
13068
|
{
|
|
13061
13069
|
Component: Email,
|
|
13062
13070
|
path: "/draft-orders/:id/email"
|
|
@@ -13069,14 +13077,6 @@ const routeModule = {
|
|
|
13069
13077
|
Component: Metadata,
|
|
13070
13078
|
path: "/draft-orders/:id/metadata"
|
|
13071
13079
|
},
|
|
13072
|
-
{
|
|
13073
|
-
Component: Promotions,
|
|
13074
|
-
path: "/draft-orders/:id/promotions"
|
|
13075
|
-
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: CustomItems,
|
|
13078
|
-
path: "/draft-orders/:id/custom-items"
|
|
13079
|
-
},
|
|
13080
13080
|
{
|
|
13081
13081
|
Component: SalesChannel,
|
|
13082
13082
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13085,13 +13085,17 @@ const routeModule = {
|
|
|
13085
13085
|
Component: Shipping,
|
|
13086
13086
|
path: "/draft-orders/:id/shipping"
|
|
13087
13087
|
},
|
|
13088
|
+
{
|
|
13089
|
+
Component: ShippingAddress,
|
|
13090
|
+
path: "/draft-orders/:id/shipping-address"
|
|
13091
|
+
},
|
|
13088
13092
|
{
|
|
13089
13093
|
Component: TransferOwnership,
|
|
13090
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13091
13095
|
},
|
|
13092
13096
|
{
|
|
13093
|
-
Component:
|
|
13094
|
-
path: "/draft-orders/:id/
|
|
13097
|
+
Component: Promotions,
|
|
13098
|
+
path: "/draft-orders/:id/promotions"
|
|
13095
13099
|
}
|
|
13096
13100
|
]
|
|
13097
13101
|
}
|