@medusajs/draft-order 2.22.1 → 2.22.2-preview-20261028132907
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 +840 -840
- package/.medusa/server/src/admin/index.mjs +840 -840
- package/package.json +20 -20
|
@@ -5976,95 +5976,6 @@ const ID = () => {
|
|
|
5976
5976
|
}
|
|
5977
5977
|
);
|
|
5978
5978
|
};
|
|
5979
|
-
const CustomItems = () => {
|
|
5980
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
5981
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
5982
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
5983
|
-
] });
|
|
5984
|
-
};
|
|
5985
|
-
const CustomItemsForm = () => {
|
|
5986
|
-
const form = useForm({
|
|
5987
|
-
resolver: zodResolver(schema$5)
|
|
5988
|
-
});
|
|
5989
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
5990
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
5991
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
5992
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
5993
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
5994
|
-
] }) })
|
|
5995
|
-
] }) });
|
|
5996
|
-
};
|
|
5997
|
-
const schema$5 = z.object({
|
|
5998
|
-
email: z.string().email()
|
|
5999
|
-
});
|
|
6000
|
-
const Email = () => {
|
|
6001
|
-
const { id } = useParams();
|
|
6002
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
6003
|
-
fields: "+email"
|
|
6004
|
-
});
|
|
6005
|
-
if (isError) {
|
|
6006
|
-
throw error;
|
|
6007
|
-
}
|
|
6008
|
-
const isReady = !isPending && !!order;
|
|
6009
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
6010
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
6011
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
6012
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
6013
|
-
] }),
|
|
6014
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
6015
|
-
] });
|
|
6016
|
-
};
|
|
6017
|
-
const EmailForm = ({ order }) => {
|
|
6018
|
-
const form = useForm({
|
|
6019
|
-
defaultValues: {
|
|
6020
|
-
email: order.email ?? ""
|
|
6021
|
-
},
|
|
6022
|
-
resolver: zodResolver(schema$4)
|
|
6023
|
-
});
|
|
6024
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6025
|
-
const { handleSuccess } = useRouteModal();
|
|
6026
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
6027
|
-
await mutateAsync(
|
|
6028
|
-
{ email: data.email },
|
|
6029
|
-
{
|
|
6030
|
-
onSuccess: () => {
|
|
6031
|
-
handleSuccess();
|
|
6032
|
-
},
|
|
6033
|
-
onError: (error) => {
|
|
6034
|
-
toast.error(error.message);
|
|
6035
|
-
}
|
|
6036
|
-
}
|
|
6037
|
-
);
|
|
6038
|
-
});
|
|
6039
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
6040
|
-
KeyboundForm,
|
|
6041
|
-
{
|
|
6042
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
6043
|
-
onSubmit,
|
|
6044
|
-
children: [
|
|
6045
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
6046
|
-
Form$2.Field,
|
|
6047
|
-
{
|
|
6048
|
-
control: form.control,
|
|
6049
|
-
name: "email",
|
|
6050
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
6051
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
6052
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
6053
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
6054
|
-
] })
|
|
6055
|
-
}
|
|
6056
|
-
) }),
|
|
6057
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6058
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6059
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
6060
|
-
] }) })
|
|
6061
|
-
]
|
|
6062
|
-
}
|
|
6063
|
-
) });
|
|
6064
|
-
};
|
|
6065
|
-
const schema$4 = z.object({
|
|
6066
|
-
email: z.string().email()
|
|
6067
|
-
});
|
|
6068
5979
|
const BillingAddress = () => {
|
|
6069
5980
|
const { id } = useParams();
|
|
6070
5981
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -6096,7 +6007,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
6096
6007
|
postal_code: order.billing_address?.postal_code ?? "",
|
|
6097
6008
|
phone: order.billing_address?.phone ?? ""
|
|
6098
6009
|
},
|
|
6099
|
-
resolver: zodResolver(schema$
|
|
6010
|
+
resolver: zodResolver(schema$5)
|
|
6100
6011
|
});
|
|
6101
6012
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6102
6013
|
const { handleSuccess } = useRouteModal();
|
|
@@ -6253,7 +6164,96 @@ const BillingAddressForm = ({ order }) => {
|
|
|
6253
6164
|
}
|
|
6254
6165
|
) });
|
|
6255
6166
|
};
|
|
6256
|
-
const schema$
|
|
6167
|
+
const schema$5 = addressSchema;
|
|
6168
|
+
const CustomItems = () => {
|
|
6169
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
6170
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
6171
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
6172
|
+
] });
|
|
6173
|
+
};
|
|
6174
|
+
const CustomItemsForm = () => {
|
|
6175
|
+
const form = useForm({
|
|
6176
|
+
resolver: zodResolver(schema$4)
|
|
6177
|
+
});
|
|
6178
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
6179
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
6180
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6181
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6182
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
6183
|
+
] }) })
|
|
6184
|
+
] }) });
|
|
6185
|
+
};
|
|
6186
|
+
const schema$4 = z.object({
|
|
6187
|
+
email: z.string().email()
|
|
6188
|
+
});
|
|
6189
|
+
const Email = () => {
|
|
6190
|
+
const { id } = useParams();
|
|
6191
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
6192
|
+
fields: "+email"
|
|
6193
|
+
});
|
|
6194
|
+
if (isError) {
|
|
6195
|
+
throw error;
|
|
6196
|
+
}
|
|
6197
|
+
const isReady = !isPending && !!order;
|
|
6198
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
6199
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
6200
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
6201
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
6202
|
+
] }),
|
|
6203
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
6204
|
+
] });
|
|
6205
|
+
};
|
|
6206
|
+
const EmailForm = ({ order }) => {
|
|
6207
|
+
const form = useForm({
|
|
6208
|
+
defaultValues: {
|
|
6209
|
+
email: order.email ?? ""
|
|
6210
|
+
},
|
|
6211
|
+
resolver: zodResolver(schema$3)
|
|
6212
|
+
});
|
|
6213
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
6214
|
+
const { handleSuccess } = useRouteModal();
|
|
6215
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
6216
|
+
await mutateAsync(
|
|
6217
|
+
{ email: data.email },
|
|
6218
|
+
{
|
|
6219
|
+
onSuccess: () => {
|
|
6220
|
+
handleSuccess();
|
|
6221
|
+
},
|
|
6222
|
+
onError: (error) => {
|
|
6223
|
+
toast.error(error.message);
|
|
6224
|
+
}
|
|
6225
|
+
}
|
|
6226
|
+
);
|
|
6227
|
+
});
|
|
6228
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
6229
|
+
KeyboundForm,
|
|
6230
|
+
{
|
|
6231
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
6232
|
+
onSubmit,
|
|
6233
|
+
children: [
|
|
6234
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
6235
|
+
Form$2.Field,
|
|
6236
|
+
{
|
|
6237
|
+
control: form.control,
|
|
6238
|
+
name: "email",
|
|
6239
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
6240
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
6241
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
6242
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
6243
|
+
] })
|
|
6244
|
+
}
|
|
6245
|
+
) }),
|
|
6246
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
6247
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
6248
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
6249
|
+
] }) })
|
|
6250
|
+
]
|
|
6251
|
+
}
|
|
6252
|
+
) });
|
|
6253
|
+
};
|
|
6254
|
+
const schema$3 = z.object({
|
|
6255
|
+
email: z.string().email()
|
|
6256
|
+
});
|
|
6257
6257
|
const NumberInput = forwardRef(
|
|
6258
6258
|
({
|
|
6259
6259
|
value,
|
|
@@ -7273,88 +7273,46 @@ const customItemSchema = z.object({
|
|
|
7273
7273
|
quantity: z.number(),
|
|
7274
7274
|
unit_price: z.union([z.number(), z.string()])
|
|
7275
7275
|
});
|
|
7276
|
-
const
|
|
7277
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
7278
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
7279
|
-
return /* @__PURE__ */ jsxs(
|
|
7280
|
-
"div",
|
|
7281
|
-
{
|
|
7282
|
-
ref,
|
|
7283
|
-
className: clx(
|
|
7284
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
7285
|
-
className
|
|
7286
|
-
),
|
|
7287
|
-
...props,
|
|
7288
|
-
children: [
|
|
7289
|
-
/* @__PURE__ */ jsx(
|
|
7290
|
-
"div",
|
|
7291
|
-
{
|
|
7292
|
-
role: "presentation",
|
|
7293
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
7294
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
7295
|
-
})
|
|
7296
|
-
}
|
|
7297
|
-
),
|
|
7298
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
7299
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
7300
|
-
labelValue,
|
|
7301
|
-
":"
|
|
7302
|
-
] }),
|
|
7303
|
-
" ",
|
|
7304
|
-
children
|
|
7305
|
-
] })
|
|
7306
|
-
]
|
|
7307
|
-
}
|
|
7308
|
-
);
|
|
7309
|
-
}
|
|
7310
|
-
);
|
|
7311
|
-
InlineTip.displayName = "InlineTip";
|
|
7312
|
-
const MetadataFieldSchema = z.object({
|
|
7313
|
-
key: z.string(),
|
|
7314
|
-
disabled: z.boolean().optional(),
|
|
7315
|
-
value: z.any()
|
|
7316
|
-
});
|
|
7317
|
-
const MetadataSchema = z.object({
|
|
7318
|
-
metadata: z.array(MetadataFieldSchema)
|
|
7319
|
-
});
|
|
7320
|
-
const Metadata = () => {
|
|
7276
|
+
const SalesChannel = () => {
|
|
7321
7277
|
const { id } = useParams();
|
|
7322
|
-
const {
|
|
7323
|
-
|
|
7324
|
-
|
|
7278
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
7279
|
+
id,
|
|
7280
|
+
{
|
|
7281
|
+
fields: "+sales_channel_id"
|
|
7282
|
+
},
|
|
7283
|
+
{
|
|
7284
|
+
enabled: !!id
|
|
7285
|
+
}
|
|
7286
|
+
);
|
|
7325
7287
|
if (isError) {
|
|
7326
7288
|
throw error;
|
|
7327
7289
|
}
|
|
7328
|
-
const
|
|
7290
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
7329
7291
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
7330
7292
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
7331
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
7332
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
7293
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
7294
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
7333
7295
|
] }),
|
|
7334
|
-
|
|
7296
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
7335
7297
|
] });
|
|
7336
7298
|
};
|
|
7337
|
-
const
|
|
7338
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
7339
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
7340
|
-
const { handleSuccess } = useRouteModal();
|
|
7341
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
7342
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
7299
|
+
const SalesChannelForm = ({ order }) => {
|
|
7343
7300
|
const form = useForm({
|
|
7344
7301
|
defaultValues: {
|
|
7345
|
-
|
|
7302
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
7346
7303
|
},
|
|
7347
|
-
resolver: zodResolver(
|
|
7304
|
+
resolver: zodResolver(schema$2)
|
|
7348
7305
|
});
|
|
7349
|
-
const
|
|
7350
|
-
|
|
7306
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
7307
|
+
const { handleSuccess } = useRouteModal();
|
|
7308
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
7351
7309
|
await mutateAsync(
|
|
7352
7310
|
{
|
|
7353
|
-
|
|
7311
|
+
sales_channel_id: data.sales_channel_id
|
|
7354
7312
|
},
|
|
7355
7313
|
{
|
|
7356
7314
|
onSuccess: () => {
|
|
7357
|
-
toast.success("
|
|
7315
|
+
toast.success("Sales channel updated");
|
|
7358
7316
|
handleSuccess();
|
|
7359
7317
|
},
|
|
7360
7318
|
onError: (error) => {
|
|
@@ -7363,365 +7321,133 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
7363
7321
|
}
|
|
7364
7322
|
);
|
|
7365
7323
|
});
|
|
7366
|
-
const { fields, insert, remove } = useFieldArray({
|
|
7367
|
-
control: form.control,
|
|
7368
|
-
name: "metadata"
|
|
7369
|
-
});
|
|
7370
|
-
function deleteRow(index) {
|
|
7371
|
-
remove(index);
|
|
7372
|
-
if (fields.length === 1) {
|
|
7373
|
-
insert(0, {
|
|
7374
|
-
key: "",
|
|
7375
|
-
value: "",
|
|
7376
|
-
disabled: false
|
|
7377
|
-
});
|
|
7378
|
-
}
|
|
7379
|
-
}
|
|
7380
|
-
function insertRow(index, position) {
|
|
7381
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
7382
|
-
key: "",
|
|
7383
|
-
value: "",
|
|
7384
|
-
disabled: false
|
|
7385
|
-
});
|
|
7386
|
-
}
|
|
7387
7324
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
7388
7325
|
KeyboundForm,
|
|
7389
7326
|
{
|
|
7390
|
-
onSubmit: handleSubmit,
|
|
7391
7327
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
7328
|
+
onSubmit,
|
|
7392
7329
|
children: [
|
|
7393
|
-
/* @__PURE__ */
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
7397
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
7398
|
-
] }),
|
|
7399
|
-
fields.map((field, index) => {
|
|
7400
|
-
const isDisabled = field.disabled || false;
|
|
7401
|
-
let placeholder = "-";
|
|
7402
|
-
if (typeof field.value === "object") {
|
|
7403
|
-
placeholder = "{ ... }";
|
|
7404
|
-
}
|
|
7405
|
-
if (Array.isArray(field.value)) {
|
|
7406
|
-
placeholder = "[ ... ]";
|
|
7407
|
-
}
|
|
7408
|
-
return /* @__PURE__ */ jsx(
|
|
7409
|
-
ConditionalTooltip,
|
|
7410
|
-
{
|
|
7411
|
-
showTooltip: isDisabled,
|
|
7412
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
7413
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
7414
|
-
/* @__PURE__ */ jsxs(
|
|
7415
|
-
"div",
|
|
7416
|
-
{
|
|
7417
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
7418
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
7419
|
-
}),
|
|
7420
|
-
children: [
|
|
7421
|
-
/* @__PURE__ */ jsx(
|
|
7422
|
-
Form$2.Field,
|
|
7423
|
-
{
|
|
7424
|
-
control: form.control,
|
|
7425
|
-
name: `metadata.${index}.key`,
|
|
7426
|
-
render: ({ field: field2 }) => {
|
|
7427
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7428
|
-
GridInput,
|
|
7429
|
-
{
|
|
7430
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
7431
|
-
...field2,
|
|
7432
|
-
disabled: isDisabled,
|
|
7433
|
-
placeholder: "Key"
|
|
7434
|
-
}
|
|
7435
|
-
) }) });
|
|
7436
|
-
}
|
|
7437
|
-
}
|
|
7438
|
-
),
|
|
7439
|
-
/* @__PURE__ */ jsx(
|
|
7440
|
-
Form$2.Field,
|
|
7441
|
-
{
|
|
7442
|
-
control: form.control,
|
|
7443
|
-
name: `metadata.${index}.value`,
|
|
7444
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
7445
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7446
|
-
GridInput,
|
|
7447
|
-
{
|
|
7448
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
7449
|
-
...field2,
|
|
7450
|
-
value: isDisabled ? placeholder : value,
|
|
7451
|
-
disabled: isDisabled,
|
|
7452
|
-
placeholder: "Value"
|
|
7453
|
-
}
|
|
7454
|
-
) }) });
|
|
7455
|
-
}
|
|
7456
|
-
}
|
|
7457
|
-
)
|
|
7458
|
-
]
|
|
7459
|
-
}
|
|
7460
|
-
),
|
|
7461
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
7462
|
-
/* @__PURE__ */ jsx(
|
|
7463
|
-
DropdownMenu.Trigger,
|
|
7464
|
-
{
|
|
7465
|
-
className: clx(
|
|
7466
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
7467
|
-
{
|
|
7468
|
-
hidden: isDisabled
|
|
7469
|
-
}
|
|
7470
|
-
),
|
|
7471
|
-
disabled: isDisabled,
|
|
7472
|
-
asChild: true,
|
|
7473
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
7474
|
-
}
|
|
7475
|
-
),
|
|
7476
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
7477
|
-
/* @__PURE__ */ jsxs(
|
|
7478
|
-
DropdownMenu.Item,
|
|
7479
|
-
{
|
|
7480
|
-
className: "gap-x-2",
|
|
7481
|
-
onClick: () => insertRow(index, "above"),
|
|
7482
|
-
children: [
|
|
7483
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
7484
|
-
"Insert row above"
|
|
7485
|
-
]
|
|
7486
|
-
}
|
|
7487
|
-
),
|
|
7488
|
-
/* @__PURE__ */ jsxs(
|
|
7489
|
-
DropdownMenu.Item,
|
|
7490
|
-
{
|
|
7491
|
-
className: "gap-x-2",
|
|
7492
|
-
onClick: () => insertRow(index, "below"),
|
|
7493
|
-
children: [
|
|
7494
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
7495
|
-
"Insert row below"
|
|
7496
|
-
]
|
|
7497
|
-
}
|
|
7498
|
-
),
|
|
7499
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
7500
|
-
/* @__PURE__ */ jsxs(
|
|
7501
|
-
DropdownMenu.Item,
|
|
7502
|
-
{
|
|
7503
|
-
className: "gap-x-2",
|
|
7504
|
-
onClick: () => deleteRow(index),
|
|
7505
|
-
children: [
|
|
7506
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
7507
|
-
"Delete row"
|
|
7508
|
-
]
|
|
7509
|
-
}
|
|
7510
|
-
)
|
|
7511
|
-
] })
|
|
7512
|
-
] })
|
|
7513
|
-
] })
|
|
7514
|
-
},
|
|
7515
|
-
field.id
|
|
7516
|
-
);
|
|
7517
|
-
})
|
|
7518
|
-
] }),
|
|
7519
|
-
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
7520
|
-
] }),
|
|
7521
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7522
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
7330
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
7331
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7332
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7523
7333
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
7524
7334
|
] }) })
|
|
7525
7335
|
]
|
|
7526
7336
|
}
|
|
7527
7337
|
) });
|
|
7528
7338
|
};
|
|
7529
|
-
const
|
|
7339
|
+
const SalesChannelField = ({ control, order }) => {
|
|
7340
|
+
const salesChannels = useComboboxData({
|
|
7341
|
+
queryFn: async (params) => {
|
|
7342
|
+
return await sdk.admin.salesChannel.list(params);
|
|
7343
|
+
},
|
|
7344
|
+
queryKey: ["sales-channels"],
|
|
7345
|
+
getOptions: (data) => {
|
|
7346
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
7347
|
+
label: salesChannel.name,
|
|
7348
|
+
value: salesChannel.id
|
|
7349
|
+
}));
|
|
7350
|
+
},
|
|
7351
|
+
defaultValue: order.sales_channel_id || void 0
|
|
7352
|
+
});
|
|
7530
7353
|
return /* @__PURE__ */ jsx(
|
|
7531
|
-
|
|
7354
|
+
Form$2.Field,
|
|
7532
7355
|
{
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7356
|
+
control,
|
|
7357
|
+
name: "sales_channel_id",
|
|
7358
|
+
render: ({ field }) => {
|
|
7359
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
7360
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
7361
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
7362
|
+
Combobox,
|
|
7363
|
+
{
|
|
7364
|
+
options: salesChannels.options,
|
|
7365
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
7366
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
7367
|
+
searchValue: salesChannels.searchValue,
|
|
7368
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
7369
|
+
placeholder: "Select sales channel",
|
|
7370
|
+
...field
|
|
7371
|
+
}
|
|
7372
|
+
) }),
|
|
7373
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
7374
|
+
] });
|
|
7375
|
+
}
|
|
7540
7376
|
}
|
|
7541
7377
|
);
|
|
7542
|
-
});
|
|
7543
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
7544
|
-
const PlaceholderInner = () => {
|
|
7545
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
7546
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
7547
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
7548
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
7549
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
7550
|
-
] }) })
|
|
7551
|
-
] });
|
|
7552
7378
|
};
|
|
7553
|
-
const
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
}
|
|
7562
|
-
];
|
|
7563
|
-
}
|
|
7564
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
7565
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
7566
|
-
return {
|
|
7567
|
-
key,
|
|
7568
|
-
value,
|
|
7569
|
-
disabled: true
|
|
7570
|
-
};
|
|
7571
|
-
}
|
|
7572
|
-
let stringValue = value;
|
|
7573
|
-
if (typeof value !== "string") {
|
|
7574
|
-
stringValue = JSON.stringify(value);
|
|
7575
|
-
}
|
|
7576
|
-
return {
|
|
7577
|
-
key,
|
|
7578
|
-
value: stringValue,
|
|
7579
|
-
original_key: key
|
|
7580
|
-
};
|
|
7379
|
+
const schema$2 = z.object({
|
|
7380
|
+
sales_channel_id: z.string().min(1)
|
|
7381
|
+
});
|
|
7382
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7383
|
+
const Shipping = () => {
|
|
7384
|
+
const { id } = useParams();
|
|
7385
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
7386
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
7581
7387
|
});
|
|
7582
|
-
}
|
|
7583
|
-
function parseValues(values) {
|
|
7584
|
-
const metadata = values.metadata;
|
|
7585
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
7586
|
-
if (isEmpty) {
|
|
7587
|
-
return null;
|
|
7588
|
-
}
|
|
7589
|
-
const update = {};
|
|
7590
|
-
metadata.forEach((field) => {
|
|
7591
|
-
let key = field.key;
|
|
7592
|
-
let value = field.value;
|
|
7593
|
-
const disabled = field.disabled;
|
|
7594
|
-
if (!key || !value) {
|
|
7595
|
-
return;
|
|
7596
|
-
}
|
|
7597
|
-
if (disabled) {
|
|
7598
|
-
update[key] = value;
|
|
7599
|
-
return;
|
|
7600
|
-
}
|
|
7601
|
-
key = key.trim();
|
|
7602
|
-
value = value.trim();
|
|
7603
|
-
if (value === "true") {
|
|
7604
|
-
update[key] = true;
|
|
7605
|
-
} else if (value === "false") {
|
|
7606
|
-
update[key] = false;
|
|
7607
|
-
} else {
|
|
7608
|
-
const parsedNumber = parseFloat(value);
|
|
7609
|
-
if (!isNaN(parsedNumber)) {
|
|
7610
|
-
update[key] = parsedNumber;
|
|
7611
|
-
} else {
|
|
7612
|
-
update[key] = value;
|
|
7613
|
-
}
|
|
7614
|
-
}
|
|
7615
|
-
});
|
|
7616
|
-
return update;
|
|
7617
|
-
}
|
|
7618
|
-
function getHasUneditableRows(metadata) {
|
|
7619
|
-
if (!metadata) {
|
|
7620
|
-
return false;
|
|
7621
|
-
}
|
|
7622
|
-
return Object.values(metadata).some(
|
|
7623
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
7624
|
-
);
|
|
7625
|
-
}
|
|
7626
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
7627
|
-
const promotionsQueryKeys = {
|
|
7628
|
-
list: (query2) => [
|
|
7629
|
-
PROMOTION_QUERY_KEY,
|
|
7630
|
-
query2 ? query2 : void 0
|
|
7631
|
-
],
|
|
7632
|
-
detail: (id, query2) => [
|
|
7633
|
-
PROMOTION_QUERY_KEY,
|
|
7634
|
-
id,
|
|
7635
|
-
query2 ? query2 : void 0
|
|
7636
|
-
]
|
|
7637
|
-
};
|
|
7638
|
-
const usePromotions = (query2, options) => {
|
|
7639
|
-
const { data, ...rest } = useQuery({
|
|
7640
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
7641
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
7642
|
-
...options
|
|
7643
|
-
});
|
|
7644
|
-
return { ...data, ...rest };
|
|
7645
|
-
};
|
|
7646
|
-
const Promotions = () => {
|
|
7647
|
-
const { id } = useParams();
|
|
7648
7388
|
const {
|
|
7649
7389
|
order: preview,
|
|
7390
|
+
isPending: isPreviewPending,
|
|
7650
7391
|
isError: isPreviewError,
|
|
7651
7392
|
error: previewError
|
|
7652
|
-
} = useOrderPreview(id
|
|
7393
|
+
} = useOrderPreview(id);
|
|
7653
7394
|
useInitiateOrderEdit({ preview });
|
|
7654
7395
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
7396
|
+
if (isError) {
|
|
7397
|
+
throw error;
|
|
7398
|
+
}
|
|
7655
7399
|
if (isPreviewError) {
|
|
7656
7400
|
throw previewError;
|
|
7657
7401
|
}
|
|
7658
|
-
const
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7402
|
+
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
7403
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
7404
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
7405
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
7406
|
+
/* @__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: [
|
|
7407
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
7408
|
+
/* @__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." }) })
|
|
7409
|
+
] }) }) }),
|
|
7410
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
7411
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
7412
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
7413
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
7414
|
+
] }) });
|
|
7663
7415
|
};
|
|
7664
|
-
const
|
|
7665
|
-
const {
|
|
7416
|
+
const ShippingForm = ({ preview, order }) => {
|
|
7417
|
+
const { setIsOpen } = useStackedModal();
|
|
7666
7418
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
7667
|
-
const [
|
|
7668
|
-
const
|
|
7669
|
-
const {
|
|
7670
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
7671
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
7419
|
+
const [data, setData] = useState(null);
|
|
7420
|
+
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
7421
|
+
const { shipping_options } = useShippingOptions(
|
|
7672
7422
|
{
|
|
7673
|
-
id:
|
|
7423
|
+
id: appliedShippingOptionIds,
|
|
7424
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
7674
7425
|
},
|
|
7675
7426
|
{
|
|
7676
|
-
enabled:
|
|
7427
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
7677
7428
|
}
|
|
7678
7429
|
);
|
|
7679
|
-
const
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
return data.promotions.map((promotion) => ({
|
|
7691
|
-
label: promotion.code,
|
|
7692
|
-
value: promotion.code
|
|
7693
|
-
}));
|
|
7694
|
-
}
|
|
7695
|
-
});
|
|
7696
|
-
const add = async (value) => {
|
|
7697
|
-
if (!value) {
|
|
7698
|
-
return;
|
|
7699
|
-
}
|
|
7700
|
-
addPromotions(
|
|
7701
|
-
{
|
|
7702
|
-
promo_codes: [value]
|
|
7703
|
-
},
|
|
7704
|
-
{
|
|
7705
|
-
onError: (e) => {
|
|
7706
|
-
toast.error(e.message);
|
|
7707
|
-
comboboxData.onSearchValueChange("");
|
|
7708
|
-
setComboboxValue("");
|
|
7709
|
-
},
|
|
7710
|
-
onSuccess: () => {
|
|
7711
|
-
comboboxData.onSearchValueChange("");
|
|
7712
|
-
setComboboxValue("");
|
|
7713
|
-
}
|
|
7714
|
-
}
|
|
7715
|
-
);
|
|
7716
|
-
};
|
|
7430
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
7431
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
7432
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
7433
|
+
profiles.set(profile.id, profile);
|
|
7434
|
+
});
|
|
7435
|
+
shipping_options?.forEach((option) => {
|
|
7436
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
7437
|
+
});
|
|
7438
|
+
return Array.from(profiles.values());
|
|
7439
|
+
}, [order.items, shipping_options]);
|
|
7440
|
+
const { handleSuccess } = useRouteModal();
|
|
7717
7441
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
7718
|
-
const { mutateAsync: requestOrderEdit } =
|
|
7442
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
7443
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
7444
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
7719
7445
|
const onSubmit = async () => {
|
|
7720
7446
|
setIsSubmitting(true);
|
|
7721
7447
|
let requestSucceeded = false;
|
|
7722
7448
|
await requestOrderEdit(void 0, {
|
|
7723
7449
|
onError: (e) => {
|
|
7724
|
-
toast.error(e.message);
|
|
7450
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
7725
7451
|
},
|
|
7726
7452
|
onSuccess: () => {
|
|
7727
7453
|
requestSucceeded = true;
|
|
@@ -7733,7 +7459,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
7733
7459
|
}
|
|
7734
7460
|
await confirmOrderEdit(void 0, {
|
|
7735
7461
|
onError: (e) => {
|
|
7736
|
-
toast.error(e.message);
|
|
7462
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
7737
7463
|
},
|
|
7738
7464
|
onSuccess: () => {
|
|
7739
7465
|
handleSuccess();
|
|
@@ -7743,258 +7469,13 @@ const PromotionForm = ({ preview }) => {
|
|
|
7743
7469
|
}
|
|
7744
7470
|
});
|
|
7745
7471
|
};
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
7752
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
7753
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
7754
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
7755
|
-
] }),
|
|
7756
|
-
/* @__PURE__ */ jsx(
|
|
7757
|
-
Combobox,
|
|
7758
|
-
{
|
|
7759
|
-
id: "promotion-combobox",
|
|
7760
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
7761
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
7762
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
7763
|
-
options: comboboxData.options,
|
|
7764
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
7765
|
-
searchValue: comboboxData.searchValue,
|
|
7766
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
7767
|
-
onChange: add,
|
|
7768
|
-
value: comboboxValue
|
|
7769
|
-
}
|
|
7770
|
-
)
|
|
7771
|
-
] }),
|
|
7772
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
7773
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
|
|
7774
|
-
PromotionItem,
|
|
7775
|
-
{
|
|
7776
|
-
promotion,
|
|
7777
|
-
orderId: preview.id,
|
|
7778
|
-
isLoading: isPending
|
|
7779
|
-
},
|
|
7780
|
-
promotion.id
|
|
7781
|
-
)) })
|
|
7782
|
-
] }) }),
|
|
7783
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
7784
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
7785
|
-
/* @__PURE__ */ jsx(
|
|
7786
|
-
Button,
|
|
7787
|
-
{
|
|
7788
|
-
size: "small",
|
|
7789
|
-
type: "submit",
|
|
7790
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
7791
|
-
children: "Save"
|
|
7792
|
-
}
|
|
7793
|
-
)
|
|
7794
|
-
] }) })
|
|
7795
|
-
] });
|
|
7796
|
-
};
|
|
7797
|
-
const PromotionItem = ({
|
|
7798
|
-
promotion,
|
|
7799
|
-
orderId,
|
|
7800
|
-
isLoading
|
|
7801
|
-
}) => {
|
|
7802
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
7803
|
-
const onRemove = async () => {
|
|
7804
|
-
removePromotions(
|
|
7805
|
-
{
|
|
7806
|
-
promo_codes: [promotion.code]
|
|
7807
|
-
},
|
|
7808
|
-
{
|
|
7809
|
-
onError: (e) => {
|
|
7810
|
-
toast.error(e.message);
|
|
7472
|
+
const onKeydown = useCallback(
|
|
7473
|
+
(e) => {
|
|
7474
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
7475
|
+
if (data || isSubmitting) {
|
|
7476
|
+
return;
|
|
7811
7477
|
}
|
|
7812
|
-
|
|
7813
|
-
);
|
|
7814
|
-
};
|
|
7815
|
-
const displayValue = getDisplayValue(promotion);
|
|
7816
|
-
return /* @__PURE__ */ jsxs(
|
|
7817
|
-
"div",
|
|
7818
|
-
{
|
|
7819
|
-
className: clx(
|
|
7820
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
7821
|
-
{
|
|
7822
|
-
"animate-pulse": isLoading
|
|
7823
|
-
}
|
|
7824
|
-
),
|
|
7825
|
-
children: [
|
|
7826
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
7827
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
7828
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
7829
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
7830
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
7831
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
7832
|
-
] }),
|
|
7833
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
7834
|
-
] })
|
|
7835
|
-
] }),
|
|
7836
|
-
/* @__PURE__ */ jsx(
|
|
7837
|
-
IconButton,
|
|
7838
|
-
{
|
|
7839
|
-
size: "small",
|
|
7840
|
-
type: "button",
|
|
7841
|
-
variant: "transparent",
|
|
7842
|
-
onClick: onRemove,
|
|
7843
|
-
isLoading: isPending || isLoading,
|
|
7844
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
7845
|
-
}
|
|
7846
|
-
)
|
|
7847
|
-
]
|
|
7848
|
-
},
|
|
7849
|
-
promotion.id
|
|
7850
|
-
);
|
|
7851
|
-
};
|
|
7852
|
-
function getDisplayValue(promotion) {
|
|
7853
|
-
const value = promotion.application_method?.value;
|
|
7854
|
-
if (!value) {
|
|
7855
|
-
return null;
|
|
7856
|
-
}
|
|
7857
|
-
if (promotion.application_method?.type === "fixed") {
|
|
7858
|
-
const currency = promotion.application_method?.currency_code;
|
|
7859
|
-
if (!currency) {
|
|
7860
|
-
return null;
|
|
7861
|
-
}
|
|
7862
|
-
return getLocaleAmount(value, currency);
|
|
7863
|
-
} else if (promotion.application_method?.type === "percentage") {
|
|
7864
|
-
return formatPercentage(value);
|
|
7865
|
-
}
|
|
7866
|
-
return null;
|
|
7867
|
-
}
|
|
7868
|
-
const formatter = new Intl.NumberFormat([], {
|
|
7869
|
-
style: "percent",
|
|
7870
|
-
minimumFractionDigits: 2
|
|
7871
|
-
});
|
|
7872
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
7873
|
-
let val = value || 0;
|
|
7874
|
-
if (!isPercentageValue) {
|
|
7875
|
-
val = val / 100;
|
|
7876
|
-
}
|
|
7877
|
-
return formatter.format(val);
|
|
7878
|
-
};
|
|
7879
|
-
function getPromotionIds(items, shippingMethods) {
|
|
7880
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
7881
|
-
for (const item of items) {
|
|
7882
|
-
if (item.adjustments) {
|
|
7883
|
-
for (const adjustment of item.adjustments) {
|
|
7884
|
-
if (adjustment.promotion_id) {
|
|
7885
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7886
|
-
}
|
|
7887
|
-
}
|
|
7888
|
-
}
|
|
7889
|
-
}
|
|
7890
|
-
for (const shippingMethod of shippingMethods) {
|
|
7891
|
-
if (shippingMethod.adjustments) {
|
|
7892
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
7893
|
-
if (adjustment.promotion_id) {
|
|
7894
|
-
promotionIds.add(adjustment.promotion_id);
|
|
7895
|
-
}
|
|
7896
|
-
}
|
|
7897
|
-
}
|
|
7898
|
-
}
|
|
7899
|
-
return Array.from(promotionIds);
|
|
7900
|
-
}
|
|
7901
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
7902
|
-
const Shipping = () => {
|
|
7903
|
-
const { id } = useParams();
|
|
7904
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
7905
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
7906
|
-
});
|
|
7907
|
-
const {
|
|
7908
|
-
order: preview,
|
|
7909
|
-
isPending: isPreviewPending,
|
|
7910
|
-
isError: isPreviewError,
|
|
7911
|
-
error: previewError
|
|
7912
|
-
} = useOrderPreview(id);
|
|
7913
|
-
useInitiateOrderEdit({ preview });
|
|
7914
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
7915
|
-
if (isError) {
|
|
7916
|
-
throw error;
|
|
7917
|
-
}
|
|
7918
|
-
if (isPreviewError) {
|
|
7919
|
-
throw previewError;
|
|
7920
|
-
}
|
|
7921
|
-
const orderHasItems = (order?.items?.length || 0) > 0;
|
|
7922
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
7923
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
7924
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
7925
|
-
/* @__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: [
|
|
7926
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
7927
|
-
/* @__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." }) })
|
|
7928
|
-
] }) }) }),
|
|
7929
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
7930
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
7931
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
7932
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
7933
|
-
] }) });
|
|
7934
|
-
};
|
|
7935
|
-
const ShippingForm = ({ preview, order }) => {
|
|
7936
|
-
const { setIsOpen } = useStackedModal();
|
|
7937
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
7938
|
-
const [data, setData] = useState(null);
|
|
7939
|
-
const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
|
|
7940
|
-
const { shipping_options } = useShippingOptions(
|
|
7941
|
-
{
|
|
7942
|
-
id: appliedShippingOptionIds,
|
|
7943
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
7944
|
-
},
|
|
7945
|
-
{
|
|
7946
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
7947
|
-
}
|
|
7948
|
-
);
|
|
7949
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
7950
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
7951
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
7952
|
-
profiles.set(profile.id, profile);
|
|
7953
|
-
});
|
|
7954
|
-
shipping_options?.forEach((option) => {
|
|
7955
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
7956
|
-
});
|
|
7957
|
-
return Array.from(profiles.values());
|
|
7958
|
-
}, [order.items, shipping_options]);
|
|
7959
|
-
const { handleSuccess } = useRouteModal();
|
|
7960
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
7961
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
7962
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
7963
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
7964
|
-
const onSubmit = async () => {
|
|
7965
|
-
setIsSubmitting(true);
|
|
7966
|
-
let requestSucceeded = false;
|
|
7967
|
-
await requestOrderEdit(void 0, {
|
|
7968
|
-
onError: (e) => {
|
|
7969
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
7970
|
-
},
|
|
7971
|
-
onSuccess: () => {
|
|
7972
|
-
requestSucceeded = true;
|
|
7973
|
-
}
|
|
7974
|
-
});
|
|
7975
|
-
if (!requestSucceeded) {
|
|
7976
|
-
setIsSubmitting(false);
|
|
7977
|
-
return;
|
|
7978
|
-
}
|
|
7979
|
-
await confirmOrderEdit(void 0, {
|
|
7980
|
-
onError: (e) => {
|
|
7981
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
7982
|
-
},
|
|
7983
|
-
onSuccess: () => {
|
|
7984
|
-
handleSuccess();
|
|
7985
|
-
},
|
|
7986
|
-
onSettled: () => {
|
|
7987
|
-
setIsSubmitting(false);
|
|
7988
|
-
}
|
|
7989
|
-
});
|
|
7990
|
-
};
|
|
7991
|
-
const onKeydown = useCallback(
|
|
7992
|
-
(e) => {
|
|
7993
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
7994
|
-
if (data || isSubmitting) {
|
|
7995
|
-
return;
|
|
7996
|
-
}
|
|
7997
|
-
onSubmit();
|
|
7478
|
+
onSubmit();
|
|
7998
7479
|
}
|
|
7999
7480
|
},
|
|
8000
7481
|
[data, isSubmitting, onSubmit]
|
|
@@ -8723,7 +8204,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8723
8204
|
postal_code: order.shipping_address?.postal_code ?? "",
|
|
8724
8205
|
phone: order.shipping_address?.phone ?? ""
|
|
8725
8206
|
},
|
|
8726
|
-
resolver: zodResolver(schema$
|
|
8207
|
+
resolver: zodResolver(schema$1)
|
|
8727
8208
|
});
|
|
8728
8209
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8729
8210
|
const { handleSuccess } = useRouteModal();
|
|
@@ -8893,7 +8374,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
8893
8374
|
}
|
|
8894
8375
|
) });
|
|
8895
8376
|
};
|
|
8896
|
-
const schema$
|
|
8377
|
+
const schema$1 = addressSchema;
|
|
8897
8378
|
const TransferOwnership = () => {
|
|
8898
8379
|
const { id } = useParams();
|
|
8899
8380
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -8916,7 +8397,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
8916
8397
|
defaultValues: {
|
|
8917
8398
|
customer_id: order.customer_id || ""
|
|
8918
8399
|
},
|
|
8919
|
-
resolver: zodResolver(schema
|
|
8400
|
+
resolver: zodResolver(schema)
|
|
8920
8401
|
});
|
|
8921
8402
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
8922
8403
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9366,117 +8847,636 @@ const Illustration = () => {
|
|
|
9366
8847
|
] })
|
|
9367
8848
|
]
|
|
9368
8849
|
}
|
|
9369
|
-
);
|
|
8850
|
+
);
|
|
8851
|
+
};
|
|
8852
|
+
const schema = z.object({
|
|
8853
|
+
customer_id: z.string().min(1)
|
|
8854
|
+
});
|
|
8855
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
8856
|
+
const promotionsQueryKeys = {
|
|
8857
|
+
list: (query2) => [
|
|
8858
|
+
PROMOTION_QUERY_KEY,
|
|
8859
|
+
query2 ? query2 : void 0
|
|
8860
|
+
],
|
|
8861
|
+
detail: (id, query2) => [
|
|
8862
|
+
PROMOTION_QUERY_KEY,
|
|
8863
|
+
id,
|
|
8864
|
+
query2 ? query2 : void 0
|
|
8865
|
+
]
|
|
8866
|
+
};
|
|
8867
|
+
const usePromotions = (query2, options) => {
|
|
8868
|
+
const { data, ...rest } = useQuery({
|
|
8869
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
8870
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
8871
|
+
...options
|
|
8872
|
+
});
|
|
8873
|
+
return { ...data, ...rest };
|
|
8874
|
+
};
|
|
8875
|
+
const Promotions = () => {
|
|
8876
|
+
const { id } = useParams();
|
|
8877
|
+
const {
|
|
8878
|
+
order: preview,
|
|
8879
|
+
isError: isPreviewError,
|
|
8880
|
+
error: previewError
|
|
8881
|
+
} = useOrderPreview(id, void 0);
|
|
8882
|
+
useInitiateOrderEdit({ preview });
|
|
8883
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
8884
|
+
if (isPreviewError) {
|
|
8885
|
+
throw previewError;
|
|
8886
|
+
}
|
|
8887
|
+
const isReady = !!preview;
|
|
8888
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
8889
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
8890
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
8891
|
+
] });
|
|
8892
|
+
};
|
|
8893
|
+
const PromotionForm = ({ preview }) => {
|
|
8894
|
+
const { items, shipping_methods } = preview;
|
|
8895
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
8896
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
8897
|
+
const { handleSuccess } = useRouteModal();
|
|
8898
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
8899
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
8900
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
8901
|
+
{
|
|
8902
|
+
id: promoIds
|
|
8903
|
+
},
|
|
8904
|
+
{
|
|
8905
|
+
enabled: !!promoIds.length
|
|
8906
|
+
}
|
|
8907
|
+
);
|
|
8908
|
+
const comboboxData = useComboboxData({
|
|
8909
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
8910
|
+
queryFn: async (params) => {
|
|
8911
|
+
return await sdk.admin.promotion.list({
|
|
8912
|
+
...params,
|
|
8913
|
+
id: {
|
|
8914
|
+
$nin: promoIds
|
|
8915
|
+
}
|
|
8916
|
+
});
|
|
8917
|
+
},
|
|
8918
|
+
getOptions: (data) => {
|
|
8919
|
+
return data.promotions.map((promotion) => ({
|
|
8920
|
+
label: promotion.code,
|
|
8921
|
+
value: promotion.code
|
|
8922
|
+
}));
|
|
8923
|
+
}
|
|
8924
|
+
});
|
|
8925
|
+
const add = async (value) => {
|
|
8926
|
+
if (!value) {
|
|
8927
|
+
return;
|
|
8928
|
+
}
|
|
8929
|
+
addPromotions(
|
|
8930
|
+
{
|
|
8931
|
+
promo_codes: [value]
|
|
8932
|
+
},
|
|
8933
|
+
{
|
|
8934
|
+
onError: (e) => {
|
|
8935
|
+
toast.error(e.message);
|
|
8936
|
+
comboboxData.onSearchValueChange("");
|
|
8937
|
+
setComboboxValue("");
|
|
8938
|
+
},
|
|
8939
|
+
onSuccess: () => {
|
|
8940
|
+
comboboxData.onSearchValueChange("");
|
|
8941
|
+
setComboboxValue("");
|
|
8942
|
+
}
|
|
8943
|
+
}
|
|
8944
|
+
);
|
|
8945
|
+
};
|
|
8946
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
8947
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
8948
|
+
const onSubmit = async () => {
|
|
8949
|
+
setIsSubmitting(true);
|
|
8950
|
+
let requestSucceeded = false;
|
|
8951
|
+
await requestOrderEdit(void 0, {
|
|
8952
|
+
onError: (e) => {
|
|
8953
|
+
toast.error(e.message);
|
|
8954
|
+
},
|
|
8955
|
+
onSuccess: () => {
|
|
8956
|
+
requestSucceeded = true;
|
|
8957
|
+
}
|
|
8958
|
+
});
|
|
8959
|
+
if (!requestSucceeded) {
|
|
8960
|
+
setIsSubmitting(false);
|
|
8961
|
+
return;
|
|
8962
|
+
}
|
|
8963
|
+
await confirmOrderEdit(void 0, {
|
|
8964
|
+
onError: (e) => {
|
|
8965
|
+
toast.error(e.message);
|
|
8966
|
+
},
|
|
8967
|
+
onSuccess: () => {
|
|
8968
|
+
handleSuccess();
|
|
8969
|
+
},
|
|
8970
|
+
onSettled: () => {
|
|
8971
|
+
setIsSubmitting(false);
|
|
8972
|
+
}
|
|
8973
|
+
});
|
|
8974
|
+
};
|
|
8975
|
+
if (isError) {
|
|
8976
|
+
throw error;
|
|
8977
|
+
}
|
|
8978
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
8979
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
8980
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
8981
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
8982
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
8983
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
8984
|
+
] }),
|
|
8985
|
+
/* @__PURE__ */ jsx(
|
|
8986
|
+
Combobox,
|
|
8987
|
+
{
|
|
8988
|
+
id: "promotion-combobox",
|
|
8989
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
8990
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
8991
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
8992
|
+
options: comboboxData.options,
|
|
8993
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
8994
|
+
searchValue: comboboxData.searchValue,
|
|
8995
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
8996
|
+
onChange: add,
|
|
8997
|
+
value: comboboxValue
|
|
8998
|
+
}
|
|
8999
|
+
)
|
|
9000
|
+
] }),
|
|
9001
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
9002
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions?.map((promotion) => /* @__PURE__ */ jsx(
|
|
9003
|
+
PromotionItem,
|
|
9004
|
+
{
|
|
9005
|
+
promotion,
|
|
9006
|
+
orderId: preview.id,
|
|
9007
|
+
isLoading: isPending
|
|
9008
|
+
},
|
|
9009
|
+
promotion.id
|
|
9010
|
+
)) })
|
|
9011
|
+
] }) }),
|
|
9012
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9013
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9014
|
+
/* @__PURE__ */ jsx(
|
|
9015
|
+
Button,
|
|
9016
|
+
{
|
|
9017
|
+
size: "small",
|
|
9018
|
+
type: "submit",
|
|
9019
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
9020
|
+
children: "Save"
|
|
9021
|
+
}
|
|
9022
|
+
)
|
|
9023
|
+
] }) })
|
|
9024
|
+
] });
|
|
9025
|
+
};
|
|
9026
|
+
const PromotionItem = ({
|
|
9027
|
+
promotion,
|
|
9028
|
+
orderId,
|
|
9029
|
+
isLoading
|
|
9030
|
+
}) => {
|
|
9031
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
9032
|
+
const onRemove = async () => {
|
|
9033
|
+
removePromotions(
|
|
9034
|
+
{
|
|
9035
|
+
promo_codes: [promotion.code]
|
|
9036
|
+
},
|
|
9037
|
+
{
|
|
9038
|
+
onError: (e) => {
|
|
9039
|
+
toast.error(e.message);
|
|
9040
|
+
}
|
|
9041
|
+
}
|
|
9042
|
+
);
|
|
9043
|
+
};
|
|
9044
|
+
const displayValue = getDisplayValue(promotion);
|
|
9045
|
+
return /* @__PURE__ */ jsxs(
|
|
9046
|
+
"div",
|
|
9047
|
+
{
|
|
9048
|
+
className: clx(
|
|
9049
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
9050
|
+
{
|
|
9051
|
+
"animate-pulse": isLoading
|
|
9052
|
+
}
|
|
9053
|
+
),
|
|
9054
|
+
children: [
|
|
9055
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
9056
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
9057
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
9058
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
9059
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
9060
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
9061
|
+
] }),
|
|
9062
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: promotion.application_method?.allocation })
|
|
9063
|
+
] })
|
|
9064
|
+
] }),
|
|
9065
|
+
/* @__PURE__ */ jsx(
|
|
9066
|
+
IconButton,
|
|
9067
|
+
{
|
|
9068
|
+
size: "small",
|
|
9069
|
+
type: "button",
|
|
9070
|
+
variant: "transparent",
|
|
9071
|
+
onClick: onRemove,
|
|
9072
|
+
isLoading: isPending || isLoading,
|
|
9073
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
9074
|
+
}
|
|
9075
|
+
)
|
|
9076
|
+
]
|
|
9077
|
+
},
|
|
9078
|
+
promotion.id
|
|
9079
|
+
);
|
|
9080
|
+
};
|
|
9081
|
+
function getDisplayValue(promotion) {
|
|
9082
|
+
const value = promotion.application_method?.value;
|
|
9083
|
+
if (!value) {
|
|
9084
|
+
return null;
|
|
9085
|
+
}
|
|
9086
|
+
if (promotion.application_method?.type === "fixed") {
|
|
9087
|
+
const currency = promotion.application_method?.currency_code;
|
|
9088
|
+
if (!currency) {
|
|
9089
|
+
return null;
|
|
9090
|
+
}
|
|
9091
|
+
return getLocaleAmount(value, currency);
|
|
9092
|
+
} else if (promotion.application_method?.type === "percentage") {
|
|
9093
|
+
return formatPercentage(value);
|
|
9094
|
+
}
|
|
9095
|
+
return null;
|
|
9096
|
+
}
|
|
9097
|
+
const formatter = new Intl.NumberFormat([], {
|
|
9098
|
+
style: "percent",
|
|
9099
|
+
minimumFractionDigits: 2
|
|
9100
|
+
});
|
|
9101
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
9102
|
+
let val = value || 0;
|
|
9103
|
+
if (!isPercentageValue) {
|
|
9104
|
+
val = val / 100;
|
|
9105
|
+
}
|
|
9106
|
+
return formatter.format(val);
|
|
9107
|
+
};
|
|
9108
|
+
function getPromotionIds(items, shippingMethods) {
|
|
9109
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
9110
|
+
for (const item of items) {
|
|
9111
|
+
if (item.adjustments) {
|
|
9112
|
+
for (const adjustment of item.adjustments) {
|
|
9113
|
+
if (adjustment.promotion_id) {
|
|
9114
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9115
|
+
}
|
|
9116
|
+
}
|
|
9117
|
+
}
|
|
9118
|
+
}
|
|
9119
|
+
for (const shippingMethod of shippingMethods) {
|
|
9120
|
+
if (shippingMethod.adjustments) {
|
|
9121
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
9122
|
+
if (adjustment.promotion_id) {
|
|
9123
|
+
promotionIds.add(adjustment.promotion_id);
|
|
9124
|
+
}
|
|
9125
|
+
}
|
|
9126
|
+
}
|
|
9127
|
+
}
|
|
9128
|
+
return Array.from(promotionIds);
|
|
9129
|
+
}
|
|
9130
|
+
const InlineTip = forwardRef(
|
|
9131
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
9132
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
9133
|
+
return /* @__PURE__ */ jsxs(
|
|
9134
|
+
"div",
|
|
9135
|
+
{
|
|
9136
|
+
ref,
|
|
9137
|
+
className: clx(
|
|
9138
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
9139
|
+
className
|
|
9140
|
+
),
|
|
9141
|
+
...props,
|
|
9142
|
+
children: [
|
|
9143
|
+
/* @__PURE__ */ jsx(
|
|
9144
|
+
"div",
|
|
9145
|
+
{
|
|
9146
|
+
role: "presentation",
|
|
9147
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
9148
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
9149
|
+
})
|
|
9150
|
+
}
|
|
9151
|
+
),
|
|
9152
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
9153
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
9154
|
+
labelValue,
|
|
9155
|
+
":"
|
|
9156
|
+
] }),
|
|
9157
|
+
" ",
|
|
9158
|
+
children
|
|
9159
|
+
] })
|
|
9160
|
+
]
|
|
9161
|
+
}
|
|
9162
|
+
);
|
|
9163
|
+
}
|
|
9164
|
+
);
|
|
9165
|
+
InlineTip.displayName = "InlineTip";
|
|
9166
|
+
const MetadataFieldSchema = z.object({
|
|
9167
|
+
key: z.string(),
|
|
9168
|
+
disabled: z.boolean().optional(),
|
|
9169
|
+
value: z.any()
|
|
9170
|
+
});
|
|
9171
|
+
const MetadataSchema = z.object({
|
|
9172
|
+
metadata: z.array(MetadataFieldSchema)
|
|
9173
|
+
});
|
|
9174
|
+
const Metadata = () => {
|
|
9175
|
+
const { id } = useParams();
|
|
9176
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9177
|
+
fields: "metadata"
|
|
9178
|
+
});
|
|
9179
|
+
if (isError) {
|
|
9180
|
+
throw error;
|
|
9181
|
+
}
|
|
9182
|
+
const isReady = !isPending && !!order;
|
|
9183
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9184
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9185
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
9186
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
9187
|
+
] }),
|
|
9188
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order?.metadata })
|
|
9189
|
+
] });
|
|
9190
|
+
};
|
|
9191
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
9192
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
9193
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
9194
|
+
const { handleSuccess } = useRouteModal();
|
|
9195
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
9196
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
9197
|
+
const form = useForm({
|
|
9198
|
+
defaultValues: {
|
|
9199
|
+
metadata: getDefaultValues(metadata)
|
|
9200
|
+
},
|
|
9201
|
+
resolver: zodResolver(MetadataSchema)
|
|
9202
|
+
});
|
|
9203
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
9204
|
+
const parsedData = parseValues(data);
|
|
9205
|
+
await mutateAsync(
|
|
9206
|
+
{
|
|
9207
|
+
metadata: parsedData
|
|
9208
|
+
},
|
|
9209
|
+
{
|
|
9210
|
+
onSuccess: () => {
|
|
9211
|
+
toast.success("Metadata updated");
|
|
9212
|
+
handleSuccess();
|
|
9213
|
+
},
|
|
9214
|
+
onError: (error) => {
|
|
9215
|
+
toast.error(error.message);
|
|
9216
|
+
}
|
|
9217
|
+
}
|
|
9218
|
+
);
|
|
9219
|
+
});
|
|
9220
|
+
const { fields, insert, remove } = useFieldArray({
|
|
9221
|
+
control: form.control,
|
|
9222
|
+
name: "metadata"
|
|
9223
|
+
});
|
|
9224
|
+
function deleteRow(index) {
|
|
9225
|
+
remove(index);
|
|
9226
|
+
if (fields.length === 1) {
|
|
9227
|
+
insert(0, {
|
|
9228
|
+
key: "",
|
|
9229
|
+
value: "",
|
|
9230
|
+
disabled: false
|
|
9231
|
+
});
|
|
9232
|
+
}
|
|
9233
|
+
}
|
|
9234
|
+
function insertRow(index, position) {
|
|
9235
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
9236
|
+
key: "",
|
|
9237
|
+
value: "",
|
|
9238
|
+
disabled: false
|
|
9239
|
+
});
|
|
9240
|
+
}
|
|
9241
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9242
|
+
KeyboundForm,
|
|
9243
|
+
{
|
|
9244
|
+
onSubmit: handleSubmit,
|
|
9245
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9246
|
+
children: [
|
|
9247
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
9248
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
9249
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
9250
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
9251
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
9252
|
+
] }),
|
|
9253
|
+
fields.map((field, index) => {
|
|
9254
|
+
const isDisabled = field.disabled || false;
|
|
9255
|
+
let placeholder = "-";
|
|
9256
|
+
if (typeof field.value === "object") {
|
|
9257
|
+
placeholder = "{ ... }";
|
|
9258
|
+
}
|
|
9259
|
+
if (Array.isArray(field.value)) {
|
|
9260
|
+
placeholder = "[ ... ]";
|
|
9261
|
+
}
|
|
9262
|
+
return /* @__PURE__ */ jsx(
|
|
9263
|
+
ConditionalTooltip,
|
|
9264
|
+
{
|
|
9265
|
+
showTooltip: isDisabled,
|
|
9266
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
9267
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
9268
|
+
/* @__PURE__ */ jsxs(
|
|
9269
|
+
"div",
|
|
9270
|
+
{
|
|
9271
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
9272
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
9273
|
+
}),
|
|
9274
|
+
children: [
|
|
9275
|
+
/* @__PURE__ */ jsx(
|
|
9276
|
+
Form$2.Field,
|
|
9277
|
+
{
|
|
9278
|
+
control: form.control,
|
|
9279
|
+
name: `metadata.${index}.key`,
|
|
9280
|
+
render: ({ field: field2 }) => {
|
|
9281
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9282
|
+
GridInput,
|
|
9283
|
+
{
|
|
9284
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
9285
|
+
...field2,
|
|
9286
|
+
disabled: isDisabled,
|
|
9287
|
+
placeholder: "Key"
|
|
9288
|
+
}
|
|
9289
|
+
) }) });
|
|
9290
|
+
}
|
|
9291
|
+
}
|
|
9292
|
+
),
|
|
9293
|
+
/* @__PURE__ */ jsx(
|
|
9294
|
+
Form$2.Field,
|
|
9295
|
+
{
|
|
9296
|
+
control: form.control,
|
|
9297
|
+
name: `metadata.${index}.value`,
|
|
9298
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
9299
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
9300
|
+
GridInput,
|
|
9301
|
+
{
|
|
9302
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
9303
|
+
...field2,
|
|
9304
|
+
value: isDisabled ? placeholder : value,
|
|
9305
|
+
disabled: isDisabled,
|
|
9306
|
+
placeholder: "Value"
|
|
9307
|
+
}
|
|
9308
|
+
) }) });
|
|
9309
|
+
}
|
|
9310
|
+
}
|
|
9311
|
+
)
|
|
9312
|
+
]
|
|
9313
|
+
}
|
|
9314
|
+
),
|
|
9315
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
9316
|
+
/* @__PURE__ */ jsx(
|
|
9317
|
+
DropdownMenu.Trigger,
|
|
9318
|
+
{
|
|
9319
|
+
className: clx(
|
|
9320
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
9321
|
+
{
|
|
9322
|
+
hidden: isDisabled
|
|
9323
|
+
}
|
|
9324
|
+
),
|
|
9325
|
+
disabled: isDisabled,
|
|
9326
|
+
asChild: true,
|
|
9327
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
9328
|
+
}
|
|
9329
|
+
),
|
|
9330
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
9331
|
+
/* @__PURE__ */ jsxs(
|
|
9332
|
+
DropdownMenu.Item,
|
|
9333
|
+
{
|
|
9334
|
+
className: "gap-x-2",
|
|
9335
|
+
onClick: () => insertRow(index, "above"),
|
|
9336
|
+
children: [
|
|
9337
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
9338
|
+
"Insert row above"
|
|
9339
|
+
]
|
|
9340
|
+
}
|
|
9341
|
+
),
|
|
9342
|
+
/* @__PURE__ */ jsxs(
|
|
9343
|
+
DropdownMenu.Item,
|
|
9344
|
+
{
|
|
9345
|
+
className: "gap-x-2",
|
|
9346
|
+
onClick: () => insertRow(index, "below"),
|
|
9347
|
+
children: [
|
|
9348
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
9349
|
+
"Insert row below"
|
|
9350
|
+
]
|
|
9351
|
+
}
|
|
9352
|
+
),
|
|
9353
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
9354
|
+
/* @__PURE__ */ jsxs(
|
|
9355
|
+
DropdownMenu.Item,
|
|
9356
|
+
{
|
|
9357
|
+
className: "gap-x-2",
|
|
9358
|
+
onClick: () => deleteRow(index),
|
|
9359
|
+
children: [
|
|
9360
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
9361
|
+
"Delete row"
|
|
9362
|
+
]
|
|
9363
|
+
}
|
|
9364
|
+
)
|
|
9365
|
+
] })
|
|
9366
|
+
] })
|
|
9367
|
+
] })
|
|
9368
|
+
},
|
|
9369
|
+
field.id
|
|
9370
|
+
);
|
|
9371
|
+
})
|
|
9372
|
+
] }),
|
|
9373
|
+
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
9374
|
+
] }),
|
|
9375
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9376
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
9377
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9378
|
+
] }) })
|
|
9379
|
+
]
|
|
9380
|
+
}
|
|
9381
|
+
) });
|
|
9370
9382
|
};
|
|
9371
|
-
const
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
const SalesChannel = () => {
|
|
9375
|
-
const { id } = useParams();
|
|
9376
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
9377
|
-
id,
|
|
9378
|
-
{
|
|
9379
|
-
fields: "+sales_channel_id"
|
|
9380
|
-
},
|
|
9383
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
9384
|
+
return /* @__PURE__ */ jsx(
|
|
9385
|
+
"input",
|
|
9381
9386
|
{
|
|
9382
|
-
|
|
9387
|
+
ref,
|
|
9388
|
+
...props,
|
|
9389
|
+
autoComplete: "off",
|
|
9390
|
+
className: clx(
|
|
9391
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
9392
|
+
className
|
|
9393
|
+
)
|
|
9383
9394
|
}
|
|
9384
9395
|
);
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
/* @__PURE__ */
|
|
9391
|
-
/* @__PURE__ */ jsx(
|
|
9392
|
-
/* @__PURE__ */ jsx(
|
|
9393
|
-
] })
|
|
9394
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
9396
|
+
});
|
|
9397
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
9398
|
+
const PlaceholderInner = () => {
|
|
9399
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
9400
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
9401
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
9402
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
9403
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
9404
|
+
] }) })
|
|
9395
9405
|
] });
|
|
9396
9406
|
};
|
|
9397
|
-
const
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
},
|
|
9402
|
-
resolver: zodResolver(schema)
|
|
9403
|
-
});
|
|
9404
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9405
|
-
const { handleSuccess } = useRouteModal();
|
|
9406
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9407
|
-
await mutateAsync(
|
|
9408
|
-
{
|
|
9409
|
-
sales_channel_id: data.sales_channel_id
|
|
9410
|
-
},
|
|
9407
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
9408
|
+
function getDefaultValues(metadata) {
|
|
9409
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
9410
|
+
return [
|
|
9411
9411
|
{
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
},
|
|
9416
|
-
onError: (error) => {
|
|
9417
|
-
toast.error(error.message);
|
|
9418
|
-
}
|
|
9412
|
+
key: "",
|
|
9413
|
+
value: "",
|
|
9414
|
+
disabled: false
|
|
9419
9415
|
}
|
|
9420
|
-
|
|
9421
|
-
}
|
|
9422
|
-
return
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9430
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9431
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9432
|
-
] }) })
|
|
9433
|
-
]
|
|
9416
|
+
];
|
|
9417
|
+
}
|
|
9418
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
9419
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
9420
|
+
return {
|
|
9421
|
+
key,
|
|
9422
|
+
value,
|
|
9423
|
+
disabled: true
|
|
9424
|
+
};
|
|
9434
9425
|
}
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
9445
|
-
label: salesChannel.name,
|
|
9446
|
-
value: salesChannel.id
|
|
9447
|
-
}));
|
|
9448
|
-
},
|
|
9449
|
-
defaultValue: order.sales_channel_id || void 0
|
|
9426
|
+
let stringValue = value;
|
|
9427
|
+
if (typeof value !== "string") {
|
|
9428
|
+
stringValue = JSON.stringify(value);
|
|
9429
|
+
}
|
|
9430
|
+
return {
|
|
9431
|
+
key,
|
|
9432
|
+
value: stringValue,
|
|
9433
|
+
original_key: key
|
|
9434
|
+
};
|
|
9450
9435
|
});
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9436
|
+
}
|
|
9437
|
+
function parseValues(values) {
|
|
9438
|
+
const metadata = values.metadata;
|
|
9439
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
9440
|
+
if (isEmpty) {
|
|
9441
|
+
return null;
|
|
9442
|
+
}
|
|
9443
|
+
const update = {};
|
|
9444
|
+
metadata.forEach((field) => {
|
|
9445
|
+
let key = field.key;
|
|
9446
|
+
let value = field.value;
|
|
9447
|
+
const disabled = field.disabled;
|
|
9448
|
+
if (!key || !value) {
|
|
9449
|
+
return;
|
|
9450
|
+
}
|
|
9451
|
+
if (disabled) {
|
|
9452
|
+
update[key] = value;
|
|
9453
|
+
return;
|
|
9454
|
+
}
|
|
9455
|
+
key = key.trim();
|
|
9456
|
+
value = value.trim();
|
|
9457
|
+
if (value === "true") {
|
|
9458
|
+
update[key] = true;
|
|
9459
|
+
} else if (value === "false") {
|
|
9460
|
+
update[key] = false;
|
|
9461
|
+
} else {
|
|
9462
|
+
const parsedNumber = parseFloat(value);
|
|
9463
|
+
if (!isNaN(parsedNumber)) {
|
|
9464
|
+
update[key] = parsedNumber;
|
|
9465
|
+
} else {
|
|
9466
|
+
update[key] = value;
|
|
9473
9467
|
}
|
|
9474
9468
|
}
|
|
9469
|
+
});
|
|
9470
|
+
return update;
|
|
9471
|
+
}
|
|
9472
|
+
function getHasUneditableRows(metadata) {
|
|
9473
|
+
if (!metadata) {
|
|
9474
|
+
return false;
|
|
9475
|
+
}
|
|
9476
|
+
return Object.values(metadata).some(
|
|
9477
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
9475
9478
|
);
|
|
9476
|
-
}
|
|
9477
|
-
const schema = z.object({
|
|
9478
|
-
sales_channel_id: z.string().min(1)
|
|
9479
|
-
});
|
|
9479
|
+
}
|
|
9480
9480
|
const widgetModule = { widgets: [] };
|
|
9481
9481
|
const routeModule = {
|
|
9482
9482
|
routes: [
|
|
@@ -9497,6 +9497,10 @@ const routeModule = {
|
|
|
9497
9497
|
handle,
|
|
9498
9498
|
loader,
|
|
9499
9499
|
children: [
|
|
9500
|
+
{
|
|
9501
|
+
Component: BillingAddress,
|
|
9502
|
+
path: "/draft-orders/:id/billing-address"
|
|
9503
|
+
},
|
|
9500
9504
|
{
|
|
9501
9505
|
Component: CustomItems,
|
|
9502
9506
|
path: "/draft-orders/:id/custom-items"
|
|
@@ -9505,21 +9509,13 @@ const routeModule = {
|
|
|
9505
9509
|
Component: Email,
|
|
9506
9510
|
path: "/draft-orders/:id/email"
|
|
9507
9511
|
},
|
|
9508
|
-
{
|
|
9509
|
-
Component: BillingAddress,
|
|
9510
|
-
path: "/draft-orders/:id/billing-address"
|
|
9511
|
-
},
|
|
9512
9512
|
{
|
|
9513
9513
|
Component: Items,
|
|
9514
9514
|
path: "/draft-orders/:id/items"
|
|
9515
9515
|
},
|
|
9516
9516
|
{
|
|
9517
|
-
Component:
|
|
9518
|
-
path: "/draft-orders/:id/
|
|
9519
|
-
},
|
|
9520
|
-
{
|
|
9521
|
-
Component: Promotions,
|
|
9522
|
-
path: "/draft-orders/:id/promotions"
|
|
9517
|
+
Component: SalesChannel,
|
|
9518
|
+
path: "/draft-orders/:id/sales-channel"
|
|
9523
9519
|
},
|
|
9524
9520
|
{
|
|
9525
9521
|
Component: Shipping,
|
|
@@ -9534,8 +9530,12 @@ const routeModule = {
|
|
|
9534
9530
|
path: "/draft-orders/:id/transfer-ownership"
|
|
9535
9531
|
},
|
|
9536
9532
|
{
|
|
9537
|
-
Component:
|
|
9538
|
-
path: "/draft-orders/:id/
|
|
9533
|
+
Component: Promotions,
|
|
9534
|
+
path: "/draft-orders/:id/promotions"
|
|
9535
|
+
},
|
|
9536
|
+
{
|
|
9537
|
+
Component: Metadata,
|
|
9538
|
+
path: "/draft-orders/:id/metadata"
|
|
9539
9539
|
}
|
|
9540
9540
|
]
|
|
9541
9541
|
}
|