@nitrogenbuilder/connector-payload 0.1.15 → 0.1.17
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.
|
@@ -7,7 +7,7 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
7
7
|
const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
|
|
8
8
|
const [slug, setSlug] = useState(undefined);
|
|
9
9
|
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
10
|
-
const [
|
|
10
|
+
const [authorId, setAuthorId] = useState(undefined);
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const segments = window.location.pathname.split("/").filter(Boolean);
|
|
13
13
|
const docId = segments.length >= 4 ? segments[3] : undefined;
|
|
@@ -25,6 +25,17 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
25
25
|
console.error("Failed to fetch document:", err);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
// Fetch the current user's ID for the authorId param
|
|
29
|
+
fetch("/api/users/me")
|
|
30
|
+
.then((res) => res.json())
|
|
31
|
+
.then((data) => {
|
|
32
|
+
if (data.user?.id) {
|
|
33
|
+
setAuthorId(String(data.user.id));
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
console.error("Failed to fetch current user:", err);
|
|
38
|
+
});
|
|
28
39
|
// Fetch the connector token and URLs from NitrogenSettings global
|
|
29
40
|
fetch("/api/globals/nitrogen-settings")
|
|
30
41
|
.then((res) => res.json())
|
|
@@ -35,9 +46,6 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
35
46
|
if (data.developmentUrl) {
|
|
36
47
|
setHasDevelopmentUrl(true);
|
|
37
48
|
}
|
|
38
|
-
if (data.instanceUrl) {
|
|
39
|
-
setInstanceUrl(data.instanceUrl.replace(/\/$/, ""));
|
|
40
|
-
}
|
|
41
49
|
const url = data.frontendUrl;
|
|
42
50
|
if (url) {
|
|
43
51
|
setFrontendUrl(url.replace(/\/$/, ""));
|
|
@@ -47,11 +55,10 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
47
55
|
console.error("Failed to fetch nitrogen settings:", err);
|
|
48
56
|
});
|
|
49
57
|
}, [collection]);
|
|
50
|
-
if (!id || !token)
|
|
58
|
+
if (!id || !token || !authorId)
|
|
51
59
|
return null;
|
|
52
60
|
const param = collection === "nitrogen-templates" ? "templateId" : "pageId";
|
|
53
|
-
const
|
|
54
|
-
const baseHref = `${editorBase}/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}`;
|
|
61
|
+
const baseHref = `/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}&authorId=${encodeURIComponent(authorId)}`;
|
|
55
62
|
const buttonStyle = {
|
|
56
63
|
display: "inline-flex",
|
|
57
64
|
alignItems: "center",
|
package/package.json
CHANGED