Skip to content

Commit

Permalink
fix: comment data path
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jan 24, 2022
1 parent 79a26e6 commit 3cc82da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 10 additions & 4 deletions src/api/auth.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/api/services/comments.js
Original file line number Diff line number Diff line change
@@ -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}`
)
);
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/components/Incidents/IncidentList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function IncidentList({ list, ...rest }) {
function IncidentItem({ incident, ...rest }) {
const { title, id, description, severity, status, type } = incident;
return (
<Link to={`/incident/${id}`} {...rest}>
<Link to={`/incidents/${id}`} {...rest}>
<div className="px-6 py-3">
<div className="text-gray-800 font-semibold">{title}</div>
<div className="text-gray-400 text-sm">description: {description}</div>
Expand Down

0 comments on commit 3cc82da

Please sign in to comment.