Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d7167305

Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)

Document preview implemented

Zobrazit rozdíly:

webapp/pages/documents/admin/index.tsx
14 14
import AssignDocumentModal from '../../../components/modals/AssignDocumentModal';
15 15
import { ShowToast } from '../../../utils/alerts';
16 16
import { TableDocInfo } from '../../../components/types/TableDocInfo';
17
import DocPreviewModal from '../../../components/modals/DocPreviewModal';
17 18

  
18 19
function AdminDocumentPage() {
19 20
    const redirecting = useUnauthRedirect('/login');
20 21
    const { logout, role } = useContext(LoggedUserContext);
21 22
    const [visibleAdd, setVisibleAdd] = React.useState(false);
22 23
    const [visibleAssign, setVisibleAssign] = React.useState(false);
24
    const [visiblePreview, setVisiblePreview] = React.useState(false);
23 25
    const router = useRouter();
24 26

  
25 27
    const [documents, setDocuments] = useState<TableDocInfo[]>([]);
26 28
    const [selectedDocs, setSelectedDocs] = useState<string[] | undefined[]>([]);
29
    const [previewDocContent, setPreviewDocContent] = useState<string>();
30
    const [previewDocName, setPreviewDocName] = useState<string>();
27 31

  
28 32
    async function fetchData() {
29 33
        const docs = (await documentController.documentsGet(0, 1000)).data.documents;
......
58 62
        setVisibleAdd(true);
59 63
    };
60 64

  
65
    const showPreviewModal = async (id: string, name: string) => {
66
        const documentContent = (await documentController.documentDocumentIdGet(id)).data
67
            .content;
68
        setPreviewDocName(name);
69
        setPreviewDocContent(documentContent);
70
        setVisiblePreview(true);
71
    };
72

  
61 73
    const hideModal = () => {
62 74
        fetchData();
63 75
        setVisibleAdd(false);
64 76
        setVisibleAssign(false);
77
        setVisiblePreview(false);
65 78
    };
66 79

  
67 80
    const columns = [
......
98 111
                );
99 112
            },
100 113
        },
114
        {
115
            title: '',
116
            key: 'action',
117
            dataIndex: ['id', 'name'],
118
            // @ts-ignore
119
            render: (text, row) => (
120
                <Button key={row.id} onClick={() => showPreviewModal(row.id, row.name)}>
121
                    Náhled
122
                </Button>
123
            ),
124
        },
101 125
    ];
102 126

  
103 127
    const rowSelection = {
......
120 144
            {visibleAssign && (
121 145
                <AssignDocumentModal documentsIds={selectedDocs} onCancel={hideModal} />
122 146
            )}
147
            {visiblePreview && (
148
                <DocPreviewModal
149
                    onCancel={hideModal}
150
                    documentName={previewDocName}
151
                    content={previewDocContent}
152
                />
153
            )}
123 154

  
124 155
            <Table
125 156
                rowSelection={{

Také k dispozici: Unified diff