import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
import {
Box,
Grid,
IconButton,
Link,
List,
ListItem,
ListItemButton,
styled,
Typography,
} from '@mui/material';
import type { Theme } from '@mui/material/styles/createTheme';
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
import { type FC, useEffect, useState } from 'react';
import { useProfile } from 'hooks/api/getters/useProfile/useProfile';
import LinkIcon from '@mui/icons-material/Link';
import { Badge } from '../common/Badge/Badge';
import { ConnectSDK, CreateFlag } from './ConnectSDK';
import { PlaceholderFlagMetricsChart } from './FlagMetricsChart';
import { WelcomeDialog } from './WelcomeDialog';
import { useLocalStorageState } from 'hooks/useLocalStorageState';
import useProjectOverview from 'hooks/api/getters/useProjectOverview/useProjectOverview';
import { ProjectSetupComplete } from './ProjectSetupComplete';
import { usePersonalDashboard } from 'hooks/api/getters/usePersonalDashboard/usePersonalDashboard';
import { getFeatureTypeIcons } from 'utils/getFeatureTypeIcons';
const ScreenExplanation = styled(Typography)(({ theme }) => ({
marginTop: theme.spacing(1),
marginBottom: theme.spacing(8),
maxWidth: theme.spacing(45),
}));
const StyledHeaderTitle = styled(Typography)(({ theme }) => ({
fontSize: theme.typography.h2.fontSize,
fontWeight: 'normal',
marginBottom: theme.spacing(2),
}));
const ContentGrid = styled(Grid)(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
borderRadius: `${theme.shape.borderRadiusLarge}px`,
}));
const ProjectBox = styled(Box)(({ theme }) => ({
display: 'flex',
gap: theme.spacing(2),
alignItems: 'center',
width: '100%',
}));
const projectStyle = (theme: Theme) => ({
borderRadius: theme.spacing(0.5),
borderLeft: `${theme.spacing(0.5)} solid transparent`,
'&.Mui-selected': {
borderLeft: `${theme.spacing(0.5)} solid ${theme.palette.primary.main}`,
},
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
gap: theme.spacing(1),
});
export const StyledCardTitle = styled('div')<{ lines?: number }>(
({ theme, lines = 2 }) => ({
fontWeight: theme.typography.fontWeightRegular,
fontSize: theme.typography.body1.fontSize,
lineClamp: `${lines}`,
WebkitLineClamp: lines,
lineHeight: '1.2',
display: '-webkit-box',
boxOrient: 'vertical',
textOverflow: 'ellipsis',
overflow: 'hidden',
alignItems: 'flex-start',
WebkitBoxOrient: 'vertical',
wordBreak: 'break-word',
}),
);
const ActiveProjectDetails: FC<{
project: { flags: number; members: number; health: number };
}> = ({ project }) => {
return (
{project.flags}
flags
{project.members}
members
{project.health}%
health
);
};
const SpacedGridItem = styled(Grid)(({ theme }) => ({
padding: theme.spacing(4),
border: `0.5px solid ${theme.palette.divider}`,
}));
const useProjects = () => {
const myProjects = useProfile().profile?.projects || [];
// TODO: add real data for flags/members/health
const projects = myProjects.map((project) => ({
name: project,
flags: 0,
members: 1,
health: 100,
}));
const [activeProject, setActiveProject] = useState(projects[0]?.name);
useEffect(() => {
if (!activeProject && projects.length > 0) {
setActiveProject(projects[0].name);
}
}, [JSON.stringify(projects)]);
return { projects, activeProject, setActiveProject };
};
const FlagListItem: FC<{
flag: { name: string; project: string; type: string };
selected: boolean;
onClick: () => void;
}> = ({ flag, selected, onClick }) => {
const IconComponent = getFeatureTypeIcons(flag.type);
return (
{flag.name}
);
};
export const PersonalDashboard = () => {
const { user } = useAuthUser();
const name = user?.name;
const { projects, activeProject, setActiveProject } = useProjects();
const { personalDashboard } = usePersonalDashboard();
const [activeFlag, setActiveFlag] = useState(null);
useEffect(() => {
if (personalDashboard?.flags.length) {
setActiveFlag(personalDashboard.flags[0].name);
}
}, [JSON.stringify(personalDashboard)]);
const { project: activeProjectOverview, loading } =
useProjectOverview(activeProject);
const onboardingCompleted = Boolean(
!loading &&
activeProject &&
activeProjectOverview?.onboardingStatus.status === 'onboarded',
);
const [welcomeDialog, setWelcomeDialog] = useLocalStorageState<
'seen' | 'not_seen'
>('welcome-dialog:v1', 'not_seen');
return (
Welcome {name}
Here are some tasks we think would be useful in order to get the
most of Unleash
Your resources
My projects
Setup incomplete
{projects.map((project) => {
return (
setActiveProject(project.name)
}
>
{project.name}
{project.name === activeProject ? (
) : null}
);
})}
{onboardingCompleted ? (
) : activeProject ? (
) : null}
{activeProject ? (
) : null}
Your roles in this project:{' '}
Member{' '}
Another
My feature flags
{personalDashboard && personalDashboard.flags.length > 0 ? (
{personalDashboard.flags.map((flag) => (
setActiveFlag(flag.name)}
/>
))}
) : (
You have not created or favorited any feature flags.
Once you do, they will show up here.
)}
Feature flag metrics
setWelcomeDialog('seen')}
/>
);
};