2022-06-20 15:28:27 -04:00
|
|
|
import { Dialog } from '@/components/elements/dialog';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { DeleteAction } from '@/components/elements/table/RowActions';
|
|
|
|
|
import { useCurrentServerUuid } from '@/api/server/queries';
|
|
|
|
|
import {
|
|
|
|
|
deleteServerAllocationInput,
|
|
|
|
|
type ServerAllocation,
|
|
|
|
|
useDeleteServerAllocation,
|
|
|
|
|
} from '@/api/server/network/queries';
|
|
|
|
|
import { ip } from '@/lib/formatters';
|
2020-10-31 21:22:44 -07:00
|
|
|
|
|
|
|
|
interface Props {
|
2026-10-05 18:10:18 -04:00
|
|
|
allocation: ServerAllocation;
|
2020-10-31 21:22:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DeleteAllocationButton = ({ allocation }: Props) => {
|
2026-10-05 18:10:18 -04:00
|
|
|
const uuid = useCurrentServerUuid()!;
|
|
|
|
|
const deleteAllocationMutation = useDeleteServerAllocation();
|
|
|
|
|
const { attributes } = allocation;
|
|
|
|
|
const address = `${attributes.ip_alias || ip(attributes.ip)}:${attributes.port}`;
|
2020-11-08 17:12:07 -08:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const deleteAllocation = (close: () => void) => {
|
|
|
|
|
deleteAllocationMutation.mutate(deleteServerAllocationInput(uuid, attributes.id), { onSuccess: close });
|
2020-10-31 21:22:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-10-05 18:10:18 -04:00
|
|
|
<Dialog.ConfirmTrigger
|
|
|
|
|
title={'Remove Allocation'}
|
|
|
|
|
confirm={'Delete'}
|
|
|
|
|
pending={deleteAllocationMutation.isPending}
|
|
|
|
|
onConfirmed={(_event, close) => deleteAllocation(close)}
|
|
|
|
|
trigger={({ onClick }) => <DeleteAction aria-label={`Delete allocation ${address}`} onClick={onClick} />}
|
|
|
|
|
>
|
|
|
|
|
This allocation will be immediately removed from your server.
|
|
|
|
|
</Dialog.ConfirmTrigger>
|
2020-10-31 21:22:44 -07:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DeleteAllocationButton;
|