import React, { useCallback, useMemo, useState } from 'react' import { useRouter } from 'next/router' import { NextPage } from 'next' import { TFunction, useTranslation } from 'next-i18next' // material-ui deps import { createStyles, makeStyles, Theme } from '@material-ui/core/styles' import { GridCellParams, GridColDef, GridValueFormatterParams, GridValueGetterParams, } from '@material-ui/data-grid' import Box from '@material-ui/core/Box' import { Button } from '@material-ui/core' // 내부 컴포넌트 및 custom hook, etc... import { convertStringToDateFormat } from '@libs/date' import CustomDataGrid from '@components/Table/CustomDataGrid' import Search, { IKeywordType } from '@components/Search' import { Page, rownum } from '@utils' // 상태관리 recoil import { useRecoilValue } from 'recoil' import { conditionAtom } from '@stores' // api import { roleService } from '@service' import usePage from '@hooks/usePage' import { GRID_PAGE_SIZE } from '@constants' // material-ui style const useStyles = makeStyles((theme: Theme) => createStyles({ root: { flexGrow: 1, '& .MuiOutlinedInput-input': { padding: theme.spacing(1), }, }, search: { padding: theme.spacing(1), textAlign: 'center', }, iconButton: { padding: theme.spacing(1), marginLeft: theme.spacing(1), backgroundColor: theme.palette.background.default, }, fab: { marginLeft: theme.spacing(1), }, }), ) // 그리드 컬럼 정의 type ColumnsType = ( data: Page, handleManageRole: (roleId: string) => void, t?: TFunction, ) => GridColDef[] const getColumns: ColumnsType = (data, handleManageRole, t) => [ { field: 'rownum', headerName: t('common.no'), headerAlign: 'center', align: 'center', sortable: false, valueGetter: (params: GridValueGetterParams) => rownum(data, params.api.getRowIndex(params.id), 'asc'), }, { field: 'roleId', headerName: t('role.role_id'), headerAlign: 'center', align: 'left', width: 200, sortable: false, }, { field: 'roleName', headerName: t('role.role_name'), headerAlign: 'center', align: 'center', width: 200, sortable: false, }, { field: 'roleContent', headerName: t('role.role_content'), headerAlign: 'center', flex: 1, sortable: false, }, { field: 'createdDate', headerName: t('common.created_datetime'), headerAlign: 'center', align: 'center', width: 200, sortable: false, valueFormatter: (params: GridValueFormatterParams) => convertStringToDateFormat(params.value as string, 'yyyy-MM-dd HH:mm:ss'), }, { field: 'buttons', headerName: t('common.manage'), headerAlign: 'center', align: 'center', width: 150, sortable: false, renderCell: function renderCellButtons(params: GridCellParams) { return (