aboutsummaryrefslogtreecommitdiffstats
path: root/webui/src/pages/identity/Identity.tsx
blob: 5170eeea54ae6e420cb95ec1c0b1ee7d6fd98455 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React from 'react';
import { Link as RouterLink } from 'react-router-dom';

import { Link, Paper, Typography } from '@material-ui/core';
import Avatar from '@material-ui/core/Avatar';
import CircularProgress from '@material-ui/core/CircularProgress';
import Grid from '@material-ui/core/Grid';
import { makeStyles } from '@material-ui/core/styles';
import InfoIcon from '@material-ui/icons/Info';
import MailOutlineIcon from '@material-ui/icons/MailOutline';

import { IdentityFragment } from '../../components/Identity/IdentityFragment.generated';

import { useGetUserStatisticQuery } from './GetUserStatistic.generated';

const useStyles = makeStyles((theme) => ({
  main: {
    maxWidth: 1000,
    margin: 'auto',
    marginTop: theme.spacing(3),
  },
  content: {
    padding: theme.spacing(0.5, 2, 2, 2),
    wordWrap: 'break-word',
  },
  large: {
    minWidth: 200,
    minHeight: 200,
    margin: 'auto',
    maxWidth: '100%',
    maxHeight: '100%',
  },
  heading: {
    marginTop: theme.spacing(3),
  },
  header: {
    ...theme.typography.h4,
    wordBreak: 'break-word',
  },
  infoIcon: {
    verticalAlign: 'bottom',
  },
}));

type Props = {
  identity: IdentityFragment;
};
const Identity = ({ identity }: Props) => {
  const classes = useStyles();
  const user = identity;

  const { loading, error, data } = useGetUserStatisticQuery({
    variables: {
      authorQuery: 'author:' + user?.id,
      participantQuery: 'participant:' + user?.id,
      actionQuery: 'actor:' + user?.id,
    },
  });

  if (loading) return <CircularProgress />;
  if (error) return <p>Error: {error}</p>;
  const statistic = data?.repository;
  const authoredCount = statistic?.authored?.totalCount;
  const participatedCount = statistic?.participated?.totalCount;
  const actionCount = statistic?.actions?.totalCount;

  return (
    <main className={classes.main}>
      <Paper elevation={3} className={classes.content}>
        <Grid spacing={2} container direction="row">
          <Grid xs={12} sm={4} className={classes.heading} item>
            <Avatar
              src={user?.avatarUrl ? user.avatarUrl : undefined}
              className={classes.large}
            >
              {user?.displayName.charAt(0).toUpperCase()}
            </Avatar>
          </Grid>
          <Grid xs={12} sm={4} item>
            <section>
              <h1 className={classes.header}>{user?.name}</h1>
              <Typography variant="subtitle1">
                Name: {user?.displayName ? user?.displayName : '---'}
              </Typography>
              <Typography variant="subtitle1">
                Id (truncated): {user?.humanId ? user?.humanId : '---'}
                <InfoIcon
                  titleAccess={user?.id ? user?.id : '---'}
                  className={classes.infoIcon}
                />
              </Typography>
              {user?.email && (
                <Typography
                  variant="subtitle1"
                  style={{
                    display: 'flex',
                    alignItems: 'center',
                    flexWrap: 'wrap',
                  }}
                >
                  <MailOutlineIcon />
                  <Link href={'mailto:' + user?.email} color={'inherit'}>
                    {user?.email}
                  </Link>
                </Typography>
              )}
            </section>
          </Grid>
          <Grid xs={12} sm={4} item>
            <section>
              <h1 className={classes.header}>Statistics</h1>
              <Link
                component={RouterLink}
                to={`/?q=author%3A${user?.id}+sort%3Acreation`}
                color={'inherit'}
              >
                <Typography variant="subtitle1">
                  Created {authoredCount} bugs.
                </Typography>
              </Link>
              <Link
                component={RouterLink}
                to={`/?q=participant%3A${user?.id}+sort%3Acreation`}
                color={'inherit'}
              >
                <Typography variant="subtitle1">
                  Participated to {participatedCount} bugs.
                </Typography>
              </Link>
              <Link
                component={RouterLink}
                to={`/?q=actor%3A${user?.id}+sort%3Acreation`}
                color={'inherit'}
              >
                <Typography variant="subtitle1">
                  Interacted with {actionCount} bugs.
                </Typography>
              </Link>
            </section>
          </Grid>
        </Grid>
      </Paper>
    </main>
  );
};

export default Identity;