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

add a certification dialog box for printing. #46

Merged
merged 4 commits into from
Nov 18, 2021
Merged
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
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-to-print": "^2.13.0",
"web-vitals": "^1.0.1"
},
"devDependencies": {
Expand Down
Binary file added public/assets/images/pring-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 86 additions & 2 deletions src/views/User/User/User.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import Grid from '@material-ui/core/Grid';
import Container from '@material-ui/core/Container';
import Typography from '@material-ui/core/Typography';
import Card from '@material-ui/core/Card';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';

import InstagramIcon from '@material-ui/icons/Instagram';
import TwitterIcon from '@material-ui/icons/Twitter';
Expand Down Expand Up @@ -39,7 +41,12 @@ import DataJoinEditor from 'components/DataJoinEditor';
import ContributionHeatmap from './ContributionHeatmap';
import RichText from 'components/RichText';
import Loading from 'components/Loading';

import Button from '@material-ui/core/Button';
import ReactToPrint from 'react-to-print';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableRow from '@material-ui/core/TableRow';
const useStyles = makeStyles((theme) => ({
container: {
paddingTop: theme.spacing(2),
Expand All @@ -61,13 +68,36 @@ const useStyles = makeStyles((theme) => ({
header: {
marginTop: theme.spacing(2),
},

certification: {
'& h2': {
textAlign: 'center',
height: '2rem',
verticalAlign: 'middle',
},
'& div': {
textAlign: 'center',
},
'textAlign': 'center',
'fontSize': '0.8rem',
'padding': '5mm',
'margin': '2mm',
},

g0vOnly: {
height: '2rem',
verticalAlign: 'middle',
marginLeft: '0.2rem',
marginBottom: '0.2rem',
},
}));

const todayFromBeginning = moment().startOf('day');
const today = moment().endOf('day');
const aYearAgo = moment().add(-1, 'years').startOf('day');

export default function User({ id: inId, computedMatch, match }) {
const componentRef = useRef();
const classes = useStyles();
const { t } = useTranslation();

Expand All @@ -83,6 +113,7 @@ export default function User({ id: inId, computedMatch, match }) {
const [needs, setNeeds] = useState([]);
const [canEdit, setCanEdit] = useState(false);
const [lastUpdatedAt, setLastUpdatedAt] = useState(Date.now());
const [open, setOpen] = useState(false);

useEffect(() => {
if (inId) {
Expand Down Expand Up @@ -225,8 +256,58 @@ export default function User({ id: inId, computedMatch, match }) {
return <Loading fullScreen={false} />;
}

const handleClickOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

const formatDate = (date) => date.substring(0, 10);

return (
<Container className={classes.container}>
<Dialog open={open}>
<Card variant="outlined" ref={componentRef} className={classes.certification}>
<div>
<img src="/assets/images/pring-logo.png"/>
</div>
<p>
Congratulation to {user.name} for contributing {userProjects.length} project,
to finshed {user.totalCompletedTasks} missions in {user.totalCompletedHours} hours.<br/>
<br/>
You are the best!......Hooray!!!!!
</p>
<h2>
Contribution Summarize
</h2>
Contributed Projects {userProjects.length}, Total Contributed Hours {user.totalCompletedHours},
Total Completed Tasks {user.totalCompletedTasks}

<Table>
<TableBody>
{userProjects.map((up)=>(
<TableRow key={up.project.name}>
<TableCell style={{ borderBottom: 'none' }}>{up.project.name}</TableCell>
<TableCell style={{ borderBottom: 'none' }}>{up.completedTasks} Missions,
{up.completedHours} Hours from {formatDate(up.project.createdAt)} to {formatDate(up.project.updatedAt)}.</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<h2>POWERED BY <img className={classes.g0vOnly} src="/assets/images/g0v-only.svg"/></h2>
{new Date().getFullYear()}&sdot;{new Date().getMonth()+1}&sdot;{new Date().getDate()}
</Card>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<ReactToPrint
trigger={() => <Button onClick={handleClose}>Print</Button>}
content={() => componentRef.current}
/>
</DialogActions>
</Dialog>

<Card className={classes.card}>
<Grid container spacing={4}>
<Grid item xs={12} md={3}>
Expand Down Expand Up @@ -257,6 +338,9 @@ export default function User({ id: inId, computedMatch, match }) {
onUpdate={() => setLastUpdatedAt(Date.now())}
/>
</Grid>}
<Grid item xs={12}>
<Button fullWidth={true} size='small' variant='outlined' onClick={handleClickOpen}>Certification</Button>
</Grid>
<Grid item xs={12}>
{details.map((item, index)=>(
<div key={index} className={classes.listItem}>
Expand Down
11 changes: 9 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13208,7 +13208,7 @@
"prop-types" "^15.5.6"
"react-side-effect" "^1.0.2"

"react-dom@*", "react-dom@^0.14 || ^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0", "react-dom@^16.6.1 || ^17", "react-dom@^16.8.0 || ^17.0.0", "react-dom@^16.8.6 || 17.0.x", "react-dom@^17.0.2", "react-dom@>= 16.7.0", "react-dom@>=0.14.0", "react-dom@>=16.3.0", "react-dom@>=16.6.0":
"react-dom@*", "react-dom@^0.14 || ^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0", "react-dom@^15.0.0 || ^16.0.0 || ^17.0.0", "react-dom@^16.6.1 || ^17", "react-dom@^16.8.0 || ^17.0.0", "react-dom@^16.8.6 || 17.0.x", "react-dom@^17.0.2", "react-dom@>= 16.7.0", "react-dom@>=0.14.0", "react-dom@>=16.3.0", "react-dom@>=16.6.0":
"integrity" "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA=="
"resolved" "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz"
"version" "17.0.2"
Expand Down Expand Up @@ -13457,6 +13457,13 @@
dependencies:
"shallowequal" "^1.0.1"

"react-to-print@^2.13.0":
"integrity" "sha512-JMX+HrMtBXWDh2ohPT2IeBkaGY4QpFeloXTXBA7hBK7dXJQei/UXMvQqbZHb0rqJwzAHltZ2zXevuSK/ReKI5w=="
"resolved" "https://registry.npmjs.org/react-to-print/-/react-to-print-2.13.0.tgz"
"version" "2.13.0"
dependencies:
"prop-types" "^15.7.2"

"react-transition-group@^4.4.0":
"integrity" "sha512-Djqr7OQ2aPUiYurhPalTrVy9ddmFCCzwhqQmtN+J3+3DzLO209Fdr70QrN8Z3DsglWql6iY1lDWAfpFiBtuKGw=="
"resolved" "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.1.tgz"
Expand All @@ -13467,7 +13474,7 @@
"loose-envify" "^1.4.0"
"prop-types" "^15.6.2"

"react@*", "react@^0.14 || ^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0", "react@^0.14 || ^15.0.1 || ^16.0.0", "react@^0.14.0 || ^15.0.0 || ^16.0.0", "react@^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0", "react@^16.6.1 || ^17", "react@^16.8.0 || ^17.0.0", "react@^16.8.3 || ^17", "react@^16.8.6 || 17.0.x", "react@^17.0.2", "react@>= 16", "react@>= 16.7.0", "react@>= 16.8.0", "react@>=0.14.0", "react@>=15", "react@>=15.0.0", "react@>=16", "react@>=16.3.0", "react@>=16.6.0", "react@>=16.8.0", "react@16.x", "react@17.0.2":
"react@*", "react@^0.14 || ^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0", "react@^0.14 || ^15.0.1 || ^16.0.0", "react@^0.14.0 || ^15.0.0 || ^16.0.0", "react@^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0", "react@^15.0.0 || ^16.0.0 || ^17.0.0", "react@^16.6.1 || ^17", "react@^16.8.0 || ^17.0.0", "react@^16.8.3 || ^17", "react@^16.8.6 || 17.0.x", "react@^17.0.2", "react@>= 16", "react@>= 16.7.0", "react@>= 16.8.0", "react@>=0.14.0", "react@>=15", "react@>=15.0.0", "react@>=16", "react@>=16.3.0", "react@>=16.6.0", "react@>=16.8.0", "react@16.x", "react@17.0.2":
"integrity" "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA=="
"resolved" "https://registry.npmjs.org/react/-/react-17.0.2.tgz"
"version" "17.0.2"
Expand Down