@empty-complete-org/medusa-product-attributes 1.0.0 → 1.1.0
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 +192 -230
- package/.medusa/server/src/admin/index.mjs +192 -230
- package/README.md +0 -1
- package/package.json +1 -1
- package/README.ru.md +0 -85
|
@@ -180,15 +180,17 @@ const en = {
|
|
|
180
180
|
};
|
|
181
181
|
const locales = { ru, en };
|
|
182
182
|
function detectLang() {
|
|
183
|
-
var _a;
|
|
184
|
-
if (typeof window === "undefined") return "
|
|
183
|
+
var _a, _b, _c;
|
|
184
|
+
if (typeof window === "undefined") return "ru";
|
|
185
185
|
const stored = window.localStorage.getItem("i18nextLng");
|
|
186
186
|
if (stored) {
|
|
187
187
|
const short = stored.slice(0, 2).toLowerCase();
|
|
188
188
|
if (locales[short]) return short;
|
|
189
189
|
}
|
|
190
|
-
const
|
|
191
|
-
|
|
190
|
+
const htmlLang = (_b = (_a = document.documentElement) == null ? void 0 : _a.lang) == null ? void 0 : _b.slice(0, 2).toLowerCase();
|
|
191
|
+
if (htmlLang && locales[htmlLang]) return htmlLang;
|
|
192
|
+
const nav = (((_c = window.navigator) == null ? void 0 : _c.language) || "ru").slice(0, 2).toLowerCase();
|
|
193
|
+
return locales[nav] ? nav : "ru";
|
|
192
194
|
}
|
|
193
195
|
function useT() {
|
|
194
196
|
const dict = React.useMemo(() => {
|
|
@@ -197,7 +199,7 @@ function useT() {
|
|
|
197
199
|
}, []);
|
|
198
200
|
return (key, fallback) => dict[key] ?? fallback ?? key;
|
|
199
201
|
}
|
|
200
|
-
const emptyForm$
|
|
202
|
+
const emptyForm$1 = () => ({ label: "", type: "text", unit: "" });
|
|
201
203
|
const CategoryAttributeTemplatesWidget = ({
|
|
202
204
|
data
|
|
203
205
|
}) => {
|
|
@@ -208,7 +210,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
208
210
|
const queryKey = ["category-custom-attributes", categoryId];
|
|
209
211
|
const [showAddForm, setShowAddForm] = React.useState(false);
|
|
210
212
|
const [showTemplateList, setShowTemplateList] = React.useState(false);
|
|
211
|
-
const [addForm, setAddForm] = React.useState(emptyForm$
|
|
213
|
+
const [addForm, setAddForm] = React.useState(emptyForm$1());
|
|
212
214
|
const [confirmDeleteId, setConfirmDeleteId] = React.useState(null);
|
|
213
215
|
const [mutationError, setMutationError] = React.useState(null);
|
|
214
216
|
const templatesQuery = reactQuery.useQuery({
|
|
@@ -248,7 +250,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
248
250
|
onSuccess: () => {
|
|
249
251
|
qc.invalidateQueries({ queryKey });
|
|
250
252
|
setShowAddForm(false);
|
|
251
|
-
setAddForm(emptyForm$
|
|
253
|
+
setAddForm(emptyForm$1());
|
|
252
254
|
setMutationError(null);
|
|
253
255
|
},
|
|
254
256
|
onError: (err) => {
|
|
@@ -273,7 +275,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
273
275
|
unit: addForm.type === "number" && addForm.unit.trim() ? addForm.unit.trim() : null
|
|
274
276
|
});
|
|
275
277
|
};
|
|
276
|
-
const
|
|
278
|
+
const typeLabel = (v) => t(`type.${v}`, v);
|
|
277
279
|
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
278
280
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
279
281
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: t("attributes") }),
|
|
@@ -287,16 +289,13 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
287
289
|
children: t("fromTemplate")
|
|
288
290
|
}
|
|
289
291
|
),
|
|
290
|
-
/* @__PURE__ */ jsxRuntime.
|
|
292
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
291
293
|
ui.Button,
|
|
292
294
|
{
|
|
293
295
|
variant: "secondary",
|
|
294
296
|
size: "small",
|
|
295
297
|
onClick: () => setShowAddForm(true),
|
|
296
|
-
children:
|
|
297
|
-
"+ ",
|
|
298
|
-
t("add")
|
|
299
|
-
]
|
|
298
|
+
children: t("add")
|
|
300
299
|
}
|
|
301
300
|
)
|
|
302
301
|
] })
|
|
@@ -325,7 +324,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
325
324
|
children: [
|
|
326
325
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: p.label }),
|
|
327
326
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
328
|
-
|
|
327
|
+
typeLabel(p.type),
|
|
329
328
|
p.unit ? `, ${p.unit}` : ""
|
|
330
329
|
] })
|
|
331
330
|
]
|
|
@@ -344,10 +343,9 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
344
343
|
children: [
|
|
345
344
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-ui-fg-subtle", children: attr.label }),
|
|
346
345
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
347
|
-
|
|
346
|
+
typeLabel(attr.type),
|
|
348
347
|
attr.unit ? `, ${attr.unit}` : ""
|
|
349
|
-
] })
|
|
350
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "blue", children: "из родителя" })
|
|
348
|
+
] })
|
|
351
349
|
]
|
|
352
350
|
},
|
|
353
351
|
attr.id
|
|
@@ -395,7 +393,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
395
393
|
children: [
|
|
396
394
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-ui-fg-base", children: attr.label }),
|
|
397
395
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
398
|
-
|
|
396
|
+
typeLabel(attr.type),
|
|
399
397
|
attr.unit ? `, ${attr.unit}` : ""
|
|
400
398
|
] }),
|
|
401
399
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -467,7 +465,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
467
465
|
size: "small",
|
|
468
466
|
onClick: () => {
|
|
469
467
|
setShowAddForm(false);
|
|
470
|
-
setAddForm(emptyForm$
|
|
468
|
+
setAddForm(emptyForm$1());
|
|
471
469
|
setMutationError(null);
|
|
472
470
|
},
|
|
473
471
|
children: "Отмена"
|
|
@@ -685,71 +683,6 @@ const ProductAttributeValuesWidget = ({
|
|
|
685
683
|
adminSdk.defineWidgetConfig({
|
|
686
684
|
zone: "product.details.after"
|
|
687
685
|
});
|
|
688
|
-
var __defProp$1 = Object.defineProperty;
|
|
689
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
690
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
691
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
692
|
-
var __defNormalProp$1 = (obj, key, value2) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key] = value2;
|
|
693
|
-
var __spreadValues$1 = (a, b) => {
|
|
694
|
-
for (var prop in b || (b = {}))
|
|
695
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
696
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
697
|
-
if (__getOwnPropSymbols$1)
|
|
698
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
699
|
-
if (__propIsEnum$1.call(b, prop))
|
|
700
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
701
|
-
}
|
|
702
|
-
return a;
|
|
703
|
-
};
|
|
704
|
-
var __objRest$1 = (source, exclude) => {
|
|
705
|
-
var target = {};
|
|
706
|
-
for (var prop in source)
|
|
707
|
-
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
708
|
-
target[prop] = source[prop];
|
|
709
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
710
|
-
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
711
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
712
|
-
target[prop] = source[prop];
|
|
713
|
-
}
|
|
714
|
-
return target;
|
|
715
|
-
};
|
|
716
|
-
const Globe = React__namespace.forwardRef(
|
|
717
|
-
(_a, ref) => {
|
|
718
|
-
var _b = _a, { color = "currentColor" } = _b, props = __objRest$1(_b, ["color"]);
|
|
719
|
-
return /* @__PURE__ */ React__namespace.createElement(
|
|
720
|
-
"svg",
|
|
721
|
-
__spreadValues$1({
|
|
722
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
723
|
-
width: 15,
|
|
724
|
-
height: 15,
|
|
725
|
-
viewBox: "0 0 15 15",
|
|
726
|
-
fill: "none",
|
|
727
|
-
ref
|
|
728
|
-
}, props),
|
|
729
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
730
|
-
"path",
|
|
731
|
-
{
|
|
732
|
-
stroke: color,
|
|
733
|
-
strokeLinecap: "round",
|
|
734
|
-
strokeLinejoin: "round",
|
|
735
|
-
strokeWidth: 1.5,
|
|
736
|
-
d: "M7.5 13.945c1.473 0 2.667-2.886 2.667-6.445S8.973 1.056 7.5 1.056 4.833 3.94 4.833 7.5s1.194 6.445 2.667 6.445M1.056 7.5h12.888"
|
|
737
|
-
}
|
|
738
|
-
),
|
|
739
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
740
|
-
"path",
|
|
741
|
-
{
|
|
742
|
-
stroke: color,
|
|
743
|
-
strokeLinecap: "round",
|
|
744
|
-
strokeLinejoin: "round",
|
|
745
|
-
strokeWidth: 1.5,
|
|
746
|
-
d: "M7.5 13.945a6.444 6.444 0 1 0 0-12.89 6.444 6.444 0 0 0 0 12.89"
|
|
747
|
-
}
|
|
748
|
-
)
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
);
|
|
752
|
-
Globe.displayName = "Globe";
|
|
753
686
|
var __defProp = Object.defineProperty;
|
|
754
687
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
755
688
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -778,7 +711,7 @@ var __objRest = (source, exclude) => {
|
|
|
778
711
|
}
|
|
779
712
|
return target;
|
|
780
713
|
};
|
|
781
|
-
const
|
|
714
|
+
const Tag = React__namespace.forwardRef(
|
|
782
715
|
(_a, ref) => {
|
|
783
716
|
var _b = _a, { color = "currentColor" } = _b, props = __objRest(_b, ["color"]);
|
|
784
717
|
return /* @__PURE__ */ React__namespace.createElement(
|
|
@@ -791,56 +724,73 @@ const SquaresPlus = React__namespace.forwardRef(
|
|
|
791
724
|
fill: "none",
|
|
792
725
|
ref
|
|
793
726
|
}, props),
|
|
794
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
727
|
+
/* @__PURE__ */ React__namespace.createElement("g", { clipPath: "url(#a)" }, /* @__PURE__ */ React__namespace.createElement(
|
|
795
728
|
"path",
|
|
796
729
|
{
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
d: "M5.056 1.944H2.833a.89.89 0 0 0-.889.89v2.221c0 .491.398.89.89.89h2.222c.49 0 .888-.399.888-.89V2.833a.89.89 0 0 0-.888-.889M12.167 1.944H9.944a.89.89 0 0 0-.888.89v2.221c0 .491.398.89.888.89h2.223c.49 0 .889-.399.889-.89V2.833a.89.89 0 0 0-.89-.889M5.056 9.056H2.833a.89.89 0 0 0-.889.889v2.222c0 .49.398.889.89.889h2.222c.49 0 .888-.398.888-.89V9.946a.89.89 0 0 0-.888-.89M11.056 8.611v4.445M13.278 10.833H8.833"
|
|
730
|
+
fill: color,
|
|
731
|
+
fillRule: "evenodd",
|
|
732
|
+
d: "M2.25 2.389a.14.14 0 0 1 .139-.139h4.375c.272 0 .534.108.727.301l5.11 5.111a1.027 1.027 0 0 1 0 1.453l-3.486 3.487a1.027 1.027 0 0 1-1.453 0L2.552 7.49a1.03 1.03 0 0 1-.302-.727zM2.389.75A1.64 1.64 0 0 0 .75 2.389v4.375c0 .67.267 1.313.74 1.787l5.112 5.111a2.527 2.527 0 0 0 3.574 0l3.486-3.486a2.527 2.527 0 0 0 0-3.574L8.552 1.49A2.53 2.53 0 0 0 6.763.75zm3.778 4.305a1.111 1.111 0 1 1-2.223 0 1.111 1.111 0 0 1 2.223 0",
|
|
733
|
+
clipRule: "evenodd"
|
|
802
734
|
}
|
|
803
|
-
)
|
|
735
|
+
)),
|
|
736
|
+
/* @__PURE__ */ React__namespace.createElement("defs", null, /* @__PURE__ */ React__namespace.createElement("clipPath", { id: "a" }, /* @__PURE__ */ React__namespace.createElement("path", { fill: "#fff", d: "M0 0h15v15H0z" })))
|
|
804
737
|
);
|
|
805
738
|
}
|
|
806
739
|
);
|
|
807
|
-
|
|
808
|
-
const emptyForm
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
740
|
+
Tag.displayName = "Tag";
|
|
741
|
+
const emptyForm = () => ({ label: "", type: "text", unit: "", description: "" });
|
|
742
|
+
const ProductAttributesSettingsPage = () => {
|
|
743
|
+
const t = useT();
|
|
744
|
+
const [tab, setTab] = React.useState("globals");
|
|
745
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
|
|
746
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-6 border-b border-ui-border-base px-6 pt-4", children: [
|
|
747
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabButton, { active: tab === "globals", onClick: () => setTab("globals"), children: t("globals") }),
|
|
748
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabButton, { active: tab === "templates", onClick: () => setTab("templates"), children: t("templates") })
|
|
749
|
+
] }),
|
|
750
|
+
tab === "globals" ? /* @__PURE__ */ jsxRuntime.jsx(GlobalsTab, {}) : /* @__PURE__ */ jsxRuntime.jsx(TemplatesTab, {})
|
|
751
|
+
] });
|
|
752
|
+
};
|
|
753
|
+
const TabButton = ({
|
|
754
|
+
active,
|
|
755
|
+
onClick,
|
|
756
|
+
children
|
|
757
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
758
|
+
"button",
|
|
759
|
+
{
|
|
760
|
+
onClick,
|
|
761
|
+
className: `-mb-px border-b-2 px-1 pb-3 text-sm font-medium transition-colors ${active ? "border-ui-border-interactive text-ui-fg-base" : "border-transparent text-ui-fg-subtle hover:text-ui-fg-base"}`,
|
|
762
|
+
children
|
|
763
|
+
}
|
|
764
|
+
);
|
|
765
|
+
const GlobalsTab = () => {
|
|
766
|
+
const t = useT();
|
|
816
767
|
const qc = reactQuery.useQueryClient();
|
|
817
|
-
const queryKey = ["
|
|
768
|
+
const queryKey = ["global-attributes"];
|
|
818
769
|
const [showAddForm, setShowAddForm] = React.useState(false);
|
|
819
|
-
const [addForm, setAddForm] = React.useState(emptyForm
|
|
770
|
+
const [addForm, setAddForm] = React.useState(emptyForm());
|
|
820
771
|
const [confirmDeleteId, setConfirmDeleteId] = React.useState(null);
|
|
821
772
|
const { data, isLoading, isError } = reactQuery.useQuery({
|
|
822
773
|
queryKey,
|
|
823
|
-
queryFn: () => sdk.client.fetch(`/admin/
|
|
774
|
+
queryFn: () => sdk.client.fetch(`/admin/global-attributes`)
|
|
824
775
|
});
|
|
825
|
-
const
|
|
776
|
+
const attrs = (data == null ? void 0 : data.global_attributes) ?? [];
|
|
826
777
|
const createMutation = reactQuery.useMutation({
|
|
827
|
-
mutationFn: (body) => sdk.client.fetch(`/admin/
|
|
778
|
+
mutationFn: (body) => sdk.client.fetch(`/admin/global-attributes`, {
|
|
828
779
|
method: "POST",
|
|
829
780
|
body: {
|
|
830
781
|
label: body.label,
|
|
831
782
|
type: body.type,
|
|
832
|
-
unit: body.type === "number" && body.unit ? body.unit : null
|
|
833
|
-
description: body.description || null
|
|
783
|
+
unit: body.type === "number" && body.unit ? body.unit : null
|
|
834
784
|
}
|
|
835
785
|
}),
|
|
836
786
|
onSuccess: () => {
|
|
837
787
|
qc.invalidateQueries({ queryKey });
|
|
838
788
|
setShowAddForm(false);
|
|
839
|
-
setAddForm(emptyForm
|
|
789
|
+
setAddForm(emptyForm());
|
|
840
790
|
}
|
|
841
791
|
});
|
|
842
792
|
const deleteMutation = reactQuery.useMutation({
|
|
843
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/
|
|
793
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/global-attributes`, {
|
|
844
794
|
method: "PATCH",
|
|
845
795
|
body: { id, deleted_at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
846
796
|
}),
|
|
@@ -858,86 +808,57 @@ const AttributeTemplatesSettingsPage = () => {
|
|
|
858
808
|
description: addForm.description.trim()
|
|
859
809
|
});
|
|
860
810
|
};
|
|
861
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
862
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-
|
|
811
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y", children: [
|
|
812
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between px-6 py-4", children: [
|
|
863
813
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
864
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "
|
|
865
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "
|
|
814
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: t("globals") }),
|
|
815
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: t("globalsDesc") })
|
|
866
816
|
] }),
|
|
867
|
-
!showAddForm && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: "
|
|
817
|
+
!showAddForm && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: t("add") })
|
|
868
818
|
] }),
|
|
869
|
-
isLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: "
|
|
870
|
-
isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error text-sm", children: "
|
|
871
|
-
!isLoading && !isError &&
|
|
872
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children:
|
|
873
|
-
(
|
|
874
|
-
/* @__PURE__ */ jsxRuntime.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
/* @__PURE__ */ jsxRuntime.
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
|
|
883
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
884
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: p.label }),
|
|
885
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
886
|
-
typeLabel$1(p.type),
|
|
887
|
-
p.unit ? `, ${p.unit}` : ""
|
|
888
|
-
] })
|
|
889
|
-
] }),
|
|
890
|
-
p.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: p.description })
|
|
819
|
+
isLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: t("loading") }) }),
|
|
820
|
+
isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error text-sm", children: t("loadFailed") }) }),
|
|
821
|
+
!isLoading && !isError && attrs.length === 0 && !showAddForm && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: t("noGlobals") }) }),
|
|
822
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children: attrs.map(
|
|
823
|
+
(a) => confirmDeleteId === a.id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 px-6 py-3 text-sm", children: [
|
|
824
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: t("confirmDelete").replace("{name}", a.label) }),
|
|
825
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "danger", onClick: () => deleteMutation.mutate(a.id), isLoading: deleteMutation.isPending, children: t("delete") }),
|
|
826
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", onClick: () => setConfirmDeleteId(null), children: t("cancel") })
|
|
827
|
+
] }, a.id) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 px-6 py-3", children: [
|
|
828
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm", children: a.label }),
|
|
829
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
830
|
+
t(`type.${a.type}`, a.type),
|
|
831
|
+
a.unit ? `, ${a.unit}` : ""
|
|
891
832
|
] }),
|
|
892
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setConfirmDeleteId(
|
|
893
|
-
] },
|
|
833
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setConfirmDeleteId(a.id), className: "text-xs text-ui-fg-error hover:underline", children: t("delete") })
|
|
834
|
+
] }, a.id)
|
|
894
835
|
) }),
|
|
895
|
-
showAddForm && /* @__PURE__ */ jsxRuntime.
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "text", children: "Текст" }),
|
|
900
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "number", children: "Число" }),
|
|
901
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "file", children: "Файл" }),
|
|
902
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "boolean", children: "Да/Нет" })
|
|
903
|
-
] }),
|
|
904
|
-
addForm.type === "number" && /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { value: addForm.unit, onChange: (e) => setAddForm((f) => ({ ...f, unit: e.target.value })), placeholder: "ед.", className: "w-28 h-8 text-sm" })
|
|
905
|
-
] }),
|
|
906
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { value: addForm.description, onChange: (e) => setAddForm((f) => ({ ...f, description: e.target.value })), placeholder: "Описание (необязательно)", className: "h-8 text-sm" }),
|
|
907
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
908
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => {
|
|
909
|
-
setShowAddForm(false);
|
|
910
|
-
setAddForm(emptyForm$1());
|
|
911
|
-
}, children: "Отмена" }),
|
|
912
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", onClick: handleAdd, isLoading: createMutation.isPending, children: "Создать" })
|
|
913
|
-
] })
|
|
914
|
-
] })
|
|
836
|
+
showAddForm && /* @__PURE__ */ jsxRuntime.jsx(AddForm, { t, form: addForm, setForm: setAddForm, onCancel: () => {
|
|
837
|
+
setShowAddForm(false);
|
|
838
|
+
setAddForm(emptyForm());
|
|
839
|
+
}, onSubmit: handleAdd, isLoading: createMutation.isPending, withDescription: false })
|
|
915
840
|
] });
|
|
916
841
|
};
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
icon: SquaresPlus
|
|
920
|
-
});
|
|
921
|
-
const emptyForm = () => ({ label: "", type: "text", unit: "" });
|
|
922
|
-
const typeLabel = (t) => t === "text" ? "Текст" : t === "number" ? "Число" : t === "file" ? "Файл" : t === "boolean" ? "Да/Нет" : t;
|
|
923
|
-
const GlobalAttributesSettingsPage = () => {
|
|
842
|
+
const TemplatesTab = () => {
|
|
843
|
+
const t = useT();
|
|
924
844
|
const qc = reactQuery.useQueryClient();
|
|
925
|
-
const queryKey = ["
|
|
845
|
+
const queryKey = ["attribute-templates"];
|
|
926
846
|
const [showAddForm, setShowAddForm] = React.useState(false);
|
|
927
847
|
const [addForm, setAddForm] = React.useState(emptyForm());
|
|
928
848
|
const [confirmDeleteId, setConfirmDeleteId] = React.useState(null);
|
|
929
849
|
const { data, isLoading, isError } = reactQuery.useQuery({
|
|
930
850
|
queryKey,
|
|
931
|
-
queryFn: () => sdk.client.fetch(`/admin/
|
|
851
|
+
queryFn: () => sdk.client.fetch(`/admin/attribute-templates`)
|
|
932
852
|
});
|
|
933
|
-
const
|
|
853
|
+
const templates2 = (data == null ? void 0 : data.attribute_templates) ?? [];
|
|
934
854
|
const createMutation = reactQuery.useMutation({
|
|
935
|
-
mutationFn: (body) => sdk.client.fetch(`/admin/
|
|
855
|
+
mutationFn: (body) => sdk.client.fetch(`/admin/attribute-templates`, {
|
|
936
856
|
method: "POST",
|
|
937
857
|
body: {
|
|
938
858
|
label: body.label,
|
|
939
859
|
type: body.type,
|
|
940
|
-
unit: body.type === "number" && body.unit ? body.unit : null
|
|
860
|
+
unit: body.type === "number" && body.unit ? body.unit : null,
|
|
861
|
+
description: body.description || null
|
|
941
862
|
}
|
|
942
863
|
}),
|
|
943
864
|
onSuccess: () => {
|
|
@@ -947,7 +868,7 @@ const GlobalAttributesSettingsPage = () => {
|
|
|
947
868
|
}
|
|
948
869
|
});
|
|
949
870
|
const deleteMutation = reactQuery.useMutation({
|
|
950
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/
|
|
871
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/attribute-templates`, {
|
|
951
872
|
method: "PATCH",
|
|
952
873
|
body: { id, deleted_at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
953
874
|
}),
|
|
@@ -959,60 +880,113 @@ const GlobalAttributesSettingsPage = () => {
|
|
|
959
880
|
const handleAdd = () => {
|
|
960
881
|
if (!addForm.label.trim()) return;
|
|
961
882
|
createMutation.mutate({
|
|
883
|
+
...addForm,
|
|
962
884
|
label: addForm.label.trim(),
|
|
963
|
-
|
|
964
|
-
|
|
885
|
+
unit: addForm.unit.trim(),
|
|
886
|
+
description: addForm.description.trim()
|
|
965
887
|
});
|
|
966
888
|
};
|
|
967
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
968
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-
|
|
889
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y", children: [
|
|
890
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between px-6 py-4", children: [
|
|
969
891
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
970
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "
|
|
971
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "
|
|
892
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: t("templates") }),
|
|
893
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: t("templatesDesc") })
|
|
972
894
|
] }),
|
|
973
|
-
!showAddForm && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: "
|
|
895
|
+
!showAddForm && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: t("add") })
|
|
974
896
|
] }),
|
|
975
|
-
isLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: "
|
|
976
|
-
isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error text-sm", children: "
|
|
977
|
-
!isLoading && !isError &&
|
|
978
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children:
|
|
979
|
-
(
|
|
980
|
-
/* @__PURE__ */ jsxRuntime.
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
897
|
+
isLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: t("loading") }) }),
|
|
898
|
+
isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error text-sm", children: t("loadFailed") }) }),
|
|
899
|
+
!isLoading && !isError && templates2.length === 0 && !showAddForm && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: t("noTemplates") }) }),
|
|
900
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children: templates2.map(
|
|
901
|
+
(p) => confirmDeleteId === p.id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 px-6 py-3 text-sm", children: [
|
|
902
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: t("confirmDelete").replace("{name}", p.label) }),
|
|
903
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "danger", onClick: () => deleteMutation.mutate(p.id), isLoading: deleteMutation.isPending, children: t("delete") }),
|
|
904
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", onClick: () => setConfirmDeleteId(null), children: t("cancel") })
|
|
905
|
+
] }, p.id) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 px-6 py-3", children: [
|
|
906
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
|
|
907
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
908
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: p.label }),
|
|
909
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { size: "2xsmall", color: "grey", children: [
|
|
910
|
+
t(`type.${p.type}`, p.type),
|
|
911
|
+
p.unit ? `, ${p.unit}` : ""
|
|
912
|
+
] })
|
|
913
|
+
] }),
|
|
914
|
+
p.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: p.description })
|
|
992
915
|
] }),
|
|
993
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setConfirmDeleteId(
|
|
994
|
-
] },
|
|
916
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setConfirmDeleteId(p.id), className: "text-xs text-ui-fg-error hover:underline", children: t("delete") })
|
|
917
|
+
] }, p.id)
|
|
995
918
|
) }),
|
|
996
|
-
showAddForm && /* @__PURE__ */ jsxRuntime.
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "number", children: "Число" }),
|
|
1001
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "file", children: "Файл" }),
|
|
1002
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "boolean", children: "Да/Нет" })
|
|
1003
|
-
] }),
|
|
1004
|
-
addForm.type === "number" && /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { value: addForm.unit, onChange: (e) => setAddForm((f) => ({ ...f, unit: e.target.value })), placeholder: "ед.", className: "w-28 h-8 text-sm" }),
|
|
1005
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", onClick: handleAdd, isLoading: createMutation.isPending, children: "Создать" }),
|
|
1006
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: () => {
|
|
1007
|
-
setShowAddForm(false);
|
|
1008
|
-
setAddForm(emptyForm());
|
|
1009
|
-
}, children: "Отмена" })
|
|
1010
|
-
] })
|
|
919
|
+
showAddForm && /* @__PURE__ */ jsxRuntime.jsx(AddForm, { t, form: addForm, setForm: setAddForm, onCancel: () => {
|
|
920
|
+
setShowAddForm(false);
|
|
921
|
+
setAddForm(emptyForm());
|
|
922
|
+
}, onSubmit: handleAdd, isLoading: createMutation.isPending, withDescription: true })
|
|
1011
923
|
] });
|
|
1012
924
|
};
|
|
925
|
+
const AddForm = ({
|
|
926
|
+
t,
|
|
927
|
+
form,
|
|
928
|
+
setForm,
|
|
929
|
+
onCancel,
|
|
930
|
+
onSubmit,
|
|
931
|
+
isLoading,
|
|
932
|
+
withDescription
|
|
933
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 px-6 py-4", children: [
|
|
934
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
935
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
936
|
+
ui.Input,
|
|
937
|
+
{
|
|
938
|
+
value: form.label,
|
|
939
|
+
onChange: (e) => setForm((f) => ({ ...f, label: e.target.value })),
|
|
940
|
+
placeholder: t("name"),
|
|
941
|
+
className: "flex-1 h-8 text-sm",
|
|
942
|
+
autoFocus: true
|
|
943
|
+
}
|
|
944
|
+
),
|
|
945
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
946
|
+
"select",
|
|
947
|
+
{
|
|
948
|
+
value: form.type,
|
|
949
|
+
onChange: (e) => setForm((f) => ({
|
|
950
|
+
...f,
|
|
951
|
+
type: e.target.value,
|
|
952
|
+
unit: e.target.value === "number" ? f.unit : ""
|
|
953
|
+
})),
|
|
954
|
+
className: "h-8 rounded border border-ui-border-base bg-ui-bg-base px-2 text-sm",
|
|
955
|
+
children: [
|
|
956
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "text", children: t("type.text") }),
|
|
957
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "number", children: t("type.number") }),
|
|
958
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "file", children: t("type.file") }),
|
|
959
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "boolean", children: t("type.boolean") })
|
|
960
|
+
]
|
|
961
|
+
}
|
|
962
|
+
),
|
|
963
|
+
form.type === "number" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
964
|
+
ui.Input,
|
|
965
|
+
{
|
|
966
|
+
value: form.unit,
|
|
967
|
+
onChange: (e) => setForm((f) => ({ ...f, unit: e.target.value })),
|
|
968
|
+
placeholder: t("unit"),
|
|
969
|
+
className: "w-28 h-8 text-sm"
|
|
970
|
+
}
|
|
971
|
+
)
|
|
972
|
+
] }),
|
|
973
|
+
withDescription && /* @__PURE__ */ jsxRuntime.jsx(
|
|
974
|
+
ui.Input,
|
|
975
|
+
{
|
|
976
|
+
value: form.description,
|
|
977
|
+
onChange: (e) => setForm((f) => ({ ...f, description: e.target.value })),
|
|
978
|
+
placeholder: t("description"),
|
|
979
|
+
className: "h-8 text-sm"
|
|
980
|
+
}
|
|
981
|
+
),
|
|
982
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
983
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: onCancel, children: t("cancel") }),
|
|
984
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", onClick: onSubmit, isLoading, children: t("create") })
|
|
985
|
+
] })
|
|
986
|
+
] });
|
|
1013
987
|
const config = adminSdk.defineRouteConfig({
|
|
1014
|
-
label: "
|
|
1015
|
-
icon:
|
|
988
|
+
label: "Product Attributes",
|
|
989
|
+
icon: Tag
|
|
1016
990
|
});
|
|
1017
991
|
const widgetModule = { widgets: [
|
|
1018
992
|
{
|
|
@@ -1027,29 +1001,17 @@ const widgetModule = { widgets: [
|
|
|
1027
1001
|
const routeModule = {
|
|
1028
1002
|
routes: [
|
|
1029
1003
|
{
|
|
1030
|
-
Component:
|
|
1031
|
-
path: "/settings/
|
|
1032
|
-
},
|
|
1033
|
-
{
|
|
1034
|
-
Component: GlobalAttributesSettingsPage,
|
|
1035
|
-
path: "/settings/global-attributes"
|
|
1004
|
+
Component: ProductAttributesSettingsPage,
|
|
1005
|
+
path: "/settings/product-attributes"
|
|
1036
1006
|
}
|
|
1037
1007
|
]
|
|
1038
1008
|
};
|
|
1039
1009
|
const menuItemModule = {
|
|
1040
1010
|
menuItems: [
|
|
1041
|
-
{
|
|
1042
|
-
label: config$1.label,
|
|
1043
|
-
icon: config$1.icon,
|
|
1044
|
-
path: "/settings/attribute-templates",
|
|
1045
|
-
nested: void 0,
|
|
1046
|
-
rank: void 0,
|
|
1047
|
-
translationNs: void 0
|
|
1048
|
-
},
|
|
1049
1011
|
{
|
|
1050
1012
|
label: config.label,
|
|
1051
1013
|
icon: config.icon,
|
|
1052
|
-
path: "/settings/
|
|
1014
|
+
path: "/settings/product-attributes",
|
|
1053
1015
|
nested: void 0,
|
|
1054
1016
|
rank: void 0,
|
|
1055
1017
|
translationNs: void 0
|