From 9134a44a711205a95b870e51eb0e0544d37bd3a2 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Thu, 16 Aug 2018 10:35:55 +0200 Subject: [PATCH] check comment owner by username --- frontend/src/actions/login/authActions.js | 1 + frontend/src/actions/orders/processActions.js | 3 +-- .../containers/orders/components/OrderComments.jsx | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/actions/login/authActions.js b/frontend/src/actions/login/authActions.js index b1b9881..55e2b4d 100644 --- a/frontend/src/actions/login/authActions.js +++ b/frontend/src/actions/login/authActions.js @@ -118,6 +118,7 @@ export const validateCredentials = (username, password) => { // if(decodedAceessToken.data.wiaas_user_type === 'customer'){ localStorage.setItem('accessToken', response.data.token); + localStorage.setItem('username', username); const serverTime = decodedAceessToken.nbf || 1; // refreshToken = response.data.refreshToken; startRefreshTimer(dispatch, serverTime); diff --git a/frontend/src/actions/orders/processActions.js b/frontend/src/actions/orders/processActions.js index 808c40c..e45d409 100644 --- a/frontend/src/actions/orders/processActions.js +++ b/frontend/src/actions/orders/processActions.js @@ -69,8 +69,7 @@ export const addComment = (idOrder, newComment, existingComments) => { const newCommentObject = { comment : newComment, date : moment().format("Do MMM, YY"), - username: 'username', - isOwner: 1, + username: localStorage.getItem('username') || '-', } const concatenatedComments = (existingComments) ? existingComments.concat(newCommentObject) : [newCommentObject]; diff --git a/frontend/src/containers/orders/components/OrderComments.jsx b/frontend/src/containers/orders/components/OrderComments.jsx index c30bcaa..9717e42 100644 --- a/frontend/src/containers/orders/components/OrderComments.jsx +++ b/frontend/src/containers/orders/components/OrderComments.jsx @@ -25,12 +25,12 @@ class OrderComments extends Component { this.setState({newComment}); } - getOffset(isOwner){ - return isOwner ? 6 : 0; + getOffset(username){ + return (username === localStorage.getItem('username')) ? 6 : 0; } - getClassByOwner(isOwner){ - return isOwner ? 'mine' : ''; + getClassByOwner(username){ + return (username === localStorage.getItem('username')) ? 'mine' : ''; } render() { @@ -46,8 +46,8 @@ class OrderComments extends Component { orderComments && orderComments.map((orderComment, index) => - -
+ +
{orderComment.username} - {orderComment.date}