aboutsummaryrefslogtreecommitdiffstats
path: root/webui/src/pages/identity/BugList.tsx
blob: c053d1cf2cf944b9c8334c39545cd2009f6579a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Card, Divider, Link, Typography } from '@material-ui/core';
import CircularProgress from '@material-ui/core/CircularProgress';
import { makeStyles } from '@material-ui/core/styles';

import Date from '../../components/Date';

import { useGetBugsByUserQuery } from './GetBugsByUser.generated';

const useStyles = makeStyles((theme) => ({
  main: {
    ...theme.typography.body2,
  },
  bugLink: {
    ...theme.typography.button,
  },
  cards: {
    backgroundColor: theme.palette.background.default,
    color: theme.palette.info.contrastText,
    padding: theme.spacing(1),
    margin: theme.spacing(1),
  },
}));

type Props = {
  id: string;
};

function BugList({ id }: Props) {
  const classes = useStyles();
  const { loading, error, data } = useGetBugsByUserQuery({
    variables: {
      query: 'author:' + id + ' sort:creation',
    },
  });

  if (loading) return <CircularProgress />;
  if (error) return <p>Error: {error}</p>;
  const bugs = data?.repository?.allBugs.nodes;

  return (
    <div className={classes.main}>
      {bugs?.map((bug, index) => {
        return (
          <Card className={classes.cards} key={index}>
            <Typography variant="overline" component="h2">
              <Link
                className={classes.bugLink}
                href={'/bug/' + bug.id}
                color={'inherit'}
              >
                {bug.title}
              </Link>
            </Typography>
            <Divider />
            <Typography variant="subtitle2">
              Created&nbsp;
              <Date date={bug.createdAt} />
            </Typography>
            <Typography variant="subtitle2">
              Last edited&nbsp;
              <Date date={bug.createdAt} />
            </Typography>
          </Card>
        );
      })}
      {bugs?.length === 0 && <p>No authored bugs by this user found.</p>}
    </div>
  );
}

export default BugList;