mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
Merge pull request #747 from Unleash/fix/remove-project
refactor: update remove project function
This commit is contained in:
commit
fafeaa4339
@ -1,18 +1,19 @@
|
|||||||
import { Card, Menu, MenuItem } from '@material-ui/core';
|
import { Card, Menu, MenuItem } from '@material-ui/core';
|
||||||
import { useStyles } from './ProjectCard.styles';
|
import { useStyles } from './ProjectCard.styles';
|
||||||
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
||||||
|
|
||||||
import { ReactComponent as ProjectIcon } from '../../../assets/icons/projectIcon.svg';
|
import { ReactComponent as ProjectIcon } from '../../../assets/icons/projectIcon.svg';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import Dialogue from '../../common/Dialogue';
|
import Dialogue from 'component/common/Dialogue';
|
||||||
import useProjectApi from '../../../hooks/api/actions/useProjectApi/useProjectApi';
|
import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi';
|
||||||
import useProjects from '../../../hooks/api/getters/useProjects/useProjects';
|
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||||
import { Delete, Edit } from '@material-ui/icons';
|
import { Delete, Edit } from '@material-ui/icons';
|
||||||
import { getProjectEditPath } from '../../../utils/route-path-helpers';
|
import { getProjectEditPath } from 'utils/route-path-helpers';
|
||||||
import PermissionIconButton from '../../common/PermissionIconButton/PermissionIconButton';
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
||||||
import useToast from '../../../hooks/useToast';
|
import useToast from 'hooks/useToast';
|
||||||
import { UPDATE_PROJECT } from '../../providers/AccessProvider/permissions';
|
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions';
|
||||||
|
import { formatUnknownError } from 'utils/format-unknown-error';
|
||||||
|
|
||||||
interface IProjectCardProps {
|
interface IProjectCardProps {
|
||||||
name: string;
|
name: string;
|
||||||
featureCount: number;
|
featureCount: number;
|
||||||
@ -22,7 +23,7 @@ interface IProjectCardProps {
|
|||||||
onHover: () => void;
|
onHover: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProjectCard = ({
|
export const ProjectCard = ({
|
||||||
name,
|
name,
|
||||||
featureCount,
|
featureCount,
|
||||||
health,
|
health,
|
||||||
@ -43,6 +44,23 @@ const ProjectCard = ({
|
|||||||
setAnchorEl(e.currentTarget);
|
setAnchorEl(e.currentTarget);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onRemoveProject = async (e: Event) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
await deleteProject(id);
|
||||||
|
refetchProjectOverview();
|
||||||
|
setToastData({
|
||||||
|
title: 'Deleted project',
|
||||||
|
type: 'success',
|
||||||
|
text: 'Successfully deleted project',
|
||||||
|
});
|
||||||
|
} catch (e: unknown) {
|
||||||
|
setToastApiError(formatUnknownError(e));
|
||||||
|
}
|
||||||
|
setShowDelDialog(false);
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={styles.projectCard} onMouseEnter={onHover}>
|
<Card className={styles.projectCard} onMouseEnter={onHover}>
|
||||||
<div className={styles.header} data-loading>
|
<div className={styles.header} data-loading>
|
||||||
@ -71,7 +89,6 @@ const ProjectCard = ({
|
|||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
history.push(getProjectEditPath(id));
|
history.push(getProjectEditPath(id));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -115,27 +132,8 @@ const ProjectCard = ({
|
|||||||
</div>
|
</div>
|
||||||
<Dialogue
|
<Dialogue
|
||||||
open={showDelDialog}
|
open={showDelDialog}
|
||||||
onClick={e => {
|
onClick={onRemoveProject}
|
||||||
e.preventDefault();
|
onClose={() => {
|
||||||
deleteProject(id)
|
|
||||||
.then(() => {
|
|
||||||
setToastData({
|
|
||||||
title: 'Deleted project',
|
|
||||||
type: 'success',
|
|
||||||
text: 'Successfully deleted project',
|
|
||||||
});
|
|
||||||
refetchProjectOverview();
|
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
setToastApiError(e.message);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setShowDelDialog(false);
|
|
||||||
setAnchorEl(null);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onClose={e => {
|
|
||||||
e.preventDefault();
|
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
setShowDelDialog(false);
|
setShowDelDialog(false);
|
||||||
}}
|
}}
|
||||||
@ -144,5 +142,3 @@ const ProjectCard = ({
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProjectCard;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user