Skip to content

Commit d09abb8

Browse files
authored
Merge pull request #5 from code-squads/Vansh
Vansh Commits
2 parents 91b7b61 + feb4285 commit d09abb8

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

src/components/AppGrid.js

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
import * as React from "react";
22
import { DataGrid } from "@mui/x-data-grid";
3+
import PropTypes from "prop-types";
4+
import Button from "@mui/material/Button";
5+
6+
function RenderDate(props) {
7+
const { hasFocus, value } = props;
8+
const buttonElement = React.useRef(null);
9+
const rippleRef = React.useRef(null);
10+
const flagColor = props.value;
11+
12+
React.useLayoutEffect(() => {
13+
if (hasFocus) {
14+
const input = buttonElement.current?.querySelector("input");
15+
input?.focus();
16+
} else if (rippleRef.current) {
17+
// Only available in @mui/material v5.4.1 or later
18+
rippleRef.current.stop({});
19+
}
20+
}, [hasFocus]);
21+
22+
return (
23+
<>
24+
{flagColor === "green" && (
25+
<button
26+
className="focus:outline-none text-white w-[8rem] bg-green-700 hover:bg-green-800 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-green-800"
27+
>
28+
Safe User
29+
</button>
30+
)}
31+
{flagColor === "red" && (
32+
<button
33+
className="focus:outline-none text-white w-[8rem] bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900"
34+
>
35+
Reported User
36+
</button>
37+
)}
38+
</>
39+
);
40+
}
41+
42+
RenderDate.propTypes = {
43+
/**
44+
* If true, the cell is the active element.
45+
*/
46+
hasFocus: PropTypes.bool.isRequired,
47+
/**
48+
* The cell value.
49+
* If the column has `valueGetter`, use `params.row` to directly access the fields.
50+
*/
51+
value: PropTypes.instanceOf(Date),
52+
};
353

454
const columns = [
555
{ field: "id", headerName: "ID", width: 90 },
@@ -22,7 +72,7 @@ const columns = [
2272
},
2373
{ field: "Email", header: "Email", width: 250 },
2474
{ field: "Aadhar", header: "Aadhar" },
25-
{ field: "Flag", header: "Flags" },
75+
{ field: "Flag", header: "Flags", renderCell: RenderDate, width: 200 },
2676
];
2777

2878
const people = [
@@ -33,7 +83,8 @@ const people = [
3383
Gender: "Male",
3484
3585
Aadhar: 3310,
36-
Flag: "flag",
86+
// Message will come with reports.message for red flag and for green, it will be from recommends.
87+
Flag: "red",
3788
},
3889
{
3990
id: 2,
@@ -42,7 +93,7 @@ const people = [
4293
Gender: "Male",
4394
4495
Aadhar: 3310,
45-
Flag: "flag",
96+
Flag: "green",
4697
},
4798
{
4899
id: 3,
@@ -51,7 +102,7 @@ const people = [
51102
Gender: "Male",
52103
53104
Aadhar: 3310,
54-
Flag: "flag",
105+
Flag: "red",
55106
},
56107
{
57108
id: 4,
@@ -60,7 +111,7 @@ const people = [
60111
Gender: "Male",
61112
62113
Aadhar: 3310,
63-
Flag: "flag",
114+
Flag: "red",
64115
},
65116
{
66117
id: 5,
@@ -69,7 +120,7 @@ const people = [
69120
Gender: "Male",
70121
71122
Aadhar: 3310,
72-
Flag: "flag",
123+
Flag: "green",
73124
},
74125
];
75126

@@ -79,20 +130,7 @@ export default function AppGrid() {
79130
style={{ width: "100%", backgroundColor: "white" }}
80131
className="h-[100vh]"
81132
>
82-
<DataGrid
83-
rows={people}
84-
columns={columns}
85-
// initialState={{
86-
// pagination: {
87-
// paginationModel: {
88-
// pageSize: 5,
89-
// },
90-
// },
91-
// }}
92-
// pageSizeOptions={[5]}
93-
checkboxSelection
94-
disableRowSelectionOnClick
95-
/>
133+
<DataGrid rows={people} columns={columns} disableRowSelectionOnClick className="bg-[#394150]" style={{color : 'white'}} />
96134
</div>
97135
);
98136
}

src/pages/reportedEmployees.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import AppGrid from '@/components/AppGrid'
12
import React from 'react'
23

4+
35
const ReportedEmployees = () => {
46
return (
57
<div>
6-
ReportedEmployees
8+
<AppGrid />
79
</div>
810
)
911
}

0 commit comments

Comments
 (0)