Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new user widget #6037

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PageHeader } from 'component/common/PageHeader/PageHeader';
import { VFC } from 'react';
import { UsersChart } from './UsersChart/UsersChart';
import { FlagsChart } from './FlagsChart/FlagsChart';
import { UserStats } from './UserStats/UserStats';

const StyledGrid = styled(Box)(({ theme }) => ({
display: 'grid',
Expand All @@ -26,7 +27,7 @@ export const ExecutiveDashboard: VFC = () => {
</Box>
{/* Dashboard */}
<StyledGrid>
<Paper>Stats</Paper>
<UserStats />
<UsersChart />
<FlagsChart />
</StyledGrid>
Expand Down
223 changes: 223 additions & 0 deletions frontend/src/component/executiveDashboard/UserStats/UserStats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import { ChevronRight } from '@mui/icons-material';
import { Box, Typography, styled } from '@mui/material';
import { Link } from 'react-router-dom';

const StyledContent = styled(Box)(({ theme }) => ({
borderRadius: `${theme.shape.borderRadiusLarge}px`,
backgroundColor: theme.palette.background.paper,
maxWidth: 300,
padding: theme.spacing(3),
}));

const StyledUserContainer = styled(Box)(({ theme }) => ({
position: 'relative',
}));

const StyledUserBox = styled(Box)(({ theme }) => ({
borderRadius: `${theme.shape.borderRadiusExtraLarge}px`,
backgroundColor: theme.palette.primary.main,
maxWidth: 300,
padding: theme.spacing(2),
marginBottom: theme.spacing(3),
position: 'relative',
zIndex: 2,
}));

const StyledCustomShadow = styled(Box)(({ theme }) => ({
width: '220px',
height: '54px',
backgroundColor: 'rgba(108, 101, 229, 0.30)',
position: 'absolute',
margin: '0 auto',
top: '45px',
left: '15px',
borderRadius: `${theme.shape.borderRadiusExtraLarge}px`,
zIndex: 1,
}));

const StyledUserDistributionContainer = styled(Box)(({ theme }) => ({
marginBottom: theme.spacing(2.5),
}));

const StyledUserCount = styled(Typography)(({ theme }) => ({
color: theme.palette.primary.contrastText,
fontWeight: 'bold',
fontSize: theme.fontSizes.extraLargeHeader,
margin: 0,
padding: 0,
}));

const StyledHeader = styled(Typography)(({ theme }) => ({
marginBottom: theme.spacing(3),
fontSize: theme.fontSizes.bodySize,
fontWeight: 'bold',
}));

const StyledDistInfoContainer = styled(Box)({
display: 'flex',
flexDirection: 'column',
gap: '12px',
});

const StyledLinkContainer = styled(Box)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
marginTop: theme.spacing(3),
}));

const StyledLink = styled(Link)({
fontWeight: 'bold',
textDecoration: 'none',
display: 'flex',
justifyContent: 'center',
});

export const UserStats = () => {
return (
<>
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<StyledContent>
<StyledHeader variant='h1'>Total users</StyledHeader>
<StyledUserContainer>
<StyledUserBox>
<StyledUserCount variant='h2'>9999</StyledUserCount>
</StyledUserBox>
<StyledCustomShadow />
</StyledUserContainer>

<StyledUserDistributionContainer>
<UserDistribution />
</StyledUserDistributionContainer>

<StyledDistInfoContainer>
<UserDistributionInfo
type='active'
percentage='70'
count='9999'
/>
<UserDistributionInfo
type='inactive'
percentage='30'
count='9999'
/>
</StyledDistInfoContainer>

<StyledLinkContainer>
<StyledLink to='/admin/users'>
View users <ChevronRight />
</StyledLink>
</StyledLinkContainer>
</StyledContent>
</Box>
</>
);
};

type UserType = 'active' | 'inactive';

interface StyledLinearProgressProps {
type: UserType;
}

const StyledUserDistributionLine = styled(Box)<StyledLinearProgressProps>(
({ theme, type }) => ({
borderRadius: theme.shape.borderRadius,
height: 16,
backgroundColor:
type === 'active'
? theme.palette.success.border
: theme.palette.warning.border,
}),
);

const UserDistribution = () => {
const getLineWidth = () => {
return [80, 20];
};

const [activeWidth, inactiveWidth] = getLineWidth();

return (
<Box sx={{ display: 'flex' }}>
<StyledUserDistributionLine
type='active'
sx={{ width: `${activeWidth}%` }}
/>
<StyledUserDistributionLine
type='inactive'
sx={(theme) => ({
width: `${inactiveWidth}%`,
marginLeft: theme.spacing(0.5),
})}
/>
</Box>
);
};

const StyledUserDistContainer = styled(Box)(({ theme }) => ({
padding: `${theme.spacing(1.5)} ${theme.spacing(2)}`,
borderRadius: `${theme.shape.borderRadius}px`,
border: `1px solid ${theme.palette.divider}`,
}));

const StyledUserDistIndicator = styled(Box)<StyledLinearProgressProps>(
({ theme, type }) => ({
width: 8,
height: 8,
backgroundColor:
type === 'active'
? theme.palette.success.border
: theme.palette.warning.border,
borderRadius: `2px`,
marginRight: theme.spacing(1),
marginTop: theme.spacing(0.8),
}),
);

interface IUserDistributionInfoProps {
type: UserType;
count: string;
percentage: string;
}

const StyledDistInfoInnerContainer = styled(Box)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
width: '100%',
}));

const StyledDistInfoTextContainer = styled(Box)(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
}));

const StyledCountTypography = styled(Typography)(({ theme }) => ({
marginLeft: 'auto',
fontWeight: 'normal',
}));

const UserDistributionInfo: React.FC<IUserDistributionInfoProps> = ({
type,
count,
percentage,
}) => {
return (
<StyledUserDistContainer>
<Box sx={{ display: 'flex' }}>
<StyledUserDistIndicator type={type} />
<StyledDistInfoInnerContainer>
<StyledDistInfoTextContainer>
<Typography variant='body1'>
{type === 'active' ? 'Active' : 'Inactive'} users
</Typography>
<Typography variant='body2'>{percentage}%</Typography>
</StyledDistInfoTextContainer>
<StyledCountTypography variant='h2'>
{count}
</StyledCountTypography>
</StyledDistInfoInnerContainer>
</Box>
</StyledUserDistContainer>
);
};
1 change: 1 addition & 0 deletions frontend/src/themes/dark-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const theme = {
},
},
fontSizes: {
extraLargeHeader: '2.5rem',
largeHeader: '2rem',
mainHeader: '1.25rem',
bodySize: '1rem',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const theme = {
},
},
fontSizes: {
extraLargeHeader: '2.5rem',
largeHeader: '2rem',
mainHeader: '1.25rem',
bodySize: '1rem',
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/themes/themeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module '@mui/material/styles' {
* @deprecated
*/
fontSizes: {
extraLargeHeader: string;
largeHeader: string;
mainHeader: string;
bodySize: string;
Expand Down Expand Up @@ -121,13 +122,16 @@ declare module '@mui/material/styles' {
**/
variants: string[];
}

// biome-ignore lint/suspicious/noEmptyInterface: We need this to keep types from breaking
interface Theme extends CustomTheme {}
// biome-ignore lint/suspicious/noEmptyInterface: We need this to keep types from breaking
interface ThemeOptions extends CustomTheme {}

// biome-ignore lint/suspicious/noEmptyInterface: We need this to keep types from breaking
interface Palette extends CustomPalette {}
// biome-ignore lint/suspicious/noEmptyInterface: We need this to keep types from breaking
interface PaletteOptions extends CustomPalette {}

// biome-ignore lint/suspicious/noEmptyInterface: We need this to keep types from breaking
interface TypeBackground extends CustomTypeBackground {}

/* Extend the background object from MUI */
Expand Down
Loading