@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
|
@@ -160,15 +160,17 @@ const en = {
|
|
|
160
160
|
};
|
|
161
161
|
const locales = { ru, en };
|
|
162
162
|
function detectLang() {
|
|
163
|
-
var _a;
|
|
164
|
-
if (typeof window === "undefined") return "
|
|
163
|
+
var _a, _b, _c;
|
|
164
|
+
if (typeof window === "undefined") return "ru";
|
|
165
165
|
const stored = window.localStorage.getItem("i18nextLng");
|
|
166
166
|
if (stored) {
|
|
167
167
|
const short = stored.slice(0, 2).toLowerCase();
|
|
168
168
|
if (locales[short]) return short;
|
|
169
169
|
}
|
|
170
|
-
const
|
|
171
|
-
|
|
170
|
+
const htmlLang = (_b = (_a = document.documentElement) == null ? void 0 : _a.lang) == null ? void 0 : _b.slice(0, 2).toLowerCase();
|
|
171
|
+
if (htmlLang && locales[htmlLang]) return htmlLang;
|
|
172
|
+
const nav = (((_c = window.navigator) == null ? void 0 : _c.language) || "ru").slice(0, 2).toLowerCase();
|
|
173
|
+
return locales[nav] ? nav : "ru";
|
|
172
174
|
}
|
|
173
175
|
function useT() {
|
|
174
176
|
const dict = useMemo(() => {
|
|
@@ -177,7 +179,7 @@ function useT() {
|
|
|
177
179
|
}, []);
|
|
178
180
|
return (key, fallback) => dict[key] ?? fallback ?? key;
|
|
179
181
|
}
|
|
180
|
-
const emptyForm$
|
|
182
|
+
const emptyForm$1 = () => ({ label: "", type: "text", unit: "" });
|
|
181
183
|
const CategoryAttributeTemplatesWidget = ({
|
|
182
184
|
data
|
|
183
185
|
}) => {
|
|
@@ -188,7 +190,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
188
190
|
const queryKey = ["category-custom-attributes", categoryId];
|
|
189
191
|
const [showAddForm, setShowAddForm] = useState(false);
|
|
190
192
|
const [showTemplateList, setShowTemplateList] = useState(false);
|
|
191
|
-
const [addForm, setAddForm] = useState(emptyForm$
|
|
193
|
+
const [addForm, setAddForm] = useState(emptyForm$1());
|
|
192
194
|
const [confirmDeleteId, setConfirmDeleteId] = useState(null);
|
|
193
195
|
const [mutationError, setMutationError] = useState(null);
|
|
194
196
|
const templatesQuery = useQuery({
|
|
@@ -228,7 +230,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
228
230
|
onSuccess: () => {
|
|
229
231
|
qc.invalidateQueries({ queryKey });
|
|
230
232
|
setShowAddForm(false);
|
|
231
|
-
setAddForm(emptyForm$
|
|
233
|
+
setAddForm(emptyForm$1());
|
|
232
234
|
setMutationError(null);
|
|
233
235
|
},
|
|
234
236
|
onError: (err) => {
|
|
@@ -253,7 +255,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
253
255
|
unit: addForm.type === "number" && addForm.unit.trim() ? addForm.unit.trim() : null
|
|
254
256
|
});
|
|
255
257
|
};
|
|
256
|
-
const
|
|
258
|
+
const typeLabel = (v) => t(`type.${v}`, v);
|
|
257
259
|
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
258
260
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
259
261
|
/* @__PURE__ */ jsx(Heading, { level: "h2", children: t("attributes") }),
|
|
@@ -267,16 +269,13 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
267
269
|
children: t("fromTemplate")
|
|
268
270
|
}
|
|
269
271
|
),
|
|
270
|
-
/* @__PURE__ */
|
|
272
|
+
/* @__PURE__ */ jsx(
|
|
271
273
|
Button,
|
|
272
274
|
{
|
|
273
275
|
variant: "secondary",
|
|
274
276
|
size: "small",
|
|
275
277
|
onClick: () => setShowAddForm(true),
|
|
276
|
-
children:
|
|
277
|
-
"+ ",
|
|
278
|
-
t("add")
|
|
279
|
-
]
|
|
278
|
+
children: t("add")
|
|
280
279
|
}
|
|
281
280
|
)
|
|
282
281
|
] })
|
|
@@ -305,7 +304,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
305
304
|
children: [
|
|
306
305
|
/* @__PURE__ */ jsx("span", { children: p.label }),
|
|
307
306
|
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
308
|
-
|
|
307
|
+
typeLabel(p.type),
|
|
309
308
|
p.unit ? `, ${p.unit}` : ""
|
|
310
309
|
] })
|
|
311
310
|
]
|
|
@@ -324,10 +323,9 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
324
323
|
children: [
|
|
325
324
|
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-ui-fg-subtle", children: attr.label }),
|
|
326
325
|
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
327
|
-
|
|
326
|
+
typeLabel(attr.type),
|
|
328
327
|
attr.unit ? `, ${attr.unit}` : ""
|
|
329
|
-
] })
|
|
330
|
-
/* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "blue", children: "из родителя" })
|
|
328
|
+
] })
|
|
331
329
|
]
|
|
332
330
|
},
|
|
333
331
|
attr.id
|
|
@@ -375,7 +373,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
375
373
|
children: [
|
|
376
374
|
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-ui-fg-base", children: attr.label }),
|
|
377
375
|
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
378
|
-
|
|
376
|
+
typeLabel(attr.type),
|
|
379
377
|
attr.unit ? `, ${attr.unit}` : ""
|
|
380
378
|
] }),
|
|
381
379
|
/* @__PURE__ */ jsx(
|
|
@@ -447,7 +445,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
447
445
|
size: "small",
|
|
448
446
|
onClick: () => {
|
|
449
447
|
setShowAddForm(false);
|
|
450
|
-
setAddForm(emptyForm$
|
|
448
|
+
setAddForm(emptyForm$1());
|
|
451
449
|
setMutationError(null);
|
|
452
450
|
},
|
|
453
451
|
children: "Отмена"
|
|
@@ -665,71 +663,6 @@ const ProductAttributeValuesWidget = ({
|
|
|
665
663
|
defineWidgetConfig({
|
|
666
664
|
zone: "product.details.after"
|
|
667
665
|
});
|
|
668
|
-
var __defProp$1 = Object.defineProperty;
|
|
669
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
670
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
671
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
672
|
-
var __defNormalProp$1 = (obj, key, value2) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key] = value2;
|
|
673
|
-
var __spreadValues$1 = (a, b) => {
|
|
674
|
-
for (var prop in b || (b = {}))
|
|
675
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
676
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
677
|
-
if (__getOwnPropSymbols$1)
|
|
678
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
679
|
-
if (__propIsEnum$1.call(b, prop))
|
|
680
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
681
|
-
}
|
|
682
|
-
return a;
|
|
683
|
-
};
|
|
684
|
-
var __objRest$1 = (source, exclude) => {
|
|
685
|
-
var target = {};
|
|
686
|
-
for (var prop in source)
|
|
687
|
-
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
688
|
-
target[prop] = source[prop];
|
|
689
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
690
|
-
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
691
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
692
|
-
target[prop] = source[prop];
|
|
693
|
-
}
|
|
694
|
-
return target;
|
|
695
|
-
};
|
|
696
|
-
const Globe = React.forwardRef(
|
|
697
|
-
(_a, ref) => {
|
|
698
|
-
var _b = _a, { color = "currentColor" } = _b, props = __objRest$1(_b, ["color"]);
|
|
699
|
-
return /* @__PURE__ */ React.createElement(
|
|
700
|
-
"svg",
|
|
701
|
-
__spreadValues$1({
|
|
702
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
703
|
-
width: 15,
|
|
704
|
-
height: 15,
|
|
705
|
-
viewBox: "0 0 15 15",
|
|
706
|
-
fill: "none",
|
|
707
|
-
ref
|
|
708
|
-
}, props),
|
|
709
|
-
/* @__PURE__ */ React.createElement(
|
|
710
|
-
"path",
|
|
711
|
-
{
|
|
712
|
-
stroke: color,
|
|
713
|
-
strokeLinecap: "round",
|
|
714
|
-
strokeLinejoin: "round",
|
|
715
|
-
strokeWidth: 1.5,
|
|
716
|
-
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"
|
|
717
|
-
}
|
|
718
|
-
),
|
|
719
|
-
/* @__PURE__ */ React.createElement(
|
|
720
|
-
"path",
|
|
721
|
-
{
|
|
722
|
-
stroke: color,
|
|
723
|
-
strokeLinecap: "round",
|
|
724
|
-
strokeLinejoin: "round",
|
|
725
|
-
strokeWidth: 1.5,
|
|
726
|
-
d: "M7.5 13.945a6.444 6.444 0 1 0 0-12.89 6.444 6.444 0 0 0 0 12.89"
|
|
727
|
-
}
|
|
728
|
-
)
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
);
|
|
732
|
-
Globe.displayName = "Globe";
|
|
733
666
|
var __defProp = Object.defineProperty;
|
|
734
667
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
735
668
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -758,7 +691,7 @@ var __objRest = (source, exclude) => {
|
|
|
758
691
|
}
|
|
759
692
|
return target;
|
|
760
693
|
};
|
|
761
|
-
const
|
|
694
|
+
const Tag = React.forwardRef(
|
|
762
695
|
(_a, ref) => {
|
|
763
696
|
var _b = _a, { color = "currentColor" } = _b, props = __objRest(_b, ["color"]);
|
|
764
697
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -771,56 +704,73 @@ const SquaresPlus = React.forwardRef(
|
|
|
771
704
|
fill: "none",
|
|
772
705
|
ref
|
|
773
706
|
}, props),
|
|
774
|
-
/* @__PURE__ */ React.createElement(
|
|
707
|
+
/* @__PURE__ */ React.createElement("g", { clipPath: "url(#a)" }, /* @__PURE__ */ React.createElement(
|
|
775
708
|
"path",
|
|
776
709
|
{
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
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"
|
|
710
|
+
fill: color,
|
|
711
|
+
fillRule: "evenodd",
|
|
712
|
+
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",
|
|
713
|
+
clipRule: "evenodd"
|
|
782
714
|
}
|
|
783
|
-
)
|
|
715
|
+
)),
|
|
716
|
+
/* @__PURE__ */ React.createElement("defs", null, /* @__PURE__ */ React.createElement("clipPath", { id: "a" }, /* @__PURE__ */ React.createElement("path", { fill: "#fff", d: "M0 0h15v15H0z" })))
|
|
784
717
|
);
|
|
785
718
|
}
|
|
786
719
|
);
|
|
787
|
-
|
|
788
|
-
const emptyForm
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
720
|
+
Tag.displayName = "Tag";
|
|
721
|
+
const emptyForm = () => ({ label: "", type: "text", unit: "", description: "" });
|
|
722
|
+
const ProductAttributesSettingsPage = () => {
|
|
723
|
+
const t = useT();
|
|
724
|
+
const [tab, setTab] = useState("globals");
|
|
725
|
+
return /* @__PURE__ */ jsxs(Container, { className: "p-0", children: [
|
|
726
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 border-b border-ui-border-base px-6 pt-4", children: [
|
|
727
|
+
/* @__PURE__ */ jsx(TabButton, { active: tab === "globals", onClick: () => setTab("globals"), children: t("globals") }),
|
|
728
|
+
/* @__PURE__ */ jsx(TabButton, { active: tab === "templates", onClick: () => setTab("templates"), children: t("templates") })
|
|
729
|
+
] }),
|
|
730
|
+
tab === "globals" ? /* @__PURE__ */ jsx(GlobalsTab, {}) : /* @__PURE__ */ jsx(TemplatesTab, {})
|
|
731
|
+
] });
|
|
732
|
+
};
|
|
733
|
+
const TabButton = ({
|
|
734
|
+
active,
|
|
735
|
+
onClick,
|
|
736
|
+
children
|
|
737
|
+
}) => /* @__PURE__ */ jsx(
|
|
738
|
+
"button",
|
|
739
|
+
{
|
|
740
|
+
onClick,
|
|
741
|
+
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"}`,
|
|
742
|
+
children
|
|
743
|
+
}
|
|
744
|
+
);
|
|
745
|
+
const GlobalsTab = () => {
|
|
746
|
+
const t = useT();
|
|
796
747
|
const qc = useQueryClient();
|
|
797
|
-
const queryKey = ["
|
|
748
|
+
const queryKey = ["global-attributes"];
|
|
798
749
|
const [showAddForm, setShowAddForm] = useState(false);
|
|
799
|
-
const [addForm, setAddForm] = useState(emptyForm
|
|
750
|
+
const [addForm, setAddForm] = useState(emptyForm());
|
|
800
751
|
const [confirmDeleteId, setConfirmDeleteId] = useState(null);
|
|
801
752
|
const { data, isLoading, isError } = useQuery({
|
|
802
753
|
queryKey,
|
|
803
|
-
queryFn: () => sdk.client.fetch(`/admin/
|
|
754
|
+
queryFn: () => sdk.client.fetch(`/admin/global-attributes`)
|
|
804
755
|
});
|
|
805
|
-
const
|
|
756
|
+
const attrs = (data == null ? void 0 : data.global_attributes) ?? [];
|
|
806
757
|
const createMutation = useMutation({
|
|
807
|
-
mutationFn: (body) => sdk.client.fetch(`/admin/
|
|
758
|
+
mutationFn: (body) => sdk.client.fetch(`/admin/global-attributes`, {
|
|
808
759
|
method: "POST",
|
|
809
760
|
body: {
|
|
810
761
|
label: body.label,
|
|
811
762
|
type: body.type,
|
|
812
|
-
unit: body.type === "number" && body.unit ? body.unit : null
|
|
813
|
-
description: body.description || null
|
|
763
|
+
unit: body.type === "number" && body.unit ? body.unit : null
|
|
814
764
|
}
|
|
815
765
|
}),
|
|
816
766
|
onSuccess: () => {
|
|
817
767
|
qc.invalidateQueries({ queryKey });
|
|
818
768
|
setShowAddForm(false);
|
|
819
|
-
setAddForm(emptyForm
|
|
769
|
+
setAddForm(emptyForm());
|
|
820
770
|
}
|
|
821
771
|
});
|
|
822
772
|
const deleteMutation = useMutation({
|
|
823
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/
|
|
773
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/global-attributes`, {
|
|
824
774
|
method: "PATCH",
|
|
825
775
|
body: { id, deleted_at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
826
776
|
}),
|
|
@@ -838,86 +788,57 @@ const AttributeTemplatesSettingsPage = () => {
|
|
|
838
788
|
description: addForm.description.trim()
|
|
839
789
|
});
|
|
840
790
|
};
|
|
841
|
-
return /* @__PURE__ */ jsxs(
|
|
842
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-
|
|
791
|
+
return /* @__PURE__ */ jsxs("div", { className: "divide-y", children: [
|
|
792
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between px-6 py-4", children: [
|
|
843
793
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
844
|
-
/* @__PURE__ */ jsx(Heading, { level: "
|
|
845
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "
|
|
794
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: t("globals") }),
|
|
795
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: t("globalsDesc") })
|
|
846
796
|
] }),
|
|
847
|
-
!showAddForm && /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: "
|
|
797
|
+
!showAddForm && /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: t("add") })
|
|
848
798
|
] }),
|
|
849
|
-
isLoading && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "
|
|
850
|
-
isError && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error text-sm", children: "
|
|
851
|
-
!isLoading && !isError &&
|
|
852
|
-
/* @__PURE__ */ jsx("div", { className: "divide-y", children:
|
|
853
|
-
(
|
|
854
|
-
/* @__PURE__ */
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
/* @__PURE__ */
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
863
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
864
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: p.label }),
|
|
865
|
-
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
866
|
-
typeLabel$1(p.type),
|
|
867
|
-
p.unit ? `, ${p.unit}` : ""
|
|
868
|
-
] })
|
|
869
|
-
] }),
|
|
870
|
-
p.description && /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-subtle", children: p.description })
|
|
799
|
+
isLoading && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: t("loading") }) }),
|
|
800
|
+
isError && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error text-sm", children: t("loadFailed") }) }),
|
|
801
|
+
!isLoading && !isError && attrs.length === 0 && !showAddForm && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: t("noGlobals") }) }),
|
|
802
|
+
/* @__PURE__ */ jsx("div", { className: "divide-y", children: attrs.map(
|
|
803
|
+
(a) => confirmDeleteId === a.id ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-6 py-3 text-sm", children: [
|
|
804
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: t("confirmDelete").replace("{name}", a.label) }),
|
|
805
|
+
/* @__PURE__ */ jsx(Button, { size: "small", variant: "danger", onClick: () => deleteMutation.mutate(a.id), isLoading: deleteMutation.isPending, children: t("delete") }),
|
|
806
|
+
/* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", onClick: () => setConfirmDeleteId(null), children: t("cancel") })
|
|
807
|
+
] }, a.id) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-6 py-3", children: [
|
|
808
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm", children: a.label }),
|
|
809
|
+
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
810
|
+
t(`type.${a.type}`, a.type),
|
|
811
|
+
a.unit ? `, ${a.unit}` : ""
|
|
871
812
|
] }),
|
|
872
|
-
/* @__PURE__ */ jsx("button", { onClick: () => setConfirmDeleteId(
|
|
873
|
-
] },
|
|
813
|
+
/* @__PURE__ */ jsx("button", { onClick: () => setConfirmDeleteId(a.id), className: "text-xs text-ui-fg-error hover:underline", children: t("delete") })
|
|
814
|
+
] }, a.id)
|
|
874
815
|
) }),
|
|
875
|
-
showAddForm && /* @__PURE__ */
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
/* @__PURE__ */ jsx("option", { value: "text", children: "Текст" }),
|
|
880
|
-
/* @__PURE__ */ jsx("option", { value: "number", children: "Число" }),
|
|
881
|
-
/* @__PURE__ */ jsx("option", { value: "file", children: "Файл" }),
|
|
882
|
-
/* @__PURE__ */ jsx("option", { value: "boolean", children: "Да/Нет" })
|
|
883
|
-
] }),
|
|
884
|
-
addForm.type === "number" && /* @__PURE__ */ jsx(Input, { value: addForm.unit, onChange: (e) => setAddForm((f) => ({ ...f, unit: e.target.value })), placeholder: "ед.", className: "w-28 h-8 text-sm" })
|
|
885
|
-
] }),
|
|
886
|
-
/* @__PURE__ */ jsx(Input, { value: addForm.description, onChange: (e) => setAddForm((f) => ({ ...f, description: e.target.value })), placeholder: "Описание (необязательно)", className: "h-8 text-sm" }),
|
|
887
|
-
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
888
|
-
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => {
|
|
889
|
-
setShowAddForm(false);
|
|
890
|
-
setAddForm(emptyForm$1());
|
|
891
|
-
}, children: "Отмена" }),
|
|
892
|
-
/* @__PURE__ */ jsx(Button, { size: "small", onClick: handleAdd, isLoading: createMutation.isPending, children: "Создать" })
|
|
893
|
-
] })
|
|
894
|
-
] })
|
|
816
|
+
showAddForm && /* @__PURE__ */ jsx(AddForm, { t, form: addForm, setForm: setAddForm, onCancel: () => {
|
|
817
|
+
setShowAddForm(false);
|
|
818
|
+
setAddForm(emptyForm());
|
|
819
|
+
}, onSubmit: handleAdd, isLoading: createMutation.isPending, withDescription: false })
|
|
895
820
|
] });
|
|
896
821
|
};
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
icon: SquaresPlus
|
|
900
|
-
});
|
|
901
|
-
const emptyForm = () => ({ label: "", type: "text", unit: "" });
|
|
902
|
-
const typeLabel = (t) => t === "text" ? "Текст" : t === "number" ? "Число" : t === "file" ? "Файл" : t === "boolean" ? "Да/Нет" : t;
|
|
903
|
-
const GlobalAttributesSettingsPage = () => {
|
|
822
|
+
const TemplatesTab = () => {
|
|
823
|
+
const t = useT();
|
|
904
824
|
const qc = useQueryClient();
|
|
905
|
-
const queryKey = ["
|
|
825
|
+
const queryKey = ["attribute-templates"];
|
|
906
826
|
const [showAddForm, setShowAddForm] = useState(false);
|
|
907
827
|
const [addForm, setAddForm] = useState(emptyForm());
|
|
908
828
|
const [confirmDeleteId, setConfirmDeleteId] = useState(null);
|
|
909
829
|
const { data, isLoading, isError } = useQuery({
|
|
910
830
|
queryKey,
|
|
911
|
-
queryFn: () => sdk.client.fetch(`/admin/
|
|
831
|
+
queryFn: () => sdk.client.fetch(`/admin/attribute-templates`)
|
|
912
832
|
});
|
|
913
|
-
const
|
|
833
|
+
const templates2 = (data == null ? void 0 : data.attribute_templates) ?? [];
|
|
914
834
|
const createMutation = useMutation({
|
|
915
|
-
mutationFn: (body) => sdk.client.fetch(`/admin/
|
|
835
|
+
mutationFn: (body) => sdk.client.fetch(`/admin/attribute-templates`, {
|
|
916
836
|
method: "POST",
|
|
917
837
|
body: {
|
|
918
838
|
label: body.label,
|
|
919
839
|
type: body.type,
|
|
920
|
-
unit: body.type === "number" && body.unit ? body.unit : null
|
|
840
|
+
unit: body.type === "number" && body.unit ? body.unit : null,
|
|
841
|
+
description: body.description || null
|
|
921
842
|
}
|
|
922
843
|
}),
|
|
923
844
|
onSuccess: () => {
|
|
@@ -927,7 +848,7 @@ const GlobalAttributesSettingsPage = () => {
|
|
|
927
848
|
}
|
|
928
849
|
});
|
|
929
850
|
const deleteMutation = useMutation({
|
|
930
|
-
mutationFn: (id) => sdk.client.fetch(`/admin/
|
|
851
|
+
mutationFn: (id) => sdk.client.fetch(`/admin/attribute-templates`, {
|
|
931
852
|
method: "PATCH",
|
|
932
853
|
body: { id, deleted_at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
933
854
|
}),
|
|
@@ -939,60 +860,113 @@ const GlobalAttributesSettingsPage = () => {
|
|
|
939
860
|
const handleAdd = () => {
|
|
940
861
|
if (!addForm.label.trim()) return;
|
|
941
862
|
createMutation.mutate({
|
|
863
|
+
...addForm,
|
|
942
864
|
label: addForm.label.trim(),
|
|
943
|
-
|
|
944
|
-
|
|
865
|
+
unit: addForm.unit.trim(),
|
|
866
|
+
description: addForm.description.trim()
|
|
945
867
|
});
|
|
946
868
|
};
|
|
947
|
-
return /* @__PURE__ */ jsxs(
|
|
948
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-
|
|
869
|
+
return /* @__PURE__ */ jsxs("div", { className: "divide-y", children: [
|
|
870
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between px-6 py-4", children: [
|
|
949
871
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
950
|
-
/* @__PURE__ */ jsx(Heading, { level: "
|
|
951
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "
|
|
872
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: t("templates") }),
|
|
873
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: t("templatesDesc") })
|
|
952
874
|
] }),
|
|
953
|
-
!showAddForm && /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: "
|
|
875
|
+
!showAddForm && /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => setShowAddForm(true), children: t("add") })
|
|
954
876
|
] }),
|
|
955
|
-
isLoading && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "
|
|
956
|
-
isError && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error text-sm", children: "
|
|
957
|
-
!isLoading && !isError &&
|
|
958
|
-
/* @__PURE__ */ jsx("div", { className: "divide-y", children:
|
|
959
|
-
(
|
|
960
|
-
/* @__PURE__ */
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
877
|
+
isLoading && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: t("loading") }) }),
|
|
878
|
+
isError && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error text-sm", children: t("loadFailed") }) }),
|
|
879
|
+
!isLoading && !isError && templates2.length === 0 && !showAddForm && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: t("noTemplates") }) }),
|
|
880
|
+
/* @__PURE__ */ jsx("div", { className: "divide-y", children: templates2.map(
|
|
881
|
+
(p) => confirmDeleteId === p.id ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-6 py-3 text-sm", children: [
|
|
882
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: t("confirmDelete").replace("{name}", p.label) }),
|
|
883
|
+
/* @__PURE__ */ jsx(Button, { size: "small", variant: "danger", onClick: () => deleteMutation.mutate(p.id), isLoading: deleteMutation.isPending, children: t("delete") }),
|
|
884
|
+
/* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", onClick: () => setConfirmDeleteId(null), children: t("cancel") })
|
|
885
|
+
] }, p.id) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-6 py-3", children: [
|
|
886
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
887
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
888
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: p.label }),
|
|
889
|
+
/* @__PURE__ */ jsxs(Badge, { size: "2xsmall", color: "grey", children: [
|
|
890
|
+
t(`type.${p.type}`, p.type),
|
|
891
|
+
p.unit ? `, ${p.unit}` : ""
|
|
892
|
+
] })
|
|
893
|
+
] }),
|
|
894
|
+
p.description && /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-subtle", children: p.description })
|
|
972
895
|
] }),
|
|
973
|
-
/* @__PURE__ */ jsx("button", { onClick: () => setConfirmDeleteId(
|
|
974
|
-
] },
|
|
896
|
+
/* @__PURE__ */ jsx("button", { onClick: () => setConfirmDeleteId(p.id), className: "text-xs text-ui-fg-error hover:underline", children: t("delete") })
|
|
897
|
+
] }, p.id)
|
|
975
898
|
) }),
|
|
976
|
-
showAddForm && /* @__PURE__ */
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
/* @__PURE__ */ jsx("option", { value: "number", children: "Число" }),
|
|
981
|
-
/* @__PURE__ */ jsx("option", { value: "file", children: "Файл" }),
|
|
982
|
-
/* @__PURE__ */ jsx("option", { value: "boolean", children: "Да/Нет" })
|
|
983
|
-
] }),
|
|
984
|
-
addForm.type === "number" && /* @__PURE__ */ jsx(Input, { value: addForm.unit, onChange: (e) => setAddForm((f) => ({ ...f, unit: e.target.value })), placeholder: "ед.", className: "w-28 h-8 text-sm" }),
|
|
985
|
-
/* @__PURE__ */ jsx(Button, { size: "small", onClick: handleAdd, isLoading: createMutation.isPending, children: "Создать" }),
|
|
986
|
-
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: () => {
|
|
987
|
-
setShowAddForm(false);
|
|
988
|
-
setAddForm(emptyForm());
|
|
989
|
-
}, children: "Отмена" })
|
|
990
|
-
] })
|
|
899
|
+
showAddForm && /* @__PURE__ */ jsx(AddForm, { t, form: addForm, setForm: setAddForm, onCancel: () => {
|
|
900
|
+
setShowAddForm(false);
|
|
901
|
+
setAddForm(emptyForm());
|
|
902
|
+
}, onSubmit: handleAdd, isLoading: createMutation.isPending, withDescription: true })
|
|
991
903
|
] });
|
|
992
904
|
};
|
|
905
|
+
const AddForm = ({
|
|
906
|
+
t,
|
|
907
|
+
form,
|
|
908
|
+
setForm,
|
|
909
|
+
onCancel,
|
|
910
|
+
onSubmit,
|
|
911
|
+
isLoading,
|
|
912
|
+
withDescription
|
|
913
|
+
}) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 px-6 py-4", children: [
|
|
914
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
915
|
+
/* @__PURE__ */ jsx(
|
|
916
|
+
Input,
|
|
917
|
+
{
|
|
918
|
+
value: form.label,
|
|
919
|
+
onChange: (e) => setForm((f) => ({ ...f, label: e.target.value })),
|
|
920
|
+
placeholder: t("name"),
|
|
921
|
+
className: "flex-1 h-8 text-sm",
|
|
922
|
+
autoFocus: true
|
|
923
|
+
}
|
|
924
|
+
),
|
|
925
|
+
/* @__PURE__ */ jsxs(
|
|
926
|
+
"select",
|
|
927
|
+
{
|
|
928
|
+
value: form.type,
|
|
929
|
+
onChange: (e) => setForm((f) => ({
|
|
930
|
+
...f,
|
|
931
|
+
type: e.target.value,
|
|
932
|
+
unit: e.target.value === "number" ? f.unit : ""
|
|
933
|
+
})),
|
|
934
|
+
className: "h-8 rounded border border-ui-border-base bg-ui-bg-base px-2 text-sm",
|
|
935
|
+
children: [
|
|
936
|
+
/* @__PURE__ */ jsx("option", { value: "text", children: t("type.text") }),
|
|
937
|
+
/* @__PURE__ */ jsx("option", { value: "number", children: t("type.number") }),
|
|
938
|
+
/* @__PURE__ */ jsx("option", { value: "file", children: t("type.file") }),
|
|
939
|
+
/* @__PURE__ */ jsx("option", { value: "boolean", children: t("type.boolean") })
|
|
940
|
+
]
|
|
941
|
+
}
|
|
942
|
+
),
|
|
943
|
+
form.type === "number" && /* @__PURE__ */ jsx(
|
|
944
|
+
Input,
|
|
945
|
+
{
|
|
946
|
+
value: form.unit,
|
|
947
|
+
onChange: (e) => setForm((f) => ({ ...f, unit: e.target.value })),
|
|
948
|
+
placeholder: t("unit"),
|
|
949
|
+
className: "w-28 h-8 text-sm"
|
|
950
|
+
}
|
|
951
|
+
)
|
|
952
|
+
] }),
|
|
953
|
+
withDescription && /* @__PURE__ */ jsx(
|
|
954
|
+
Input,
|
|
955
|
+
{
|
|
956
|
+
value: form.description,
|
|
957
|
+
onChange: (e) => setForm((f) => ({ ...f, description: e.target.value })),
|
|
958
|
+
placeholder: t("description"),
|
|
959
|
+
className: "h-8 text-sm"
|
|
960
|
+
}
|
|
961
|
+
),
|
|
962
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
963
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", onClick: onCancel, children: t("cancel") }),
|
|
964
|
+
/* @__PURE__ */ jsx(Button, { size: "small", onClick: onSubmit, isLoading, children: t("create") })
|
|
965
|
+
] })
|
|
966
|
+
] });
|
|
993
967
|
const config = defineRouteConfig({
|
|
994
|
-
label: "
|
|
995
|
-
icon:
|
|
968
|
+
label: "Product Attributes",
|
|
969
|
+
icon: Tag
|
|
996
970
|
});
|
|
997
971
|
const widgetModule = { widgets: [
|
|
998
972
|
{
|
|
@@ -1007,29 +981,17 @@ const widgetModule = { widgets: [
|
|
|
1007
981
|
const routeModule = {
|
|
1008
982
|
routes: [
|
|
1009
983
|
{
|
|
1010
|
-
Component:
|
|
1011
|
-
path: "/settings/
|
|
1012
|
-
},
|
|
1013
|
-
{
|
|
1014
|
-
Component: GlobalAttributesSettingsPage,
|
|
1015
|
-
path: "/settings/global-attributes"
|
|
984
|
+
Component: ProductAttributesSettingsPage,
|
|
985
|
+
path: "/settings/product-attributes"
|
|
1016
986
|
}
|
|
1017
987
|
]
|
|
1018
988
|
};
|
|
1019
989
|
const menuItemModule = {
|
|
1020
990
|
menuItems: [
|
|
1021
|
-
{
|
|
1022
|
-
label: config$1.label,
|
|
1023
|
-
icon: config$1.icon,
|
|
1024
|
-
path: "/settings/attribute-templates",
|
|
1025
|
-
nested: void 0,
|
|
1026
|
-
rank: void 0,
|
|
1027
|
-
translationNs: void 0
|
|
1028
|
-
},
|
|
1029
991
|
{
|
|
1030
992
|
label: config.label,
|
|
1031
993
|
icon: config.icon,
|
|
1032
|
-
path: "/settings/
|
|
994
|
+
path: "/settings/product-attributes",
|
|
1033
995
|
nested: void 0,
|
|
1034
996
|
rank: void 0,
|
|
1035
997
|
translationNs: void 0
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empty-complete-org/medusa-product-attributes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Custom attributes module for Medusa v2 with support for text, number, file types and units of measurement",
|
|
5
5
|
"author": "empty-complete",
|
|
6
6
|
"license": "MIT",
|