-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from TharindaPrabhath/frontend-day-09-stepper
Frontend day 09 stepper
- Loading branch information
Showing
15 changed files
with
276 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import React, { useState } from "react"; | ||
|
||
import { | ||
Button, | ||
|
@@ -13,13 +13,12 @@ import { DataGrid, GridColDef } from "@mui/x-data-grid"; | |
|
||
import { useButtonStyles } from "../data/styles"; | ||
import { Redirect } from "react-router-dom"; | ||
import UserDto from "../types/models/UserDto"; | ||
|
||
import { useDispatch, useSelector } from "react-redux"; | ||
import { bindActionCreators } from "redux"; | ||
import { actionCreators } from "../redux"; | ||
import { toUserDtos } from "../utils/mapper"; | ||
import { deleteUser, fetchUsers } from "../utils/requestHelper"; | ||
import { deleteUser } from "../utils/requestHelper"; | ||
import { useSnackbar } from "notistack"; | ||
import { ReducerType } from "../redux/store"; | ||
import colors from "../data/colors"; | ||
|
@@ -31,36 +30,40 @@ import useSWR from "swr"; | |
import requests from "../data/requests"; | ||
import useAxios from "../utils/axios"; | ||
|
||
const getRow = ( | ||
id: string, | ||
fname: string, | ||
lname: string, | ||
email: string, | ||
role: string, | ||
birthday: string | ||
) => { | ||
return { id, fname, lname, email, role, birthday }; | ||
}; | ||
// const getRow = ( | ||
// id: string, | ||
// fname: string, | ||
// lname: string, | ||
// email: string, | ||
// role: string, | ||
// birthday: string | ||
// ) => { | ||
// return { id, fname, lname, email, role, birthday }; | ||
// }; | ||
|
||
const rows = [ | ||
getRow("001", "Tharinda", "P", "[email protected]", "Uni", "2001.03.12"), | ||
getRow("002", "Prabhath", "", "[email protected]", "Uni", "2001.03.12"), | ||
getRow("003", "Lasana", "sanketh", "[email protected]", "Uni", "2001.03.12"), | ||
getRow( | ||
"004", | ||
"Lishitha", | ||
"Alahakoon", | ||
"[email protected]", | ||
"Uni", | ||
"2001.03.12" | ||
), | ||
getRow("005", "Nadun", "", "[email protected]", "Uni", "2001.03.12"), | ||
getRow("006", "Chamath", "Roo", "[email protected]", "Uni", "2001.03.12"), | ||
getRow("007", "Hasitha", "G", "[email protected]", "Uni", "2001.03.12"), | ||
]; | ||
// const rows = [ | ||
// getRow("001", "Tharinda", "P", "[email protected]", "Uni", "2001.03.12"), | ||
// getRow("002", "Prabhath", "", "[email protected]", "Uni", "2001.03.12"), | ||
// getRow("003", "Lasana", "sanketh", "[email protected]", "Uni", "2001.03.12"), | ||
// getRow( | ||
// "004", | ||
// "Lishitha", | ||
// "Alahakoon", | ||
// "[email protected]", | ||
// "Uni", | ||
// "2001.03.12" | ||
// ), | ||
// getRow("005", "Nadun", "", "[email protected]", "Uni", "2001.03.12"), | ||
// getRow("006", "Chamath", "Roo", "[email protected]", "Uni", "2001.03.12"), | ||
// getRow("007", "Hasitha", "G", "[email protected]", "Uni", "2001.03.12"), | ||
// ]; | ||
|
||
const UserTable = () => { | ||
//const [users, setUsers] = useState<UserDto[]>([]); | ||
// pagination & sorting | ||
const [pageNo, setPageNo] = useState(0); | ||
const [pageSize, setPageSize] = useState(5); | ||
const [sortBy, setSortBy] = useState("uid"); | ||
|
||
const [selectedUserId, setSelectedUserId] = useState<number>(); | ||
const [redirect, setRedirect] = useState<boolean>(false); | ||
const [openConfirmBox, setOpenConfirmBox] = useState<boolean>(false); | ||
|
@@ -77,23 +80,15 @@ const UserTable = () => { | |
const { StatusBadge } = useBadge(); | ||
const axios = useAxios(); | ||
|
||
const { data: users } = useSWR(requests.fetchUsers, (url: string) => | ||
axios | ||
.get(url) | ||
.then((r) => toUserDtos(r.data)) | ||
.catch((err) => console.error(err)) | ||
const { data: users } = useSWR( | ||
`${requests.fetchUsers}?page_no=${pageNo}&page_size=${pageSize}&sort_by=${sortBy}`, | ||
(url: string) => | ||
axios | ||
.get(url) | ||
.then((r) => toUserDtos(r.data)) | ||
.catch((err) => console.error(err)) | ||
); | ||
|
||
// useEffect(() => { | ||
// fetchUsers() | ||
// .then((res) => { | ||
// setUsers(toUserDtos(res.data)); | ||
// }) | ||
// .catch((err) => { | ||
// console.error(err); | ||
// }); | ||
// }, []); | ||
|
||
const handleViewClick = (event: React.MouseEvent<unknown>, id: number) => { | ||
// set current user in redux store | ||
setUser(users?.find((u) => u.id === id)!); | ||
|
@@ -238,8 +233,13 @@ const UserTable = () => { | |
<DataGrid | ||
rows={users || []} | ||
columns={columns} | ||
pageSize={5} | ||
rowsPerPageOptions={[5]} | ||
rowCount={100} | ||
rowsPerPageOptions={[5, 10]} | ||
paginationMode="server" | ||
pagination | ||
pageSize={pageSize} | ||
onPageChange={(n) => setPageNo(n)} | ||
onPageSizeChange={(s) => setPageSize(s)} | ||
checkboxSelection | ||
disableSelectionOnClick | ||
style={{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.