diff --git a/myems-api/core/webmessage.py b/myems-api/core/webmessage.py index 9130d083..e701ad50 100644 --- a/myems-api/core/webmessage.py +++ b/myems-api/core/webmessage.py @@ -367,7 +367,7 @@ class WebMessageItem: if 'status' not in new_values['data'].keys() or \ not isinstance(new_values['data']['status'], str) or \ len(str.strip(new_values['data']['status'])) == 0 or \ - str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'timeout'): + str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'timeout', 'read'): raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STATUS') status = str.strip(new_values['data']['status']) diff --git a/web/src/components/MyEMS/Notification/Notification.js b/web/src/components/MyEMS/Notification/Notification.js index ca8223a8..a8451fb7 100644 --- a/web/src/components/MyEMS/Notification/Notification.js +++ b/web/src/components/MyEMS/Notification/Notification.js @@ -128,7 +128,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { const subjectFormatter = (dataField, { url }) => ( - {dataField} + {dataField} ); @@ -143,16 +143,16 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { let icon = ''; let text = ''; switch (status) { + case 'acknowledged': + color = 'success'; + icon = 'envelope-open'; + text = t('Notification Acknowledged'); + break; case 'read': color = 'success'; icon = 'envelope-open'; text = t('Notification Read'); break; - case 'unread': - color = 'primary'; - icon = 'envelope'; - text = t('Notification Unread'); - break; default: color = 'primary'; icon = 'envelope'; @@ -175,9 +175,9 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { handleRead(id)}>{t('Notification Mark As Read')} - console.log('Archive: ', id)}>{t('Notification Archive')} + handleAcknowledged(id)}>{t('Notification Mark As Acknowledged')} - console.log('Delete: ', id)} className="text-danger">{t('Notification Delete')} + handledelete(id)} className="text-danger">{t('Notification Delete')} ); @@ -260,7 +260,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }, body: JSON.stringify({ "data": { - "status": 'acknowledged', + "status": 'read', "reply": 'ok' } }), @@ -283,6 +283,71 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }); }; + const handleAcknowledged = (id, ) => { + console.log('Mark As Acknowledged: ', id) + let isResponseOK = false; + fetch(APIBaseURL + '/webmessages/' + id, { + method: 'PUT', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: JSON.stringify({ + "data": { + "status": 'acknowledged', + "reply": 'ok' + } + }), + }).then(response => { + if (response.ok) { + isResponseOK = true; + return null; + } else { + return response.json(); + } + }).then(json => { + console.log(isResponseOK); + if (isResponseOK) { + + } else { + toast.error(json.description) + } + }).catch(err => { + console.log(err); + }); + }; + + const handledelete = (id, ) => { + console.log('Delete: ', id) + let isResponseOK = false; + fetch(APIBaseURL + '/webmessages/' + id, { + method: 'DELETE', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + }).then(response => { + if (response.ok) { + isResponseOK = true; + return null; + } else { + return response.json(); + } + }).then(json => { + console.log(isResponseOK); + if (isResponseOK) { + + } else { + toast.error(json.description) + } + }).catch(err => { + console.log(err); + }); + }; + return ( @@ -294,7 +359,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { - +