Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | 4x 15x 14x 14x 14x 14x 14x 14x 14x 6x 14x 14x 5x 9x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 9x 9x 9x 1x 1x 1x 9x 1x 1x 1x 9x 2x 2x 9x 9x 1x 9x 9x | import React, { ReactElement, useEffect, useState } from 'react'; import { Message } from '@props/RecordProps'; import { Button, Modal, Space } from 'antd'; import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import { ExclamationCircleOutlined } from '@ant-design/icons'; import './App.less'; import { saveDomain } from '@utils/FetchUtils'; import { emptyMethod } from '@utils/Constants'; import { SaveDomainProps } from '@utils/FetchUtilsProps'; import { SERVER_URL } from '@config/base'; import { RedirectComponent } from '../redirect'; export interface ActionRequiredNotificationProps { messages: Array<Message>; zIndex: number; } const ActionRequiredNotification = (props: ActionRequiredNotificationProps): ReactElement => { const { messages, zIndex } = props; const [dismissedMessages, setDismissedMessages] = useState<number[]>([]); const [displayActionUrlMessageId, setDisplayActionUrlMessageId] = useState<number>(); const [displayModal, setDisplayModal] = useState<boolean>(true); const [currentMessageIndex, setCurrentMessageIndex] = useState<number>(0); const domainName = 'Message'; const message = messages[currentMessageIndex]; useEffect(() => { setDisplayModal(messages.length > 0); }, [messages]); const { t } = useTranslation(); if (messages.length === 0) { return (<></>); } const handleDismiss = (id: number): void => { markMessageAsRead(id).then(() => { setDismissedMessages([...dismissedMessages, id]); if (currentMessageIndex < messages.length - 1) { const nextIdx = currentMessageIndex + 1; setCurrentMessageIndex(nextIdx); } else E{ setDisplayModal(false); } }).catch((e: unknown) => console.error(`Failed to mark message ${id} as read: ${e}`)); }; const onHandle = (id: number): React.MouseEventHandler<HTMLElement> | undefined => { return () => { markMessageAsRead(id).then(() => { setDisplayActionUrlMessageId(id); if (currentMessageIndex < messages.length - 1) { const nextIdx = currentMessageIndex + 1; setCurrentMessageIndex(nextIdx); } else { setTimeout(() => { setDisplayModal(false); }, 1000); } }).catch((e: unknown) => console.error(`Failed to mark message ${message} as read: ${e}`)); }; }; const renderMessage = (message: Message): ReactElement => { return ( <> <ReactMarkdown linkTarget="_blank" > {message.content} </ReactMarkdown> {displayActionUrlMessageId === message.id && <RedirectComponent redirect={message.actionUrl ?? '/inbox'} forMultiple={false} fetchDataCallback={() => setDisplayActionUrlMessageId(undefined)} zIndex={zIndex + 3} showText={false} /> } </> ); }; const nextMessage = (): void => { Eif (currentMessageIndex < messages.length - 1) { const nextIdx = currentMessageIndex + 1; setCurrentMessageIndex(nextIdx); } }; const prevMessage = (): void => { Eif (currentMessageIndex > 0) { const nextIdx = currentMessageIndex - 1; setCurrentMessageIndex(nextIdx); } }; const markMessageAsRead = (id: number): Promise<unknown> => { const data: SaveDomainProps = { values: { id: id, isUnRead: false, }, domainName, method: "PUT", successCallback: emptyMethod, failCallback: (e: unknown) => console.log(`Failed to mark ${message} as readed: ${e}`), skipInfoNotification: true, url: `${SERVER_URL}/${domainName}/${message.id}` }; return saveDomain(data); }; const modalContent = ( <> {renderMessage(message)} </> ); const title = <> <Space style={{ fontSize: "120%" }}> <ExclamationCircleOutlined style={{ color: "orange", fontSize: "150%", }} /> {t('Immediately action required messages')} </Space> <Space className="handle-buttons"> <Button onClick={onHandle(message.id)} type="primary" > {t('Handle immediately')} </Button> <Button onClick={() => handleDismiss(message.id)} > {t('Handle later')} </Button> </Space> </>; const footer = <Space> <Button onClick={prevMessage} disabled={currentMessageIndex === 0} > {t('Previous')} </Button> <Button onClick={nextMessage} disabled={currentMessageIndex === messages.length - 1} > {t('Next')} </Button> </Space>; return ( <Modal className="action-required-notification-modal" open={displayModal} closeIcon={<></>} footer={footer} zIndex={zIndex + 3} width={800} title={title} > {modalContent} </Modal> ); }; export default ActionRequiredNotification; |