require('./notificationLookup.less'); const React = require('react'); const { useState } = require('react'); const request = require('superagent'); const Moment = require('moment'); const NotificationDetail = ({ notification, onDelete })=>( <>
Key
{notification.dismissKey}
Title
{notification.title || 'No Title'}
Text
{notification.text || 'No Text'}
Created
{Moment(notification.createdAt).format('LLLL')}
Start
{Moment(notification.startAt).format('LLLL') || 'No Start Time'}
Stop
{Moment(notification.stopAt).format('LLLL') || 'No End Time'}
); const NotificationLookup = ()=>{ const [searching, setSearching] = useState(false); const [error, setError] = useState(null); const [notifications, setNotifications] = useState([]); const lookupAll = async ()=>{ setSearching(true); setError(null); try { const res = await request.get('/admin/notification/all'); setNotifications(res.body || []); } catch (err) { console.log(err); setError(`Error looking up notifications: ${err.response.body.message}`); } finally { setSearching(false); } }; const deleteNotification = async (dismissKey)=>{ if(!dismissKey) return; const confirmed = window.confirm( `Really delete notification ${dismissKey}?` ); if(!confirmed) { console.log('Delete notification cancelled'); return; } console.log('Delete notification confirm'); try { await request.delete(`/admin/notification/delete/${dismissKey}`); lookupAll(); } catch (err) { console.log(err); setError(`Error deleting notification: ${err.response.body.message}`); }; }; const renderNotificationsList = ()=>{ if(error) return
{error}
; if(notifications.length === 0) return
No notifications available.
; return ( ); }; return (

Check all Notifications

{renderNotificationsList()}
); }; module.exports = NotificationLookup;