forked from MicrosoftStudentChapter/Linky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
approvals component in admin page added
- Loading branch information
1 parent
d99095b
commit a74606d
Showing
1 changed file
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { useState, useEffect } from 'react'; // Import useEffect | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
import { Grid, Avatar, Button, Dialog, DialogTitle, DialogContent, DialogActions, IconButton } from '@mui/material'; | ||
import OpenInNewRoundedIcon from '@mui/icons-material/OpenInNewRounded'; | ||
import data from '../data/approvals.json'; | ||
|
||
const columns = [ | ||
{ | ||
field: 'avatar', | ||
headerName: 'Avatar', | ||
width: 80, | ||
disableColumnMenu: true, | ||
renderCell: (params) => { | ||
const firstInitial = params.row.username.charAt(0).toUpperCase(); | ||
return ( | ||
<Grid container alignItems="center" justifyContent="left" sx={{ display: 'flex', width: '100%', height: '100%' }}> | ||
<Avatar sx={{ bgcolor: 'primary.main' }}> | ||
{firstInitial} | ||
</Avatar> | ||
</Grid> | ||
); | ||
}, | ||
sortable: false, | ||
filterable: false, | ||
}, | ||
{ field: 'username', headerName: 'From', width: 200 }, | ||
{ field: 'websiteAlias', headerName: 'Website Alias', width: 200 }, | ||
{ field: 'date', headerName: 'Submitted', width: 200, sortable: false, filterable: false }, | ||
{ | ||
field: 'actions', | ||
headerName: 'Link and Actions', | ||
width: 150, | ||
disableColumnMenu: true, | ||
renderCell: (params) => { | ||
const [openLink, setOpenLink] = useState(false); | ||
|
||
const handleClickOpen = () => { | ||
setOpenLink(true); | ||
}; | ||
|
||
const handleApprove = () => { | ||
console.log('Approve link:', params.row.link); | ||
}; | ||
|
||
const handleDeny = () => { | ||
console.log('Deny link:', params.row.link); | ||
}; | ||
|
||
return ( | ||
<> | ||
<IconButton onClick={handleClickOpen}> | ||
<OpenInNewRoundedIcon /> | ||
</IconButton> | ||
<Dialog open={openLink} onClose={() => setOpenLink(false)}> | ||
<DialogTitle>Open Link</DialogTitle> | ||
<DialogContent> | ||
<a href={params.row.link} target="_blank" rel="noreferrer noopener"> | ||
{params.row.link} | ||
</a> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button variant="contained" color="primary" onClick={handleApprove}> | ||
Approve | ||
</Button> | ||
<Button variant="contained" color="error" onClick={handleDeny}> | ||
Deny | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
}, | ||
sortable: false, | ||
filterable: false, | ||
}, | ||
]; | ||
|
||
const Approvals = () => { | ||
const [rows, setRows] = useState([]); | ||
|
||
useEffect(() => { | ||
setRows(data); | ||
}, []); | ||
|
||
return ( | ||
<DataGrid rows={rows} columns={columns} disableColumnSelector={true} /> | ||
); | ||
}; | ||
|
||
export default Approvals; |