Revize 9bfa1e39
Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)
webapp/pages/documents/admin/index.tsx | ||
---|---|---|
11 | 11 |
import AddDocumentModal from '../../../components/modals/AddDocumentModal'; |
12 | 12 |
import { AnnotationListInfo, DocumentListInfo, UserInfo } from '../../../api'; |
13 | 13 |
import { documentController, userController } from '../../../controllers'; |
14 |
import AssignDocumentModal from '../../../components/modals/AssignDocumentModal'; |
|
15 |
import { ShowToast } from '../../../utils/alerts'; |
|
14 | 16 |
|
15 | 17 |
function AdminDocumentPage() { |
16 | 18 |
const redirecting = useUnauthRedirect('/login'); |
17 | 19 |
const { logout, role } = useContext(LoggedUserContext); |
18 |
const [visible, setVisible] = React.useState(false); |
|
20 |
const [visibleAdd, setVisibleAdd] = React.useState(false); |
|
21 |
const [visibleAssign, setVisibleAssign] = React.useState(false); |
|
19 | 22 |
const router = useRouter(); |
20 | 23 |
|
21 | 24 |
const [documents, setDocuments] = useState<DocumentListInfo[]>([]); |
25 |
const [selectedDocs, setSelectedDocs] = useState<string[] | undefined[]>([]); |
|
22 | 26 |
|
23 | 27 |
useEffect(() => { |
24 | 28 |
async function fetchData() { |
25 | 29 |
let docs = (await documentController.documentsGet(0, 1000)).data.documents; |
30 |
docs?.forEach((doc) => (doc.key = doc.id)); |
|
31 |
|
|
26 | 32 |
if (!docs) { |
27 | 33 |
setDocuments([]); |
28 | 34 |
} else { |
... | ... | |
35 | 41 |
} |
36 | 42 |
}, [logout, redirecting, role, router]); |
37 | 43 |
|
38 |
const showModal = () => { |
|
39 |
setVisible(true); |
|
44 |
const showAssignModal = () => { |
|
45 |
if (selectedDocs.length == 0) { |
|
46 |
ShowToast('Vyberte dokument pro přiřazení', 'warning', 3000, 'top-end'); |
|
47 |
} else { |
|
48 |
setVisibleAssign(true); |
|
49 |
} |
|
50 |
}; |
|
51 |
|
|
52 |
const showAddModal = () => { |
|
53 |
setVisibleAdd(true); |
|
40 | 54 |
}; |
41 | 55 |
|
42 | 56 |
const hideModal = () => { |
43 |
setVisible(false); |
|
57 |
setVisibleAdd(false); |
|
58 |
setVisibleAssign(false); |
|
44 | 59 |
}; |
45 | 60 |
|
46 | 61 |
const columns = [ |
... | ... | |
79 | 94 |
}, |
80 | 95 |
]; |
81 | 96 |
|
97 |
const rowSelection = { |
|
98 |
onChange: (selectedRowKeys: React.Key[], selectedRows: DocumentListInfo[]) => { |
|
99 |
setSelectedDocs(selectedRows.map((row) => row.id)); |
|
100 |
}, |
|
101 |
}; |
|
102 |
|
|
82 | 103 |
return redirecting || role !== 'ADMINISTRATOR' ? null : ( |
83 | 104 |
<MainLayout> |
84 | 105 |
<Typography.Title level={2}> |
85 | 106 |
<FontAwesomeIcon icon={faFileLines} /> Dokumenty |
86 | 107 |
</Typography.Title> |
87 |
<Button type={'primary'} onClick={showModal}> |
|
108 |
<Button type={'primary'} onClick={showAddModal}>
|
|
88 | 109 |
Nahrát dokument |
89 | 110 |
</Button> |
90 |
{visible && <AddDocumentModal onCancel={hideModal} />} |
|
111 |
<Button onClick={showAssignModal}>Přiřadit dokumenty</Button> |
|
112 |
{visibleAdd && <AddDocumentModal onCancel={hideModal} />} |
|
113 |
{visibleAssign && ( |
|
114 |
<AssignDocumentModal documentsIds={selectedDocs} onCancel={hideModal} /> |
|
115 |
)} |
|
91 | 116 |
|
92 | 117 |
<Table |
118 |
rowSelection={{ |
|
119 |
type: 'checkbox', |
|
120 |
...rowSelection, |
|
121 |
}} |
|
93 | 122 |
columns={columns} |
94 | 123 |
dataSource={documents} |
95 |
size="small"
|
|
96 |
scroll={{ y: 500 }}
|
|
124 |
size="middle"
|
|
125 |
scroll={{ y: 600 }}
|
|
97 | 126 |
/> |
98 | 127 |
</MainLayout> |
99 | 128 |
); |
Také k dispozici: Unified diff
Document assigning implemented