delete mission
This commit is contained in:
@@ -76,6 +76,9 @@ const MissionsPage = () => {
|
|||||||
onRunMission={() => {
|
onRunMission={() => {
|
||||||
refetch();
|
refetch();
|
||||||
}}
|
}}
|
||||||
|
onDeleteMission={() => {
|
||||||
|
refetch();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { Process, selectTheme } from "@/data/consts";
|
|||||||
import { Button, Switch } from "@material-tailwind/react";
|
import { Button, Switch } from "@material-tailwind/react";
|
||||||
import { useMutation, useQuery } from "@apollo/client";
|
import { useMutation, useQuery } from "@apollo/client";
|
||||||
import {
|
import {
|
||||||
|
DELETE_MISSION,
|
||||||
GET_AGENTS,
|
GET_AGENTS,
|
||||||
RUN_MISSION,
|
RUN_MISSION,
|
||||||
UPDATE_MISSION,
|
UPDATE_MISSION,
|
||||||
@@ -34,6 +35,7 @@ export default function MissionModal(props: {
|
|||||||
setShowModal: Function;
|
setShowModal: Function;
|
||||||
onUpdateMission?: Function;
|
onUpdateMission?: Function;
|
||||||
onRunMission?: Function;
|
onRunMission?: Function;
|
||||||
|
onDeleteMission?: Function;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const {
|
const {
|
||||||
mission,
|
mission,
|
||||||
@@ -41,6 +43,7 @@ export default function MissionModal(props: {
|
|||||||
setShowModal,
|
setShowModal,
|
||||||
onUpdateMission = () => {},
|
onUpdateMission = () => {},
|
||||||
onRunMission = () => {},
|
onRunMission = () => {},
|
||||||
|
onDeleteMission = () => {},
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isEdit, setEdit] = useState(false);
|
const [isEdit, setEdit] = useState(false);
|
||||||
@@ -97,6 +100,20 @@ export default function MissionModal(props: {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [deleteMission] = useMutation(DELETE_MISSION);
|
||||||
|
const [deleteMissionLoading, setDeleteMissionLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleDeleteMission = async () => {
|
||||||
|
setDeleteMissionLoading(true);
|
||||||
|
return deleteMission({
|
||||||
|
variables: {
|
||||||
|
id: Number.parseInt(mission.id as string),
|
||||||
|
},
|
||||||
|
}).finally(() => {
|
||||||
|
setDeleteMissionLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TEModal show={showModal} setShow={setShowModal}>
|
<TEModal show={showModal} setShow={setShowModal}>
|
||||||
@@ -323,15 +340,52 @@ export default function MissionModal(props: {
|
|||||||
{/* Update Mission */}
|
{/* Update Mission */}
|
||||||
<TEModalFooter>
|
<TEModalFooter>
|
||||||
{!isEdit && (
|
{!isEdit && (
|
||||||
<TERipple rippleColor="light">
|
<>
|
||||||
<Button
|
<TERipple rippleColor="light">
|
||||||
color="green"
|
<Button
|
||||||
onClick={() => setEdit(true)}
|
color="red"
|
||||||
placeholder={undefined}
|
className="mx-1"
|
||||||
>
|
loading={deleteMissionLoading}
|
||||||
Edit
|
onClick={() => {
|
||||||
</Button>
|
ReactSwal.fire({
|
||||||
</TERipple>
|
title: "Pay Attention",
|
||||||
|
text: "Are you sure you want to delete this mission?",
|
||||||
|
icon: "error",
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
handleDeleteMission().then(() => {
|
||||||
|
setShowModal(false);
|
||||||
|
onDeleteMission();
|
||||||
|
ReactSwal.fire({
|
||||||
|
title: "Deleted",
|
||||||
|
text: "Mission deleted successfully",
|
||||||
|
icon: "success",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
ReactSwal.fire({
|
||||||
|
title: "Error",
|
||||||
|
text: error,
|
||||||
|
icon: "warning",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
placeholder={undefined}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</TERipple>
|
||||||
|
<TERipple rippleColor="light">
|
||||||
|
<Button
|
||||||
|
color="green"
|
||||||
|
onClick={() => setEdit(true)}
|
||||||
|
placeholder={undefined}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</TERipple>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{isEdit && (
|
{isEdit && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user