Skip to content

Commit 760b8f5

Browse files
committed
refactor(tsx): convert UserList view
1 parent cdeec69 commit 760b8f5

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

src/ui/views/UserList/Components/TabList.jsx renamed to src/ui/views/UserList/Components/TabList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import GridItem from '../../../components/Grid/GridItem';
33
import GridContainer from '../../../components/Grid/GridContainer';
44
import UserList from './UserList';
55

6-
export default function Dashboard() {
6+
const Dashboard: React.FC = () => {
77
return (
88
<div>
99
<GridContainer>
@@ -13,4 +13,6 @@ export default function Dashboard() {
1313
</GridContainer>
1414
</div>
1515
);
16-
}
16+
};
17+
18+
export default Dashboard;

src/ui/views/UserList/Components/UserList.jsx renamed to src/ui/views/UserList/Components/UserList.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,37 @@ import Pagination from '../../../components/Pagination/Pagination';
1717
import { CloseRounded, Check, KeyboardArrowRight } from '@material-ui/icons';
1818
import Search from '../../../components/Search/Search';
1919

20-
const useStyles = makeStyles(styles);
20+
interface User {
21+
username: string;
22+
displayName?: string;
23+
title?: string;
24+
email?: string;
25+
gitAccount?: string;
26+
admin?: boolean;
27+
}
28+
29+
interface UserListProps {
30+
[key: string]: any;
31+
}
2132

22-
export default function UserList(props) {
33+
const useStyles = makeStyles(styles as any);
34+
35+
const UserList: React.FC<UserListProps> = (props) => {
2336
const classes = useStyles();
24-
const [data, setData] = useState([]);
25-
const [, setAuth] = useState(true);
26-
const [isLoading, setIsLoading] = useState(false);
27-
const [isError, setIsError] = useState(false);
37+
const [data, setData] = useState<User[]>([]);
38+
const [, setAuth] = useState<boolean>(true);
39+
const [isLoading, setIsLoading] = useState<boolean>(false);
40+
const [isError, setIsError] = useState<boolean>(false);
2841
const navigate = useNavigate();
29-
const [currentPage, setCurrentPage] = useState(1);
42+
const [currentPage, setCurrentPage] = useState<number>(1);
3043
const itemsPerPage = 5;
31-
const [searchQuery, setSearchQuery] = useState('');
44+
const [searchQuery, setSearchQuery] = useState<string>('');
3245

33-
const openUser = (username) => navigate(`/dashboard/admin/user/${username}`, { replace: true });
46+
const openUser = (username: string) =>
47+
navigate(`/dashboard/admin/user/${username}`, { replace: true });
3448

3549
useEffect(() => {
36-
const query = {};
50+
const query: Record<string, any> = {};
3751

3852
for (const k in props) {
3953
if (!k) continue;
@@ -56,11 +70,11 @@ export default function UserList(props) {
5670
const currentItems = filteredUsers.slice(indexOfFirstItem, indexOfLastItem);
5771
const totalItems = filteredUsers.length;
5872

59-
const handlePageChange = (page) => {
73+
const handlePageChange = (page: number) => {
6074
setCurrentPage(page);
6175
};
6276

63-
const handleSearch = (query) => {
77+
const handleSearch = (query: string) => {
6478
setSearchQuery(query);
6579
setCurrentPage(1);
6680
};
@@ -128,4 +142,6 @@ export default function UserList(props) {
128142
</GridItem>
129143
</GridContainer>
130144
);
131-
}
145+
};
146+
147+
export default UserList;

src/ui/views/UserList/UserList.jsx renamed to src/ui/views/UserList/UserList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import GridItem from '../../components/Grid/GridItem';
33
import GridContainer from '../../components/Grid/GridContainer';
44
import TabList from './Components/TabList';
55

6-
export default function UserList() {
6+
const UserList: React.FC = () => {
77
return (
88
<GridContainer>
99
<GridItem xs={12} sm={12} md={12}>
1010
<TabList />
1111
</GridItem>
1212
</GridContainer>
1313
);
14-
}
14+
};
15+
16+
export default UserList;

0 commit comments

Comments
 (0)