diff --git a/resources/scripts/api/server/network/newServerAllocation.ts b/resources/scripts/api/server/network/createServerAllocation.ts similarity index 100% rename from resources/scripts/api/server/network/newServerAllocation.ts rename to resources/scripts/api/server/network/createServerAllocation.ts diff --git a/resources/scripts/components/server/network/NetworkContainer.tsx b/resources/scripts/components/server/network/NetworkContainer.tsx index d28e10c60..cd789657d 100644 --- a/resources/scripts/components/server/network/NetworkContainer.tsx +++ b/resources/scripts/components/server/network/NetworkContainer.tsx @@ -10,15 +10,16 @@ import { useDeepMemoize } from '@/plugins/useDeepMemoize'; import AllocationRow from '@/components/server/network/AllocationRow'; import setPrimaryServerAllocation from '@/api/server/network/setPrimaryServerAllocation'; import Button from '@/components/elements/Button'; -import newServerAllocation from '@/api/server/network/newServerAllocation'; +import createServerAllocation from '@/api/server/network/createServerAllocation'; import tw from 'twin.macro'; -import GreyRowBox from '@/components/elements/GreyRowBox'; +import Can from '@/components/elements/Can'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; const NetworkContainer = () => { + const [ loading, setLoading ] = useState(false); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations); const allocations = useDeepMemoize(ServerContext.useStoreState(state => state.server.data!.allocations)); - const [ addingAllocation, setAddingAllocation ] = useState(false); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { data, error, mutate } = useSWR(uuid, key => getServerAllocations(key), { @@ -32,7 +33,7 @@ const NetworkContainer = () => { } }, [ error ]); - const setPrimaryAllocation = useCallback((id: number) => { + const setPrimaryAllocation = (id: number) => { clearFlashes('server:network'); const initial = data; @@ -43,24 +44,16 @@ const NetworkContainer = () => { clearAndAddHttpError({ key: 'server:network', error }); mutate(initial, false); }); - }, []); + }; - const getNewAllocation = () => { + const onCreateAllocation = () => { clearFlashes('server:network'); - setAddingAllocation(true); - const initial = data; - - newServerAllocation(uuid) - .then(allocation => { - mutate(data?.concat(allocation), false); - setAddingAllocation(false); - }) - .catch(error => { - clearAndAddHttpError({ key: 'server:network', error }); - mutate(initial, false); - setAddingAllocation(false); - }); + setLoading(true); + createServerAllocation(uuid) + .then(allocation => mutate(data?.concat(allocation), false)) + .catch(error => clearAndAddHttpError({ key: 'server:network', error })) + .then(() => setLoading(false)); }; const onNotesAdded = useCallback((id: number, notes: string) => { @@ -72,37 +65,32 @@ const NetworkContainer = () => { {!data ? : - data.map(allocation => ( - - )) - } - {allocationLimit > data!.length ? - - {addingAllocation ? - - : - + <> + { + data.map(allocation => ( + + )) } - - : -

- You have reached the max number of allocations allowed for your server. -

+ + +
+

+ You are currently using {data.length} of {allocationLimit} allowed allocations for this + server. +

+ {allocationLimit > data.length && + + } +
+
+ } );