|
| 1 | +/** |
| 2 | + * This is a modal window for quality status overview |
| 3 | + */ |
| 4 | + |
| 5 | +import React, { memo, useCallback, useContext, useState } from 'react'; |
| 6 | +import { Dialog, DialogContent, Divider, Grid, IconButton, makeStyles, Popover, Table, TableBody, TableCell, TableRow, TextField, Tooltip, Typography } from '@material-ui/core'; |
| 7 | +import { QualityStatusLight } from './QualityStatusLight'; |
| 8 | +import { QUALITY_STATUSES } from './constants'; |
| 9 | +import { Add, Check } from '@material-ui/icons'; |
| 10 | +import classNames from 'classnames'; |
| 11 | +import { addPeerReviewStatus } from './api/apiActions'; |
| 12 | +import { useDispatch } from 'react-redux'; |
| 13 | +import { ToastContext } from '../../../../toast'; |
| 14 | + |
| 15 | +const useStyles = makeStyles(theme => ({ |
| 16 | + root: { |
| 17 | + padding: 16, |
| 18 | + minWidth: 260, |
| 19 | + '& $gridItem': { |
| 20 | + padding: 4 |
| 21 | + } |
| 22 | + }, |
| 23 | + gridItem: { |
| 24 | + // padding: 4 |
| 25 | + }, |
| 26 | + paper: { |
| 27 | + overflow: 'hidden' |
| 28 | + }, |
| 29 | + highlight: { |
| 30 | + boxShadow: '0px 0px 0px 2px #ccc', |
| 31 | + borderRadius: 5 |
| 32 | + }, |
| 33 | + statusLight: { |
| 34 | + cursor: 'pointer' |
| 35 | + } |
| 36 | +})); |
| 37 | + |
| 38 | +export const PeerReviewModal = memo(({ openDialog, onDialogClose, anchorEl, site_observation }) => { |
| 39 | + |
| 40 | + const dispatch = useDispatch(); |
| 41 | + const classes = useStyles(); |
| 42 | + const [comment, setComment] = useState(''); |
| 43 | + const [selectedStatus, setSelectedStatus] = useState(QUALITY_STATUSES.NONE); |
| 44 | + |
| 45 | + const { toastInfo } = useContext(ToastContext); |
| 46 | + |
| 47 | + const addPeerReviewStatusHandler = () => { |
| 48 | + dispatch(addPeerReviewStatus({ status: selectedStatus, comment: comment, site_observation: site_observation })); |
| 49 | + toastInfo('Peer review was added', { autoHideDuration: 5000 }); |
| 50 | + onDialogClose(); |
| 51 | + }; |
| 52 | + |
| 53 | + return ( |
| 54 | + <Popover |
| 55 | + // id={id} |
| 56 | + open={openDialog} |
| 57 | + anchorEl={anchorEl} |
| 58 | + onClose={onDialogClose} |
| 59 | + anchorOrigin={{ |
| 60 | + vertical: 'center', |
| 61 | + horizontal: 'right' |
| 62 | + }} |
| 63 | + classes={{ paper: classes.paper }} |
| 64 | + > |
| 65 | + <Grid container justifyContent="flex-start" direction="column" spacing={2} className={classes.root}> |
| 66 | + <Grid item container direction="row" justifyContent="space-between" alignItems="center" spacing={2}> |
| 67 | + <Grid className={classes.gridItem} item xs={4}> |
| 68 | + <Typography variant="body1">Set status:</Typography> |
| 69 | + </Grid> |
| 70 | + {Object.values(QUALITY_STATUSES).map((status, index) => ( |
| 71 | + <Grid key={index} item xs |
| 72 | + className={classNames(classes.gridItem, classes.statusLight)} |
| 73 | + onClick={() => setSelectedStatus(status)} |
| 74 | + > |
| 75 | + <QualityStatusLight size={16} status={status} props={{ className: classNames({ [classes.highlight]: status === selectedStatus }) }} /> |
| 76 | + </Grid> |
| 77 | + ))} |
| 78 | + <Tooltip title={'Add peer review'}> |
| 79 | + <Grid className={classes.gridItem} item xs> |
| 80 | + <IconButton size="small" onClick={addPeerReviewStatusHandler} disabled={!comment}> |
| 81 | + <Check /> |
| 82 | + </IconButton> |
| 83 | + </Grid> |
| 84 | + </Tooltip> |
| 85 | + </Grid> |
| 86 | + <Grid item container direction="row" justifyContent="space-between" alignItems="center" spacing={2}> |
| 87 | + <Grid className={classes.gridItem} item xs={5}> |
| 88 | + <Typography variant="body1">Add comment:</Typography> |
| 89 | + </Grid> |
| 90 | + <Grid className={classes.gridItem} item xs> |
| 91 | + <TextField value={comment} onChange={event => setComment(event.target.value)} placeholder='write a comment' /> |
| 92 | + </Grid> |
| 93 | + </Grid> |
| 94 | + </Grid> |
| 95 | + </Popover> |
| 96 | + ); |
| 97 | +}); |
0 commit comments