From ef9bdf5cd55f5c834ceaa4b6c60b8548c7a515a2 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 9 Jan 2021 10:42:13 -0700 Subject: [PATCH] admin(ui): add ability to delete mounts --- .../admin/locations/LocationEditContainer.tsx | 3 +- .../admin/mounts/MountDeleteButton.tsx | 58 +++++++++++++++++++ .../admin/mounts/MountEditContainer.tsx | 23 ++++++-- .../admin/nests/NestEditContainer.tsx | 3 +- 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 resources/scripts/components/admin/mounts/MountDeleteButton.tsx diff --git a/resources/scripts/components/admin/locations/LocationEditContainer.tsx b/resources/scripts/components/admin/locations/LocationEditContainer.tsx index 83e3d53b3..c41def2e8 100644 --- a/resources/scripts/components/admin/locations/LocationEditContainer.tsx +++ b/resources/scripts/components/admin/locations/LocationEditContainer.tsx @@ -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; diff --git a/resources/scripts/components/admin/mounts/MountDeleteButton.tsx b/resources/scripts/components/admin/mounts/MountDeleteButton.tsx new file mode 100644 index 000000000..bd0699fbe --- /dev/null +++ b/resources/scripts/components/admin/mounts/MountDeleteButton.tsx @@ -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) => 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 ( + <> + setVisible(false)} + > + Are you sure you want to delete this mount? Deleting a mount will not delete files on any nodes. + + + + + ); +}; diff --git a/resources/scripts/components/admin/mounts/MountEditContainer.tsx b/resources/scripts/components/admin/mounts/MountEditContainer.tsx index 6004f3a55..d0b3ad1d1 100644 --- a/resources/scripts/components/admin/mounts/MountEditContainer.tsx +++ b/resources/scripts/components/admin/mounts/MountEditContainer.tsx @@ -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) => actions.flashes); + const mount = Context.useStoreState(state => state.mount); const setMount = Context.useStoreActions(actions => actions.setMount); @@ -124,10 +128,19 @@ const EditInformationContainer = () => { /> -
- +
+
+ history.push('/admin/mounts')} + /> +
+ +
+ +
diff --git a/resources/scripts/components/admin/nests/NestEditContainer.tsx b/resources/scripts/components/admin/nests/NestEditContainer.tsx index 30b46268f..4802fed45 100644 --- a/resources/scripts/components/admin/nests/NestEditContainer.tsx +++ b/resources/scripts/components/admin/nests/NestEditContainer.tsx @@ -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;