1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-07 01:16:28 +02:00
unleash.unleash/frontend/src/component/project/ProjectCard/ProjectCardFooter/ProjectOwners/ProjectOwners.tsx
Thomas Heartman 6655b2d961
feat: create page for when you have no projects (#8285)
This adds a front end fallback screen for when you have no projects.


![image](https://github.com/user-attachments/assets/1e6e0a63-968a-43cf-84ee-9a67d9f0ca91)
2024-09-27 10:41:25 +02:00

92 lines
2.7 KiB
TypeScript

import type { FC } from 'react';
import { styled } from '@mui/material';
import type { ProjectSchema, ProjectSchemaOwners } from 'openapi';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { AvatarComponent } from 'component/common/AvatarGroup/AvatarGroup';
import { AvatarGroupFromOwners } from 'component/common/AvatarGroupFromOwners/AvatarGroupFromOwners';
export interface IProjectOwnersProps {
owners?: ProjectSchema['owners'];
}
const StyledUserName = styled('span')(({ theme }) => ({
fontSize: theme.typography.body2.fontSize,
lineHeight: 1,
lineClamp: `1`,
WebkitLineClamp: 1,
display: '-webkit-box',
boxOrient: 'vertical',
textOverflow: 'ellipsis',
overflow: 'hidden',
alignItems: 'flex-start',
WebkitBoxOrient: 'vertical',
wordBreak: 'break-word',
maxWidth: '100%',
}));
const StyledContainer = styled('div')(() => ({
display: 'flex',
flexDirection: 'column',
borderRadius: '50%',
}));
const StyledOwnerName = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(0.25),
margin: theme.spacing(0, 0, 0, 1),
}));
const StyledHeader = styled('span')(({ theme }) => ({
lineHeight: 1,
fontSize: theme.fontSizes.smallerBody,
color: theme.palette.text.secondary,
fontWeight: theme.typography.fontWeightRegular,
marginRight: 'auto',
}));
const StyledWrapper = styled('div')(({ theme }) => ({
padding: theme.spacing(1.5, 0, 1.5, 2),
display: 'flex',
alignItems: 'center',
}));
const StyledAvatarComponent = styled(AvatarComponent)(({ theme }) => ({
cursor: 'default',
}));
const getOwnerName = (owner?: ProjectSchemaOwners[number]) => {
switch (owner?.ownerType) {
case 'user':
case 'group':
return owner.name;
default:
return 'System';
}
};
export const ProjectOwners: FC<IProjectOwnersProps> = ({ owners = [] }) => {
return (
<StyledWrapper data-testid='test'>
<StyledContainer data-loading>
<AvatarGroupFromOwners
users={owners}
avatarLimit={6}
AvatarComponent={StyledAvatarComponent}
/>
</StyledContainer>
<ConditionallyRender
condition={owners.length === 1}
show={
<StyledOwnerName>
<StyledHeader data-loading>Owner</StyledHeader>
<StyledUserName data-loading>
{getOwnerName(owners[0])}
</StyledUserName>
</StyledOwnerName>
}
/>
</StyledWrapper>
);
};