Skip to content

Commit

Permalink
Merge pull request #66 from notum-cz/bugfix/crashing-with-strapi-4.17.3
Browse files Browse the repository at this point in the history
fix: crashing with latest strapi
  • Loading branch information
omikulcik authored Jan 25, 2024
2 parents 97dc41d + 7daab07 commit dec072c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
27 changes: 14 additions & 13 deletions admin/src/components/EntityLock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import { io } from "socket.io-client";
import { Button, Typography } from "@strapi/design-system";
import { useIntl } from "react-intl";

import { request, auth } from "@strapi/helper-plugin";
import { useFetchClient, auth } from "@strapi/helper-plugin";
import { useRouteMatch, useHistory } from "react-router-dom";

import getTrad from "../../utils/getTrad";

export default function EntityLock() {
const collectionType = useRouteMatch(
"/content-manager/collectionType/:slug/:id"
"/content-manager/collection-types/:slug/:id"
);
const singleType = useRouteMatch("/content-manager/singleType/:slug");
const singleType = useRouteMatch("/content-manager/single-types/:slug");
const { get } = useFetchClient();

let params, statusUrl;
if (collectionType) {
Expand All @@ -37,21 +38,21 @@ export default function EntityLock() {

const [isLocked, setIsLocked] = useState(false);
const [username, setUsername] = useState("");
const [settings, setSettings] = useState(null)
const [settings, setSettings] = useState(null);

const socket = useRef({});

const { id: userId } = auth.getUserInfo();
const { id: userId } = auth.get("userInfo");
const lockingData = { entityId: id, entitySlug: slug, userId };

const attemptLocking = () => {
try {
request(statusUrl).then((response) => {
if (!response) {
get(statusUrl).then((response) => {
if (!response.data) {
socket.current?.emit("openEntity", lockingData);
} else {
setIsLocked(true);
setUsername(response.editedBy);
setUsername(response.data.editedBy);
}
});
} catch (error) {
Expand All @@ -60,10 +61,10 @@ export default function EntityLock() {
};

useEffect(() => {
request('/record-locking/settings/').then((response) => {
setSettings(response)
})
}, [])
get("/record-locking/settings/").then((response) => {
setSettings(response);
});
}, []);

useEffect(() => {
if (id !== "create" && settings) {
Expand All @@ -77,7 +78,7 @@ export default function EntityLock() {
JSON.parse(sessionStorage.getItem("jwtToken")),
});
},
transports: settings.transports
transports: settings.transports,
});
socket.current.io.on("reconnect", attemptLocking);

Expand Down
9 changes: 2 additions & 7 deletions server/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
const { Server } = require("socket.io")
const {DEFAULT_TRANSPORTS} = require("./constants/transports");
const { Server } = require("socket.io");

module.exports = ({ strapi }) => {
// bootstrap phase

const config = strapi.config.get('plugin.record-locking')

const io = new Server(strapi.server.httpServer, {
transports: config?.transports || DEFAULT_TRANSPORTS
});
const io = new Server(strapi.server.httpServer);

io.on("connection", function (socket) {
socket.on("openEntity", async ({ entitySlug, entityId }) => {
Expand Down

0 comments on commit dec072c

Please sign in to comment.