Skip to content
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

Added Squiggles management system #481

Open
wants to merge 2 commits into
base: feat/admin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["next/core-web-vitals", "prettier"],
"extends": ["next/core-web-vitals","next/babel", "prettier"],
Pratyush2722 marked this conversation as resolved.
Show resolved Hide resolved
"rules": {
"no-plusplus": 0,
"react/jsx-props-no-spreading": 0,
Expand Down
13 changes: 13 additions & 0 deletions client/src/graphql/queries/squiggles/getSquigglesById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';

const getSquigglesById = gql`
query ($getSquigglesByIdId: ID!) {
getSquigglesByID(id: $getSquigglesByIdId) {
id
content
createdAt
}
}
`;

export default getSquigglesById;
13 changes: 13 additions & 0 deletions client/src/graphql/queries/squiggles/listSquiggles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';

const listSquiggles = gql`
query ($offset: Int, $limit: Int) {
listSquiggles(offset: $offset, limit: $limit) {
content
createdAt
id
}
}
`;

export default listSquiggles;
66 changes: 66 additions & 0 deletions client/src/pages/admin_v2/squiggle/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import Squiggle from '../../../screens/admin_v2/Squiggle';
import Custom500 from '../../500.jsx';
import getAccess from '../../../utils/getAccess';
import { parseCookies } from 'nookies';
import { getGraphClient } from '../../../context/ApolloContextProvider';
import listSquiggles from '../../../graphql/queries/squiggles/listSquiggles'
const SquigglePage = ({ isError, squiggles }) => {
if (isError) {
return <Custom500 />;
}

return <Squiggle squiggles={squiggles} />;
};

export default SquigglePage;


export async function getServerSideProps(ctx) {
try {
const requiredPermissions = ['squiggle.read.all'];
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);

const {
data: { listSquiggles: squiggles },
} = await graphClient.query({
query: listSquiggles,
variables: {
limit: 10,
offset: 0,
},
});
return {
props: { squiggles, userPermissions },
};
} catch {
return {
props: {
isError: true,
},
};
}
}
103 changes: 103 additions & 0 deletions client/src/screens/admin_v2/Squiggle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { useEffect, useState } from 'react';
Pratyush2722 marked this conversation as resolved.
Show resolved Hide resolved
import Marginals from '../../components/admin_v2/Marginals/Marginals';
import { Button } from '@mui/material';
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Delete';
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 { styled } from '@mui/material/styles';
import listSquiggles from '../../graphql/queries/squiggles/listSquiggles';
// import SquiggleDialogBox from '../../components/admin_v2/Squiggles/SquiggleDialogBox';
Pratyush2722 marked this conversation as resolved.
Show resolved Hide resolved
import { getGraphClient } from '../../context/ApolloContextProvider';


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,
},
'&:last-child td, &:last-child th': {
border: 0,
},
}));
const Squiggle = ({ squiggles }) => {
const graphClient = getGraphClient(true);
const [squiggleList, setSquiggleList] = useState(squiggles || []);
const [offset, setOffset] = useState(0);
const getMoreSquiggles = async () => {
// setDialogBoxOpen(true);
Pratyush2722 marked this conversation as resolved.
Show resolved Hide resolved
const {
data: { listSquiggles: squiggles },
} = await graphClient.query({
query: listSquiggles,
variables: {
limit: 9,
offset: offset + 10,
},
});
setOffset((prev) => prev + 10);
setSquiggleList((prev) => [...prev, ...squiggles])
};
return (
<div>
<Marginals>
<Button
sx={{
marginBottom: '10px',
}}
variant='contained'
color='secondary'
onClick={() => {
// setAction('Add'), setDialogBoxOpen(true);
}}>
Pratyush2722 marked this conversation as resolved.
Show resolved Hide resolved
<AddCircleOutlineIcon sx={{ marginRight: '10px' }} />
Add Squiggle
</Button>
<Table sx={{ minWidth: 700 }} stickyHeader aria-label='sticky table'>
<TableHead>
<TableRow>
<StyledTableCell>Squiggle</StyledTableCell>
<StyledTableCell align='left'>Created Date</StyledTableCell>
<StyledTableCell align='center'>Edit</StyledTableCell>
<StyledTableCell align='center'>Delete</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{squiggleList.map((data, index) => {
return (
<StyledTableRow key={index}>
<StyledTableCell scope='row'>{data.content}</StyledTableCell>
<StyledTableCell align='left'>
{data.createdAt}
</StyledTableCell>
<StyledTableCell align='center'>
<EditIcon />
</StyledTableCell>
<StyledTableCell align='center'>
<DeleteIcon />
</StyledTableCell>
</StyledTableRow>
)
})}
</TableBody>
</Table>
<Button onClick={() => getMoreSquiggles()}>Load More</Button>
</Marginals>
</div>
)
}

export default Squiggle