diff --git a/src/api/auth.js b/src/api/auth.js index fa359f604..271b03a5d 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -1,15 +1,21 @@ import { IncidentCommander } from "./axios"; import { resolve } from "./resolve"; +// eslint-disable-next-line import/no-mutable-exports export let User = null; -export const getUser = async () => - resolve( +export const getUser = async () => { + if (User != null) { + return User; + } + return resolve( IncidentCommander.get(`/person?limit=1`).then((res) => { - console.log("user", res.data[0]); - return res.data[0]; + // eslint-disable-next-line prefer-destructuring + User = res.data[0]; + return User; }) ); +}; getUser().then((user) => { User = user; diff --git a/src/api/services/comments.js b/src/api/services/comments.js index 9a00c3cd3..b1025dae2 100644 --- a/src/api/services/comments.js +++ b/src/api/services/comments.js @@ -1,10 +1,10 @@ -import { getUserID } from "../auth"; -import { apiRequestIC } from "../axios"; +import { User } from "../auth"; +import { IncidentCommander } from "../axios"; import { resolve } from "../resolve"; export const getCommentsByHypothesis = async (hypothesisId) => resolve( - apiRequestIC.get( + IncidentCommander.get( `/comment?select=*,created_by(name)&hypothesis_id=eq.${hypothesisId}` ) ); @@ -17,9 +17,9 @@ export const createComment = async ( params ) => resolve( - apiRequestIC.post(`/comment`, { + IncidentCommander.post(`/comment`, { id: commentId, - created_by: getUserID(), + created_by: User.id, incident_id: incidentId, hypothesis_id: hypothesisId, comment, diff --git a/src/components/HypothesisBuilder/components/HypothesisDetails/index.js b/src/components/HypothesisBuilder/components/HypothesisDetails/index.js index 9072e0233..5c4e27a04 100644 --- a/src/components/HypothesisBuilder/components/HypothesisDetails/index.js +++ b/src/components/HypothesisBuilder/components/HypothesisDetails/index.js @@ -50,8 +50,8 @@ export function HypothesisDetails({ nodePath, tree, setTree, api, ...rest }) { const fetchComments = (id) => getCommentsByHypothesis(id) - .then((data) => { - setComments(data?.data?.data || []); + .then((comments) => { + setComments(comments?.data || []); }) .catch((err) => console.error(err)); diff --git a/src/components/Incidents/IncidentList/index.js b/src/components/Incidents/IncidentList/index.js index 78004dedb..708718fce 100644 --- a/src/components/Incidents/IncidentList/index.js +++ b/src/components/Incidents/IncidentList/index.js @@ -15,7 +15,7 @@ export function IncidentList({ list, ...rest }) { function IncidentItem({ incident, ...rest }) { const { title, id, description, severity, status, type } = incident; return ( - +