/
GroupCard.tsx
156 lines (144 loc) · 5.75 KB
/
GroupCard.tsx
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
148
149
150
151
152
153
154
155
156
import { styled, Tooltip } from '@mui/material';
import { IGroup } from 'interfaces/group';
import { Link, useNavigate } from 'react-router-dom';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { GroupCardAvatars } from './GroupCardAvatars/GroupCardAvatars';
import { Badge } from 'component/common/Badge/Badge';
import { GroupCardActions } from './GroupCardActions/GroupCardActions';
import TopicOutlinedIcon from '@mui/icons-material/TopicOutlined';
const StyledLink = styled(Link)(({ theme }) => ({
textDecoration: 'none',
color: theme.palette.text.primary,
}));
const StyledGroupCard = styled('aside')(({ theme }) => ({
padding: theme.spacing(2.5),
height: '100%',
border: `1px solid ${theme.palette.dividerAlternative}`,
borderRadius: theme.shape.borderRadiusLarge,
boxShadow: theme.boxShadows.card,
display: 'flex',
flexDirection: 'column',
[theme.breakpoints.up('md')]: {
padding: theme.spacing(4),
},
'&:hover': {
transition: 'background-color 0.2s ease-in-out',
backgroundColor: theme.palette.neutral.light,
},
}));
const StyledRow = styled('div')(() => ({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}));
const StyledTitleRow = styled(StyledRow)(() => ({
alignItems: 'flex-start',
}));
const StyledBottomRow = styled(StyledRow)(() => ({
marginTop: 'auto',
}));
const StyledHeaderTitle = styled('h2')(({ theme }) => ({
fontSize: theme.fontSizes.mainHeader,
fontWeight: theme.fontWeight.medium,
}));
const StyledHeaderActions = styled('div')(({ theme }) => ({
display: 'flex',
alignItems: 'center',
color: theme.palette.text.secondary,
fontSize: theme.fontSizes.smallBody,
}));
const StyledDescription = styled('p')(({ theme }) => ({
color: theme.palette.text.secondary,
fontSize: theme.fontSizes.smallBody,
marginTop: theme.spacing(1),
marginBottom: theme.spacing(4),
}));
const StyledCounterDescription = styled('span')(({ theme }) => ({
color: theme.palette.text.secondary,
marginLeft: theme.spacing(1),
}));
const ProjectBadgeContainer = styled('div')(({ theme }) => ({
maxWidth: '50%',
display: 'flex',
justifyContent: 'flex-end',
gap: theme.spacing(0.5),
flexWrap: 'wrap',
}));
interface IGroupCardProps {
group: IGroup;
onEditUsers: (group: IGroup) => void;
onRemoveGroup: (group: IGroup) => void;
}
export const GroupCard = ({
group,
onEditUsers,
onRemoveGroup,
}: IGroupCardProps) => {
const navigate = useNavigate();
return (
<>
<StyledLink key={group.id} to={`/admin/groups/${group.id}`}>
<StyledGroupCard>
<StyledTitleRow>
<StyledHeaderTitle>{group.name}</StyledHeaderTitle>
<StyledHeaderActions>
<GroupCardActions
groupId={group.id}
onEditUsers={() => onEditUsers(group)}
onRemove={() => onRemoveGroup(group)}
/>
</StyledHeaderActions>
</StyledTitleRow>
<StyledDescription>{group.description}</StyledDescription>
<StyledBottomRow>
<ConditionallyRender
condition={group.users?.length > 0}
show={<GroupCardAvatars users={group.users} />}
elseShow={
<StyledCounterDescription>
This group has no users.
</StyledCounterDescription>
}
/>
<ProjectBadgeContainer>
<ConditionallyRender
condition={group.projects.length > 0}
show={group.projects.map(project => (
<Tooltip
key={project}
title="View project"
arrow
placement="bottom-end"
describeChild
>
<Badge
onClick={e => {
e.preventDefault();
navigate(
`/projects/${project}/settings/access`
);
}}
color="secondary"
icon={<TopicOutlinedIcon />}
>
{project}
</Badge>
</Tooltip>
))}
elseShow={
<Tooltip
title="This group is not used in any project"
arrow
describeChild
>
<Badge>Not used</Badge>
</Tooltip>
}
/>
</ProjectBadgeContainer>
</StyledBottomRow>
</StyledGroupCard>
</StyledLink>
</>
);
};