2022-11-13 10:29:25 +00:00
|
|
|
import { useMutation } from 'react-query';
|
2022-11-28 02:00:28 +00:00
|
|
|
import { Trash2 } from 'lucide-react';
|
2022-11-13 10:29:25 +00:00
|
|
|
|
|
|
|
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
|
|
|
|
import { Job } from '@/react/nomad/types';
|
|
|
|
|
2023-02-14 08:19:41 +00:00
|
|
|
import { confirmDelete } from '@@/modals/confirm';
|
2022-11-13 10:29:25 +00:00
|
|
|
import { LoadingButton } from '@@/buttons/LoadingButton';
|
|
|
|
|
|
|
|
import { deleteJobs } from './delete';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
selectedItems: Job[];
|
|
|
|
refreshData: () => Promise<void> | void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function JobActions({ selectedItems, refreshData }: Props) {
|
|
|
|
const environmentId = useEnvironmentId();
|
|
|
|
|
|
|
|
const mutation = useMutation(() => deleteJobs(environmentId, selectedItems));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LoadingButton
|
|
|
|
loadingText="Removing..."
|
|
|
|
isLoading={mutation.isLoading}
|
|
|
|
disabled={selectedItems.length < 1 || mutation.isLoading}
|
|
|
|
color="danger"
|
|
|
|
onClick={handleDeleteClicked}
|
2022-11-28 02:00:28 +00:00
|
|
|
icon={Trash2}
|
2022-11-13 10:29:25 +00:00
|
|
|
>
|
|
|
|
Remove
|
|
|
|
</LoadingButton>
|
|
|
|
);
|
|
|
|
|
|
|
|
async function handleDeleteClicked() {
|
2023-02-14 08:19:41 +00:00
|
|
|
const confirmed = await confirmDelete(
|
2022-11-13 10:29:25 +00:00
|
|
|
'Are you sure to delete all selected jobs?'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!confirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutation.mutate(undefined, {
|
|
|
|
onSuccess() {
|
|
|
|
return refreshData();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|