Revize 43d49a98
Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)
webapp/pages/documents/admin/index.tsx | ||
---|---|---|
13 | 13 |
import { documentController, userController } from '../../../controllers'; |
14 | 14 |
import AssignDocumentModal from '../../../components/modals/AssignDocumentModal'; |
15 | 15 |
import { ShowToast } from '../../../utils/alerts'; |
16 |
import { TableDocInfo } from '../../../components/types/TableDocInfo'; |
|
16 | 17 |
|
17 | 18 |
function AdminDocumentPage() { |
18 | 19 |
const redirecting = useUnauthRedirect('/login'); |
... | ... | |
21 | 22 |
const [visibleAssign, setVisibleAssign] = React.useState(false); |
22 | 23 |
const router = useRouter(); |
23 | 24 |
|
24 |
const [documents, setDocuments] = useState<DocumentListInfo[]>([]);
|
|
25 |
const [documents, setDocuments] = useState<TableDocInfo[]>([]);
|
|
25 | 26 |
const [selectedDocs, setSelectedDocs] = useState<string[] | undefined[]>([]); |
26 | 27 |
|
27 |
useEffect(() => { |
|
28 |
async function fetchData() { |
|
29 |
let docs = (await documentController.documentsGet(0, 1000)).data.documents; |
|
30 |
docs?.forEach((doc) => (doc.key = doc.id)); |
|
28 |
async function fetchData() { |
|
29 |
const docs = (await documentController.documentsGet(0, 1000)).data.documents; |
|
30 |
|
|
31 |
// @ts-ignore |
|
32 |
const tableDocs: TableDocInfo[] = docs?.map((doc, index) => { |
|
33 |
return { key: index, ...doc }; |
|
34 |
}); |
|
31 | 35 |
|
32 |
if (!docs) { |
|
33 |
setDocuments([]); |
|
34 |
} else { |
|
35 |
setDocuments(docs); |
|
36 |
} |
|
36 |
if (!docs) { |
|
37 |
setDocuments([]); |
|
38 |
} else { |
|
39 |
setDocuments(tableDocs); |
|
37 | 40 |
} |
41 |
} |
|
38 | 42 |
|
43 |
useEffect(() => { |
|
39 | 44 |
if (!redirecting && role === 'ADMINISTRATOR') { |
40 | 45 |
fetchData(); |
41 | 46 |
} |
... | ... | |
54 | 59 |
}; |
55 | 60 |
|
56 | 61 |
const hideModal = () => { |
62 |
fetchData(); |
|
57 | 63 |
setVisibleAdd(false); |
58 | 64 |
setVisibleAssign(false); |
59 | 65 |
}; |
... | ... | |
96 | 102 |
|
97 | 103 |
const rowSelection = { |
98 | 104 |
onChange: (selectedRowKeys: React.Key[], selectedRows: DocumentListInfo[]) => { |
105 |
// @ts-ignore |
|
99 | 106 |
setSelectedDocs(selectedRows.map((row) => row.id)); |
100 | 107 |
}, |
101 | 108 |
}; |
Také k dispozici: Unified diff
Modal windows for user edit, delete and assigned documents were implemented