diff --git a/src/components/Dashboard/DashboardDocumentList/DashboardDocumentList.js b/src/components/Dashboard/DashboardDocumentList/DashboardDocumentList.js
index 71748ce9..22648376 100644
--- a/src/components/Dashboard/DashboardDocumentList/DashboardDocumentList.js
+++ b/src/components/Dashboard/DashboardDocumentList/DashboardDocumentList.js
@@ -2,12 +2,13 @@
import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import {
- Badge, Button, Card, Col, ListGroup, Row, Tab, Tabs,
+ Badge, Button, Card, Col, ListGroup, OverlayTrigger, Row, Tab, Tabs, Tooltip,
} from 'react-bootstrap';
+import { Plus } from 'react-bootstrap-icons';
import { format } from 'date-fns';
import LoadingSpinner from '../../LoadingSpinner';
import { getSharedDocumentsByGroup, getDocumentsByUser } from '../../../utils/docUtil';
-import { getGroupNameById } from '../../../utils/groupUtil';
+import { getGroupNameById, filterGroupIdsByUser } from '../../../utils/groupUtil';
const DashboardDocumentList = ({
session,
@@ -70,73 +71,109 @@ const DashboardDocumentList = ({
}, [documents, documentGroupState]);
return (
-
-
- Documents
- {
- setKey(k);
- }}
- >
-
-
-
-
- {listLoading && (
-
- )}
- {!listLoading && documents && documents.length > 0 && (
-
- {documents.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)).map(
- (document) => (
-
-
-
- {document.title}
-
-
- {document.groups && document.groups.length > 0 && (
-
- {documentGroupState[document.groups.sort()[0]]}
-
- )}
- <>
- {format(new Date(document.createdAt), 'MM/dd/yyyy')}
- >
-
-
-
- ),
+ <>
+
+
+ Documents
+ {
+ setKey(k);
+ }}
+ >
+
+
+
+
+ {listLoading && (
+
)}
-
-
- {`See all ${key === 'shared' ? key : 'created'} documents...`}
-
-
-
- )}
- {!listLoading && documents && documents.length === 0 && (
-
- {`You have no ${key === 'shared' ? key : 'created'} documents.`}
-
- )}
-
-
-
-
+ {!listLoading && documents && documents.length > 0 && (
+
+ {documents.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)).map(
+ (document) => (
+
+
+
+ {document.title}
+
+
+ {session && session.user.groups && document.groups
+ && filterGroupIdsByUser(document.groups, session.user.groups).length > 0 && (
+
+ {documentGroupState[filterGroupIdsByUser(document.groups, session.user.groups)
+ .sort()[0]]}
+
+ )}
+ {document.groups && session && session.user.groups
+ && filterGroupIdsByUser(document.groups, session.user.groups).length > 1 && (
+
+ Shared with additional groups
+
+ )}
+ placement="top"
+ >
+
+
+ )}
+ <>
+ {format(new Date(document.createdAt), 'MM/dd/yyyy')}
+ >
+
+
+
+ ),
+ )}
+
+
+ {`See all ${key === 'shared' ? key : 'created'} documents...`}
+
+
+
+ )}
+ {!listLoading && documents && documents.length === 0 && (
+
+ {`You have no ${key === 'shared' ? key : 'created'} documents.`}
+
+ )}
+
+
+
+
+
+ >
);
};
diff --git a/src/components/DocumentList/DocumentList.js b/src/components/DocumentList/DocumentList.js
index 3745c46f..86fdefe0 100644
--- a/src/components/DocumentList/DocumentList.js
+++ b/src/components/DocumentList/DocumentList.js
@@ -14,7 +14,7 @@ import {
} from 'react-bootstrap-icons';
import { format } from 'date-fns';
import LoadingSpinner from '../LoadingSpinner';
-import { getGroupNameById } from '../../utils/groupUtil';
+import { getGroupNameById, filterGroupIdsByUser } from '../../utils/groupUtil';
import { deleteDocumentById } from '../../utils/docUtil';
import ConfirmationDialog from '../ConfirmationDialog';
import { ucFirst } from '../../utils/stringUtil';
@@ -27,6 +27,7 @@ const DocumentList = ({
userId,
alerts,
setAlerts,
+ userGroups,
}) => {
const [groupState, setGroupState] = useState({});
const [showModal, setShowModal] = useState('');
@@ -114,8 +115,8 @@ const DocumentList = ({
{format(new Date(document.createdAt), 'MM/dd/yyyy')}
- {(document.groups && document.groups.length > 0)
- ? document.groups.sort().map((group) => (
+ {(document.groups && document.groups.length > 0 && userGroups)
+ ? filterGroupIdsByUser(document.groups, userGroups).sort().map((group) => (
)}
diff --git a/src/utils/groupUtil.js b/src/utils/groupUtil.js
index 133e577a..f93b9bcf 100644
--- a/src/utils/groupUtil.js
+++ b/src/utils/groupUtil.js
@@ -358,6 +358,14 @@ const getGroupById = async (id) => {
return Promise.resolve(res.json());
} return Promise.reject(Error(`Unable to get group ${id}: error ${res.status} received from server`));
};
+
+const filterGroupIdsByUser = (groupIds, userGroups) => {
+ if (userGroups) {
+ const filtered = userGroups.filter((grp) => groupIds.includes(grp.id));
+ return filtered.map((grp) => grp.id);
+ } return [];
+};
+
export {
addGroupToUser,
addUserToGroup,
@@ -365,6 +373,7 @@ export {
deleteGroup,
deleteGroupById,
deleteInviteToken,
+ filterGroupIdsByUser,
generateInviteToken,
getGroupById,
getGroupNameById,
|