forked from Alex/Pterodactyl-Panel
admin(ui): add ability to delete mounts
This commit is contained in:
parent
0c7e787d44
commit
ef9bdf5cd5
@ -1,5 +1,3 @@
|
||||
import DatabaseDeleteButton from '@/components/admin/databases/DatabaseDeleteButton';
|
||||
import LocationDeleteButton from '@/components/admin/locations/LocationDeleteButton';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import tw from 'twin.macro';
|
||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
@ -17,6 +15,7 @@ import Field from '@/components/elements/Field';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import updateLocation from '@/api/admin/locations/updateLocation';
|
||||
import LocationDeleteButton from '@/components/admin/locations/LocationDeleteButton';
|
||||
|
||||
interface ctx {
|
||||
location: Location | undefined;
|
||||
|
@ -0,0 +1,58 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Actions, useStoreActions } from 'easy-peasy';
|
||||
import { ApplicationStore } from '@/state';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import ConfirmationModal from '@/components/elements/ConfirmationModal';
|
||||
import deleteMount from '@/api/admin/mounts/deleteMount';
|
||||
|
||||
interface Props {
|
||||
mountId: number;
|
||||
onDeleted: () => void;
|
||||
}
|
||||
|
||||
export default ({ mountId, onDeleted }: Props) => {
|
||||
const [ visible, setVisible ] = useState(false);
|
||||
const [ loading, setLoading ] = useState(false);
|
||||
|
||||
const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
const onDelete = () => {
|
||||
setLoading(true);
|
||||
clearFlashes('mount');
|
||||
|
||||
deleteMount(mountId)
|
||||
.then(() => {
|
||||
setLoading(false);
|
||||
onDeleted();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
clearAndAddHttpError({ key: 'mount', error });
|
||||
|
||||
setLoading(false);
|
||||
setVisible(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ConfirmationModal
|
||||
visible={visible}
|
||||
title={'Delete mount?'}
|
||||
buttonText={'Yes, delete mount'}
|
||||
onConfirmed={onDelete}
|
||||
showSpinnerOverlay={loading}
|
||||
onModalDismissed={() => setVisible(false)}
|
||||
>
|
||||
Are you sure you want to delete this mount? Deleting a mount will not delete files on any nodes.
|
||||
</ConfirmationModal>
|
||||
|
||||
<Button type={'button'} size={'xsmall'} color={'red'} onClick={() => setVisible(true)}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" css={tw`h-5 w-5`}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import tw from 'twin.macro';
|
||||
import { useRouteMatch } from 'react-router-dom';
|
||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy';
|
||||
import { Mount } from '@/api/admin/mounts/getMounts';
|
||||
import getMount from '@/api/admin/mounts/getMount';
|
||||
@ -15,6 +15,7 @@ import Button from '@/components/elements/Button';
|
||||
import Field from '@/components/elements/Field';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import MountDeleteButton from '@/components/admin/mounts/MountDeleteButton';
|
||||
|
||||
interface ctx {
|
||||
mount: Mount | undefined;
|
||||
@ -39,7 +40,10 @@ interface Values {
|
||||
}
|
||||
|
||||
const EditInformationContainer = () => {
|
||||
const history = useHistory();
|
||||
|
||||
const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
const mount = Context.useStoreState(state => state.mount);
|
||||
const setMount = Context.useStoreActions(actions => actions.setMount);
|
||||
|
||||
@ -124,10 +128,19 @@ const EditInformationContainer = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div css={tw`mt-6 text-right`}>
|
||||
<Button type={'submit'} disabled={isSubmitting || !isValid}>
|
||||
Save
|
||||
</Button>
|
||||
<div css={tw`w-full flex flex-row items-center mt-6`}>
|
||||
<div css={tw`flex`}>
|
||||
<MountDeleteButton
|
||||
mountId={mount.id}
|
||||
onDeleted={() => history.push('/admin/mounts')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div css={tw`flex ml-auto`}>
|
||||
<Button type={'submit'} disabled={isSubmitting || !isValid}>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</AdminBox>
|
||||
|
@ -1,5 +1,3 @@
|
||||
import LocationDeleteButton from '@/components/admin/locations/LocationDeleteButton';
|
||||
import NestDeleteButton from '@/components/admin/nests/NestDeleteButton';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { NavLink, useHistory, useRouteMatch } from 'react-router-dom';
|
||||
import tw from 'twin.macro';
|
||||
@ -22,6 +20,7 @@ import AdminTable, { ContentWrapper, NoItems, TableBody, TableHead, TableHeader,
|
||||
import CopyOnClick from '@/components/elements/CopyOnClick';
|
||||
import Input from '@/components/elements/Input';
|
||||
import Label from '@/components/elements/Label';
|
||||
import NestDeleteButton from '@/components/admin/nests/NestDeleteButton';
|
||||
|
||||
interface ctx {
|
||||
nest: Nest | undefined;
|
||||
|
Loading…
Reference in New Issue
Block a user