import { useHistory, useParams } from 'react-router';
import useProject from 'hooks/api/getters/useProject/useProject';
import useLoading from 'hooks/useLoading';
import ApiError from 'component/common/ApiError/ApiError';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useStyles } from './Project.styles';
import { Tab, Tabs } from '@mui/material';
import { Edit } from '@mui/icons-material';
import useToast from 'hooks/useToast';
import useQueryParams from 'hooks/useQueryParams';
import { useEffect } from 'react';
import { ProjectAccess } from '../ProjectAccess/ProjectAccess';
import ProjectEnvironment from '../ProjectEnvironment/ProjectEnvironment';
import { ProjectFeaturesArchive } from './ProjectFeaturesArchive/ProjectFeaturesArchive';
import ProjectOverview from './ProjectOverview';
import ProjectHealth from './ProjectHealth/ProjectHealth';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions';
import { TabPanel } from 'component/common/TabNav/TabPanel/TabPanel';
const Project = () => {
const { id, activeTab } = useParams<{ id: string; activeTab: string }>();
const params = useQueryParams();
const { project, error, loading, refetch } = useProject(id);
const ref = useLoading(loading);
const { setToastData } = useToast();
const { classes: styles } = useStyles();
const history = useHistory();
const basePath = `/projects/${id}`;
const tabData = [
{
title: 'Overview',
component: ,
path: basePath,
name: 'overview',
},
{
title: 'Health',
component: ,
path: `${basePath}/health`,
name: 'health',
},
{
title: 'Access',
component: ,
path: `${basePath}/access`,
name: 'access',
},
{
title: 'Environments',
component: ,
path: `${basePath}/environments`,
name: 'environments',
},
{
title: 'Archive',
component: ,
path: `${basePath}/archive`,
name: 'archive',
},
];
const activeTabIdx = activeTab
? tabData.findIndex(tab => tab.name === activeTab)
: 0;
useEffect(() => {
const created = params.get('created');
const edited = params.get('edited');
if (created || edited) {
const text = created ? 'Project created' : 'Project updated';
setToastData({
type: 'success',
title: text,
});
}
// @ts-expect-error
tabData.filter(tab => !tab.disabled);
/* eslint-disable-next-line */
}, []);
const renderTabs = () => {
return tabData.map((tab, index) => {
return (
history.push(tab.path)}
className={styles.tabButton}
/>
);
});
};
const renderTabContent = () => {
return tabData.map((tab, index) => {
return (
{tab.component}
);
});
};
return (
{project?.name}
history.push(`/projects/${id}/edit`)}
tooltip="Edit project"
data-loading
>
}
/>
{renderTabs()}
{renderTabContent()}
);
};
export default Project;