Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

refactor: add empty component

robin2031b76ee552
diff --git a/ui/src/pages/Notifications/components/Achievements/index.tsx b/ui/src/pages/Notifications/components/Achievements/index.tsx
index 406cfbab..12cfe93b 100644
--- a/ui/src/pages/Notifications/components/Achievements/index.tsx
+++ b/ui/src/pages/Notifications/components/Achievements/index.tsx
@@ -2,6 +2,9 @@ import { ListGroup } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
+import { isEmpty } from 'lodash';
+
+import { Empty } from '@answer/components';
import './index.scss';
@@ -9,24 +12,33 @@ const Achievements = ({ data, handleReadNotification }) => {
if (!data) {
return null;
}
+ if (isEmpty(data)) {
+ return <Empty />;
+ }
return (
<ListGroup
className="border-top border-bottom achievement-wrap"
variant="flush">
{data.map((item) => {
+ const { comment, question, answer } =
+ item?.object_info?.object_map || {};
let url = '';
switch (item.object_info.object_type) {
case 'question':
url = `/questions/${item.object_info.object_id}`;
break;
case 'answer':
- url = `/questions/${item.object_info?.object_map?.question}/${item.object_info.object_id}`;
+ url = `/questions/${question}/${item.object_info.object_id}`;
+ break;
+ case 'comment':
+ url = `/questions/${question}/${answer}?commentId=${comment}`;
break;
default:
url = '';
}
return (
<ListGroup.Item
+ key={item.id}
className={classNames('d-flex', !item.is_read && 'warning')}>
{item.rank > 0 && (
<div className="text-success num text-end">{`+${item.rank}`}</div>
diff --git a/ui/src/pages/Notifications/components/Inbox/index.tsx b/ui/src/pages/Notifications/components/Inbox/index.tsx
index dd56c7cc..9f43c58d 100644
--- a/ui/src/pages/Notifications/components/Inbox/index.tsx
+++ b/ui/src/pages/Notifications/components/Inbox/index.tsx
@@ -2,17 +2,22 @@ import { ListGroup } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
+import { isEmpty } from 'lodash';
-import { FormatTime } from '@answer/components';
+import { FormatTime, Empty } from '@answer/components';
const Inbox = ({ data, handleReadNotification }) => {
if (!data) {
return null;
}
+ if (isEmpty(data)) {
+ return <Empty />;
+ }
return (
<ListGroup className="border-top border-bottom" variant="flush">
{data.map((item) => {
- const { comment, question, answer } = item.object_info.object_map;
+ const { comment, question, answer } =
+ item?.object_info?.object_map || {};
let url = '';
switch (item.object_info.object_type) {
case 'question':
diff --git a/ui/src/pages/Notifications/index.tsx b/ui/src/pages/Notifications/index.tsx
index 4350c44e..7ae123df 100644
--- a/ui/src/pages/Notifications/index.tsx
+++ b/ui/src/pages/Notifications/index.tsx
@@ -9,12 +9,11 @@ import {
clearNotificationRedDot,
readNotification,
} from '@answer/services/notification.api';
+import { PageTitle } from '@answer/components';
import Inbox from './components/Inbox';
import Achievements from './components/Achievements';
-import { PageTitle } from '@/components';
-
const PAGE_SIZE = 10;
const Notifications = () => {