import React, { useEffect } from "react"; import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; import TableCell from '@material-ui/core/TableCell'; import TableContainer from '@material-ui/core/TableContainer'; import TableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; import { retrieveReceivedInvites, retrieveSentInvites, sendInvite } from "../../../social/reducers/invite/service"; import { createStyles, makeStyles, Theme, useTheme } from '@material-ui/core/styles'; import { selectInviteState } from "../../../social/reducers/invite/selector"; import { bindActionCreators, Dispatch } from "redux"; import { connect } from "react-redux"; import { Delete } from "@material-ui/icons"; import IconButton from '@material-ui/core/IconButton'; import FirstPageIcon from '@material-ui/icons/FirstPage'; import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft'; import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight'; import LastPageIcon from '@material-ui/icons/LastPage'; import TableFooter from '@material-ui/core/TableFooter'; import TablePagination from '@material-ui/core/TablePagination'; interface Props { receivedInvites?: any, retrieveReceivedInvites?: any, sendInvite?: any, sentInvites?: any, invites: any } const mapStateToProps = (state: any): any => { return { receivedInvites: selectInviteState(state), sentInvites: selectInviteState(state) }; }; const mapDispatchToProps = (dispatch: Dispatch): any => ({ retrieveReceivedInvites: bindActionCreators(retrieveReceivedInvites, dispatch), sendInvite: bindActionCreators(sendInvite, dispatch), retrieveSentInvites: bindActionCreators(retrieveSentInvites, dispatch) }); const useStyles = makeStyles({ table: { minWidth: 650, }, }); function createData(id: string, name: string, userRole: string, passcode: string, type: string) { return { id, name, userRole, passcode, type }; } const useStyles1 = makeStyles((theme: Theme) => createStyles({ root: { flexShrink: 0, marginLeft: theme.spacing(2.5), }, }), ); interface TablePaginationActionsProps { count: number; page: number; rowsPerPage: number; onChangePage: (event: React.MouseEvent, newPage: number) => void; } function TablePaginationActions(props: TablePaginationActionsProps) { const classes = useStyles1(); const theme = useTheme(); const { count, page, rowsPerPage, onChangePage } = props; const handleFirstPageButtonClick = (event: React.MouseEvent) => { onChangePage(event, 0); }; const handleBackButtonClick = (event: React.MouseEvent) => { onChangePage(event, page - 1); }; const handleNextButtonClick = (event: React.MouseEvent) => { onChangePage(event, page + 1); }; const handleLastPageButtonClick = (event: React.MouseEvent) => { onChangePage(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1)); }; return (
{theme.direction === 'rtl' ? : } {theme.direction === 'rtl' ? : } = Math.ceil(count / rowsPerPage) - 1} aria-label="next page" > {theme.direction === 'rtl' ? : } = Math.ceil(count / rowsPerPage) - 1} aria-label="last page" > {theme.direction === 'rtl' ? : }
); } const RecievedInvite = (props: Props) => { const classes = useStyles(); const { invites } = props; const [page, setPage] = React.useState(0); const [rowsPerPage, setRowsPerPage] = React.useState(5); const rows = invites.map((el, index) => createData(el.id, el.user.name, el.user.userRole, el.passcode, el.inviteType)); const emptyRows = rowsPerPage - Math.min(rowsPerPage, rows.length - page * rowsPerPage); const handleChangePage = (event: React.MouseEvent | null, newPage: number) => { setPage(newPage); }; const handleChangeRowsPerPage = ( event: React.ChangeEvent, ) => { setRowsPerPage(parseInt(event.target.value, 10)); setPage(0); }; return ( Id Name User role Passcode Type Action {(rowsPerPage > 0 ? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) : rows ).map((row, index) => ( {row.id} {row.name} {row.userRole} {row.passcode} {row.type} ))} {emptyRows > 0 && ( )}
); }; export default connect(mapStateToProps, mapDispatchToProps)(RecievedInvite);