diff --git a/FRONTEND/src/pages/Document/Document.tsx b/FRONTEND/src/pages/Document/Document.tsx index 3da430f..703e1e5 100644 --- a/FRONTEND/src/pages/Document/Document.tsx +++ b/FRONTEND/src/pages/Document/Document.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from 'react' import { get } from '@/rtk/helpers/apiService' import { deleteDocument, listDocument } from '@/api/Admin' import { Xdelete } from '@/rtk/helpers/CRUD' +import { useSelector } from 'react-redux' +import { RootState } from '@/rtk/store' import { Anchor, Box, Button, Dialog, Group, Loader, Text } from '@mantine/core' import { useDisclosure } from '@mantine/hooks' @@ -20,7 +22,6 @@ import ModalFileDocument from './ModalFileDocument' import classes from './Document.module.css' import ModalAddDocument from './ModalAddDocument' import ModalEditDocument from './ModalEditDocument' -import { checkPermissions } from '@/utils/checkRoles' interface TDocument { id: number @@ -38,6 +39,8 @@ type RequestPagination = { } const Document = () => { + const user = useSelector((state: RootState) => state.authentication) + const [loader, setLoader] = useState(false) const [rows, setRows] = useState({ data: [], @@ -91,42 +94,68 @@ const Document = () => { } } - const getFileTypeIcon = (uri: string) => { + const getFileTypeIcon = (row: TDocument) => { + const uri = row?.uri if (!uri) return null const extension = uri.split('.').pop()?.toLowerCase() - if (['doc', 'docx'].includes(extension!)) { - return + if (['doc'].includes(extension!)) { + return ( + + + + ) } if (['xls', 'xlsx'].includes(extension!)) { - return + return ( + + + + ) } - return + if (['docx'].includes(extension!)) { + return ( + { + openModalFile() + setSelectDataRow(row) + }} + style={{ color: '#1e62c1' }} + /> + ) + } + + return ( + { + openModalFile() + setSelectDataRow(row) + }} + style={{ color: '#ff1b0e' }} + /> + ) } const columns = [ - { - name: 'id', - size: '5%', - header: 'ID', - render: (row: TDocument) => { - return {row?.id ? row.id : ''} - }, - }, { name: 'title', size: '50%', header: 'Title', - render: (row: TDocument) => { - return {row?.title} - }, }, { name: 'uri', - size: '40%', + size: '45%', header: 'URI', render: (row: TDocument) => { return ( @@ -135,16 +164,12 @@ const Document = () => { { - setSelectDataRow(row) - openModalFile() - }} - title={`File ${row?.uri + title={`File .${row?.uri .split('.') .pop() ?.toLowerCase()} detail`} > - {getFileTypeIcon(row?.uri)} + {getFileTypeIcon(row)} ) : ( { size: '5%', header: 'Action', render: (row: TDocument) => { - if (checkPermissions('admin')) { - return ( - - { - setSelectDataRow(row) - openModalEdit() - }} - width={20} - height={20} - /> - { - setOpenedDialogDelete(true) - setSelectDataRow(row) - }} - width={20} - height={20} - /> - - ) + if (!user.user.user.permission.includes('admin')) { + return '' } - return + return ( + + { + setSelectDataRow(row) + openModalEdit() + }} + width={20} + height={20} + /> + { + setOpenedDialogDelete(true) + setSelectDataRow(row) + }} + width={20} + height={20} + /> + + ) }, }, ] @@ -203,7 +228,7 @@ const Document = () => { Documents - {checkPermissions('admin') ? ( + {user.user.user.permission.includes('admin') ? ( diff --git a/FRONTEND/src/pages/Document/ModalEditDocument.tsx b/FRONTEND/src/pages/Document/ModalEditDocument.tsx index 6f90b16..4633c41 100644 --- a/FRONTEND/src/pages/Document/ModalEditDocument.tsx +++ b/FRONTEND/src/pages/Document/ModalEditDocument.tsx @@ -9,6 +9,7 @@ import { FileInput, Badge, TextInput, + Group, } from '@mantine/core' import { update } from '@/rtk/helpers/CRUD' @@ -113,15 +114,51 @@ const ModalEditDocument = ({ const extension = uri.split('.').pop()?.toLowerCase() - if (['doc', 'docx'].includes(extension!)) { - return + if (['doc'].includes(extension!)) { + return ( + + + + ) } if (['xls', 'xlsx'].includes(extension!)) { - return + return ( + + + + ) } - return + if (['docx'].includes(extension!)) { + return ( + { + openModalFile() + setSelectDataFileRow(selectDataRow) + }} + style={{ color: '#1e62c1' }} + /> + ) + } + + return ( + { + openModalFile() + setSelectDataFileRow(selectDataRow) + }} + style={{ color: '#ff1b0e' }} + /> + ) } const resetForm = () => { @@ -179,7 +216,7 @@ const ModalEditDocument = ({ {form.values.file ? ( '' ) : ( - { - openModalFile() - setSelectDataFileRow(selectDataRow) - }} > {getFileTypeIcon(form.values.uri)} - + + .{form.values.uri.split('.').pop()?.toLowerCase()} + )} ) : (