-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(admin): add poll page #470
Open
SUNNYKUMAR1232
wants to merge
6
commits into
Monday-Morning:feat/admin
Choose a base branch
from
SUNNYKUMAR1232:feat/cms
base: feat/admin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39d678d
feat: implement new poll feature
SUNNYKUMAR1232 0375333
Update PolllDialogBox.js
SUNNYKUMAR1232 69b959c
Update PolllDialogBox.js
SUNNYKUMAR1232 1c2c33d
Rename PolllDialogBox.js to PollDialogBox.js
SUNNYKUMAR1232 d20ae48
Update Poll.jsx
SUNNYKUMAR1232 72b9c8d
Change class name in camel case
SUNNYKUMAR1232 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,150 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogContent, | ||
DialogTitle, | ||
FormControl, | ||
InputLabel, | ||
MenuItem, | ||
Select, | ||
TextField, | ||
Typography, | ||
} from '@mui/material'; | ||
import makeStyles from '@mui/styles/makeStyles'; | ||
|
||
const DialogPoll = ({ dialogBoxOpen, setDialogBoxOpen }) => { | ||
const [value, setValue] = useState(0); | ||
const [live, setLive] = useState('offline'); | ||
const [Options, setOptions] = useState(''); | ||
const DialogBoxClose = () => { | ||
setDialogBoxOpen(false); | ||
setValue(0); | ||
setLive('offline'); | ||
}; | ||
const handleOptions = (e) => { | ||
setOptions(e.target.value); | ||
}; | ||
const handleValue = (e) => { | ||
setValue(e.target.value); | ||
}; | ||
const handleLive = () => { | ||
setLive('Live'); | ||
}; | ||
const handleSave = () => { | ||
DialogBoxClose(); | ||
}; | ||
const classes = useStyles(); | ||
useEffect(() => { | ||
console.log(live); | ||
}, [live]); | ||
return ( | ||
<> | ||
<Dialog | ||
open={dialogBoxOpen} | ||
onClose={DialogBoxClose} | ||
scroll='paper' | ||
aria-labelledby='scroll-dialog-title' | ||
aria-describedby='scroll-dialog-description' | ||
fullWidth | ||
maxWidth='md' | ||
> | ||
<DialogTitle id='scroll-dialog-title' className={classes.dialogtitle}> | ||
SUNNYKUMAR1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Create Poll | ||
</DialogTitle> | ||
{live === 'offline' ? ( | ||
<DialogContent> | ||
<div> | ||
<Typography variant='h6'>Question</Typography> | ||
<TextField | ||
multiline | ||
variant='outlined' | ||
placeholder='Poll Question' | ||
sx={{ width: '100%', marginBottom: '1rem ', marginTop: '1rem' }} | ||
></TextField> | ||
</div> | ||
<FormControl sx={{ m: 1, minWidth: 120 }}> | ||
<InputLabel id='demo-multiple-name-label'>Options</InputLabel> | ||
<Select | ||
labelId='demo-multiple-name-label' | ||
id='demo-multiple-name' | ||
label='Options' | ||
onChange={handleValue} | ||
renderValue={(selected) => { | ||
return selected; | ||
}} | ||
> | ||
{[...Array(10).keys()].map((num) => { | ||
return <MenuItem value={num + 1}>{num + 1}</MenuItem>; | ||
})} | ||
</Select> | ||
</FormControl> | ||
{[...Array(value).keys()].map((num) => { | ||
return ( | ||
<div> | ||
<TextField | ||
onChange={(e) => handleOptions(e)} | ||
key={num} | ||
placeholder={`Poll Option ${num + 1}`} | ||
variant='outlined' | ||
margin='dense' | ||
fullWidth | ||
/> | ||
</div> | ||
); | ||
})} | ||
</DialogContent> | ||
) : ( | ||
<DialogContent className={classes.livereturn}> | ||
<Typography variant='h3'>Poll Going Live </Typography> | ||
</DialogContent> | ||
)} | ||
|
||
<div className={classes.btnbox}> | ||
<Button | ||
className={classes.livebtn} | ||
onClick={() => { | ||
handleLive(); | ||
}} | ||
> | ||
Live | ||
</Button> | ||
<Button | ||
className={classes.livebtn} | ||
onClick={() => { | ||
handleSave(); | ||
}} | ||
> | ||
Save | ||
</Button> | ||
</div> | ||
</Dialog> | ||
</> | ||
); | ||
}; | ||
const useStyles = makeStyles((theme) => ({ | ||
dialogtitle: { | ||
textAlign: 'center', | ||
}, | ||
btnbox: { | ||
display: 'flex', | ||
justifyContent: 'end', | ||
}, | ||
livebtn: { | ||
width: '3rem', | ||
margin: '1rem 1rem 1rem 0', | ||
backgroundColor: 'green', | ||
color: '#fff', | ||
'&:hover': { | ||
backgroundColor: '#f50057', | ||
}, | ||
}, | ||
livereturn: { | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '10rem', | ||
width: '100%', | ||
}, | ||
})); | ||
export default DialogPoll; |
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,53 @@ | ||
import React from 'react'; | ||
import Poll from '../../screens/admin_v2/Poll'; | ||
import getAccess from '../../utils/getAccess'; | ||
import { parseCookies } from 'nookies'; | ||
import { getGraphClient } from '../../context/ApolloContextProvider'; | ||
import Custom500 from '../500.jsx'; | ||
|
||
const PollPage = ({ isError, PollList }) => { | ||
if (isError) { | ||
return <Custom500 />; | ||
} | ||
return <Poll PollList={PollList} />; | ||
}; | ||
export default PollPage; | ||
export async function getServerSideProps(ctx) { | ||
try { | ||
const requiredPermissions = ['poll.write.restricted']; | ||
const userPermissions = await getAccess({ ctx }); | ||
|
||
if (!userPermissions.data) { | ||
return { | ||
redirect: { | ||
destination: '/', | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
|
||
const acsessPermitted = requiredPermissions.every((permission) => { | ||
return userPermissions?.data?.includes(permission); | ||
}); | ||
|
||
if (!acsessPermitted) { | ||
return { | ||
redirect: { | ||
destination: '/', | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
const cookies = parseCookies(ctx); | ||
const graphClient = getGraphClient(false, cookies.firebaseToken); | ||
return { | ||
props: { userPermissions }, | ||
}; | ||
} catch { | ||
return { | ||
props: { | ||
isError: true, | ||
}, | ||
}; | ||
} | ||
} |
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,77 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Marginals from '../../components/admin_v2/Marginals/Marginals'; | ||
//mui | ||
import { styled } from '@mui/material/styles'; | ||
import Table from '@mui/material/Table'; | ||
import TableBody from '@mui/material/TableBody'; | ||
import TableCell, { tableCellClasses } from '@mui/material/TableCell'; | ||
import TableHead from '@mui/material/TableHead'; | ||
import TableRow from '@mui/material/TableRow'; | ||
import EditIcon from '@mui/icons-material/Edit'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import Button from '@mui/material/Button'; | ||
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'; | ||
import DialogPoll from '../../components/admin_v2/Poll/PolllDialogBox'; | ||
SUNNYKUMAR1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const StyledTableCell = styled(TableCell)(({ theme }) => ({ | ||
[`&.${tableCellClasses.head}`]: { | ||
backgroundColor: theme.palette.common.black, | ||
color: theme.palette.common.white, | ||
}, | ||
[`&.${tableCellClasses.body}`]: { | ||
fontSize: 13, | ||
}, | ||
})); | ||
|
||
const StyledTableRow = styled(TableRow)(({ theme }) => ({ | ||
'&:nth-of-type(odd)': { | ||
backgroundColor: theme.palette.action.hover, | ||
}, | ||
// hide last border | ||
'&:last-child td, &:last-child th': { | ||
border: 0, | ||
}, | ||
})); | ||
|
||
const Poll = ({ PollList }) => { | ||
const [dialogBoxOpen, setDialogBoxOpen] = useState(false); | ||
const handleDialogBoxOpen = () => setDialogBoxOpen(true); | ||
return ( | ||
<> | ||
<div> | ||
<Marginals> | ||
<DialogPoll | ||
dialogBoxOpen={dialogBoxOpen} | ||
setDialogBoxOpen={setDialogBoxOpen} | ||
/> | ||
<Button | ||
sx={{ | ||
marginBottom: '10px', | ||
}} | ||
variant='contained' | ||
color='primary' | ||
onClick={handleDialogBoxOpen} | ||
> | ||
<AddCircleOutlineIcon sx={{ marginRight: '10px' }} /> | ||
Add Poll | ||
</Button> | ||
<Table sx={{ minWidth: 700 }} stickyHeader aria-label='sticky table'> | ||
<TableHead> | ||
<TableRow> | ||
<StyledTableCell align='left'>Content</StyledTableCell> | ||
<StyledTableCell align='center'>Date</StyledTableCell> | ||
<StyledTableCell align='center'>Timer</StyledTableCell> | ||
<StyledTableCell align='center'>Status</StyledTableCell> | ||
<StyledTableCell align='center'>Edit</StyledTableCell> | ||
<StyledTableCell align='center'>Delete</StyledTableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody></TableBody> | ||
</Table> | ||
<Button>Load More</Button> | ||
</Marginals> | ||
</div> | ||
</> | ||
); | ||
}; | ||
export default Poll; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SUNNYKUMAR1232 can you please remove this part of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done