// ** React Imports import { useEffect, useCallback, useState } from 'react' // ** Next Import import Link from 'next/link' // ** MUI Imports import Box from '@mui/material/Box' import Card from '@mui/material/Card' import Grid from '@mui/material/Grid' import IconButton from '@mui/material/IconButton' import Typography from '@mui/material/Typography' import { DataGrid, GridColDef } from '@mui/x-data-grid' import { SelectChangeEvent } from '@mui/material/Select' // ** Icon Imports import Icon from 'src/@core/components/icon' // ** Store Imports import { useDispatch, useSelector } from 'react-redux' // ** Custom Components Imports import CustomChip from 'src/@core/components/mui/chip' import CustomAvatar from 'src/@core/components/mui/avatar' // ** Utils Import import { getInitials } from 'src/@core/utils/get-initials' // ** Actions Imports import { fetchData } from 'src/store/apps/user' // ** Types Imports import { RootState, AppDispatch } from 'src/store' import { UsersType } from 'src/types/apps/userTypes' import { ThemeColor } from 'src/@core/layouts/types' // ** Custom Components Imports import TableHeader from 'src/views/apps/roles/TableHeader' interface UserRoleType { [key: string]: { icon: string; color: string } } interface UserStatusType { [key: string]: ThemeColor } interface CellType { row: UsersType } // ** Vars const userRoleObj: UserRoleType = { admin: { icon: 'mdi:laptop', color: 'error.main' }, author: { icon: 'mdi:cog-outline', color: 'warning.main' }, editor: { icon: 'mdi:pencil-outline', color: 'info.main' }, maintainer: { icon: 'mdi:chart-donut', color: 'success.main' }, subscriber: { icon: 'mdi:account-outline', color: 'primary.main' } } const userStatusObj: UserStatusType = { active: 'success', pending: 'warning', inactive: 'secondary' } // ** renders client column const renderClient = (row: UsersType) => { if (row.avatar.length) { return } else { return ( {getInitials(row.fullName ? row.fullName : 'John Doe')} ) } } const columns: GridColDef[] = [ { flex: 0.2, minWidth: 230, field: 'fullName', headerName: 'User', renderCell: ({ row }: CellType) => { const { fullName, username } = row return ( {renderClient(row)} {fullName} {`@${username}`} ) } }, { flex: 0.2, minWidth: 250, field: 'email', headerName: 'Email', renderCell: ({ row }: CellType) => { return ( {row.email} ) } }, { flex: 0.15, field: 'role', minWidth: 150, headerName: 'Role', renderCell: ({ row }: CellType) => { return ( {row.role} ) } }, { flex: 0.15, minWidth: 120, headerName: 'Plan', field: 'currentPlan', renderCell: ({ row }: CellType) => { return ( {row.currentPlan} ) } }, { flex: 0.1, minWidth: 110, field: 'status', headerName: 'Status', renderCell: ({ row }: CellType) => { return ( ) } }, { flex: 0.1, minWidth: 100, sortable: false, field: 'actions', headerName: 'Actions', renderCell: () => ( ) } ] const UserList = () => { // ** State const [plan, setPlan] = useState('') const [value, setValue] = useState('') const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: 10 }) // ** Hooks const dispatch = useDispatch() const store = useSelector((state: RootState) => state.user) useEffect(() => { dispatch( fetchData({ role: '', q: value, status: '', currentPlan: plan }) ) }, [dispatch, plan, value]) const handleFilter = useCallback((val: string) => { setValue(val) }, []) const handlePlanChange = useCallback((e: SelectChangeEvent) => { setPlan(e.target.value) }, []) return ( ) } export default UserList